Skip to main content

ephemeris_forge_forgejo/
plan.rs

1//! The pure comparison between the desired and the live Forgejo state.
2
3mod access;
4mod actions_variables;
5pub(crate) mod branch_rules;
6mod deploy_keys;
7mod labels;
8mod repository;
9mod tag_protection;
10mod webhooks;
11
12use ephemeris_forge::Planned;
13
14use crate::operation::Operation;
15use crate::{Config, Live};
16
17pub(crate) fn plan(config: &Config, live: &Live) -> Planned<Operation> {
18    let mut planned = Planned::default();
19    planned.extend(|report| branch_rules::plan(config.branch_rules.as_ref(), live, report));
20    planned.extend(|report| access::plan(config.access.as_ref(), live, report));
21    planned.extend(|report| labels::plan(config.labels.as_ref(), live, report));
22    planned.extend(|report| tag_protection::plan(config.tag_protection.as_ref(), live, report));
23    planned.extend(|report| webhooks::plan(config.webhooks.as_ref(), live, report));
24    planned.extend(|report| deploy_keys::plan(config.deploy_keys.as_ref(), live, report));
25    planned
26        .extend(|report| actions_variables::plan(config.actions_variables.as_ref(), live, report));
27    planned.extend(|report| repository::plan(&config.repository, live, report));
28    let live_archived = live.repository.archived.unwrap_or(false);
29    planned.report.archived = live_archived
30        && (config.repository.archived != Some(true) || !planned.operations.is_empty());
31    planned.report.admin = live
32        .repository
33        .permissions
34        .and_then(|permissions| permissions.admin);
35    planned
36}