2019-06-24 13:52:37 +00:00
|
|
|
from src import ModuleManager, utils
|
2019-06-24 14:20:29 +00:00
|
|
|
from . import colors
|
2018-11-30 21:53:47 +00:00
|
|
|
|
2018-10-26 10:25:28 +00:00
|
|
|
COMMIT_URL = "https://github.com/%s/commit/%s"
|
2018-11-17 22:07:32 +00:00
|
|
|
COMMIT_RANGE_URL = "https://github.com/%s/compare/%s...%s"
|
2018-11-17 20:59:24 +00:00
|
|
|
CREATE_URL = "https://github.com/%s/tree/%s"
|
2019-06-27 10:06:58 +00:00
|
|
|
|
2019-06-27 09:59:22 +00:00
|
|
|
PR_COMMIT_RANGE_URL = "https://github.com/%s/pull/%s/files/%s..%s"
|
2019-06-27 10:06:58 +00:00
|
|
|
PR_COMMIT_URL = "https://github.com/%s/pull/%s/commits/%s"
|
2018-10-26 10:25:28 +00:00
|
|
|
|
2019-01-16 22:26:31 +00:00
|
|
|
DEFAULT_EVENT_CATEGORIES = [
|
|
|
|
"ping", "code", "pr", "issue", "repo"
|
2018-11-17 22:32:44 +00:00
|
|
|
]
|
2019-01-16 22:26:31 +00:00
|
|
|
EVENT_CATEGORIES = {
|
2019-01-18 08:08:39 +00:00
|
|
|
"ping": [
|
2019-01-17 14:31:23 +00:00
|
|
|
"ping" # new webhook received
|
|
|
|
],
|
2019-01-18 08:08:39 +00:00
|
|
|
"code": [
|
2019-01-17 14:31:23 +00:00
|
|
|
"push", "commit_comment"
|
|
|
|
],
|
2019-01-18 08:08:39 +00:00
|
|
|
"pr-minimal": [
|
|
|
|
"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",
|
2019-12-06 07:11:31 +00:00
|
|
|
"pull_request/locked", "pull_request/unlocked",
|
2019-01-18 08:08:39 +00:00
|
|
|
"pull_request_review_comment"
|
|
|
|
],
|
|
|
|
"pr-all": [
|
|
|
|
"pull_request", "pull_request_review", "pull_request_review_comment"
|
|
|
|
],
|
2019-03-15 21:13:39 +00:00
|
|
|
"pr-review-minimal": [
|
|
|
|
"pull_request_review/submitted", "pull_request_review/dismissed"
|
|
|
|
],
|
|
|
|
"pr-review-comment-minimal": [
|
|
|
|
"pull_request_review_comment/created",
|
|
|
|
"pull_request_review_comment/deleted"
|
|
|
|
],
|
2019-01-18 08:08:39 +00:00
|
|
|
"issue-minimal": [
|
2020-01-05 23:20:08 +00:00
|
|
|
"issues/opened", "issues/closed", "issues/reopened", "issues/deleted",
|
|
|
|
"issues/transferred"
|
2019-01-17 14:31:23 +00:00
|
|
|
],
|
|
|
|
"issue": [
|
2019-01-18 08:08:39 +00:00
|
|
|
"issues/opened", "issues/closed", "issues/reopened", "issues/deleted",
|
2019-12-06 07:11:31 +00:00
|
|
|
"issues/edited", "issues/assigned", "issues/unassigned",
|
2020-01-05 23:20:08 +00:00
|
|
|
"issues/locked", "issues/unlocked", "issues/transferred",
|
|
|
|
"issue_comment",
|
2019-01-18 08:08:39 +00:00
|
|
|
],
|
|
|
|
"issue-all": [
|
2019-01-17 14:31:23 +00:00
|
|
|
"issues", "issue_comment"
|
|
|
|
],
|
2019-03-15 21:13:39 +00:00
|
|
|
"issue-comment-minimal": [
|
|
|
|
"issue_comment/created", "issue_comment/deleted"
|
|
|
|
],
|
2019-01-18 08:08:39 +00:00
|
|
|
"repo": [
|
2019-02-15 07:49:07 +00:00
|
|
|
"create", # a repository, branch or tag has been created
|
2019-01-17 14:31:23 +00:00
|
|
|
"delete", # same as above but deleted
|
|
|
|
"release",
|
|
|
|
"fork"
|
|
|
|
],
|
2019-01-18 08:08:39 +00:00
|
|
|
"team": [
|
2019-01-17 14:31:23 +00:00
|
|
|
"membership"
|
2019-01-22 20:49:31 +00:00
|
|
|
],
|
|
|
|
"star": [
|
|
|
|
# "watch" is a misleading name for this event so this add "star" as an
|
|
|
|
# alias for "watch"
|
|
|
|
"watch"
|
2019-01-17 14:31:23 +00:00
|
|
|
]
|
2019-01-16 22:26:31 +00:00
|
|
|
}
|
2018-11-17 22:32:44 +00:00
|
|
|
|
2018-11-06 17:23:27 +00:00
|
|
|
COMMENT_ACTIONS = {
|
2018-11-06 17:05:40 +00:00
|
|
|
"created": "commented",
|
|
|
|
"edited": "edited a comment",
|
|
|
|
"deleted": "deleted a comment"
|
|
|
|
}
|
2019-11-19 12:22:46 +00:00
|
|
|
COMMENT_MAX = 100
|
2018-11-06 17:05:40 +00:00
|
|
|
|
2019-02-07 22:30:50 +00:00
|
|
|
CHECK_RUN_CONCLUSION = {
|
|
|
|
"success": "passed",
|
|
|
|
"failure": "failed",
|
|
|
|
"neutral": "finished",
|
|
|
|
"cancelled": "was cancelled",
|
|
|
|
"timed_out": "timed out",
|
|
|
|
"action_required": "requires action"
|
|
|
|
}
|
|
|
|
CHECK_RUN_FAILURES = ["failure", "cancelled", "timed_out", "action_required"]
|
|
|
|
|
2019-06-24 13:52:37 +00:00
|
|
|
class GitHub(object):
|
2020-10-17 14:07:02 +00:00
|
|
|
def __init__(self, log, exports):
|
2019-06-28 14:29:59 +00:00
|
|
|
self.log = log
|
2020-10-17 14:07:02 +00:00
|
|
|
self.exports = exports
|
2019-06-28 14:29:59 +00:00
|
|
|
|
2019-06-24 17:32:20 +00:00
|
|
|
def is_private(self, data, headers):
|
|
|
|
if "repository" in data:
|
|
|
|
return data["repository"]["private"]
|
|
|
|
return False
|
|
|
|
|
2019-06-24 13:52:37 +00:00
|
|
|
def names(self, data, headers):
|
|
|
|
full_name = None
|
|
|
|
repo_username = None
|
|
|
|
repo_name = None
|
|
|
|
if "repository" in data:
|
|
|
|
full_name = data["repository"]["full_name"]
|
|
|
|
repo_username, repo_name = full_name.split("/", 1)
|
|
|
|
|
|
|
|
organisation = None
|
|
|
|
if "organization" in data:
|
|
|
|
organisation = data["organization"]["login"]
|
2019-06-24 14:20:29 +00:00
|
|
|
return full_name, repo_username, repo_name, organisation
|
2019-01-18 12:05:56 +00:00
|
|
|
|
2019-06-24 13:52:37 +00:00
|
|
|
def branch(self, data, headers):
|
|
|
|
if "ref" in data:
|
|
|
|
return data["ref"].rpartition("/")[2]
|
|
|
|
return None
|
|
|
|
|
|
|
|
def event(self, data, headers):
|
|
|
|
event = headers["X-GitHub-Event"]
|
2019-11-01 13:30:31 +00:00
|
|
|
action = None
|
2019-06-24 13:52:37 +00:00
|
|
|
event_action = None
|
|
|
|
if "action" in data:
|
2019-11-01 13:30:31 +00:00
|
|
|
action = data["action"]
|
|
|
|
|
|
|
|
category = None
|
|
|
|
category_action = None
|
|
|
|
if "review" in data and "state" in data["review"]:
|
|
|
|
category = "%s+%s" % (event, data["review"]["state"])
|
2020-10-17 17:13:52 +00:00
|
|
|
elif "check_run" in data and "status" in data["check_run"]:
|
|
|
|
category = "%s+%s" % (event, data["check_run"]["status"])
|
2019-11-01 13:30:31 +00:00
|
|
|
|
|
|
|
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]))
|
2018-10-05 22:29:59 +00:00
|
|
|
|
2019-06-24 14:20:29 +00:00
|
|
|
def event_categories(self, event):
|
|
|
|
return EVENT_CATEGORIES.get(event, [event])
|
|
|
|
|
|
|
|
def webhook(self, full_name, event, data, headers):
|
2019-10-18 13:03:20 +00:00
|
|
|
out = []
|
2019-06-24 14:20:29 +00:00
|
|
|
if event == "push":
|
2019-10-18 13:03:20 +00:00
|
|
|
out = self.push(full_name, data)
|
2019-06-24 14:20:29 +00:00
|
|
|
elif event == "commit_comment":
|
2019-10-18 13:03:20 +00:00
|
|
|
out = self.commit_comment(full_name, data)
|
2019-06-24 14:20:29 +00:00
|
|
|
elif event == "pull_request":
|
2019-10-18 13:03:20 +00:00
|
|
|
out = self.pull_request(full_name, data)
|
2019-06-24 14:20:29 +00:00
|
|
|
elif event == "pull_request_review":
|
2019-10-18 13:03:20 +00:00
|
|
|
out = self.pull_request_review(full_name, data)
|
2019-06-24 14:20:29 +00:00
|
|
|
elif event == "pull_request_review_comment":
|
2019-10-18 13:03:20 +00:00
|
|
|
out = self.pull_request_review_comment(full_name, data)
|
2019-06-24 14:20:29 +00:00
|
|
|
elif event == "issue_comment":
|
2019-10-18 13:03:20 +00:00
|
|
|
out = self.issue_comment(full_name, data)
|
2019-06-24 14:20:29 +00:00
|
|
|
elif event == "issues":
|
2019-10-18 13:03:20 +00:00
|
|
|
out = self.issues(full_name, data)
|
2019-06-24 14:20:29 +00:00
|
|
|
elif event == "create":
|
2019-10-18 13:03:20 +00:00
|
|
|
out = self.create(full_name, data)
|
2019-06-24 14:20:29 +00:00
|
|
|
elif event == "delete":
|
2019-10-18 13:03:20 +00:00
|
|
|
out = self.delete(full_name, data)
|
2019-06-24 14:20:29 +00:00
|
|
|
elif event == "release":
|
2019-10-18 13:03:20 +00:00
|
|
|
out = self.release(full_name, data)
|
2019-06-24 14:20:29 +00:00
|
|
|
elif event == "check_run":
|
2019-10-18 13:03:20 +00:00
|
|
|
out = self.check_run(data)
|
2019-06-24 14:20:29 +00:00
|
|
|
elif event == "fork":
|
2019-10-18 13:03:20 +00:00
|
|
|
out = self.fork(full_name, data)
|
2019-06-24 14:20:29 +00:00
|
|
|
elif event == "ping":
|
2019-10-18 13:03:20 +00:00
|
|
|
out = self.ping(data)
|
2019-06-24 14:20:29 +00:00
|
|
|
elif event == "membership":
|
2019-10-18 13:03:20 +00:00
|
|
|
out = self.membership(organisation, data)
|
2019-06-24 14:20:29 +00:00
|
|
|
elif event == "watch":
|
2019-10-18 13:03:20 +00:00
|
|
|
out = self.watch(data)
|
|
|
|
return list(zip(out, [None]*len(out)))
|
2019-06-28 14:29:59 +00:00
|
|
|
|
2018-12-11 22:27:04 +00:00
|
|
|
def _short_url(self, url):
|
2019-06-28 14:29:59 +00:00
|
|
|
self.log.debug("git.io shortening: %s" % url)
|
2018-12-14 08:49:37 +00:00
|
|
|
try:
|
|
|
|
page = utils.http.request("https://git.io", method="POST",
|
2019-11-26 13:41:40 +00:00
|
|
|
post_data={"url": url})
|
2018-12-14 08:49:37 +00:00
|
|
|
return page.headers["Location"]
|
|
|
|
except utils.http.HTTPTimeoutException:
|
2019-01-22 22:06:25 +00:00
|
|
|
self.log.warn(
|
2019-05-04 07:26:27 +00:00
|
|
|
"HTTPTimeoutException while waiting for github short URL", [])
|
2018-12-14 08:49:37 +00:00
|
|
|
return url
|
2018-12-11 22:27:04 +00:00
|
|
|
|
2019-02-07 22:30:50 +00:00
|
|
|
def _iso8601(self, s):
|
2020-01-30 21:12:31 +00:00
|
|
|
return utils.datetime.parse.iso8601(s)
|
2019-02-07 22:30:50 +00:00
|
|
|
|
2019-01-26 10:33:45 +00:00
|
|
|
def ping(self, data):
|
2019-01-10 22:24:04 +00:00
|
|
|
return ["Received new webhook"]
|
2019-01-10 22:14:40 +00:00
|
|
|
|
2018-11-16 20:39:37 +00:00
|
|
|
def _change_count(self, n, symbol, color):
|
2018-11-17 08:21:40 +00:00
|
|
|
return utils.irc.color("%s%d" % (symbol, n), color)+utils.irc.bold("")
|
2018-11-16 20:39:37 +00:00
|
|
|
def _added(self, n):
|
2019-06-24 14:20:29 +00:00
|
|
|
return self._change_count(n, "+", colors.COLOR_POSITIVE)
|
2018-11-16 20:39:37 +00:00
|
|
|
def _removed(self, n):
|
2019-06-24 14:20:29 +00:00
|
|
|
return self._change_count(n, "-", colors.COLOR_NEGATIVE)
|
2018-11-16 20:39:37 +00:00
|
|
|
def _modified(self, n):
|
2018-11-26 14:47:47 +00:00
|
|
|
return self._change_count(n, "~", utils.consts.PURPLE)
|
2018-11-16 20:39:37 +00:00
|
|
|
|
|
|
|
def _short_hash(self, hash):
|
2019-11-11 13:37:40 +00:00
|
|
|
return hash[:7]
|
2018-11-16 20:39:37 +00:00
|
|
|
|
2018-11-17 08:15:28 +00:00
|
|
|
def _flat_unique(self, commits, key):
|
|
|
|
return set(itertools.chain(*(commit[key] for commit in commits)))
|
|
|
|
|
2019-01-26 10:33:45 +00:00
|
|
|
def push(self, full_name, data):
|
2018-11-06 13:43:06 +00:00
|
|
|
outputs = []
|
2018-11-18 10:27:19 +00:00
|
|
|
branch = data["ref"].split("/", 2)[2]
|
2019-06-24 14:20:29 +00:00
|
|
|
branch = utils.irc.color(branch, colors.COLOR_BRANCH)
|
2019-04-16 09:20:11 +00:00
|
|
|
author = utils.irc.bold(data["pusher"]["name"])
|
2018-11-18 10:27:19 +00:00
|
|
|
|
2019-06-28 05:51:58 +00:00
|
|
|
range_url = None
|
|
|
|
if len(data["commits"]):
|
|
|
|
first_id = data["before"]
|
|
|
|
last_id = data["commits"][-1]["id"]
|
2019-07-02 06:31:26 +00:00
|
|
|
range_url = COMMIT_RANGE_URL % (full_name, first_id, last_id)
|
2019-06-28 05:51:58 +00:00
|
|
|
|
2019-06-28 06:25:09 +00:00
|
|
|
single_url = COMMIT_URL % (full_name, "%s")
|
2019-02-10 15:06:26 +00:00
|
|
|
|
2019-06-27 10:01:08 +00:00
|
|
|
return self._format_push(branch, author, data["commits"],
|
2019-06-28 05:51:58 +00:00
|
|
|
data["forced"], single_url, range_url)
|
2019-06-27 09:59:22 +00:00
|
|
|
|
2019-06-27 10:06:58 +00:00
|
|
|
def _format_push(self, branch, author, commits, forced, single_url,
|
|
|
|
range_url):
|
2019-06-27 09:59:22 +00:00
|
|
|
outputs = []
|
|
|
|
|
|
|
|
forced_str = ""
|
|
|
|
if forced:
|
|
|
|
forced_str = "%s " % utils.irc.color("force", utils.consts.RED)
|
|
|
|
|
|
|
|
if len(commits) == 0 and forced:
|
2019-04-16 09:20:11 +00:00
|
|
|
outputs.append(
|
2019-06-27 09:59:22 +00:00
|
|
|
"%s %spushed to %s" % (author, forced_str, branch))
|
|
|
|
elif len(commits) <= 3:
|
|
|
|
for commit in commits:
|
2019-03-14 13:58:42 +00:00
|
|
|
hash = commit["id"]
|
2019-06-24 14:20:29 +00:00
|
|
|
hash_colored = utils.irc.color(self._short_hash(hash), colors.COLOR_ID)
|
2019-06-27 09:04:52 +00:00
|
|
|
message = commit["message"].split("\n")[0].strip()
|
2019-06-27 10:06:58 +00:00
|
|
|
url = self._short_url(single_url % hash)
|
2018-11-06 13:43:06 +00:00
|
|
|
|
2019-02-10 15:06:26 +00:00
|
|
|
outputs.append(
|
2019-03-10 10:31:32 +00:00
|
|
|
"%s %spushed %s to %s: %s - %s"
|
2019-06-27 09:59:22 +00:00
|
|
|
% (author, forced_str, hash_colored, branch, message, url))
|
2018-11-16 20:39:37 +00:00
|
|
|
else:
|
2019-03-03 22:49:06 +00:00
|
|
|
outputs.append("%s %spushed %d commits to %s - %s"
|
2019-06-27 10:08:18 +00:00
|
|
|
% (author, forced_str, len(commits), branch,
|
|
|
|
self._short_url(range_url)))
|
2018-11-12 08:35:16 +00:00
|
|
|
|
2018-11-06 13:43:06 +00:00
|
|
|
return outputs
|
|
|
|
|
2019-11-19 12:22:46 +00:00
|
|
|
def _comment(self, s):
|
2019-12-13 06:03:54 +00:00
|
|
|
s_line = s.split("\n")[0].strip()
|
2019-11-19 12:22:46 +00:00
|
|
|
left, right = s_line[:COMMENT_MAX], s_line[COMMENT_MAX:]
|
|
|
|
if not right:
|
|
|
|
return left
|
|
|
|
else:
|
|
|
|
if " " in left:
|
|
|
|
left = left.rsplit(" ", 1)[0]
|
|
|
|
return "%s[...]" % left
|
|
|
|
|
2019-01-26 10:33:45 +00:00
|
|
|
def commit_comment(self, full_name, data):
|
2018-11-06 13:43:06 +00:00
|
|
|
action = data["action"]
|
2019-02-07 15:46:07 +00:00
|
|
|
commit = self._short_hash(data["comment"]["commit_id"])
|
2018-11-12 17:16:17 +00:00
|
|
|
commenter = utils.irc.bold(data["comment"]["user"]["login"])
|
2018-12-11 22:27:04 +00:00
|
|
|
url = self._short_url(data["comment"]["html_url"])
|
2019-06-05 10:40:23 +00:00
|
|
|
return ["[commit/%s] %s %s a comment - %s" % (commit, commenter,
|
|
|
|
action, url)]
|
2018-11-06 13:43:06 +00:00
|
|
|
|
2019-01-26 10:33:45 +00:00
|
|
|
def pull_request(self, full_name, data):
|
2019-06-27 09:59:22 +00:00
|
|
|
raw_number = data["pull_request"]["number"]
|
2019-11-19 17:14:31 +00:00
|
|
|
branch = data["pull_request"]["base"]["ref"]
|
|
|
|
colored_branch = utils.irc.color(branch, colors.COLOR_BRANCH)
|
|
|
|
sender = utils.irc.bold(data["sender"]["login"])
|
|
|
|
|
2020-02-17 11:39:09 +00:00
|
|
|
author = utils.irc.bold(data["sender"]["login"])
|
2019-02-28 17:10:42 +00:00
|
|
|
number = utils.irc.color("#%s" % data["pull_request"]["number"],
|
2019-06-24 14:20:29 +00:00
|
|
|
colors.COLOR_ID)
|
2019-11-19 17:14:31 +00:00
|
|
|
identifier = "%s by %s" % (number, author)
|
|
|
|
|
2018-11-06 13:43:06 +00:00
|
|
|
action = data["action"]
|
2019-11-19 17:14:31 +00:00
|
|
|
action_desc = "%s %s" % (action, identifier)
|
2018-11-20 10:27:28 +00:00
|
|
|
|
|
|
|
if action == "opened":
|
2019-03-07 08:35:29 +00:00
|
|
|
action_desc = "requested %s merge into %s" % (number,
|
|
|
|
colored_branch)
|
2018-11-20 10:27:28 +00:00
|
|
|
elif action == "closed":
|
2018-11-07 11:47:54 +00:00
|
|
|
if data["pull_request"]["merged"]:
|
2019-03-07 08:35:29 +00:00
|
|
|
action_desc = "%s %s into %s" % (
|
2019-11-19 17:14:31 +00:00
|
|
|
utils.irc.color("merged", colors.COLOR_POSITIVE),
|
|
|
|
identifier, colored_branch)
|
2018-11-07 11:47:54 +00:00
|
|
|
else:
|
2019-04-11 12:09:30 +00:00
|
|
|
action_desc = "%s %s" % (
|
2019-11-19 17:14:31 +00:00
|
|
|
utils.irc.color("closed", colors.COLOR_NEGATIVE),
|
|
|
|
identifier)
|
2019-06-07 10:29:11 +00:00
|
|
|
elif action == "ready_for_review":
|
|
|
|
action_desc = "marked %s ready for review" % number
|
2018-11-15 07:06:20 +00:00
|
|
|
elif action == "synchronize":
|
2020-02-12 11:35:18 +00:00
|
|
|
action_desc = "committed to %s" % identifier
|
2018-11-07 08:23:07 +00:00
|
|
|
|
2019-06-27 09:59:22 +00:00
|
|
|
commits_url = data["pull_request"]["commits_url"]
|
2019-11-26 13:41:40 +00:00
|
|
|
commits = utils.http.request(commits_url).json()
|
2019-06-27 09:59:22 +00:00
|
|
|
if commits:
|
|
|
|
seen_before = False
|
|
|
|
new_commits = []
|
2019-11-26 13:41:40 +00:00
|
|
|
for commit in commits:
|
2019-06-27 09:59:22 +00:00
|
|
|
if seen_before:
|
2019-06-27 10:21:09 +00:00
|
|
|
new_commits.append({"id": commit["sha"],
|
2019-06-27 09:59:22 +00:00
|
|
|
"message": commit["commit"]["message"]})
|
|
|
|
elif commit["sha"] == data["before"]:
|
|
|
|
seen_before = True
|
|
|
|
|
|
|
|
range_url = PR_COMMIT_RANGE_URL % (full_name, raw_number,
|
|
|
|
data["before"], data["after"])
|
2019-06-27 10:06:58 +00:00
|
|
|
single_url = PR_COMMIT_URL % (full_name, raw_number, "%s")
|
2019-06-27 09:59:22 +00:00
|
|
|
if new_commits:
|
2020-02-12 15:20:31 +00:00
|
|
|
pr_identifier = "%s (%s)" % (
|
|
|
|
number, data["pull_request"]["title"])
|
|
|
|
outputs = self._format_push(pr_identifier, author,
|
|
|
|
new_commits, False, single_url, range_url)
|
|
|
|
|
2019-06-27 10:27:15 +00:00
|
|
|
for i, output in enumerate(outputs):
|
|
|
|
outputs[i] = "[PR] %s" % output
|
|
|
|
return outputs
|
2019-07-09 08:46:10 +00:00
|
|
|
elif action == "labeled":
|
2019-11-19 17:14:31 +00:00
|
|
|
action_desc = "labled %s as '%s'" % (
|
|
|
|
identifier, data["label"]["name"])
|
2019-11-25 12:01:33 +00:00
|
|
|
elif action == "edited" and "title" in data["changes"]:
|
|
|
|
action_desc = "renamed %s" % identifier
|
2019-06-27 09:59:22 +00:00
|
|
|
|
2019-06-27 09:04:52 +00:00
|
|
|
pr_title = data["pull_request"]["title"]
|
2018-12-11 22:27:04 +00:00
|
|
|
url = self._short_url(data["pull_request"]["html_url"])
|
2019-03-07 08:35:29 +00:00
|
|
|
return ["[PR] %s %s: %s - %s" % (
|
2019-11-19 17:14:31 +00:00
|
|
|
sender, action_desc, pr_title, url)]
|
2018-11-06 13:43:06 +00:00
|
|
|
|
2019-01-26 10:33:45 +00:00
|
|
|
def pull_request_review(self, full_name, data):
|
2019-04-17 09:33:12 +00:00
|
|
|
if not data["action"] == "submitted":
|
|
|
|
return []
|
|
|
|
|
2019-02-21 11:19:36 +00:00
|
|
|
if not "submitted_at" in data["review"]:
|
|
|
|
return []
|
2018-11-07 19:21:59 +00:00
|
|
|
|
2019-03-15 10:33:02 +00:00
|
|
|
state = data["review"]["state"]
|
2019-03-19 16:10:59 +00:00
|
|
|
if state == "commented":
|
|
|
|
return []
|
|
|
|
|
2019-02-28 17:10:42 +00:00
|
|
|
number = utils.irc.color("#%s" % data["pull_request"]["number"],
|
2019-06-24 14:20:29 +00:00
|
|
|
colors.COLOR_ID)
|
2018-11-06 13:43:06 +00:00
|
|
|
action = data["action"]
|
|
|
|
pr_title = data["pull_request"]["title"]
|
2018-12-06 18:35:46 +00:00
|
|
|
reviewer = utils.irc.bold(data["sender"]["login"])
|
2018-12-11 22:27:04 +00:00
|
|
|
url = self._short_url(data["review"]["html_url"])
|
2019-03-15 10:33:02 +00:00
|
|
|
|
|
|
|
state_desc = state
|
|
|
|
if state == "approved":
|
|
|
|
state_desc = "approved changes"
|
|
|
|
elif state == "changes_requested":
|
|
|
|
state_desc = "requested changes"
|
|
|
|
elif state == "dismissed":
|
|
|
|
state_desc = "dismissed a review"
|
|
|
|
|
|
|
|
return ["[PR] %s %s on %s: %s - %s" %
|
2019-03-15 19:28:37 +00:00
|
|
|
(reviewer, state_desc, number, pr_title, url)]
|
2018-11-06 13:43:06 +00:00
|
|
|
|
2019-01-26 10:33:45 +00:00
|
|
|
def pull_request_review_comment(self, full_name, data):
|
2019-02-28 17:10:42 +00:00
|
|
|
number = utils.irc.color("#%s" % data["pull_request"]["number"],
|
2019-06-24 14:20:29 +00:00
|
|
|
colors.COLOR_ID)
|
2018-11-06 13:43:06 +00:00
|
|
|
action = data["action"]
|
|
|
|
pr_title = data["pull_request"]["title"]
|
2019-01-09 22:33:02 +00:00
|
|
|
sender = utils.irc.bold(data["sender"]["login"])
|
2018-12-11 22:27:04 +00:00
|
|
|
url = self._short_url(data["comment"]["html_url"])
|
2019-02-28 23:16:37 +00:00
|
|
|
return ["[PR] %s %s on a review on %s: %s - %s" %
|
2019-02-28 23:15:13 +00:00
|
|
|
(sender, COMMENT_ACTIONS[action], number, pr_title, url)]
|
2018-11-06 13:43:06 +00:00
|
|
|
|
2019-01-26 10:33:45 +00:00
|
|
|
def issues(self, full_name, data):
|
2019-07-09 08:42:42 +00:00
|
|
|
number = utils.irc.color("#%s" % data["issue"]["number"],
|
|
|
|
colors.COLOR_ID)
|
2018-11-06 13:43:06 +00:00
|
|
|
action = data["action"]
|
2019-07-09 08:42:42 +00:00
|
|
|
action_str = "%s %s" % (action, number)
|
|
|
|
if action == "labeled":
|
|
|
|
action_str = "labeled %s as '%s'" % (number, data["label"]["name"])
|
2019-11-25 12:01:33 +00:00
|
|
|
elif action == "edited" and "title" in data["changes"]:
|
|
|
|
action_str = "renamed %s" % number
|
2019-07-09 08:42:42 +00:00
|
|
|
|
2018-11-06 13:43:06 +00:00
|
|
|
issue_title = data["issue"]["title"]
|
2018-11-12 17:16:17 +00:00
|
|
|
author = utils.irc.bold(data["sender"]["login"])
|
2018-12-11 22:27:04 +00:00
|
|
|
url = self._short_url(data["issue"]["html_url"])
|
2019-07-09 08:42:42 +00:00
|
|
|
return ["[issue] %s %s: %s - %s" %
|
|
|
|
(author, action_str, issue_title, url)]
|
2019-01-26 10:33:45 +00:00
|
|
|
def issue_comment(self, full_name, data):
|
2019-01-13 01:34:07 +00:00
|
|
|
if "changes" in data:
|
|
|
|
# don't show this event when nothing has actually changed
|
|
|
|
if data["changes"]["body"]["from"] == data["comment"]["body"]:
|
|
|
|
return
|
|
|
|
|
2019-06-24 14:20:29 +00:00
|
|
|
number = utils.irc.color("#%s" % data["issue"]["number"], colors.COLOR_ID)
|
2018-11-06 13:43:06 +00:00
|
|
|
action = data["action"]
|
2018-11-06 15:01:02 +00:00
|
|
|
issue_title = data["issue"]["title"]
|
2019-03-01 21:12:46 +00:00
|
|
|
type = "PR" if "pull_request" in data["issue"] else "issue"
|
2020-02-10 10:37:27 +00:00
|
|
|
title = data["issue"]["title"]
|
2019-02-26 21:55:34 +00:00
|
|
|
commenter = utils.irc.bold(data["sender"]["login"])
|
2018-12-11 22:27:04 +00:00
|
|
|
url = self._short_url(data["comment"]["html_url"])
|
2019-11-19 12:22:46 +00:00
|
|
|
|
|
|
|
body = ""
|
|
|
|
if not action == "deleted":
|
2019-11-19 12:24:30 +00:00
|
|
|
body = ": %s" % self._comment(data["comment"]["body"])
|
2019-11-19 12:22:46 +00:00
|
|
|
|
2020-02-10 10:37:27 +00:00
|
|
|
return ["[%s] %s %s on %s (%s)%s - %s" %
|
|
|
|
(type, commenter, COMMENT_ACTIONS[action], number, title, body,
|
|
|
|
url)]
|
2018-11-17 20:59:24 +00:00
|
|
|
|
2019-01-26 10:33:45 +00:00
|
|
|
def create(self, full_name, data):
|
2018-11-19 21:36:24 +00:00
|
|
|
ref = data["ref"]
|
2019-06-24 14:20:29 +00:00
|
|
|
ref_color = utils.irc.color(ref, colors.COLOR_BRANCH)
|
2018-11-19 21:34:36 +00:00
|
|
|
type = data["ref_type"]
|
2018-11-17 21:06:27 +00:00
|
|
|
sender = utils.irc.bold(data["sender"]["login"])
|
2018-12-11 22:27:04 +00:00
|
|
|
url = self._short_url(CREATE_URL % (full_name, ref))
|
2018-11-19 21:36:24 +00:00
|
|
|
return ["%s created a %s: %s - %s" % (sender, type, ref_color, url)]
|
2018-11-17 21:10:03 +00:00
|
|
|
|
2019-01-26 10:33:45 +00:00
|
|
|
def delete(self, full_name, data):
|
2018-11-17 21:10:03 +00:00
|
|
|
ref = data["ref"]
|
2019-06-24 14:20:29 +00:00
|
|
|
ref_color = utils.irc.color(ref, colors.COLOR_BRANCH)
|
2018-11-17 21:10:03 +00:00
|
|
|
type = data["ref_type"]
|
|
|
|
sender = utils.irc.bold(data["sender"]["login"])
|
2019-06-22 21:42:52 +00:00
|
|
|
return ["%s deleted a %s: %s" % (sender, type, ref_color)]
|
2018-11-17 21:21:32 +00:00
|
|
|
|
2019-01-26 10:33:45 +00:00
|
|
|
def release(self, full_name, data):
|
2018-11-17 21:21:32 +00:00
|
|
|
action = data["action"]
|
2018-11-17 22:17:14 +00:00
|
|
|
tag = data["release"]["tag_name"]
|
2018-11-17 21:21:32 +00:00
|
|
|
name = data["release"]["name"] or ""
|
|
|
|
if name:
|
2019-05-12 21:09:19 +00:00
|
|
|
name = ": %s" % name
|
2018-11-17 21:21:32 +00:00
|
|
|
author = utils.irc.bold(data["release"]["author"]["login"])
|
2018-12-11 22:27:04 +00:00
|
|
|
url = self._short_url(data["release"]["html_url"])
|
2018-11-17 21:44:52 +00:00
|
|
|
return ["%s %s a release%s - %s" % (author, action, name, url)]
|
2018-12-10 17:17:40 +00:00
|
|
|
|
2019-02-07 22:30:50 +00:00
|
|
|
def check_run(self, data):
|
|
|
|
name = data["check_run"]["name"]
|
|
|
|
commit = self._short_hash(data["check_run"]["head_sha"])
|
|
|
|
commit = utils.irc.color(commit, utils.consts.LIGHTBLUE)
|
|
|
|
|
2020-10-18 00:37:05 +00:00
|
|
|
pr = ""
|
|
|
|
if ("pull_requests" in data["check_run"] and
|
|
|
|
data["check_run"]["pull_requests"]):
|
|
|
|
pr_num = data["check_run"]["pull_requests"][0]["number"]
|
|
|
|
pr = "/PR%s" % utils.irc.color("#%s" % pr_num, colors.COLOR_ID)
|
|
|
|
|
2019-02-07 22:30:50 +00:00
|
|
|
url = ""
|
|
|
|
if data["check_run"]["details_url"]:
|
|
|
|
url = data["check_run"]["details_url"]
|
2020-03-08 14:14:00 +00:00
|
|
|
url = " - %s" % self.exports.get("shorturl-any")(url)
|
2019-02-07 22:30:50 +00:00
|
|
|
|
|
|
|
duration = ""
|
|
|
|
if data["check_run"]["completed_at"]:
|
|
|
|
started_at = self._iso8601(data["check_run"]["started_at"])
|
|
|
|
completed_at = self._iso8601(data["check_run"]["completed_at"])
|
2019-02-07 22:59:50 +00:00
|
|
|
if completed_at > started_at:
|
|
|
|
seconds = (completed_at-started_at).total_seconds()
|
2020-01-30 21:12:31 +00:00
|
|
|
duration = " in %s" % utils.datetime.format.to_pretty_time(
|
|
|
|
seconds)
|
2019-02-07 22:30:50 +00:00
|
|
|
|
|
|
|
status = data["check_run"]["status"]
|
|
|
|
status_str = ""
|
|
|
|
if status == "queued":
|
2019-02-07 23:05:29 +00:00
|
|
|
status_str = utils.irc.bold("queued")
|
2019-02-07 22:30:50 +00:00
|
|
|
elif status == "in_progress":
|
|
|
|
status_str = utils.irc.bold("started")
|
|
|
|
elif status == "completed":
|
|
|
|
conclusion = data["check_run"]["conclusion"]
|
2019-06-24 14:20:29 +00:00
|
|
|
conclusion_color = colors.COLOR_POSITIVE
|
2019-02-07 22:30:50 +00:00
|
|
|
if conclusion in CHECK_RUN_FAILURES:
|
2019-06-24 14:20:29 +00:00
|
|
|
conclusion_color = colors.COLOR_NEGATIVE
|
2019-02-07 22:30:50 +00:00
|
|
|
if conclusion == "neutral":
|
2019-06-24 14:20:29 +00:00
|
|
|
conclusion_color = colors.COLOR_NEUTRAL
|
2019-02-07 22:30:50 +00:00
|
|
|
|
|
|
|
status_str = utils.irc.color(
|
|
|
|
CHECK_RUN_CONCLUSION[conclusion], conclusion_color)
|
|
|
|
|
2020-10-18 00:37:05 +00:00
|
|
|
return ["[build @%s%s] %s: %s%s%s" % (
|
|
|
|
commit, pr, name, status_str, duration, url)]
|
2018-12-10 18:47:54 +00:00
|
|
|
|
2019-01-26 10:33:45 +00:00
|
|
|
def fork(self, full_name, data):
|
2018-12-10 18:47:54 +00:00
|
|
|
forker = utils.irc.bold(data["sender"]["login"])
|
|
|
|
fork_full_name = utils.irc.color(data["forkee"]["full_name"],
|
|
|
|
utils.consts.LIGHTBLUE)
|
2018-12-11 22:27:04 +00:00
|
|
|
url = self._short_url(data["forkee"]["html_url"])
|
2018-12-10 18:47:54 +00:00
|
|
|
return ["%s forked into %s - %s" %
|
|
|
|
(forker, fork_full_name, url)]
|
2019-01-16 22:13:38 +00:00
|
|
|
|
2019-01-26 10:33:45 +00:00
|
|
|
def membership(self, organisation, data):
|
2019-01-16 22:13:38 +00:00
|
|
|
return ["%s %s %s to team %s" %
|
2019-01-16 22:14:26 +00:00
|
|
|
(data["sender"]["login"], data["action"], data["member"]["login"],
|
2019-01-16 22:13:38 +00:00
|
|
|
data["team"]["name"])]
|
2019-01-22 20:49:31 +00:00
|
|
|
|
2019-01-26 10:33:45 +00:00
|
|
|
def watch(self, data):
|
2019-01-22 20:50:44 +00:00
|
|
|
return ["%s starred the repository" % data["sender"]["login"]]
|