Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/bin/pr-metadata-validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -190,6 +204,15 @@ async fn validate_pr(
});
}

if pr_in_question.body.contains("Briefly explain your PR.")
Comment thread
AnnaFYZ marked this conversation as resolved.
|| 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)
}

Expand Down
5 changes: 5 additions & 0 deletions src/prs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<chrono::Utc>,
pub is_closed: bool,
Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand All @@ -122,6 +126,7 @@ pub async fn get_prs(
updated_at,
repo_name,
title,
body,
is_closed,
})
},
Expand Down
Loading