Skip to content

Commit feb2129

Browse files
committed
refactor: delete branch protection if ruleset enabled
1 parent 2b33998 commit feb2129

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

sync-team/src/github/mod.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@ impl SyncGitHub {
360360

361361
// Additionally create rulesets if configured
362362
let mut rulesets = Vec::new();
363-
if self.should_use_rulesets(expected_repo) {
363+
let use_rulesets = self.should_use_rulesets(expected_repo);
364+
if use_rulesets {
364365
for branch_protection in &expected_repo.branch_protections {
365366
let ruleset = construct_ruleset(expected_repo, branch_protection);
366367
rulesets.push(ruleset);
@@ -377,7 +378,12 @@ impl SyncGitHub {
377378
auto_merge_enabled: expected_repo.auto_merge_enabled,
378379
},
379380
permissions,
380-
branch_protections,
381+
// Don't create branch protections if using rulesets
382+
branch_protections: if use_rulesets {
383+
vec![]
384+
} else {
385+
branch_protections
386+
},
381387
rulesets,
382388
environments: expected_repo
383389
.environments
@@ -460,6 +466,18 @@ impl SyncGitHub {
460466
let mut actual_protections = self
461467
.github
462468
.branch_protections(&actual_repo.org, &actual_repo.name)?;
469+
470+
// If rulesets are enabled, delete all existing branch protections
471+
// to avoid conflicts between branch protections and rulesets
472+
if self.should_use_rulesets(expected_repo) {
473+
return Ok(actual_protections
474+
.into_iter()
475+
.map(|(name, (id, _))| BranchProtectionDiff {
476+
pattern: name,
477+
operation: BranchProtectionDiffOperation::Delete(id),
478+
})
479+
.collect());
480+
}
463481
for branch_protection in &expected_repo.branch_protections {
464482
let actual_branch_protection = actual_protections.remove(&branch_protection.pattern);
465483
let mut expected_branch_protection =

0 commit comments

Comments
 (0)