combine github events and their actions to be able to filter by event type and

action. add/change event categories to use these (github.py)
This commit is contained in:
jesopo 2019-01-18 08:08:39 +00:00
parent 5dc5e3fbfd
commit 4981d70be4

View file

@ -14,25 +14,41 @@ DEFAULT_EVENT_CATEGORIES = [
"ping", "code", "pr", "issue", "repo" "ping", "code", "pr", "issue", "repo"
] ]
EVENT_CATEGORIES = { EVENT_CATEGORIES = {
"ping": [ "ping": [
"ping" # new webhook received "ping" # new webhook received
], ],
"code": [ "code": [
"push", "commit_comment" "push", "commit_comment"
], ],
"pr": [ "pr-minimal": [
"pull_request", "pull_request_review", "pull_request_review_commend" "pull_request/opened", "pull_request/closed", "pull_request/reopened"
],
"pr": [
"pull_request/opened", "pull_request/closed", "pull_request/reopened",
"pull_request/edited", "pull_request/assigned",
"pull_request/unassigned", "pull_request_review",
"pull_request_review_comment"
],
"pr-all": [
"pull_request", "pull_request_review", "pull_request_review_comment"
],
"issue-minimal": [
"issues/opened", "issues/closed", "issues/reopened", "issues/deleted"
], ],
"issue": [ "issue": [
"issues/opened", "issues/closed", "issues/reopened", "issues/deleted",
"issues/edited", "issues/assigned", "issues/unassigned", "issue_comment"
],
"issue-all": [
"issues", "issue_comment" "issues", "issue_comment"
], ],
"repo": [ "repo": [
"create", # a repository, branch or tage has been created "create", # a repository, branch or tage has been created
"delete", # same as above but deleted "delete", # same as above but deleted
"release", "release",
"fork" "fork"
], ],
"team": [ "team": [
"membership" "membership"
] ]
} }
@ -43,10 +59,6 @@ COMMENT_ACTIONS = {
"deleted": "deleted a comment" "deleted": "deleted a comment"
} }
ISSUE_ACTIONS = ["opened", "closed", "reopened", "edited", "deleted"]
PULL_REQUEST_ACTIONS = ["opened", "closed", "reopened", "edited",
"synchronized"]
@utils.export("channelset", {"setting": "github-hook", @utils.export("channelset", {"setting": "github-hook",
"help": ("Disable/Enable showing BitBot's github commits in the " "help": ("Disable/Enable showing BitBot's github commits in the "
"current channel"), "array": True}) "current channel"), "array": True})
@ -157,6 +169,10 @@ class Module(ModuleManager.BaseModule):
if "organization" in data: if "organization" in data:
organisation = data["organization"]["login"] organisation = data["organization"]["login"]
event_action = None
if "action" in data:
event_action = "%s/%s" % (github_event, data["action"])
hooks = self.bot.database.channel_settings.find_by_setting( hooks = self.bot.database.channel_settings.find_by_setting(
"github-hook") "github-hook")
targets = [] targets = []
@ -177,7 +193,8 @@ class Module(ModuleManager.BaseModule):
github_events = list(itertools.chain( github_events = list(itertools.chain(
*[EVENT_CATEGORIES[c] for c in event_categories])) *[EVENT_CATEGORIES[c] for c in event_categories]))
if github_event in github_events: if (github_event in github_events or
(event_action and event_action in github_events)):
targets.append([server, channel]) targets.append([server, channel])
if not targets: if not targets:
@ -304,9 +321,6 @@ class Module(ModuleManager.BaseModule):
branch = data["pull_request"]["base"]["ref"] branch = data["pull_request"]["base"]["ref"]
colored_branch = utils.irc.color(branch, utils.consts.LIGHTBLUE) colored_branch = utils.irc.color(branch, utils.consts.LIGHTBLUE)
if not action in PULL_REQUEST_ACTIONS:
return
if action == "opened": if action == "opened":
action_desc = "requested merge into %s" % colored_branch action_desc = "requested merge into %s" % colored_branch
elif action == "closed": elif action == "closed":
@ -352,9 +366,6 @@ class Module(ModuleManager.BaseModule):
action = data["action"] action = data["action"]
action_desc = action action_desc = action
if not action in ISSUE_ACTIONS:
return
issue_title = data["issue"]["title"] issue_title = data["issue"]["title"]
author = utils.irc.bold(data["sender"]["login"]) author = utils.irc.bold(data["sender"]["login"])
url = self._short_url(data["issue"]["html_url"]) url = self._short_url(data["issue"]["html_url"])