Skip to content

Commit 8edf528

Browse files
committed
tidy: add check to verify paths in triagebot.toml
1 parent 81d8edc commit 8edf528

File tree

5 files changed

+98
-0
lines changed

5 files changed

+98
-0
lines changed

Diff for: Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -5260,6 +5260,7 @@ dependencies = [
52605260
"serde",
52615261
"similar",
52625262
"termcolor",
5263+
"toml 0.7.8",
52635264
"walkdir",
52645265
]
52655266

Diff for: src/tools/tidy/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ termcolor = "1.1.3"
1717
rustc-hash = "2.0.0"
1818
fluent-syntax = "0.11.1"
1919
similar = "2.5.0"
20+
toml = "0.7.8"
2021

2122
[features]
2223
build-metrics = ["dep:serde"]

Diff for: src/tools/tidy/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ pub mod target_policy;
8888
pub mod target_specific_tests;
8989
pub mod tests_placement;
9090
pub mod tests_revision_unpaired_stdout_stderr;
91+
pub mod triagebot;
9192
pub mod ui_tests;
9293
pub mod unit_tests;
9394
pub mod unknown_revision;

Diff for: src/tools/tidy/src/main.rs

+2
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ fn main() {
146146

147147
check!(x_version, &root_path, &cargo);
148148

149+
check!(triagebot, &root_path);
150+
149151
let collected = {
150152
drain_handles(&mut handles);
151153

Diff for: src/tools/tidy/src/triagebot.rs

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
//! Tidy check to ensure paths mentioned in triagebot.toml exist in the project.
2+
3+
use std::path::Path;
4+
5+
use toml::Value;
6+
7+
pub fn check(path: &Path, bad: &mut bool) {
8+
let triagebot_path = path.join("triagebot.toml");
9+
if !triagebot_path.exists() {
10+
tidy_error!(bad, "triagebot.toml file not found");
11+
return;
12+
}
13+
14+
let contents = std::fs::read_to_string(&triagebot_path).unwrap();
15+
let config: Value = toml::from_str(&contents).unwrap();
16+
17+
// Check [mentions."*"] sections, i.e. [mentions."compiler/rustc_const_eval/src/"]
18+
if let Some(Value::Table(mentions)) = config.get("mentions") {
19+
for path_str in mentions.keys() {
20+
// Remove quotes from the path
21+
let clean_path = path_str.trim_matches('"');
22+
let full_path = path.join(clean_path);
23+
24+
if !full_path.exists() {
25+
tidy_error!(
26+
bad,
27+
"triagebot.toml [mentions.*] contains path '{}' which doesn't exist",
28+
clean_path
29+
);
30+
}
31+
}
32+
} else {
33+
tidy_error!(
34+
bad,
35+
"triagebot.toml missing [mentions.*] section, this wrong for rust-lang/rust repo."
36+
);
37+
}
38+
39+
// Check [assign.owners] sections, i.e.
40+
// [assign.owners]
41+
// "/.github/workflows" = ["infra-ci"]
42+
if let Some(Value::Table(assign)) = config.get("assign") {
43+
if let Some(Value::Table(owners)) = assign.get("owners") {
44+
for path_str in owners.keys() {
45+
// Remove quotes and leading slash from the path
46+
let clean_path = path_str.trim_matches('"').trim_start_matches('/');
47+
let full_path = path.join(clean_path);
48+
49+
if !full_path.exists() {
50+
tidy_error!(
51+
bad,
52+
"triagebot.toml [assign.owners] contains path '{}' which doesn't exist",
53+
clean_path
54+
);
55+
}
56+
}
57+
} else {
58+
tidy_error!(
59+
bad,
60+
"triagebot.toml missing [assign.owners] section, this wrong for rust-lang/rust repo."
61+
);
62+
}
63+
}
64+
65+
// Verify that trigger_files in [autolabel."*"] exist in the project, i.e.
66+
// [autolabel."A-rustdoc-search"]
67+
// trigger_files = [
68+
// "src/librustdoc/html/static/js/search.js",
69+
// "tests/rustdoc-js",
70+
// "tests/rustdoc-js-std",
71+
// ]
72+
if let Some(Value::Table(autolabels)) = config.get("autolabel") {
73+
for (label, content) in autolabels {
74+
if let Some(trigger_files) = content.get("trigger_files").and_then(|v| v.as_array()) {
75+
for file in trigger_files {
76+
if let Some(file_str) = file.as_str() {
77+
let full_path = path.join(file_str);
78+
79+
// Handle both file and directory paths
80+
if !full_path.exists() {
81+
tidy_error!(
82+
bad,
83+
"triagebot.toml [autolabel.{}] contains trigger_files path '{}' which doesn't exist",
84+
label,
85+
file_str
86+
);
87+
}
88+
}
89+
}
90+
}
91+
}
92+
}
93+
}

0 commit comments

Comments
 (0)