From d5c3561b16513909b8c22525a9290d9a837e1abe Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 14 May 2020 14:49:31 -0300 Subject: [PATCH 1/2] Use prioritize_on field to start prioritization process --- src/config.rs | 4 ++++ src/handlers/prioritize.rs | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/config.rs b/src/config.rs index 0c6f5f2e..cf73536b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -78,6 +78,10 @@ pub(crate) struct RelabelConfig { #[derive(PartialEq, Eq, Debug, serde::Deserialize)] pub(crate) struct PrioritizeConfig { pub(crate) label: String, + #[serde(default)] + pub(crate) prioritize_on: Vec, + #[serde(default)] + pub(crate) priority_labels: String, pub(crate) zulip_stream: u64, } diff --git a/src/handlers/prioritize.rs b/src/handlers/prioritize.rs index 3c311e83..b4a74fda 100644 --- a/src/handlers/prioritize.rs +++ b/src/handlers/prioritize.rs @@ -38,6 +38,20 @@ impl Handler for PrioritizeHandler { if e.label.as_ref().expect("label").name == config.label { // We need to take the exact same action in this case. return Ok(Some(Prioritize::Start)); + } else { + match glob::Pattern::new(&config.priority_labels) { + Ok(glob) => { + let issue_labels = event.issue().unwrap().labels(); + let label_name = &e.label.as_ref().expect("label").name; + + if issue_labels.iter().all(|l| !glob.matches(&l.name)) + && config.prioritize_on.iter().any(|l| l == label_name) + { + return Ok(Some(Prioritize::Label)); + } + } + Err(error) => log::error!("Invalid glob pattern: {}", error), + } } } } From e21d9f6c9a1b6634b15ee7e691c6c2d354947317 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 14 May 2020 14:19:03 -0300 Subject: [PATCH 2/2] cargo fmt --- src/handlers/prioritize.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/handlers/prioritize.rs b/src/handlers/prioritize.rs index b4a74fda..389c41b7 100644 --- a/src/handlers/prioritize.rs +++ b/src/handlers/prioritize.rs @@ -114,13 +114,11 @@ async fn handle_input( } None } - Prioritize::Start => { - Some(format!( - "@*WG-prioritization* issue [#{}]({}) has been requested for prioritization.", - issue.number, - event.html_url().unwrap() - )) - } + Prioritize::Start => Some(format!( + "@*WG-prioritization* issue [#{}]({}) has been requested for prioritization.", + issue.number, + event.html_url().unwrap() + )), Prioritize::End => { // Shouldn't be necessary in practice as we only end on label // removal, but if we add support in the future let's be sure to do