Skip to main content

ephemeris_forge_forgejo/reconcile/
repository.rs

1use ephemeris_forge::RepoRef;
2
3use super::Client;
4use crate::api::{Api, ForgeError};
5use crate::operation::repository::Operation;
6use crate::{Live, TopicName};
7
8impl<A: Api> Client<A> {
9    pub(super) async fn read_repository(
10        &self,
11        repository: &RepoRef,
12        live: &mut Live,
13    ) -> Result<(), ForgeError> {
14        live.repository = self.api.repository(repository).await?;
15        Ok(())
16    }
17
18    pub(super) async fn read_topics(
19        &self,
20        repository: &RepoRef,
21        topics: Option<&Vec<TopicName>>,
22        live: &mut Live,
23    ) -> Result<(), ForgeError> {
24        if topics.is_some() {
25            live.topics = self.api.topics(repository).await?;
26        }
27        Ok(())
28    }
29
30    pub(super) async fn apply_repository(
31        &self,
32        repository: &RepoRef,
33        operation: &Operation,
34    ) -> Result<(), ForgeError> {
35        let Operation { topics, edit } = operation;
36        // Topics have their own endpoint. Apply them before the
37        // repository PATCH so a simultaneous name change cannot make
38        // the topic request address the stale repository slug.
39        if let Some(topics) = topics {
40            self.api.replace_topics(repository, topics).await?;
41        }
42        if edit.is_empty() {
43            Ok(())
44        } else {
45            self.api.patch_repository(repository, edit).await
46        }
47    }
48}