Skip to content

Commit

Permalink
Adding support for or condition in must have labels
Browse files Browse the repository at this point in the history
  • Loading branch information
ronykoz committed May 19, 2020
1 parent fb0673e commit b6c8c84
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/github_automation/management/event_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import json

from github_automation.common.constants import OR
from github_automation.common.utils import (get_column_issues_with_prev_column,
get_first_column_issues)
from github_automation.core.issue.issue import Issue, parse_issue
Expand Down Expand Up @@ -35,7 +36,12 @@ def is_matching_issue(issue_labels, must_have_labels, cant_have_labels, filter_l
return False

for label in must_have_labels:
if label not in issue_labels:
if OR in label:
new_labels = label.split(OR)
if not any(new_label not in issue_labels for new_label in new_labels):
return False

elif label not in issue_labels:
return False

for label in cant_have_labels:
Expand Down
8 changes: 7 additions & 1 deletion src/github_automation/management/project_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import absolute_import

from github_automation.common.constants import OR
from github_automation.common.utils import (get_column_issues_with_prev_column,
get_first_column_issues)
from github_automation.core.issue.issue import Issue, get_labels, parse_issue
Expand All @@ -23,7 +24,12 @@ def is_matching_issue(issue_labels, must_have_labels, cant_have_labels, filter_l
return False

for label in must_have_labels:
if label not in issue_labels:
if OR in label:
new_labels = label.split(OR)
if not any(new_label not in issue_labels for new_label in new_labels):
return False

elif label not in issue_labels:
return False

for label in cant_have_labels:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_files/event_manager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ def test_matching_issue_filter():
assert EventManager.is_matching_issue(['not bug', 'test'], config.must_have_labels, config.cant_have_labels,
config.filter_labels) is True

config.must_have_labels = ['test||something']
assert EventManager.is_matching_issue(['not bug', 'test'], config.must_have_labels, config.cant_have_labels,
config.filter_labels) is True
assert EventManager.is_matching_issue(['not bug', 'something'], config.must_have_labels, config.cant_have_labels,
config.filter_labels) is True
assert EventManager.is_matching_issue(['not bug', 'else'], config.must_have_labels, config.cant_have_labels,
config.filter_labels) is True


def test_get_prev_column():
event = {
Expand Down
8 changes: 8 additions & 0 deletions tests/test_files/project_manager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,3 +423,11 @@ def test_matching_issue_filter():
config.filter_labels) is False
assert ProjectManager.is_matching_issue(['not bug', 'test'], config.must_have_labels, config.cant_have_labels,
config.filter_labels) is True

config.must_have_labels = ['test||something']
assert ProjectManager.is_matching_issue(['not bug', 'test'], config.must_have_labels, config.cant_have_labels,
config.filter_labels) is True
assert ProjectManager.is_matching_issue(['not bug', 'something'], config.must_have_labels, config.cant_have_labels,
config.filter_labels) is True
assert ProjectManager.is_matching_issue(['not bug', 'else'], config.must_have_labels, config.cant_have_labels,
config.filter_labels) is True

0 comments on commit b6c8c84

Please sign in to comment.