Skip to content

Commit 4f57d87

Browse files
committed
Always include message about how to ignore for non-coursework
1 parent efe9f36 commit 4f57d87

1 file changed

Lines changed: 18 additions & 39 deletions

File tree

src/bin/pr-metadata-validator.rs

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -66,52 +66,31 @@ async fn main() {
6666
)
6767
.await
6868
.expect("Failed to validate PR");
69-
match result {
70-
ValidationResult::Ok => {}
71-
ValidationResult::CouldNotMatch => {
72-
eprintln!("Validation error: Could not match PR against assignment");
73-
octocrab
74-
.issues(github_org_name, module_name.clone())
75-
.create_comment(pr_number, COULD_NOT_MATCH_COMMENT)
76-
.await
77-
.expect("Failed to create comment with validation error");
78-
exit(2);
79-
}
80-
ValidationResult::BodyTemplateNotFilledOut => {
81-
eprintln!("Validation error: Template not filled out");
82-
octocrab
83-
.issues(github_org_name, module_name.clone())
84-
.create_comment(pr_number, BODY_TEMPLATE_NOT_FILLED_IN_COMMENT)
85-
.await
86-
.expect("Failed to create comment with validation error");
87-
exit(2);
69+
let message = match result {
70+
ValidationResult::Ok => {
71+
exit(0);
8872
}
73+
ValidationResult::CouldNotMatch => COULD_NOT_MATCH_COMMENT,
74+
ValidationResult::BodyTemplateNotFilledOut => BODY_TEMPLATE_NOT_FILLED_IN_COMMENT,
8975
ValidationResult::BadTitleFormat { reason } => {
90-
eprintln!("Validation error: Bad title: {}", reason);
91-
octocrab
92-
.issues(github_org_name, module_name.clone())
93-
.create_comment(pr_number, format!("{}{}", BAD_TITLE_COMMENT_PREFIX, reason))
94-
.await
95-
.expect("Failed to create comment with validation error");
96-
exit(2);
97-
}
98-
ValidationResult::UnknownRegion => {
99-
eprintln!("Validation error: Could not find region in PR title");
100-
octocrab
101-
.issues(github_org_name, module_name.clone())
102-
.create_comment(pr_number, UNKNOWN_REGION_COMMENT)
103-
.await
104-
.expect("Failed to create comment with validation error");
105-
exit(2);
76+
&format!("{}{}", BAD_TITLE_COMMENT_PREFIX, reason)
10677
}
107-
}
78+
ValidationResult::UnknownRegion => UNKNOWN_REGION_COMMENT,
79+
};
80+
81+
let full_message = format!("{message}\n\nIf this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed).");
82+
eprintln!("{}", full_message);
83+
octocrab
84+
.issues(github_org_name, module_name)
85+
.create_comment(pr_number, full_message)
86+
.await
87+
.expect("Failed to create comment with validation error");
88+
exit(2);
10889
}
10990

11091
const COULD_NOT_MATCH_COMMENT: &str = r#"Your PR couldn't be matched to an assignment in this module.
11192
112-
Please check its title is in the correct format, and that you only have one PR per assignment.
113-
114-
If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed)."#;
93+
Please check its title is in the correct format, and that you only have one PR per assignment."#;
11594

11695
const BODY_TEMPLATE_NOT_FILLED_IN_COMMENT: &str = r#"Your PR description contained template fields which weren't filled in.
11796

0 commit comments

Comments
 (0)