|
| 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