diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-03-09 10:34:48 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-09 10:34:48 +0100 |
| commit | cdd97bae84aba172b38f307392b073fb331f0d7a (patch) | |
| tree | cf877b25b71eaa903fb4994777848e49e6866b67 /src | |
| parent | eade7e99476633bffaabbff0b58b869da837f585 (diff) | |
| parent | aa72de9330d7803374d4200833c39ec5daea1012 (diff) | |
Rollup merge of #137885 - klensy:tidy-triagebot, r=jieyouxu
tidy: add triagebot checks Validates triagebot.toml to have existing paths: `[mentions."*"]` sections, i.e. ```toml [mentions."compiler/rustc_const_eval/src/"] ``` or ```toml [assign.owners] "/.github/workflows" = ["infra-ci"] ``` or ```toml trigger_files = [ "src/librustdoc/html/static/js/search.js", "tests/rustdoc-js", "tests/rustdoc-js-std", ] ``` Looked at #137876 and implemented check.
Diffstat (limited to 'src')
| -rw-r--r-- | src/tools/tidy/Cargo.toml | 1 | ||||
| -rw-r--r-- | src/tools/tidy/src/lib.rs | 1 | ||||
| -rw-r--r-- | src/tools/tidy/src/main.rs | 2 | ||||
| -rw-r--r-- | src/tools/tidy/src/triagebot.rs | 93 |
4 files changed, 97 insertions, 0 deletions
diff --git a/src/tools/tidy/Cargo.toml b/src/tools/tidy/Cargo.toml index 9a4d0891b4a..dfdbc0878f2 100644 --- a/src/tools/tidy/Cargo.toml +++ b/src/tools/tidy/Cargo.toml @@ -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"] diff --git a/src/tools/tidy/src/lib.rs b/src/tools/tidy/src/lib.rs index 9f6d563166e..66856f5247b 100644 --- a/src/tools/tidy/src/lib.rs +++ b/src/tools/tidy/src/lib.rs @@ -87,6 +87,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; diff --git a/src/tools/tidy/src/main.rs b/src/tools/tidy/src/main.rs index 1d8514ef4c9..bc3519142dd 100644 --- a/src/tools/tidy/src/main.rs +++ b/src/tools/tidy/src/main.rs @@ -144,6 +144,8 @@ fn main() { check!(x_version, &root_path, &cargo); + check!(triagebot, &root_path); + let collected = { drain_handles(&mut handles); diff --git a/src/tools/tidy/src/triagebot.rs b/src/tools/tidy/src/triagebot.rs new file mode 100644 index 00000000000..7131c16ec30 --- /dev/null +++ b/src/tools/tidy/src/triagebot.rs @@ -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 + ); + } + } + } + } + } + } +} |
