aboutsummaryrefslogtreecommitdiff
path: root/modules/git_webhooks/github.py
diff options
context:
space:
mode:
Diffstat (limited to 'modules/git_webhooks/github.py')
-rw-r--r--modules/git_webhooks/github.py55
1 files changed, 40 insertions, 15 deletions
diff --git a/modules/git_webhooks/github.py b/modules/git_webhooks/github.py
index cdf9016d..b7f13805 100644
--- a/modules/git_webhooks/github.py
+++ b/modules/git_webhooks/github.py
@@ -71,6 +71,7 @@ COMMENT_ACTIONS = {
"edited": "edited a comment",
"deleted": "deleted a comment"
}
+COMMENT_MAX = 100
CHECK_RUN_CONCLUSION = {
"success": "passed",
@@ -170,7 +171,7 @@ class GitHub(object):
self.log.debug("git.io shortening: %s" % url)
try:
page = utils.http.request("https://git.io", method="POST",
- post_data={"url": url}, detect_encoding=False)
+ post_data={"url": url})
return page.headers["Location"]
except utils.http.HTTPTimeoutException:
self.log.warn(
@@ -243,6 +244,16 @@ class GitHub(object):
return outputs
+ def _comment(self, s):
+ s_line = utils.parse.line_normalise(s)
+ 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
+
def commit_comment(self, full_name, data):
action = data["action"]
commit = self._short_hash(data["comment"]["commit_id"])
@@ -253,13 +264,17 @@ class GitHub(object):
def pull_request(self, full_name, data):
raw_number = data["pull_request"]["number"]
+ branch = data["pull_request"]["base"]["ref"]
+ colored_branch = utils.irc.color(branch, colors.COLOR_BRANCH)
+ sender = utils.irc.bold(data["sender"]["login"])
+
+ author = utils.irc.bold(data["pull_request"]["user"]["login"])
number = utils.irc.color("#%s" % data["pull_request"]["number"],
colors.COLOR_ID)
+ identifier = "%s by %s" % (number, author)
+
action = data["action"]
- action_desc = "%s %s" % (action, number)
- branch = data["pull_request"]["base"]["ref"]
- colored_branch = utils.irc.color(branch, colors.COLOR_BRANCH)
- author = utils.irc.bold(data["sender"]["login"])
+ action_desc = "%s %s" % (action, identifier)
if action == "opened":
action_desc = "requested %s merge into %s" % (number,
@@ -267,22 +282,23 @@ class GitHub(object):
elif action == "closed":
if data["pull_request"]["merged"]:
action_desc = "%s %s into %s" % (
- utils.irc.color("merged", colors.COLOR_POSITIVE), number,
- colored_branch)
+ utils.irc.color("merged", colors.COLOR_POSITIVE),
+ identifier, colored_branch)
else:
action_desc = "%s %s" % (
- utils.irc.color("closed", colors.COLOR_NEGATIVE), number)
+ utils.irc.color("closed", colors.COLOR_NEGATIVE),
+ identifier)
elif action == "ready_for_review":
action_desc = "marked %s ready for review" % number
elif action == "synchronize":
action_desc = "committed to %s" % number
commits_url = data["pull_request"]["commits_url"]
- commits = utils.http.request(commits_url, json=True)
+ commits = utils.http.request(commits_url).json()
if commits:
seen_before = False
new_commits = []
- for commit in commits.data:
+ for commit in commits:
if seen_before:
new_commits.append({"id": commit["sha"],
"message": commit["commit"]["message"]})
@@ -299,12 +315,15 @@ class GitHub(object):
outputs[i] = "[PR] %s" % output
return outputs
elif action == "labeled":
- action_desc = "labled %s as '%s'" % (number, data["label"]["name"])
+ action_desc = "labled %s as '%s'" % (
+ identifier, data["label"]["name"])
+ elif action == "edited" and "title" in data["changes"]:
+ action_desc = "renamed %s" % identifier
pr_title = data["pull_request"]["title"]
url = self._short_url(data["pull_request"]["html_url"])
return ["[PR] %s %s: %s - %s" % (
- author, action_desc, pr_title, url)]
+ sender, action_desc, pr_title, url)]
def pull_request_review(self, full_name, data):
if not data["action"] == "submitted":
@@ -352,6 +371,8 @@ class GitHub(object):
action_str = "%s %s" % (action, number)
if action == "labeled":
action_str = "labeled %s as '%s'" % (number, data["label"]["name"])
+ elif action == "edited" and "title" in data["changes"]:
+ action_str = "renamed %s" % number
issue_title = data["issue"]["title"]
author = utils.irc.bold(data["sender"]["login"])
@@ -370,9 +391,13 @@ class GitHub(object):
type = "PR" if "pull_request" in data["issue"] else "issue"
commenter = utils.irc.bold(data["sender"]["login"])
url = self._short_url(data["comment"]["html_url"])
- return ["[%s] %s %s on %s: %s - %s" %
- (type, commenter, COMMENT_ACTIONS[action], number, issue_title,
- url)]
+
+ body = ""
+ if not action == "deleted":
+ body = ": %s" % self._comment(data["comment"]["body"])
+
+ return ["[%s] %s %s on %s%s - %s" %
+ (type, commenter, COMMENT_ACTIONS[action], number, body, url)]
def create(self, full_name, data):
ref = data["ref"]