Skip to content

Commit 3c2148c

Browse files
KobzolMark-Simulacrum
authored andcommitted
Add validation
1 parent 432b180 commit 3c2148c

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/validate.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::data::Data;
22
use crate::github::GitHubApi;
3-
use crate::schema::{Email, Permissions, Team, TeamKind, TeamPeople, ZulipGroupMember};
3+
use crate::schema::{Bot, Email, Permissions, Team, TeamKind, TeamPeople, ZulipGroupMember};
44
use crate::zulip::ZulipApi;
55
use anyhow::{bail, Error};
66
use log::{error, warn};
@@ -44,6 +44,7 @@ static CHECKS: &[Check<fn(&Data, &mut Vec<String>)>] = checks![
4444
validate_zulip_group_ids,
4545
validate_zulip_group_extra_people,
4646
validate_repos,
47+
validate_branch_protections,
4748
];
4849

4950
#[allow(clippy::type_complexity)]
@@ -774,6 +775,24 @@ fn validate_repos(data: &Data, errors: &mut Vec<String>) {
774775
});
775776
}
776777

778+
/// Validate that branch protections make sense in combination with used bots.
779+
fn validate_branch_protections(data: &Data, errors: &mut Vec<String>) {
780+
wrapper(data.repos(), errors, |repo, _| {
781+
let bors_used = repo.bots.iter().any(|b| matches!(b, Bot::Bors));
782+
for protection in &repo.branch_protections {
783+
if bors_used && protection.required_approvals.is_some() {
784+
bail!(
785+
r#"repo '{}' uses bors and its branch protection for {} uses the `required-approvals` attribute;
786+
please remove the attribute when using bors"#,
787+
repo.name,
788+
protection.pattern,
789+
);
790+
}
791+
}
792+
Ok(())
793+
})
794+
}
795+
777796
fn wrapper<T, I, F>(iter: I, errors: &mut Vec<String>, mut func: F)
778797
where
779798
I: Iterator<Item = T>,

0 commit comments

Comments
 (0)