diff options
author | kongr45gpen <electrovesta@gmail.com> | 2016-07-17 22:19:27 +0300 |
---|---|---|
committer | kongr45gpen <electrovesta@gmail.com> | 2016-07-17 22:20:19 +0300 |
commit | 8dd785e693406693ca2a1b92efecd1d9e53e17d9 (patch) | |
tree | 8ab21b180f487ffbcbcb9b85db8119f47f432237 | |
parent | dd39db4330b1dc762c3e0f68f43cfb7b65651aef (diff) | |
download | supybot_github-8dd785e693406693ca2a1b92efecd1d9e53e17d9.tar.gz supybot_github-8dd785e693406693ca2a1b92efecd1d9e53e17d9.tar.bz2 supybot_github-8dd785e693406693ca2a1b92efecd1d9e53e17d9.zip |
Add support for Github releases
-rw-r--r-- | __init__.py | 2 | ||||
-rw-r--r-- | local/handler/GithubHandler.py | 3 | ||||
-rw-r--r-- | local/handler/ReleaseHandler.py | 13 | ||||
-rw-r--r-- | local/theme/DefaultTheme.py | 12 | ||||
-rw-r--r-- | local/utility.py | 3 | ||||
-rw-r--r-- | samples/release.json | 149 | ||||
-rw-r--r-- | test.py | 13 |
7 files changed, 194 insertions, 1 deletions
diff --git a/__init__.py b/__init__.py index 674e0aa..52060c2 100644 --- a/__init__.py +++ b/__init__.py @@ -36,6 +36,7 @@ import local.handler.IssueHandler import local.handler.StatusHandler import local.handler.TravisHandler import local.handler.MessageHandler +import local.handler.ReleaseHandler import local.handler.CreateDeleteHandler import local.handler.IssueCommentHandler import local.theme.Theme @@ -51,6 +52,7 @@ reload(local.handler.IssueHandler) reload(local.handler.StatusHandler) reload(local.handler.TravisHandler) reload(local.handler.MessageHandler) +reload(local.handler.ReleaseHandler) reload(local.handler.CreateDeleteHandler) reload(local.handler.IssueCommentHandler) reload(local.theme.Theme) diff --git a/local/handler/GithubHandler.py b/local/handler/GithubHandler.py index 8788ea3..ffb5010 100644 --- a/local/handler/GithubHandler.py +++ b/local/handler/GithubHandler.py @@ -33,6 +33,7 @@ import IssueHandler import StatusHandler import TravisHandler import MessageHandler +import ReleaseHandler import CreateDeleteHandler import IssueCommentHandler @@ -166,6 +167,8 @@ class GithubHandler(BaseHTTPServer.BaseHTTPRequestHandler): IssueHandler.handle(data, theme) elif 'ref_type' in data: CreateDeleteHandler.handle(data, theme) + elif 'release' in data: + ReleaseHandler.handle(data, theme) elif 'zen' in data: PingHandler.handle(data, theme) elif 'message' in data: diff --git a/local/handler/ReleaseHandler.py b/local/handler/ReleaseHandler.py new file mode 100644 index 0000000..4c13a69 --- /dev/null +++ b/local/handler/ReleaseHandler.py @@ -0,0 +1,13 @@ +from ..utility import * + +def handle(data, theme): + theme.release( + action = data['action'], + author = data['release']['author']['login'], + commit = data['release']['target_commitish'], + description = data['release']['body'], + name = data['release']['name'], + prerelease = data['release']['prerelease'], + tag = data['release']['tag_name'], + url = getShortURL(data['release']['html_url']) + ) diff --git a/local/theme/DefaultTheme.py b/local/theme/DefaultTheme.py index 55d0863..3f29022 100644 --- a/local/theme/DefaultTheme.py +++ b/local/theme/DefaultTheme.py @@ -103,6 +103,18 @@ class DefaultTheme(Theme): ": %s" % maxLen(comment, 70) if comment else '' )) + def release(self, author, action, name, tag, description, commit, prerelease, url): + self.msgs.append( "%s: %s %s%s %s (%s): %s %s" % ( + self.repo(), + ircutils.mircColor(author, "green"), + colorAction(action), + " %s" % (ircutils.mircColor('prerelease', "orange")) if prerelease else '', + ircutils.bold(name), + ircutils.mircColor(tag, "dark gray"), + maxLen(description, 100), + self.enclose(url) + )) + def wikiPush(self, actor, count, url): self.msgs.append( "%s: %s modified %s wiki %s %s:" % ( self.repo(), diff --git a/local/utility.py b/local/utility.py index ef37c28..a1d41bd 100644 --- a/local/utility.py +++ b/local/utility.py @@ -80,7 +80,8 @@ def maxLen(msg, maxn=400, splitLines=True): def colorAction(action): """Give an action string (e.g. created, edited) and get a nice IRC colouring""" - if action in [ "created", "opened", "tagged", "success", "passed", "fixed" ]: + if action in [ "created", "opened", "tagged", "success", "passed", "fixed", + "published" ]: return ircutils.bold(ircutils.mircColor(action, "green")) if action in [ "deleted" ,"closed", "re-tagged", "deleted tag", "failed", "errored", "failure", "still failing", diff --git a/samples/release.json b/samples/release.json new file mode 100644 index 0000000..ebc3f5c --- /dev/null +++ b/samples/release.json @@ -0,0 +1,149 @@ +{ + "action": "published", + "release": { + "url": "https://api.github.com/repos/kongr45gpen/myproject/releases/3676458", + "assets_url": "https://api.github.com/repos/kongr45gpen/myproject/releases/3676458/assets", + "upload_url": "https://uploads.github.com/repos/kongr45gpen/myproject/releases/3676458/assets{?name,label}", + "html_url": "https://github.com/kongr45gpen/myproject/releases/tag/v2.6.5", + "id": 3676458, + "tag_name": "v2.6.5", + "target_commitish": "toast", + "name": "Useless Release", + "draft": false, + "author": { + "login": "kongr45gpen", + "id": 720678, + "avatar_url": "https://avatars.githubusercontent.com/u/720678?v=3", + "gravatar_id": "", + "url": "https://api.github.com/users/kongr45gpen", + "html_url": "https://github.com/kongr45gpen", + "followers_url": "https://api.github.com/users/kongr45gpen/followers", + "following_url": "https://api.github.com/users/kongr45gpen/following{/other_user}", + "gists_url": "https://api.github.com/users/kongr45gpen/gists{/gist_id}", + "starred_url": "https://api.github.com/users/kongr45gpen/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/kongr45gpen/subscriptions", + "organizations_url": "https://api.github.com/users/kongr45gpen/orgs", + "repos_url": "https://api.github.com/users/kongr45gpen/repos", + "events_url": "https://api.github.com/users/kongr45gpen/events{/privacy}", + "received_events_url": "https://api.github.com/users/kongr45gpen/received_events", + "type": "User", + "site_admin": false + }, + "prerelease": true, + "created_at": "2014-12-31T14:14:32Z", + "published_at": "2016-07-17T18:09:44Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/kongr45gpen/myproject/tarball/v2.6.5", + "zipball_url": "https://api.github.com/repos/kongr45gpen/myproject/zipball/v2.6.5", + "body": "This release is completely useless!" + }, + "repository": { + "id": 7406434, + "name": "myproject", + "full_name": "kongr45gpen/myproject", + "owner": { + "login": "kongr45gpen", + "id": 720678, + "avatar_url": "https://avatars.githubusercontent.com/u/720678?v=3", + "gravatar_id": "", + "url": "https://api.github.com/users/kongr45gpen", + "html_url": "https://github.com/kongr45gpen", + "followers_url": "https://api.github.com/users/kongr45gpen/followers", + "following_url": "https://api.github.com/users/kongr45gpen/following{/other_user}", + "gists_url": "https://api.github.com/users/kongr45gpen/gists{/gist_id}", + "starred_url": "https://api.github.com/users/kongr45gpen/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/kongr45gpen/subscriptions", + "organizations_url": "https://api.github.com/users/kongr45gpen/orgs", + "repos_url": "https://api.github.com/users/kongr45gpen/repos", + "events_url": "https://api.github.com/users/kongr45gpen/events{/privacy}", + "received_events_url": "https://api.github.com/users/kongr45gpen/received_events", + "type": "User", + "site_admin": false + }, + "private": false, + "html_url": "https://github.com/kongr45gpen/myproject", + "description": "You can safely ignore this repo :)", + "fork": false, + "url": "https://api.github.com/repos/kongr45gpen/myproject", + "forks_url": "https://api.github.com/repos/kongr45gpen/myproject/forks", + "keys_url": "https://api.github.com/repos/kongr45gpen/myproject/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/kongr45gpen/myproject/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/kongr45gpen/myproject/teams", + "hooks_url": "https://api.github.com/repos/kongr45gpen/myproject/hooks", + "issue_events_url": "https://api.github.com/repos/kongr45gpen/myproject/issues/events{/number}", + "events_url": "https://api.github.com/repos/kongr45gpen/myproject/events", + "assignees_url": "https://api.github.com/repos/kongr45gpen/myproject/assignees{/user}", + "branches_url": "https://api.github.com/repos/kongr45gpen/myproject/branches{/branch}", + "tags_url": "https://api.github.com/repos/kongr45gpen/myproject/tags", + "blobs_url": "https://api.github.com/repos/kongr45gpen/myproject/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/kongr45gpen/myproject/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/kongr45gpen/myproject/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/kongr45gpen/myproject/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/kongr45gpen/myproject/statuses/{sha}", + "languages_url": "https://api.github.com/repos/kongr45gpen/myproject/languages", + "stargazers_url": "https://api.github.com/repos/kongr45gpen/myproject/stargazers", + "contributors_url": "https://api.github.com/repos/kongr45gpen/myproject/contributors", + "subscribers_url": "https://api.github.com/repos/kongr45gpen/myproject/subscribers", + "subscription_url": "https://api.github.com/repos/kongr45gpen/myproject/subscription", + "commits_url": "https://api.github.com/repos/kongr45gpen/myproject/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/kongr45gpen/myproject/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/kongr45gpen/myproject/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/kongr45gpen/myproject/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/kongr45gpen/myproject/contents/{+path}", + "compare_url": "https://api.github.com/repos/kongr45gpen/myproject/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/kongr45gpen/myproject/merges", + "archive_url": "https://api.github.com/repos/kongr45gpen/myproject/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/kongr45gpen/myproject/downloads", + "issues_url": "https://api.github.com/repos/kongr45gpen/myproject/issues{/number}", + "pulls_url": "https://api.github.com/repos/kongr45gpen/myproject/pulls{/number}", + "milestones_url": "https://api.github.com/repos/kongr45gpen/myproject/milestones{/number}", + "notifications_url": "https://api.github.com/repos/kongr45gpen/myproject/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/kongr45gpen/myproject/labels{/name}", + "releases_url": "https://api.github.com/repos/kongr45gpen/myproject/releases{/id}", + "deployments_url": "https://api.github.com/repos/kongr45gpen/myproject/deployments", + "created_at": "2013-01-02T12:33:20Z", + "updated_at": "2016-02-07T12:41:16Z", + "pushed_at": "2016-07-17T18:09:44Z", + "git_url": "git://github.com/kongr45gpen/myproject.git", + "ssh_url": "git@github.com:kongr45gpen/myproject.git", + "clone_url": "https://github.com/kongr45gpen/myproject.git", + "svn_url": "https://github.com/kongr45gpen/myproject", + "homepage": "", + "size": 20, + "stargazers_count": 0, + "watchers_count": 0, + "language": null, + "has_issues": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 0, + "mirror_url": null, + "open_issues_count": 2, + "forks": 0, + "open_issues": 2, + "watchers": 0, + "default_branch": "pullr1" + }, + "sender": { + "login": "kongr45gpen", + "id": 720678, + "avatar_url": "https://avatars.githubusercontent.com/u/720678?v=3", + "gravatar_id": "", + "url": "https://api.github.com/users/kongr45gpen", + "html_url": "https://github.com/kongr45gpen", + "followers_url": "https://api.github.com/users/kongr45gpen/followers", + "following_url": "https://api.github.com/users/kongr45gpen/following{/other_user}", + "gists_url": "https://api.github.com/users/kongr45gpen/gists{/gist_id}", + "starred_url": "https://api.github.com/users/kongr45gpen/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/kongr45gpen/subscriptions", + "organizations_url": "https://api.github.com/users/kongr45gpen/orgs", + "repos_url": "https://api.github.com/users/kongr45gpen/repos", + "events_url": "https://api.github.com/users/kongr45gpen/events{/privacy}", + "received_events_url": "https://api.github.com/users/kongr45gpen/received_events", + "type": "User", + "site_admin": false + } +} @@ -128,6 +128,19 @@ class GithubTestCase(ExpectationPluginTestCase): it().should.contain('https://github.com/baxterthehacker/public-repo/branches') ) + def testRelease(self): + self.sendRequest('release') + + self.describe('first message', + it().should.contain('myproject'), + it().should.contain('kongr45gpen'), + it().should.contain('prerelease'), + it().should_not.contain('draft'), + it().should.contain('Useless Release'), + it().should.contain('v2.6.5'), + it().should.contain('https://github.com/kongr45gpen/myproject/releases/tag/v2.6.5') + ) + def testPing(self): self.conf('allowArbitraryMessages', False) self.sendRequest('ping') |