Skip to content

Commit 5823058

Browse files
committed
tidy: add check to verify paths in triagebot.toml
1 parent 96cfc75 commit 5823058

File tree

5 files changed

+59
-0
lines changed

5 files changed

+59
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5257,6 +5257,7 @@ dependencies = [
52575257
"serde",
52585258
"similar",
52595259
"termcolor",
5260+
"toml 0.7.8",
52605261
"walkdir",
52615262
]
52625263

src/tools/tidy/Cargo.toml

Lines changed: 1 addition & 0 deletions
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"]

src/tools/tidy/src/lib.rs

Lines changed: 1 addition & 0 deletions
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;

src/tools/tidy/src/main.rs

Lines changed: 2 additions & 0 deletions
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

src/tools/tidy/src/triagebot.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
}
33+
34+
// Check [assign.owners] sections, i.e.
35+
// [assign.owners]
36+
// "/.github/workflows" = ["infra-ci"]
37+
if let Some(Value::Table(assign)) = config.get("assign") {
38+
if let Some(Value::Table(owners)) = assign.get("owners") {
39+
for path_str in owners.keys() {
40+
// Remove quotes and leading slash from the path
41+
let clean_path = path_str.trim_matches('"').trim_start_matches('/');
42+
let full_path = path.join(clean_path);
43+
44+
if !full_path.exists() {
45+
tidy_error!(
46+
bad,
47+
"triagebot.toml [assign.owners] contains path '{}' which doesn't exist",
48+
clean_path
49+
);
50+
}
51+
}
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)