|
1 | 1 | use crate::data::Data;
|
2 | 2 | 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}; |
4 | 4 | use crate::zulip::ZulipApi;
|
5 | 5 | use anyhow::{bail, Error};
|
6 | 6 | use log::{error, warn};
|
@@ -44,6 +44,7 @@ static CHECKS: &[Check<fn(&Data, &mut Vec<String>)>] = checks![
|
44 | 44 | validate_zulip_group_ids,
|
45 | 45 | validate_zulip_group_extra_people,
|
46 | 46 | validate_repos,
|
| 47 | + validate_branch_protections, |
47 | 48 | ];
|
48 | 49 |
|
49 | 50 | #[allow(clippy::type_complexity)]
|
@@ -774,6 +775,24 @@ fn validate_repos(data: &Data, errors: &mut Vec<String>) {
|
774 | 775 | });
|
775 | 776 | }
|
776 | 777 |
|
| 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 | + |
777 | 796 | fn wrapper<T, I, F>(iter: I, errors: &mut Vec<String>, mut func: F)
|
778 | 797 | where
|
779 | 798 | I: Iterator<Item = T>,
|
|
0 commit comments