Skip to content

Commit e7fc7c7

Browse files
authored
Merge pull request #1751 from Kobzol/homu-branch-protection
Do not require PRs for branches managed by homu
2 parents d23607e + d13d4c6 commit e7fc7c7

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

sync-team/src/github/mod.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -513,17 +513,21 @@ pub fn construct_branch_protection(
513513
branch_protection: &rust_team_data::v1::BranchProtection,
514514
) -> api::BranchProtection {
515515
let uses_homu = branch_protection.merge_bots.contains(&MergeBot::Homu);
516-
let required_approving_review_count: u8 = if uses_homu {
517-
0
516+
// When homu manages a branch, we should not require a PR nor approvals
517+
// for that branch, because homu pushes to these branches directly.
518+
let branch_protection_mode = if uses_homu {
519+
BranchProtectionMode::PrNotRequired
518520
} else {
519-
match branch_protection.mode {
520-
BranchProtectionMode::PrRequired {
521-
required_approvals, ..
522-
} => required_approvals
523-
.try_into()
524-
.expect("Too large required approval count"),
525-
BranchProtectionMode::PrNotRequired => 0,
526-
}
521+
branch_protection.mode.clone()
522+
};
523+
524+
let required_approving_review_count: u8 = match branch_protection_mode {
525+
BranchProtectionMode::PrRequired {
526+
required_approvals, ..
527+
} => required_approvals
528+
.try_into()
529+
.expect("Too large required approval count"),
530+
BranchProtectionMode::PrNotRequired => 0,
527531
};
528532
let mut push_allowances: Vec<PushAllowanceActor> = branch_protection
529533
.allowed_merge_teams
@@ -544,7 +548,7 @@ pub fn construct_branch_protection(
544548
}));
545549
}
546550

547-
let mut checks = match &branch_protection.mode {
551+
let mut checks = match &branch_protection_mode {
548552
BranchProtectionMode::PrRequired { ci_checks, .. } => ci_checks.clone(),
549553
BranchProtectionMode::PrNotRequired => {
550554
vec![]
@@ -561,7 +565,7 @@ pub fn construct_branch_protection(
561565
required_status_check_contexts: checks,
562566
push_allowances,
563567
requires_approving_reviews: matches!(
564-
branch_protection.mode,
568+
branch_protection_mode,
565569
BranchProtectionMode::PrRequired { .. }
566570
),
567571
}

0 commit comments

Comments
 (0)