1use 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 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 if let Some(Value::Table(mentions)) = config.get("mentions") {
22 for (entry_key, entry_val) in mentions.iter() {
23 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 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 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 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 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 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}