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