1use std::path::Path;
4
5use toml::Value;
6
7use crate::diagnostics::TidyCtx;
8
9pub fn check(path: &Path, tidy_ctx: TidyCtx) {
10 let mut check = tidy_ctx.start_check("triagebot");
11 let triagebot_path = path.join("triagebot.toml");
12
13 if !triagebot_path.exists() {
17 return;
18 }
19
20 let contents = std::fs::read_to_string(&triagebot_path).unwrap();
21 let config: Value = toml::from_str(&contents).unwrap();
22
23 if let Some(Value::Table(mentions)) = config.get("mentions") {
25 for (entry_key, entry_val) in mentions.iter() {
26 if entry_val.get("type").is_some_and(|t| t.as_str().unwrap_or_default() != "filename") {
28 continue;
29 }
30 let path_str = entry_key;
31 let clean_path = path_str.trim_matches('"');
33 let full_path = path.join(clean_path);
34
35 if !full_path.exists() {
36 check.error(format!(
37 "triagebot.toml [mentions.*] contains path '{clean_path}' which doesn't exist"
38 ));
39 }
40 }
41 } else {
42 check.error(
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 check.error(format!(
59 "triagebot.toml [assign.owners] contains path '{clean_path}' which doesn't exist"
60 ));
61 }
62 }
63 } else {
64 check.error(
65 "triagebot.toml missing [assign.owners] section, this wrong for rust-lang/rust repo."
66 );
67 }
68 }
69
70 if let Some(Value::Table(autolabels)) = config.get("autolabel") {
78 for (label, content) in autolabels {
79 if let Some(trigger_files) = content.get("trigger_files").and_then(|v| v.as_array()) {
80 for file in trigger_files {
81 if let Some(file_str) = file.as_str() {
82 let full_path = path.join(file_str);
83
84 if !full_path.exists() {
86 check.error(format!(
87 "triagebot.toml [autolabel.{label}] contains trigger_files path '{file_str}' which doesn't exist",
88 ));
89 }
90 }
91 }
92 }
93 }
94 }
95}