From 6baf47ca43946a3e0ca10abac50d755d53f6bb3a Mon Sep 17 00:00:00 2001 From: l Date: Mon, 17 Nov 2025 12:17:32 +0000 Subject: [PATCH 1/3] remove labels if issue detected --- src/bin/pr-metadata-validator.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/bin/pr-metadata-validator.rs b/src/bin/pr-metadata-validator.rs index 144f52e..e5cea4f 100644 --- a/src/bin/pr-metadata-validator.rs +++ b/src/bin/pr-metadata-validator.rs @@ -78,13 +78,18 @@ async fn main() { ValidationResult::UnknownRegion => UNKNOWN_REGION_COMMENT, }; - 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)."); + 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."); eprintln!("{}", full_message); octocrab - .issues(github_org_name, module_name) + .issues(&github_org_name, &module_name) .create_comment(pr_number, full_message) .await .expect("Failed to create comment with validation error"); + octocrab + .issues(&github_org_name, &module_name) + .remove_label(pr_number, "Needs Review") + .await + .ok(); // this gives an error if the label does not exist (i.e. already removed), we allow it exit(2); } From 9c8c682f152699478aa5ff990883a0e7082b6eb6 Mon Sep 17 00:00:00 2001 From: l Date: Tue, 18 Nov 2025 16:25:09 +0000 Subject: [PATCH 2/3] better missing label error handling --- src/bin/pr-metadata-validator.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/bin/pr-metadata-validator.rs b/src/bin/pr-metadata-validator.rs index e5cea4f..0800fe7 100644 --- a/src/bin/pr-metadata-validator.rs +++ b/src/bin/pr-metadata-validator.rs @@ -85,11 +85,18 @@ async fn main() { .create_comment(pr_number, full_message) .await .expect("Failed to create comment with validation error"); - octocrab + let remove_label_response = octocrab .issues(&github_org_name, &module_name) .remove_label(pr_number, "Needs Review") - .await - .ok(); // this gives an error if the label does not exist (i.e. already removed), we allow it + .await; + match remove_label_response { + Ok(_) => { println!("Found issues for PR #{}, notified and removed label", pr_number); }, + Err(octocrab::Error::GitHub { source, .. }) if source.status_code == 404 => { + println!("Found issues for PR #{}, notified and label already removed", pr_number); + // The only time this API 404s is if the label is already removed. Continue without error. + }, + err => { eprintln!("Error removing label: {:?}", err); }, + }; exit(2); } From 7a4dd7b86e5efffcf642848f7cc8e12bb3150245 Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Tue, 18 Nov 2025 16:58:58 +0000 Subject: [PATCH 3/3] fmt --- src/bin/pr-metadata-validator.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/bin/pr-metadata-validator.rs b/src/bin/pr-metadata-validator.rs index 0800fe7..d9d5b16 100644 --- a/src/bin/pr-metadata-validator.rs +++ b/src/bin/pr-metadata-validator.rs @@ -90,12 +90,22 @@ async fn main() { .remove_label(pr_number, "Needs Review") .await; match remove_label_response { - Ok(_) => { println!("Found issues for PR #{}, notified and removed label", pr_number); }, + Ok(_) => { + println!( + "Found issues for PR #{}, notified and removed label", + pr_number + ); + } Err(octocrab::Error::GitHub { source, .. }) if source.status_code == 404 => { - println!("Found issues for PR #{}, notified and label already removed", pr_number); + println!( + "Found issues for PR #{}, notified and label already removed", + pr_number + ); // The only time this API 404s is if the label is already removed. Continue without error. - }, - err => { eprintln!("Error removing label: {:?}", err); }, + } + err => { + eprintln!("Error removing label: {:?}", err); + } }; exit(2); }