|
1 | 1 | use crate::data::Data; |
2 | 2 | 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 | +}; |
4 | 6 | use crate::zulip::ZulipApi; |
5 | 7 | use anyhow::{bail, Error}; |
6 | 8 | use log::{error, warn}; |
@@ -824,7 +826,8 @@ fn validate_branch_protections(data: &Data, errors: &mut Vec<String>) { |
824 | 826 | let github_teams = data.github_teams(); |
825 | 827 |
|
826 | 828 | 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 | + |
828 | 831 | for protection in &repo.branch_protections { |
829 | 832 | for team in &protection.allowed_merge_teams { |
830 | 833 | let key = (repo.org.clone(), team.clone()); |
@@ -858,19 +861,24 @@ but that team does not seem to exist"#, |
858 | 861 | } |
859 | 862 | } |
860 | 863 |
|
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 { |
863 | 867 | 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"#, |
866 | 869 | repo.name, |
867 | 870 | protection.pattern, |
868 | 871 | ); |
869 | 872 | } |
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 | + { |
871 | 878 | 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"#, |
874 | 882 | repo.name, |
875 | 883 | protection.pattern, |
876 | 884 | ); |
|
0 commit comments