From 6a137eb6b239649d77f210cfc69fefc359eea737 Mon Sep 17 00:00:00 2001 From: mibac138 <5672750+mibac138@users.noreply.github.com> Date: Mon, 7 Jun 2021 13:28:00 +0200 Subject: [PATCH 1/2] Add disallowed labels to notify_zulip config --- src/config.rs | 2 ++ src/handlers/notify_zulip.rs | 39 +++++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/config.rs b/src/config.rs index a10b943c..277409e6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -125,6 +125,8 @@ pub(crate) struct NotifyZulipLabelConfig { pub(crate) message_on_remove: Option, #[serde(default)] pub(crate) required_labels: Vec, + #[serde(default)] + pub(crate) disallowed_labels: Vec, } #[derive(PartialEq, Eq, Debug, serde::Deserialize)] diff --git a/src/handlers/notify_zulip.rs b/src/handlers/notify_zulip.rs index 73deefe9..0fee3829 100644 --- a/src/handlers/notify_zulip.rs +++ b/src/handlers/notify_zulip.rs @@ -1,6 +1,6 @@ use crate::{ config::NotifyZulipConfig, - github::{IssuesAction, IssuesEvent}, + github::{IssuesAction, IssuesEvent, Label}, handlers::Context, }; @@ -21,23 +21,30 @@ pub(super) fn parse_input( if let IssuesAction::Labeled | IssuesAction::Unlabeled = event.action { let applied_label = &event.label.as_ref().expect("label").name; if let Some(config) = config.and_then(|c| c.labels.get(applied_label)) { - for label in &config.required_labels { - let pattern = match glob::Pattern::new(label) { - Ok(pattern) => pattern, - Err(err) => { - log::error!("Invalid glob pattern: {}", err); - continue; + let contains_label = |haystack: &[Label], needles: &[String]| { + for needle in needles { + let pattern = match glob::Pattern::new(needle) { + Ok(pattern) => pattern, + Err(err) => { + log::error!("Invalid glob pattern: {}", err); + continue; + } + }; + if haystack.iter().any(|l| pattern.matches(&l.name)) { + return true; } - }; - if !event - .issue - .labels() - .iter() - .any(|l| pattern.matches(&l.name)) - { - // Issue misses a required label, ignore this event - return Ok(None); } + false + }; + + if !contains_label(event.issue.labels(), &config.required_labels) { + // Issue misses a required label, ignore this event + return Ok(None); + } + + if contains_label(event.issue.labels(), &config.disallowed_labels) { + // Issue contains a disallowed label, ignore this event + return Ok(None); } if event.action == IssuesAction::Labeled && config.message_on_add.is_some() { From eb869a68a75418d42dbcd69fe3586a9c366c0980 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Wed, 13 Apr 2022 09:28:47 -0400 Subject: [PATCH 2/2] Update src/handlers/notify_zulip.rs --- src/handlers/notify_zulip.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/handlers/notify_zulip.rs b/src/handlers/notify_zulip.rs index 0fee3829..148fddee 100644 --- a/src/handlers/notify_zulip.rs +++ b/src/handlers/notify_zulip.rs @@ -38,7 +38,7 @@ pub(super) fn parse_input( }; if !contains_label(event.issue.labels(), &config.required_labels) { - // Issue misses a required label, ignore this event + // Ignore this event when none of the required labels are present. (Only one is enough). return Ok(None); }