git_webhooks/github.py: handle url shortening like everyone else

This commit is contained in:
David Schultz 2022-01-20 13:43:26 -06:00
parent d58a77ecb9
commit 9e4e4925c0
No known key found for this signature in database
GPG key ID: F6DED672FFFD5E5E

View file

@ -172,13 +172,7 @@ class GitHub(object):
out = self.membership(organisation, data)
elif event == "watch":
out = self.watch(data)
return list(zip(out, [None]*len(out)))
def _short_url(self, url):
# TODO: find an alternative to git.io
# see https://github.com/jesopo/bitbot/issues/338
# ~ examknow 1/19/2022
return url
return out
def _iso8601(self, s):
return utils.datetime.parse.iso8601(s)
@ -234,15 +228,14 @@ class GitHub(object):
hash = commit["id"]
hash_colored = utils.irc.color(self._short_hash(hash), colors.COLOR_ID)
message = commit["message"].split("\n")[0].strip()
url = self._short_url(single_url % hash)
url = single_url % hash
outputs.append(
"%s %spushed %s to %s: %s - %s"
% (author, forced_str, hash_colored, branch, message, url))
else:
outputs.append("%s %spushed %d commits to %s - %s"
% (author, forced_str, len(commits), branch,
self._short_url(range_url)))
outputs.append(("%s %spushed %d commits to %s"
% (author, forced_str, len(commits), branch), url))
return outputs
@ -260,9 +253,9 @@ class GitHub(object):
action = data["action"]
commit = self._short_hash(data["comment"]["commit_id"])
commenter = utils.irc.bold(data["comment"]["user"]["login"])
url = self._short_url(data["comment"]["html_url"])
return ["[commit/%s] %s %s a comment - %s" % (commit, commenter,
action, url)]
url = data["comment"]["html_url"]
return [("[commit/%s] %s %s a comment" % (commit, commenter,
action), url)]
def pull_request(self, full_name, data):
raw_number = data["pull_request"]["number"]
@ -326,9 +319,9 @@ class GitHub(object):
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" % (
sender, action_desc, pr_title, url)]
url = data["pull_request"]["html_url"]
return ["[PR] %s %s: %s" % (
sender, action_desc, pr_title), url]
def pull_request_review(self, full_name, data):
if not data["action"] == "submitted":
@ -346,7 +339,7 @@ class GitHub(object):
action = data["action"]
pr_title = data["pull_request"]["title"]
reviewer = utils.irc.bold(data["sender"]["login"])
url = self._short_url(data["review"]["html_url"])
url = data["review"]["html_url"]
state_desc = state
if state == "approved":
@ -356,8 +349,8 @@ class GitHub(object):
elif state == "dismissed":
state_desc = "dismissed a review"
return ["[PR] %s %s on %s: %s - %s" %
(reviewer, state_desc, number, pr_title, url)]
return [("[PR] %s %s on %s: %s" %
(reviewer, state_desc, number, pr_title), url)]
def pull_request_review_comment(self, full_name, data):
number = utils.irc.color("#%s" % data["pull_request"]["number"],
@ -365,9 +358,9 @@ class GitHub(object):
action = data["action"]
pr_title = data["pull_request"]["title"]
sender = utils.irc.bold(data["sender"]["login"])
url = self._short_url(data["comment"]["html_url"])
return ["[PR] %s %s on a review on %s: %s - %s" %
(sender, COMMENT_ACTIONS[action], number, pr_title, url)]
url = data["comment"]["html_url"]
return [("[PR] %s %s on a review on %s: %s" %
(sender, COMMENT_ACTIONS[action], number, pr_title), url)]
def issues(self, full_name, data):
number = utils.irc.color("#%s" % data["issue"]["number"],
@ -381,9 +374,9 @@ class GitHub(object):
issue_title = data["issue"]["title"]
author = utils.irc.bold(data["sender"]["login"])
url = self._short_url(data["issue"]["html_url"])
return ["[issue] %s %s: %s - %s" %
(author, action_str, issue_title, url)]
url = data["issue"]["html_url"]
return [("[issue] %s %s: %s" %
(author, action_str, issue_title), url)]
def issue_comment(self, full_name, data):
if "changes" in data:
# don't show this event when nothing has actually changed
@ -396,23 +389,22 @@ class GitHub(object):
type = "PR" if "pull_request" in data["issue"] else "issue"
title = data["issue"]["title"]
commenter = utils.irc.bold(data["sender"]["login"])
url = self._short_url(data["comment"]["html_url"])
url = data["comment"]["html_url"]
body = ""
if not action == "deleted":
body = ": %s" % self._comment(data["comment"]["body"])
return ["[%s] %s %s on %s (%s)%s - %s" %
(type, commenter, COMMENT_ACTIONS[action], number, title, body,
url)]
return [("[%s] %s %s on %s (%s)%s" %
(type, commenter, COMMENT_ACTIONS[action], number, title, body), url)]
def create(self, full_name, data):
ref = data["ref"]
ref_color = utils.irc.color(ref, colors.COLOR_BRANCH)
type = data["ref_type"]
sender = utils.irc.bold(data["sender"]["login"])
url = self._short_url(CREATE_URL % (full_name, ref))
return ["%s created a %s: %s - %s" % (sender, type, ref_color, url)]
url = CREATE_URL % (full_name, ref)
return [("%s created a %s: %s" % (sender, type, ref_color), url)]
def delete(self, full_name, data):
ref = data["ref"]
@ -428,8 +420,8 @@ class GitHub(object):
if name:
name = ": %s" % name
author = utils.irc.bold(data["release"]["author"]["login"])
url = self._short_url(data["release"]["html_url"])
return ["%s %s a release%s - %s" % (author, action, name, url)]
url = data["release"]["html_url"]
return [("%s %s a release%s" % (author, action, name), url)]
def check_suite(self, full_name, data):
suite = data["check_suite"]
@ -442,8 +434,7 @@ class GitHub(object):
if suite["pull_requests"]:
pr_num = suite["pull_requests"][0]["number"]
pr = "/PR%s" % utils.irc.color("#%s" % pr_num, colors.COLOR_ID)
url = self._short_url(PR_URL % (full_name, pr_num))
url = " - %s" % url
url = PR_URL % (full_name, pr_num)
name = suite["app"]["name"]
conclusion = suite["conclusion"]
@ -455,16 +446,16 @@ class GitHub(object):
seconds = (updated_at-created_at).total_seconds()
duration = utils.datetime.format.to_pretty_time(seconds)
return ["[build @%s%s] %s: %s in %s%s" % (
commit, pr, name, conclusion, duration, url)]
return [("[build @%s%s] %s: %s in %s" % (
commit, pr, name, conclusion, duration), url)]
def fork(self, full_name, data):
forker = utils.irc.bold(data["sender"]["login"])
fork_full_name = utils.irc.color(data["forkee"]["full_name"],
utils.consts.LIGHTBLUE)
url = self._short_url(data["forkee"]["html_url"])
return ["%s forked into %s - %s" %
(forker, fork_full_name, url)]
url = data["forkee"]["html_url"]
return [("%s forked into %s" %
(forker, fork_full_name), url)]
def membership(self, organisation, data):
return ["%s %s %s to team %s" %