Skip to content

Commit 0ab70d3

Browse files
authored
Remove needs review labels if issue detected (#34)
* Remove the label if any issues are found * Add message to prompt re-adding label one issues resolved
1 parent f7b18aa commit 0ab70d3

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/bin/pr-metadata-validator.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,35 @@ async fn main() {
7878
ValidationResult::UnknownRegion => UNKNOWN_REGION_COMMENT,
7979
};
8080

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).");
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).\n\nIf this PR needs reviewed, please add the 'Needs Review' label to this PR after you have resolved the issues listed above.");
8282
eprintln!("{}", full_message);
8383
octocrab
84-
.issues(github_org_name, module_name)
84+
.issues(&github_org_name, &module_name)
8585
.create_comment(pr_number, full_message)
8686
.await
8787
.expect("Failed to create comment with validation error");
88+
let remove_label_response = octocrab
89+
.issues(&github_org_name, &module_name)
90+
.remove_label(pr_number, "Needs Review")
91+
.await;
92+
match remove_label_response {
93+
Ok(_) => {
94+
println!(
95+
"Found issues for PR #{}, notified and removed label",
96+
pr_number
97+
);
98+
}
99+
Err(octocrab::Error::GitHub { source, .. }) if source.status_code == 404 => {
100+
println!(
101+
"Found issues for PR #{}, notified and label already removed",
102+
pr_number
103+
);
104+
// The only time this API 404s is if the label is already removed. Continue without error.
105+
}
106+
err => {
107+
eprintln!("Error removing label: {:?}", err);
108+
}
109+
};
88110
exit(2);
89111
}
90112

0 commit comments

Comments
 (0)