Shorten github urls in github.py
This commit is contained in:
parent
793d234a0b
commit
22c38ad083
1 changed files with 17 additions and 11 deletions
|
@ -104,6 +104,11 @@ class Module(ModuleManager.BaseModule):
|
|||
|
||||
return ""
|
||||
|
||||
def _short_url(self, url):
|
||||
page = utils.http.get_url("https://git.io", method="POST",
|
||||
post_data={"url": url})
|
||||
return page.headers["Location"]
|
||||
|
||||
def _change_count(self, n, symbol, color):
|
||||
return utils.irc.color("%s%d" % (symbol, n), color)+utils.irc.bold("")
|
||||
def _added(self, n):
|
||||
|
@ -130,7 +135,7 @@ class Module(ModuleManager.BaseModule):
|
|||
message = commit["message"].split("\n")[0].strip()
|
||||
author = commit["author"]["name"] or commit["author"]["login"]
|
||||
author = utils.irc.bold(author)
|
||||
url = COMMIT_URL % (full_name, id)
|
||||
url = self._short_url(COMMIT_URL % (full_name, id))
|
||||
|
||||
added = self._added(len(commit["added"]))
|
||||
removed = self._removed(len(commit["removed"]))
|
||||
|
@ -142,7 +147,8 @@ class Module(ModuleManager.BaseModule):
|
|||
first_id = self._short_hash(data["before"])
|
||||
last_id = self._short_hash(data["commits"][-1]["id"])
|
||||
pusher = utils.irc.bold(data["pusher"]["name"])
|
||||
url = COMMIT_RANGE_URL % (full_name, first_id, last_id)
|
||||
url = self._short_url(
|
||||
COMMIT_RANGE_URL % (full_name, first_id, last_id))
|
||||
|
||||
commits = data["commits"]
|
||||
added = self._added(len(self._flat_unique(commits, "added")))
|
||||
|
@ -161,7 +167,7 @@ class Module(ModuleManager.BaseModule):
|
|||
action = data["action"]
|
||||
commit = data["commit_id"][:8]
|
||||
commenter = utils.irc.bold(data["comment"]["user"]["login"])
|
||||
url = data["comment"]["html_url"]
|
||||
url = self._short_url(data["comment"]["html_url"])
|
||||
return ["[commit/%s] %s commented" % (commit, commenter, action)]
|
||||
|
||||
def pull_request(self, event, full_name, data):
|
||||
|
@ -189,7 +195,7 @@ class Module(ModuleManager.BaseModule):
|
|||
|
||||
pr_title = data["pull_request"]["title"]
|
||||
author = utils.irc.bold(data["sender"]["login"])
|
||||
url = data["pull_request"]["html_url"]
|
||||
url = self._short_url(data["pull_request"]["html_url"])
|
||||
return ["[pr] %s %s: %s - %s" % (author, action_desc, pr_title, url)]
|
||||
|
||||
def pull_request_review(self, event, full_name, data):
|
||||
|
@ -199,7 +205,7 @@ class Module(ModuleManager.BaseModule):
|
|||
action = data["action"]
|
||||
pr_title = data["pull_request"]["title"]
|
||||
reviewer = utils.irc.bold(data["sender"]["login"])
|
||||
url = data["review"]["html_url"]
|
||||
url = self._short_url(data["review"]["html_url"])
|
||||
return ["[pr] %s %s a review on: %s - %s" % (reviewer, action, pr_title,
|
||||
url)]
|
||||
|
||||
|
@ -207,7 +213,7 @@ class Module(ModuleManager.BaseModule):
|
|||
action = data["action"]
|
||||
pr_title = data["pull_request"]["title"]
|
||||
commenter = data["comment"]["user"]["login"]
|
||||
url = data["comment"]["html_url"]
|
||||
url = self._short_url(data["comment"]["html_url"])
|
||||
return ["[pr] %s %s on a review: %s - %s" %
|
||||
(commenter, COMMENT_ACTIONS[action], pr_title, url)]
|
||||
|
||||
|
@ -221,7 +227,7 @@ class Module(ModuleManager.BaseModule):
|
|||
|
||||
issue_title = data["issue"]["title"]
|
||||
author = utils.irc.bold(data["sender"]["login"])
|
||||
url = data["issue"]["html_url"]
|
||||
url = self._short_url(data["issue"]["html_url"])
|
||||
return ["[issue] %s %s: %s - %s" %
|
||||
(author, action_desc, issue_title, url)]
|
||||
def issue_comment(self, event, full_name, data):
|
||||
|
@ -229,7 +235,7 @@ class Module(ModuleManager.BaseModule):
|
|||
issue_title = data["issue"]["title"]
|
||||
type = "pr" if "pull_request" in data["issue"] else "issue"
|
||||
commenter = utils.irc.bold(data["comment"]["user"]["login"])
|
||||
url = data["comment"]["html_url"]
|
||||
url = self._short_url(data["comment"]["html_url"])
|
||||
return ["[%s] %s %s on: %s - %s" %
|
||||
(type, commenter, COMMENT_ACTIONS[action], issue_title,
|
||||
url)]
|
||||
|
@ -239,7 +245,7 @@ class Module(ModuleManager.BaseModule):
|
|||
ref_color = utils.irc.color(ref, utils.consts.LIGHTBLUE)
|
||||
type = data["ref_type"]
|
||||
sender = utils.irc.bold(data["sender"]["login"])
|
||||
url = CREATE_URL % (full_name, ref)
|
||||
url = self._short_url(CREATE_URL % (full_name, ref))
|
||||
return ["%s created a %s: %s - %s" % (sender, type, ref_color, url)]
|
||||
|
||||
def delete(self, event, full_name, data):
|
||||
|
@ -255,7 +261,7 @@ class Module(ModuleManager.BaseModule):
|
|||
if name:
|
||||
name = ": %s"
|
||||
author = utils.irc.bold(data["release"]["author"]["login"])
|
||||
url = data["release"]["html_url"]
|
||||
url = self._short_url(data["release"]["html_url"])
|
||||
return ["%s %s a release%s - %s" % (author, action, name, url)]
|
||||
|
||||
def status(self, event, full_name, data):
|
||||
|
@ -270,6 +276,6 @@ class Module(ModuleManager.BaseModule):
|
|||
forker = utils.irc.bold(data["sender"]["login"])
|
||||
fork_full_name = utils.irc.color(data["forkee"]["full_name"],
|
||||
utils.consts.LIGHTBLUE)
|
||||
url = data["forkee"]["html_url"]
|
||||
url = self._short_url(data["forkee"]["html_url"])
|
||||
return ["%s forked into %s - %s" %
|
||||
(forker, fork_full_name, url)]
|
||||
|
|
Loading…
Reference in a new issue