Skip to content

Add exclude labels pattern handling #561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub(crate) struct PrioritizeConfig {
#[serde(default)]
pub(crate) prioritize_on: Vec<String>,
#[serde(default)]
pub(crate) priority_labels: String,
pub(crate) exclude_labels: Vec<String>,
pub(crate) zulip_stream: u64,
}

Expand Down
38 changes: 27 additions & 11 deletions src/handlers/prioritize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,38 @@ impl Handler for PrioritizeHandler {
if let Event::Issue(e) = event {
if e.action == github::IssuesAction::Labeled {
if let Some(config) = config {
if e.label.as_ref().expect("label").name == config.label {
let applied_label = &e.label.as_ref().expect("label").name;

if *applied_label == 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));
// Checks if an `applied_label` needs prioritization according to the
// labels the issue already have and the config's `exclude_labels` pattern
// which are the ones we don't want to prioritize.
if config.prioritize_on.iter().any(|l| l == applied_label) {
let mut prioritize = false;

for label in event.issue().unwrap().labels() {
for exclude_label in &config.exclude_labels {
match glob::Pattern::new(exclude_label) {
Ok(exclude_glob) => {
prioritize = !exclude_glob.matches(&label.name);
}
Err(error) => {
log::error!("Invalid glob pattern: {}", error);
}
}

if !prioritize {
break;
}
}
}
Err(error) => log::error!("Invalid glob pattern: {}", error),

if prioritize {
return Ok(Some(Prioritize::Label));
}
}
}
}
Expand Down