Skip to main content

ephemeris_forge_github/reconcile/
labels.rs

1use ephemeris_forge::{Label, Labels, RepoRef};
2
3use super::Client;
4use crate::Live;
5use crate::api::{Api, ForgeError};
6use crate::operation::labels::Operation;
7
8impl<A: Api> Client<A> {
9    pub(super) async fn read_labels(
10        &self,
11        repository: &RepoRef,
12        config: Option<&Labels<Label>>,
13        live: &mut Live,
14    ) -> Result<(), ForgeError> {
15        if config.is_some() {
16            live.labels = self.api.labels(repository).await?;
17        }
18        Ok(())
19    }
20
21    pub(super) async fn apply_labels(
22        &self,
23        repository: &RepoRef,
24        operation: &Operation,
25    ) -> Result<(), ForgeError> {
26        match operation {
27            Operation::Create {
28                name,
29                color,
30                description,
31            } => {
32                self.api
33                    .create_label(repository, name, color, description)
34                    .await
35            }
36            Operation::Update {
37                name,
38                color,
39                description,
40            } => {
41                self.api
42                    .update_label(repository, name, color, description)
43                    .await
44            }
45            Operation::Delete { name } => self.api.delete_label(repository, name).await,
46        }
47    }
48}