Skip to content

Commit c1e454b

Browse files
authored
Check for PR templates which aren't filled in (#12)
Many of our trainees ignore the PR template. Rather than wasting a bunch of reviewer time on this (or just ignoring it), attempt to automate this detection. I will also send out some changes simplifying and clarifying the template.
1 parent 550eecb commit c1e454b

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/bin/pr-metadata-validator.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ async fn main() {
7777
.expect("Failed to create comment with validation error");
7878
exit(2);
7979
}
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);
88+
}
8089
ValidationResult::BadTitleFormat { reason } => {
8190
eprintln!("Validation error: Bad title: {}", reason);
8291
octocrab
@@ -104,6 +113,10 @@ Please check its title is in the correct format, and that you only have one PR p
104113
105114
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)."#;
106115

116+
const BODY_TEMPLATE_NOT_FILLED_IN_COMMENT: &str = r#"Your PR description contained template fields which weren't filled in.
117+
118+
Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed."#;
119+
107120
const BAD_TITLE_COMMENT_PREFIX: &str = r#"Your PR's title isn't in the expected format.
108121
109122
Please check the expected title format, and update yours to match.
@@ -116,6 +129,7 @@ Please check the expected title format, and make sure your region is in the corr
116129

117130
enum ValidationResult {
118131
Ok,
132+
BodyTemplateNotFilledOut,
119133
CouldNotMatch,
120134
BadTitleFormat { reason: String },
121135
UnknownRegion,
@@ -190,6 +204,15 @@ async fn validate_pr(
190204
});
191205
}
192206

207+
if pr_in_question.body.contains("Briefly explain your PR.")
208+
|| pr_in_question
209+
.body
210+
.contains("Ask any questions you have for your reviewer.")
211+
|| pr_in_question.body.contains("- [ ]")
212+
{
213+
return Ok(ValidationResult::BodyTemplateNotFilledOut);
214+
}
215+
193216
Ok(ValidationResult::Ok)
194217
}
195218

src/prs.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub struct Pr {
1919
pub url: String,
2020
pub title: String,
2121
pub author: GithubLogin,
22+
pub body: String,
2223
pub state: PrState,
2324
pub updated_at: DateTime<chrono::Utc>,
2425
pub is_closed: bool,
@@ -96,6 +97,7 @@ pub async fn get_prs(
9697
updated_at,
9798
title,
9899
state,
100+
body,
99101
..
100102
}| {
101103
// If a user is deleted from GitHub, their User will be None - ignore PRs from deleted users.
@@ -114,6 +116,8 @@ pub async fn get_prs(
114116
let updated_at = updated_at?;
115117
let url = html_url?.to_string();
116118
let title = title?;
119+
let body = body.unwrap_or_default();
120+
117121
Some(Pr {
118122
number,
119123
url,
@@ -122,6 +126,7 @@ pub async fn get_prs(
122126
updated_at,
123127
repo_name,
124128
title,
129+
body,
125130
is_closed,
126131
})
127132
},

0 commit comments

Comments
 (0)