From 8d3064d50cd7146413cbc51c652f335af38f0dfe Mon Sep 17 00:00:00 2001 From: jesopo Date: Wed, 9 Jan 2019 22:45:33 +0000 Subject: [PATCH] Add !ghpull, to get information on a pull request from github (github.py) --- modules/github.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/modules/github.py b/modules/github.py index 982e2ab2..e7b686b3 100644 --- a/modules/github.py +++ b/modules/github.py @@ -8,6 +8,7 @@ COMMIT_RANGE_URL = "https://github.com/%s/compare/%s...%s" CREATE_URL = "https://github.com/%s/tree/%s" API_ISSUE_URL = "https://api.github.com/repos/%s/%s/issues/%s" +API_PULL_URL = "https://api.github.com/repos/%s/%s/pulls/%s" DEFAULT_EVENTS = [ "push", @@ -57,6 +58,30 @@ class Module(ModuleManager.BaseModule): username, repository, number, page.data["title"], ", ".join(labels), url)) + @utils.hook("received.command.ghpull", min_args=1) + def github_pull(self, event): + repo, _, number = event["args_split"][0].partition("#") + username, _, repository = repo.partition("/") + + if not username or not repository or not number: + raise utils.EventError("Please provide username/repo#number") + if not number.isdigit(): + raise utils.EventError("Issue number must be a number") + + page = utils.http.request( + API_PULL_URL % (username, repository, number), + json=True) + if page: + repo_from = page.data["head"]["label"] + to_from = page.data["base"]["label"] + added = self._added(page.data["additions"]) + removed = self._added(page.data["deletions"]) + url = self._short_url(page.data["html_url"]) + + event["stdout"].write("%s/%s pull#%s) [%s/%s] %s %s" % ( + username, repository, number, added, removed, + page.data["title"], url)) + @utils.hook("api.post.github") def github(self, event): payload = event["data"].decode("utf8")