support event 'category' for GitLab (e.g. Note events but only for Issues)
This commit is contained in:
parent
6ee76af907
commit
7766c889f4
4 changed files with 22 additions and 13 deletions
|
@ -67,7 +67,7 @@ class Module(ModuleManager.BaseModule):
|
|||
organisation_lower = (organisation or "").lower()
|
||||
|
||||
branch = handler.branch(data, headers)
|
||||
current_event, event_action = handler.event(data, headers)
|
||||
current_events = handler.event(data, headers)
|
||||
|
||||
unfiltered_targets = []
|
||||
if "channels" in params:
|
||||
|
@ -101,13 +101,12 @@ class Module(ModuleManager.BaseModule):
|
|||
not branch in hook["branches"]):
|
||||
continue
|
||||
|
||||
events = []
|
||||
hooked_events = []
|
||||
for hooked_event in hook["events"]:
|
||||
events.append(handler.event_categories(hooked_event))
|
||||
events = list(itertools.chain(*events))
|
||||
hooked_events.append(handler.event_categories(hooked_event))
|
||||
hooked_events = set(itertools.chain(*hooked_events))
|
||||
|
||||
if (current_event in events or
|
||||
(event_action and event_action in events)):
|
||||
if bool(set(current_events)&set(hooked_events)):
|
||||
targets.append([server, channel])
|
||||
|
||||
if not targets:
|
||||
|
|
|
@ -72,7 +72,7 @@ class Gitea(object):
|
|||
event_action = None
|
||||
if "action" in data:
|
||||
event_action = "%s/%s" % (event, data["action"])
|
||||
return event, event_action
|
||||
return [event]+([event_action] if event_action else [])
|
||||
|
||||
def event_categories(self, event):
|
||||
return EVENT_CATEGORIES.get(event, [event])
|
||||
|
|
|
@ -114,7 +114,7 @@ class GitHub(object):
|
|||
event_action = None
|
||||
if "action" in data:
|
||||
event_action = "%s/%s" % (event, data["action"])
|
||||
return event, event_action
|
||||
return [event]+([event_action] if event_action else [])
|
||||
|
||||
def event_categories(self, event):
|
||||
return EVENT_CATEGORIES.get(event, [event])
|
||||
|
|
|
@ -71,13 +71,23 @@ class GitLab(object):
|
|||
|
||||
def event(self, data, headers):
|
||||
event = headers["X-GitLab-Event"].rsplit(" ", 1)[0].lower()
|
||||
|
||||
event = event.replace(" ", "_")
|
||||
event_action = None
|
||||
if ("object_attributes" in data and
|
||||
"action" in data["object_attributes"]):
|
||||
event_action = "%s/%s" % (
|
||||
event, data["object_attributes"]["action"])
|
||||
return event, event_action
|
||||
|
||||
category = None
|
||||
category_action = None
|
||||
|
||||
if "object_attributes" in data:
|
||||
if "action" in data["object_attributes"]:
|
||||
event_action = "%s/%s" % (
|
||||
event, data["object_attributes"]["action"])
|
||||
if "noteable_type" in data["object_attributes"]:
|
||||
category = data["object_attributes"]["noteable_type"].lower()
|
||||
category = "%s+%s" % (event, category)
|
||||
category_action = "%s/%s" % (category, action)
|
||||
|
||||
return list(filter([event, event_action, category, category_action]))
|
||||
|
||||
def event_categories(self, event):
|
||||
return EVENT_CATEGORIES.get(event, [event])
|
||||
|
|
Loading…
Reference in a new issue