tidy: add check to verify paths in triagebot.toml
This commit is contained in:
parent
81d8edc200
commit
8edf528eb4
5 changed files with 98 additions and 0 deletions
|
|
@ -5260,6 +5260,7 @@ dependencies = [
|
|||
"serde",
|
||||
"similar",
|
||||
"termcolor",
|
||||
"toml 0.7.8",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ termcolor = "1.1.3"
|
|||
rustc-hash = "2.0.0"
|
||||
fluent-syntax = "0.11.1"
|
||||
similar = "2.5.0"
|
||||
toml = "0.7.8"
|
||||
|
||||
[features]
|
||||
build-metrics = ["dep:serde"]
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ pub mod target_policy;
|
|||
pub mod target_specific_tests;
|
||||
pub mod tests_placement;
|
||||
pub mod tests_revision_unpaired_stdout_stderr;
|
||||
pub mod triagebot;
|
||||
pub mod ui_tests;
|
||||
pub mod unit_tests;
|
||||
pub mod unknown_revision;
|
||||
|
|
|
|||
|
|
@ -146,6 +146,8 @@ fn main() {
|
|||
|
||||
check!(x_version, &root_path, &cargo);
|
||||
|
||||
check!(triagebot, &root_path);
|
||||
|
||||
let collected = {
|
||||
drain_handles(&mut handles);
|
||||
|
||||
|
|
|
|||
93
src/tools/tidy/src/triagebot.rs
Normal file
93
src/tools/tidy/src/triagebot.rs
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
//! Tidy check to ensure paths mentioned in triagebot.toml exist in the project.
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
use toml::Value;
|
||||
|
||||
pub fn check(path: &Path, bad: &mut bool) {
|
||||
let triagebot_path = path.join("triagebot.toml");
|
||||
if !triagebot_path.exists() {
|
||||
tidy_error!(bad, "triagebot.toml file not found");
|
||||
return;
|
||||
}
|
||||
|
||||
let contents = std::fs::read_to_string(&triagebot_path).unwrap();
|
||||
let config: Value = toml::from_str(&contents).unwrap();
|
||||
|
||||
// Check [mentions."*"] sections, i.e. [mentions."compiler/rustc_const_eval/src/"]
|
||||
if let Some(Value::Table(mentions)) = config.get("mentions") {
|
||||
for path_str in mentions.keys() {
|
||||
// Remove quotes from the path
|
||||
let clean_path = path_str.trim_matches('"');
|
||||
let full_path = path.join(clean_path);
|
||||
|
||||
if !full_path.exists() {
|
||||
tidy_error!(
|
||||
bad,
|
||||
"triagebot.toml [mentions.*] contains path '{}' which doesn't exist",
|
||||
clean_path
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tidy_error!(
|
||||
bad,
|
||||
"triagebot.toml missing [mentions.*] section, this wrong for rust-lang/rust repo."
|
||||
);
|
||||
}
|
||||
|
||||
// Check [assign.owners] sections, i.e.
|
||||
// [assign.owners]
|
||||
// "/.github/workflows" = ["infra-ci"]
|
||||
if let Some(Value::Table(assign)) = config.get("assign") {
|
||||
if let Some(Value::Table(owners)) = assign.get("owners") {
|
||||
for path_str in owners.keys() {
|
||||
// Remove quotes and leading slash from the path
|
||||
let clean_path = path_str.trim_matches('"').trim_start_matches('/');
|
||||
let full_path = path.join(clean_path);
|
||||
|
||||
if !full_path.exists() {
|
||||
tidy_error!(
|
||||
bad,
|
||||
"triagebot.toml [assign.owners] contains path '{}' which doesn't exist",
|
||||
clean_path
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tidy_error!(
|
||||
bad,
|
||||
"triagebot.toml missing [assign.owners] section, this wrong for rust-lang/rust repo."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Verify that trigger_files in [autolabel."*"] exist in the project, i.e.
|
||||
// [autolabel."A-rustdoc-search"]
|
||||
// trigger_files = [
|
||||
// "src/librustdoc/html/static/js/search.js",
|
||||
// "tests/rustdoc-js",
|
||||
// "tests/rustdoc-js-std",
|
||||
// ]
|
||||
if let Some(Value::Table(autolabels)) = config.get("autolabel") {
|
||||
for (label, content) in autolabels {
|
||||
if let Some(trigger_files) = content.get("trigger_files").and_then(|v| v.as_array()) {
|
||||
for file in trigger_files {
|
||||
if let Some(file_str) = file.as_str() {
|
||||
let full_path = path.join(file_str);
|
||||
|
||||
// Handle both file and directory paths
|
||||
if !full_path.exists() {
|
||||
tidy_error!(
|
||||
bad,
|
||||
"triagebot.toml [autolabel.{}] contains trigger_files path '{}' which doesn't exist",
|
||||
label,
|
||||
file_str
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue