Hoster: Add IssueActions.ASSIGNEES_CHANGED events

parent 301774f3
......@@ -201,8 +201,15 @@ class GitHub(GitHubMixin, Hoster):
'reopened': IssueActions.REOPENED,
'labeled': IssueActions.LABELED,
'unlabeled': IssueActions.UNLABELED,
'assigned': IssueActions.ASSIGNEES_CHANGED,
'unassigned': IssueActions.ASSIGNEES_CHANGED
}.get(data['action'], IssueActions.ATTRIBUTES_CHANGED)
if trigger_event == IssueActions.ASSIGNEES_CHANGED:
assignees = data.get('assignees') or set()
users = {user['login'] for user in assignees}
return IssueActions.ASSIGNEES_CHANGED, [issue_obj, users]
if (trigger_event is IssueActions.LABELED
or trigger_event is IssueActions.UNLABELED):
yield trigger_event, [issue_obj, data['label']['name']]
......
......@@ -209,6 +209,12 @@ class GitLab(GitLabMixin, Hoster):
'reopen': IssueActions.REOPENED,
}.get(issue['action'], IssueActions.ATTRIBUTES_CHANGED)
if (trigger_event == IssueActions.ATTRIBUTES_CHANGED and
'assignees' in data['changes']):
assignees = data['changes']['assignees']['current']
users = {user['username'] for user in assignees}
return IssueActions.ASSIGNEES_CHANGED, [issue_obj, users]
if (trigger_event == IssueActions.ATTRIBUTES_CHANGED and
'labels' in data['changes']):
# labels are changed
......
......@@ -42,13 +42,15 @@ class IssueActions(Enum):
REOPENED = 3
# When someone comments on an issue.
COMMENTED = 4
# When an issue gets reassigned, or the linked
# When an issue gets updated, or the linked
# milestone is changed
ATTRIBUTES_CHANGED = 5
# When a new label is added to the issue
LABELED = 6
# When a label is removed from an issue
UNLABELED = 7
# When the assignees on an issue are changed.
ASSIGNEES_CHANGED = 8
class PipelineActions(Enum):
"""
......
......@@ -217,3 +217,20 @@ class TestGitHubWebhook(IGittTestCase):
self.assertEqual(event, MergeRequestActions.UNLABELED)
self.assertIsInstance(obj[0], GitHubMergeRequest)
self.assertEqual(obj[1], 'title')
def test_issue_assignees_changed(self):
self.default_data.update({
'assignees': [{'login': 'gitmate-bot'}],
'action': 'assigned',
})
for event, obj in self.gh.handle_webhook('issues', self.default_data):
self.assertEqual(event, IssueActions.ASSIGNEES_CHANGED)
self.assertIsInstance(obj[0], GitHubIssue)
self.assertEqual(obj[1], {'gitmate-bot'})
self.default_data.update({
'action': 'unassigned'
})
for event, obj in self.gh.handle_webhook('issues', self.default_data):
self.assertEqual(event, IssueActions.UNLABELED)
self.assertIsInstance(obj[0], GitHubIssue)
self.assertEqual(obj[1], set())
......@@ -208,3 +208,23 @@ class GitLabWebhookTest(IGittTestCase):
self.assertEqual(unlabeled_labels, {'old', 'old2'})
self.assertEqual(labeled_labels, {'new'})
def test_issue_assignees_changed(self):
obj_attrs = self.default_data['object_attributes']
obj_attrs.update({'action': 'update'})
self.default_data.update({
'object_attributes': obj_attrs,
'changes': {
'assignees': {
'previous': [],
'current': [{'username': 'gitmate-bot'}],
},
},
})
for event, obj in self.gl.handle_webhook('Issue Hook',
self.default_data):
self.assertEqual(event, IssueActions.ASSIGNEES_CHANGED)
self.assertIsInstance(obj[0], GitLabIssue)
self.assertEqual(obj[1], {'gitmate-bot'})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment