Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix allow_auto_merge in combination with repository archiving #74

Merged
merged 2 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/github/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ pub(crate) struct Repo {
pub(crate) description: Option<String>,
pub(crate) homepage: Option<String>,
pub(crate) archived: bool,
pub(crate) allow_auto_merge: bool,
#[serde(default)]
pub(crate) allow_auto_merge: Option<bool>,
}

fn repo_owner<'de, D>(deserializer: D) -> Result<String, D::Error>
Expand Down
2 changes: 1 addition & 1 deletion src/github/api/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl GitHubWrite {
description: settings.description.clone(),
homepage: settings.homepage.clone(),
archived: false,
allow_auto_merge: settings.auto_merge_enabled,
allow_auto_merge: Some(settings.auto_merge_enabled),
})
} else {
Ok(self
Expand Down
20 changes: 19 additions & 1 deletion src/github/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ impl SyncGitHub {
description: actual_repo.description.clone(),
homepage: actual_repo.homepage.clone(),
archived: actual_repo.archived,
auto_merge_enabled: actual_repo.allow_auto_merge,
auto_merge_enabled: actual_repo.allow_auto_merge.unwrap_or(false),
};
let new_settings = RepoSettings {
description: Some(expected_repo.description.clone()),
Expand Down Expand Up @@ -629,12 +629,30 @@ struct UpdateRepoDiff {

impl UpdateRepoDiff {
pub(crate) fn noop(&self) -> bool {
if !self.can_be_modified() {
return true;
}

self.settings_diff.0 == self.settings_diff.1
&& self.permission_diffs.is_empty()
&& self.branch_protection_diffs.is_empty()
}

fn can_be_modified(&self) -> bool {
// Archived repositories cannot be modified
// If the repository should be archived, and we do not change its archival status,
// we should not change any other properties of the repo.
if self.settings_diff.1.archived && self.settings_diff.0.archived {
return false;
}
true
}

fn apply(&self, sync: &GitHubWrite) -> anyhow::Result<()> {
if !self.can_be_modified() {
return Ok(());
}

if self.settings_diff.0 != self.settings_diff.1 {
sync.edit_repo(&self.org, &self.name, &self.settings_diff.1)?;
}
Expand Down
Loading