diff options
Diffstat (limited to 'modules/git_webhooks/gitlab.py')
| -rw-r--r-- | modules/git_webhooks/gitlab.py | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/modules/git_webhooks/gitlab.py b/modules/git_webhooks/gitlab.py index 9f481384..c602eb61 100644 --- a/modules/git_webhooks/gitlab.py +++ b/modules/git_webhooks/gitlab.py @@ -55,7 +55,10 @@ class GitLab(object): return False def names(self, data, headers): - full_name = data["project"]["path_with_namespace"] + if "project" in data: + full_name = data["project"]["path_with_namespace"] + else: + full_name = data["project_name"].replace(" ", "") repo_username, repo_name = full_name.split("/", 1) organisation = None @@ -72,8 +75,8 @@ class GitLab(object): def event(self, data, headers): event = headers["X-GitLab-Event"].rsplit(" ", 1)[0].lower() - event = event.replace(" ", "_") + action = None event_action = None @@ -152,7 +155,7 @@ class GitLab(object): number = utils.irc.color("!%s" % data["object_attributes"]["iid"], colors.COLOR_ID) action = data["object_attributes"]["action"] - action_desc = "%s %s" % (ISSUE_ACTIONS[action], number) + action_desc = "%s %s" % (ISSUE_ACTIONS.get(action, action), number) branch = data["object_attributes"]["target_branch"] colored_branch = utils.irc.color(branch, colors.COLOR_BRANCH) @@ -173,9 +176,13 @@ class GitLab(object): return [["[MR] %s %s: %s" % (author, action_desc, pr_title), url]] def issues(self, full_name, data): + if not "action" in data["object_attributes"]: + return + number = utils.irc.color("#%s" % data["object_attributes"]["iid"], colors.COLOR_ID) - action = ISSUE_ACTIONS[data["object_attributes"]["action"]] + action = data["object_attributes"]["action"] + action = ISSUE_ACTIONS.get(action, action) issue_title = data["object_attributes"]["title"] author = utils.irc.bold(data["user"]["username"]) url = data["object_attributes"]["url"] @@ -185,17 +192,18 @@ class GitLab(object): def note(self, full_name, data): type = data["object_attributes"]["noteable_type"] - if type in ["Issue", "MergeRequest"]: - return self.issue_note(full_name, data) + if type == "Issue": + return self._note(full_name, data, data["issue"]) + elif type == "MergeRequest": + return self._note(full_name, data, data["merge_request"]) - def issue_note(self, full_name, data): - number = utils.irc.color("#%s" % data["issue"]["iid"], - colors.COLOR_ID) + def _note(self, full_name, data, object): + number = utils.irc.color("#%s" % object["iid"], colors.COLOR_ID) type = data["object_attributes"]["noteable_type"] type == "issue" if type == "Issue" else "MR" - issue_title = data["issue"]["title"] + title = object["title"] commenter = utils.irc.bold(data["user"]["username"]) url = data["object_attributes"]["url"] return [["[%s] %s commented on %s: %s" % - (type, commenter, number, issue_title), url]] + (type, commenter, number, title), url]] |
