diff --git a/src/bin/pr-metadata-validator.rs b/src/bin/pr-metadata-validator.rs index 29d43c2..f7a962f 100644 --- a/src/bin/pr-metadata-validator.rs +++ b/src/bin/pr-metadata-validator.rs @@ -77,6 +77,15 @@ async fn main() { .expect("Failed to create comment with validation error"); exit(2); } + ValidationResult::BodyTemplateNotFilledOut => { + eprintln!("Validation error: Template not filled out"); + octocrab + .issues(github_org_name, module_name.clone()) + .create_comment(pr_number, BODY_TEMPLATE_NOT_FILLED_IN_COMMENT) + .await + .expect("Failed to create comment with validation error"); + exit(2); + } ValidationResult::BadTitleFormat { reason } => { eprintln!("Validation error: Bad title: {}", reason); octocrab @@ -104,6 +113,10 @@ Please check its title is in the correct format, and that you only have one PR p 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)."#; +const BODY_TEMPLATE_NOT_FILLED_IN_COMMENT: &str = r#"Your PR description contained template fields which weren't filled in. + +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."#; + const BAD_TITLE_COMMENT_PREFIX: &str = r#"Your PR's title isn't in the expected format. 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 enum ValidationResult { Ok, + BodyTemplateNotFilledOut, CouldNotMatch, BadTitleFormat { reason: String }, UnknownRegion, @@ -190,6 +204,15 @@ async fn validate_pr( }); } + if pr_in_question.body.contains("Briefly explain your PR.") + || pr_in_question + .body + .contains("Ask any questions you have for your reviewer.") + || pr_in_question.body.contains("- [ ]") + { + return Ok(ValidationResult::BodyTemplateNotFilledOut); + } + Ok(ValidationResult::Ok) } diff --git a/src/prs.rs b/src/prs.rs index 38ac7e7..a6e487e 100644 --- a/src/prs.rs +++ b/src/prs.rs @@ -19,6 +19,7 @@ pub struct Pr { pub url: String, pub title: String, pub author: GithubLogin, + pub body: String, pub state: PrState, pub updated_at: DateTime, pub is_closed: bool, @@ -96,6 +97,7 @@ pub async fn get_prs( updated_at, title, state, + body, .. }| { // 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( let updated_at = updated_at?; let url = html_url?.to_string(); let title = title?; + let body = body.unwrap_or_default(); + Some(Pr { number, url, @@ -122,6 +126,7 @@ pub async fn get_prs( updated_at, repo_name, title, + body, is_closed, }) },