Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ pub(crate) struct NotifyZulipLabelConfig {
pub(crate) message_on_remove: Option<String>,
#[serde(default)]
pub(crate) required_labels: Vec<String>,
#[serde(default)]
pub(crate) disallowed_labels: Vec<String>,
}

#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
Expand Down
39 changes: 23 additions & 16 deletions src/handlers/notify_zulip.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
config::NotifyZulipConfig,
github::{IssuesAction, IssuesEvent},
github::{IssuesAction, IssuesEvent, Label},
handlers::Context,
};

Expand All @@ -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) {
// Ignore this event when none of the required labels are present. (Only one is enough).
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() {
Expand Down