tidy/
triagebot.rs

1//! Tidy check to ensure paths mentioned in triagebot.toml exist in the project.
2
3use std::path::Path;
4
5use toml::Value;
6
7pub fn check(path: &Path, bad: &mut bool) {
8    let triagebot_path = path.join("triagebot.toml");
9
10    // This check is mostly to catch broken path filters *within* `triagebot.toml`, and not enforce
11    // the existence of `triagebot.toml` itself (which is more obvious), as distribution tarballs
12    // will not include non-essential bits like `triagebot.toml`.
13    if !triagebot_path.exists() {
14        return;
15    }
16
17    let contents = std::fs::read_to_string(&triagebot_path).unwrap();
18    let config: Value = toml::from_str(&contents).unwrap();
19
20    // Check [mentions."*"] sections, i.e. [mentions."compiler/rustc_const_eval/src/"]
21    if let Some(Value::Table(mentions)) = config.get("mentions") {
22        for (entry_key, entry_val) in mentions.iter() {
23            // If the type is set to something other than "filename", then this is not a path.
24            if entry_val.get("type").is_some_and(|t| t.as_str().unwrap_or_default() != "filename") {
25                continue;
26            }
27            let path_str = entry_key;
28            // Remove quotes from the path
29            let clean_path = path_str.trim_matches('"');
30            let full_path = path.join(clean_path);
31
32            if !full_path.exists() {
33                tidy_error!(
34                    bad,
35                    "triagebot.toml [mentions.*] contains path '{}' which doesn't exist",
36                    clean_path
37                );
38            }
39        }
40    } else {
41        tidy_error!(
42            bad,
43            "triagebot.toml missing [mentions.*] section, this wrong for rust-lang/rust repo."
44        );
45    }
46
47    // Check [assign.owners] sections, i.e.
48    // [assign.owners]
49    // "/.github/workflows" = ["infra-ci"]
50    if let Some(Value::Table(assign)) = config.get("assign") {
51        if let Some(Value::Table(owners)) = assign.get("owners") {
52            for path_str in owners.keys() {
53                // Remove quotes and leading slash from the path
54                let clean_path = path_str.trim_matches('"').trim_start_matches('/');
55                let full_path = path.join(clean_path);
56
57                if !full_path.exists() {
58                    tidy_error!(
59                        bad,
60                        "triagebot.toml [assign.owners] contains path '{}' which doesn't exist",
61                        clean_path
62                    );
63                }
64            }
65        } else {
66            tidy_error!(
67                bad,
68                "triagebot.toml missing [assign.owners] section, this wrong for rust-lang/rust repo."
69            );
70        }
71    }
72
73    // Verify that trigger_files in [autolabel."*"] exist in the project, i.e.
74    // [autolabel."A-rustdoc-search"]
75    // trigger_files = [
76    //    "src/librustdoc/html/static/js/search.js",
77    //    "tests/rustdoc-js",
78    //    "tests/rustdoc-js-std",
79    // ]
80    if let Some(Value::Table(autolabels)) = config.get("autolabel") {
81        for (label, content) in autolabels {
82            if let Some(trigger_files) = content.get("trigger_files").and_then(|v| v.as_array()) {
83                for file in trigger_files {
84                    if let Some(file_str) = file.as_str() {
85                        let full_path = path.join(file_str);
86
87                        // Handle both file and directory paths
88                        if !full_path.exists() {
89                            tidy_error!(
90                                bad,
91                                "triagebot.toml [autolabel.{}] contains trigger_files path '{}' which doesn't exist",
92                                label,
93                                file_str
94                            );
95                        }
96                    }
97                }
98            }
99        }
100    }
101}