Skip to content

Commit 61ab7b6

Browse files
committed
Add merge-bots configuration per branch protection
Instead of just assuming that when bors (homu) is enabled for a repository, all its repositories will be automatically managed by it, this PR adds an opt-in mechanism to use bors/homu for specific branch protections.
1 parent 6cd7af5 commit 61ab7b6

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

docs/toml-schema.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,4 +352,12 @@ required-approvals = 1
352352
# can push/merge to the branch.
353353
# (optional)
354354
allowed-merge-teams = ["awesome-team"]
355+
# Determines the merge queue bot(s) that manage pushes to this branch.
356+
# When a bot manages the queue, some other options, like
357+
# `required-approvals` and `pr-required` options are not valid.
358+
#
359+
# Currently, only the "homu" option is supported.
360+
# When "homu" is used, "bors" has to be in the `bots` array.
361+
# (optional)
362+
merge-bots = ["homu"]
355363
```

src/schema.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,12 @@ pub(crate) enum RepoPermission {
787787
Admin,
788788
}
789789

790+
#[derive(serde_derive::Deserialize, Debug, PartialEq, Eq)]
791+
#[serde(rename_all = "kebab-case")]
792+
pub(crate) enum MergeBot {
793+
Homu,
794+
}
795+
790796
#[derive(serde_derive::Deserialize, Debug)]
791797
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
792798
pub(crate) struct BranchProtection {
@@ -801,4 +807,6 @@ pub(crate) struct BranchProtection {
801807
pub pr_required: bool,
802808
#[serde(default)]
803809
pub allowed_merge_teams: Vec<String>,
810+
#[serde(default)]
811+
pub merge_bots: Vec<MergeBot>,
804812
}

src/validate.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::data::Data;
22
use crate::github::GitHubApi;
3-
use crate::schema::{Bot, Email, Permissions, Team, TeamKind, TeamPeople, ZulipGroupMember};
3+
use crate::schema::{
4+
Bot, Email, MergeBot, Permissions, Team, TeamKind, TeamPeople, ZulipGroupMember,
5+
};
46
use crate::zulip::ZulipApi;
57
use anyhow::{bail, Error};
68
use log::{error, warn};
@@ -824,7 +826,8 @@ fn validate_branch_protections(data: &Data, errors: &mut Vec<String>) {
824826
let github_teams = data.github_teams();
825827

826828
wrapper(data.repos(), errors, |repo, _| {
827-
let bors_used = repo.bots.iter().any(|b| matches!(b, Bot::Bors));
829+
let homu_configured = repo.bots.iter().any(|b| matches!(b, Bot::Bors));
830+
828831
for protection in &repo.branch_protections {
829832
for team in &protection.allowed_merge_teams {
830833
let key = (repo.org.clone(), team.clone());
@@ -858,19 +861,24 @@ but that team does not seem to exist"#,
858861
}
859862
}
860863

861-
if bors_used {
862-
if protection.required_approvals.is_some() {
864+
let managed_by_homu = protection.merge_bots.contains(&MergeBot::Homu);
865+
if managed_by_homu {
866+
if !homu_configured {
863867
bail!(
864-
r#"repo '{}' uses bors and its branch protection for {} uses the `required-approvals` attribute;
865-
please remove the attribute when using bors"#,
868+
r#"repo '{}' uses homu to manage a branch protection for '{}', but homu is not enabled. Add "bors" to the `bots` array"#,
866869
repo.name,
867870
protection.pattern,
868871
);
869872
}
870-
if !protection.allowed_merge_teams.is_empty() {
873+
if protection.required_approvals.is_some()
874+
|| protection.dismiss_stale_review
875+
|| !protection.pr_required
876+
|| !protection.allowed_merge_teams.is_empty()
877+
{
871878
bail!(
872-
r#"repo '{}' uses bors and its branch protection for {} uses the `allowed-merge-teams` attribute;
873-
please remove the attribute when using bors"#,
879+
r#"repo '{}' uses the homu merge bot, but its branch protection for {} uses invalid
880+
attributes (`required-approvals`, `dismiss-stale-review`, `pr-required` or `allowed-merge-teams`).
881+
Please remove the attributes when using bors"#,
874882
repo.name,
875883
protection.pattern,
876884
);

0 commit comments

Comments
 (0)