aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/git_webhooks/__init__.py11
-rw-r--r--modules/git_webhooks/gitea.py2
-rw-r--r--modules/git_webhooks/github.py2
-rw-r--r--modules/git_webhooks/gitlab.py20
4 files changed, 22 insertions, 13 deletions
diff --git a/modules/git_webhooks/__init__.py b/modules/git_webhooks/__init__.py
index 7a1154fb..c847866e 100644
--- a/modules/git_webhooks/__init__.py
+++ b/modules/git_webhooks/__init__.py
@@ -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:
diff --git a/modules/git_webhooks/gitea.py b/modules/git_webhooks/gitea.py
index 19abd8bf..53172f6f 100644
--- a/modules/git_webhooks/gitea.py
+++ b/modules/git_webhooks/gitea.py
@@ -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])
diff --git a/modules/git_webhooks/github.py b/modules/git_webhooks/github.py
index 7195f354..1ff1e57d 100644
--- a/modules/git_webhooks/github.py
+++ b/modules/git_webhooks/github.py
@@ -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])
diff --git a/modules/git_webhooks/gitlab.py b/modules/git_webhooks/gitlab.py
index 98ddd933..998e8faf 100644
--- a/modules/git_webhooks/gitlab.py
+++ b/modules/git_webhooks/gitlab.py
@@ -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])