Skip to content

Commit dbe30bf

Browse files
committed
use rulesets in the rust repo
1 parent d134d4c commit dbe30bf

File tree

3 files changed

+53
-5
lines changed

3 files changed

+53
-5
lines changed

config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,5 @@ enable-rulesets-repos = [
8787
"rust-lang/cargo",
8888
"rust-lang/crates.io",
8989
"rust-lang/rustfmt",
90+
"rust-lang/rust",
9091
]

repos/rust-lang/rust.toml

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,64 +27,102 @@ style = "write"
2727
types = "write"
2828
triage = "write"
2929

30+
# Only `bors` can push to `main`
3031
[[branch-protections]]
32+
name = "main"
3133
pattern = "main"
3234
allowed-merge-apps = ["bors"]
35+
prevent-update = true
3336

37+
# No one can force push to main
3438
[[branch-protections]]
39+
name = "main - force-push"
40+
pattern = "main"
41+
42+
# Only `bors` and `promote-release` can push to `stable`
43+
[[branch-protections]]
44+
name = "stable"
3545
pattern = "stable"
36-
allowed-merge-apps = ["bors"]
46+
allowed-merge-apps = ["bors", "promote-release"]
47+
prevent-update = true
3748

49+
# Only `promote-release` can force-push to `stable`
3850
[[branch-protections]]
51+
name = "stable - force-push"
52+
pattern = "stable"
53+
allowed-merge-apps = ["promote-release"]
54+
55+
# Only `bors` and `promote-release` can push to `beta`
56+
[[branch-protections]]
57+
name = "beta"
3958
pattern = "beta"
40-
allowed-merge-apps = ["bors"]
59+
allowed-merge-apps = ["bors", "promote-release"]
60+
prevent-update = true
61+
62+
# Only `promote-release` can force-push to `beta`
63+
[[branch-protections]]
64+
name = "beta - force-push"
65+
pattern = "beta"
66+
allowed-merge-apps = ["promote-release"]
4167

4268
[[branch-protections]]
4369
pattern = "*"
70+
allowed-merge-apps = ["promote-release"]
71+
prevent-deletion = false
72+
prevent-update = true
4473

4574
[[branch-protections]]
4675
pattern = "*/**/*"
4776
pr-required = false
77+
prevent-update = true
78+
prevent-deletion = false
4879

4980
[[branch-protections]]
5081
pattern = "cargo_update"
5182
pr-required = false
83+
prevent-deletion = false
5284

5385
# Required for running try builds created by bors.
5486
# Must support force-pushes.
5587
[[branch-protections]]
5688
pattern = "automation/bors/try"
5789
allowed-merge-apps = ["bors"]
90+
prevent-update = true
5891

5992
# Required for running try builds created by bors.
6093
# Must support force-pushes.
6194
[[branch-protections]]
6295
pattern = "automation/bors/try-merge"
6396
allowed-merge-apps = ["bors"]
97+
prevent-update = true
6498

6599
# Required for running auto builds created by bors.
66100
# Must support force-pushes.
67101
[[branch-protections]]
68102
pattern = "automation/bors/auto"
69103
allowed-merge-apps = ["bors"]
104+
prevent-update = true
70105

71106
# Required for running auto builds created by bors.
72107
# Must support force-pushes.
73108
[[branch-protections]]
74109
pattern = "automation/bors/auto-merge"
75110
allowed-merge-apps = ["bors"]
111+
prevent-update = true
76112

77113
# Required for unrolled PR builds created by perfbot.
78114
# Must support force-pushes.
79115
[[branch-protections]]
80116
pattern = "try-perf"
81117
allowed-merge-apps = ["rust-timer"]
118+
prevent-update = true
82119

83120
# Required for unrolled PR builds created by perfbot.
84121
# Must support force-pushes.
85122
[[branch-protections]]
86123
pattern = "perf-tmp"
87124
allowed-merge-apps = ["rust-timer"]
125+
prevent-update = true
88126

89127
[environments.bors]
90128
branches = ["automation/bors/auto", "automation/bors/try", "try-perf"]

src/validate.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,12 +1150,21 @@ fn validate_branch_protections(data: &Data, errors: &mut Vec<String>) {
11501150

11511151
wrapper(data.repos(), errors, |repo, _| {
11521152
let bors_configured = repo.bots.iter().any(|b| matches!(b, Bot::Bors));
1153-
let mut patterns = HashSet::new();
1153+
let mut pattern_counts = HashMap::new();
11541154

11551155
for protection in &repo.branch_protections {
1156-
if !patterns.insert((protection.target, &protection.pattern)) {
1156+
*pattern_counts
1157+
.entry((protection.target, protection.pattern.as_str()))
1158+
.or_insert(0usize) += 1;
1159+
}
1160+
1161+
for protection in &repo.branch_protections {
1162+
let key = (protection.target, protection.pattern.as_str());
1163+
if pattern_counts.get(&key).copied().unwrap_or_default() > 1
1164+
&& protection.name.is_none()
1165+
{
11571166
bail!(
1158-
r#"repo '{}' uses multiple {:?} protections with the pattern `{}`"#,
1167+
r#"repo '{}' uses multiple {:?} protections with the pattern `{}`; when multiple protections share the same target and pattern, each protection must specify `name`"#,
11591168
repo.name,
11601169
protection.target,
11611170
protection.pattern,

0 commit comments

Comments
 (0)