From fb55bfc0f1e866ec99016a0276a6bbe169561add Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Mon, 31 Mar 2025 17:45:14 +0200 Subject: [PATCH] Change repository sync order to handle archiving --- sync-team/src/github/mod.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sync-team/src/github/mod.rs b/sync-team/src/github/mod.rs index 7197e074b..b4e0c9e23 100644 --- a/sync-team/src/github/mod.rs +++ b/sync-team/src/github/mod.rs @@ -732,9 +732,16 @@ impl UpdateRepoDiff { return Ok(()); } - if self.settings_diff.0 != self.settings_diff.1 { + // If we're unarchiving, we have to unarchive first and *then* modify other properties + // of the repository. On the other hand, if we're achiving, we need to perform + // the archiving *last* (otherwise permissions and branch protections cannot be modified) + // anymore. If we're not changing the archival status, the order doesn't really matter. + let is_unarchive = self.settings_diff.0.archived && !self.settings_diff.1.archived; + + if is_unarchive { sync.edit_repo(&self.org, &self.name, &self.settings_diff.1)?; } + for permission in &self.permission_diffs { permission.apply(sync, &self.org, &self.name)?; } @@ -743,6 +750,10 @@ impl UpdateRepoDiff { branch_protection.apply(sync, &self.org, &self.name, &self.repo_node_id)?; } + if !is_unarchive && self.settings_diff.0 != self.settings_diff.1 { + sync.edit_repo(&self.org, &self.name, &self.settings_diff.1)?; + } + Ok(()) } }