ephemeris_forge_github/reconcile/
autolinks.rs1use ephemeris_forge::{Mode, RepoRef};
2
3use super::Client;
4use crate::api::request::AutolinkBody;
5use crate::api::{Api, ForgeError};
6use crate::operation::autolinks::Operation;
7use crate::{Autolinks, Live};
8
9impl<A: Api> Client<A> {
10 pub(super) async fn read_autolinks(
11 &self,
12 repository: &RepoRef,
13 config: Option<&Autolinks>,
14 live: &mut Live,
15 ) -> Result<(), ForgeError> {
16 let Some(config) = config else {
17 return Ok(());
18 };
19 if config.mode != Mode::Owned && config.autolinks.is_empty() {
20 return Ok(());
21 }
22 live.autolinks = self.api.autolinks(repository).await?;
23 Ok(())
24 }
25
26 pub(super) async fn apply_autolinks(
27 &self,
28 repository: &RepoRef,
29 operation: &Operation,
30 ) -> Result<(), ForgeError> {
31 match operation {
32 Operation::Create {
33 key_prefix,
34 autolink,
35 } => {
36 let body = AutolinkBody {
37 key_prefix: key_prefix.clone(),
38 url_template: autolink.url_template.clone(),
39 is_alphanumeric: autolink.is_alphanumeric,
40 };
41 self.api.create_autolink(repository, &body).await
42 }
43 Operation::Delete { key_prefix: _, id } => {
44 self.api.delete_autolink(repository, *id).await
45 }
46 }
47 }
48}