aboutsummaryrefslogtreecommitdiff
path: root/modules/git_webhooks
diff options
context:
space:
mode:
authorGravatar jesopo2019-11-01 13:30:31 +0000
committerGravatar jesopo2019-11-01 13:30:31 +0000
commit1d777f88b3d9131f2edce63ef772f9092ed6ec73 (patch)
tree03dd587b3f09dd568e39517be4eb062226297f46 /modules/git_webhooks
parentfix Gitea `release` event return (diff)
signature
support "event category" for github so we can e.g. show only approvals
Diffstat (limited to 'modules/git_webhooks')
-rw-r--r--modules/git_webhooks/github.py17
-rw-r--r--modules/git_webhooks/gitlab.py10
2 files changed, 22 insertions, 5 deletions
diff --git a/modules/git_webhooks/github.py b/modules/git_webhooks/github.py
index 1ff1e57d..fc25f0f8 100644
--- a/modules/git_webhooks/github.py
+++ b/modules/git_webhooks/github.py
@@ -111,10 +111,23 @@ class GitHub(object):
def event(self, data, headers):
event = headers["X-GitHub-Event"]
+ action = None
event_action = None
if "action" in data:
- event_action = "%s/%s" % (event, data["action"])
- return [event]+([event_action] if event_action else [])
+ action = data["action"]
+
+ category = None
+ category_action = None
+ if "review" in data and "state" in data["review"]:
+ category = "%s+%s" % (event, data["review"]["state"])
+
+ if action:
+ if category:
+ category_action = "%s/%s" % (category, action)
+ event_action = "%s/%s" % (event, action)
+
+ return [event]+list(filter(None,
+ [event_action, category, category_action]))
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 872f529f..fca8fcf3 100644
--- a/modules/git_webhooks/gitlab.py
+++ b/modules/git_webhooks/gitlab.py
@@ -74,6 +74,7 @@ class GitLab(object):
event = headers["X-GitLab-Event"].rsplit(" ", 1)[0].lower()
event = event.replace(" ", "_")
+ action = None
event_action = None
category = None
@@ -81,12 +82,15 @@ class GitLab(object):
if "object_attributes" in data:
if "action" in data["object_attributes"]:
- event_action = "%s/%s" % (
- event, data["object_attributes"]["action"])
+ action = 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, event_action)
+
+ if action:
+ if category:
+ category_action = "%s/%s" % (category, action)
+ event_action = "%s/%s" % (event, action)
return [event]+list(filter(None,
[event_action, category, category_action]))