From 4c7f3a6e15562721e64e9fdad294aa156ab561f4 Mon Sep 17 00:00:00 2001 From: kongr45gpen Date: Thu, 17 Mar 2016 20:40:21 +0200 Subject: Add support for github ping events --- __init__.py | 2 + local/handler/GithubHandler.py | 3 + local/handler/PingHandler.py | 7 +++ local/theme/DefaultTheme.py | 6 ++ samples/ping.json | 134 +++++++++++++++++++++++++++++++++++++++++ test.py | 21 +++++++ 6 files changed, 173 insertions(+) create mode 100644 local/handler/PingHandler.py create mode 100644 samples/ping.json diff --git a/__init__.py b/__init__.py index e6644b8..674e0aa 100644 --- a/__init__.py +++ b/__init__.py @@ -29,6 +29,7 @@ reload(plugin) # In case we're being reloaded. # Add more reloads here if you add third-party modules and want them to be # reloaded when this plugin is reloaded. Don't forget to import them as well! import local.handler.GithubHandler as RequestHandler +import local.handler.PingHandler import local.handler.PushHandler import local.handler.WikiHandler import local.handler.IssueHandler @@ -43,6 +44,7 @@ import local.theme.CompactTheme import local.utility import local.globals reload(RequestHandler) +reload(local.handler.PingHandler) reload(local.handler.PushHandler) reload(local.handler.WikiHandler) reload(local.handler.IssueHandler) diff --git a/local/handler/GithubHandler.py b/local/handler/GithubHandler.py index 07665fa..8788ea3 100644 --- a/local/handler/GithubHandler.py +++ b/local/handler/GithubHandler.py @@ -26,6 +26,7 @@ import supybot.callbacks as callbacks from ..utility import * +import PingHandler import PushHandler import WikiHandler import IssueHandler @@ -165,6 +166,8 @@ class GithubHandler(BaseHTTPServer.BaseHTTPRequestHandler): IssueHandler.handle(data, theme) elif 'ref_type' in data: CreateDeleteHandler.handle(data, theme) + elif 'zen' in data: + PingHandler.handle(data, theme) elif 'message' in data: MessageHandler.handle(data, theme) else: diff --git a/local/handler/PingHandler.py b/local/handler/PingHandler.py new file mode 100644 index 0000000..81628dc --- /dev/null +++ b/local/handler/PingHandler.py @@ -0,0 +1,7 @@ +from ..utility import * + +def handle(data, theme): + theme.ping( + message = data['zen'], + zen = not configValue('allowArbitraryMessages') + ) diff --git a/local/theme/DefaultTheme.py b/local/theme/DefaultTheme.py index 2a17845..36166dd 100644 --- a/local/theme/DefaultTheme.py +++ b/local/theme/DefaultTheme.py @@ -163,6 +163,12 @@ class DefaultTheme(Theme): message )) + def ping(self, message, zen): + self.msgs.append( "%s: %s" % ( + self.repo("zen" if zen else None), + ircutils.mircColor(message, "light blue") + )) + def unknown(self, eventType): self.msgs.append( "%s: %s happened" % ( self.repo(), diff --git a/samples/ping.json b/samples/ping.json new file mode 100644 index 0000000..dc66ee3 --- /dev/null +++ b/samples/ping.json @@ -0,0 +1,134 @@ +{ + "zen": "Mind your words, they are important.", + "hook_id": 7709437, + "hook": { + "url": "https://api.github.com/repos/kongr45gpen/test/hooks/7709437", + "test_url": "https://api.github.com/repos/kongr45gpen/test/hooks/7709437/test", + "ping_url": "https://api.github.com/repos/kongr45gpen/test/hooks/7709437/pings", + "id": 7709437, + "name": "web", + "active": true, + "events": [ + "push" + ], + "config": { + "url": "http://helit.tech:8093/aioerjeiocraje98375ndf/++alezakos", + "content_type": "json", + "insecure_ssl": "0" + }, + "last_response": { + "code": null, + "status": "unused", + "message": null + }, + "updated_at": "2016-03-16T19:34:15Z", + "created_at": "2016-03-16T19:34:15Z" + }, + "repository": { + "id": 7406434, + "name": "test", + "full_name": "kongr45gpen/test", + "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/test", + "description": "You can safely ignore this repo :)", + "fork": false, + "url": "https://api.github.com/repos/kongr45gpen/test", + "forks_url": "https://api.github.com/repos/kongr45gpen/test/forks", + "keys_url": "https://api.github.com/repos/kongr45gpen/test/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/kongr45gpen/test/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/kongr45gpen/test/teams", + "hooks_url": "https://api.github.com/repos/kongr45gpen/test/hooks", + "issue_events_url": "https://api.github.com/repos/kongr45gpen/test/issues/events{/number}", + "events_url": "https://api.github.com/repos/kongr45gpen/test/events", + "assignees_url": "https://api.github.com/repos/kongr45gpen/test/assignees{/user}", + "branches_url": "https://api.github.com/repos/kongr45gpen/test/branches{/branch}", + "tags_url": "https://api.github.com/repos/kongr45gpen/test/tags", + "blobs_url": "https://api.github.com/repos/kongr45gpen/test/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/kongr45gpen/test/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/kongr45gpen/test/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/kongr45gpen/test/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/kongr45gpen/test/statuses/{sha}", + "languages_url": "https://api.github.com/repos/kongr45gpen/test/languages", + "stargazers_url": "https://api.github.com/repos/kongr45gpen/test/stargazers", + "contributors_url": "https://api.github.com/repos/kongr45gpen/test/contributors", + "subscribers_url": "https://api.github.com/repos/kongr45gpen/test/subscribers", + "subscription_url": "https://api.github.com/repos/kongr45gpen/test/subscription", + "commits_url": "https://api.github.com/repos/kongr45gpen/test/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/kongr45gpen/test/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/kongr45gpen/test/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/kongr45gpen/test/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/kongr45gpen/test/contents/{+path}", + "compare_url": "https://api.github.com/repos/kongr45gpen/test/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/kongr45gpen/test/merges", + "archive_url": "https://api.github.com/repos/kongr45gpen/test/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/kongr45gpen/test/downloads", + "issues_url": "https://api.github.com/repos/kongr45gpen/test/issues{/number}", + "pulls_url": "https://api.github.com/repos/kongr45gpen/test/pulls{/number}", + "milestones_url": "https://api.github.com/repos/kongr45gpen/test/milestones{/number}", + "notifications_url": "https://api.github.com/repos/kongr45gpen/test/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/kongr45gpen/test/labels{/name}", + "releases_url": "https://api.github.com/repos/kongr45gpen/test/releases{/id}", + "deployments_url": "https://api.github.com/repos/kongr45gpen/test/deployments", + "created_at": "2013-01-02T12:33:20Z", + "updated_at": "2016-02-07T12:41:16Z", + "pushed_at": "2016-03-11T23:05:02Z", + "git_url": "git://github.com/kongr45gpen/test.git", + "ssh_url": "git@github.com:kongr45gpen/test.git", + "clone_url": "https://github.com/kongr45gpen/test.git", + "svn_url": "https://github.com/kongr45gpen/test", + "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 + } +} diff --git a/test.py b/test.py index 7a103ea..c0c6d98 100644 --- a/test.py +++ b/test.py @@ -128,4 +128,25 @@ class GithubTestCase(ExpectationPluginTestCase): it().should.contain('https://github.com/baxterthehacker/public-repo/branches') ) + def testPing(self): + self.conf('allowArbitraryMessages', False) + self.sendRequest('ping') + + self.describe('first message', + it().should.contain('Mind your words, they are important.'), + it().should.contain('test'), + it().should.contain('zen') + ) + + self.conf('allowArbitraryMessages', True) + self.sendRequest('ping') + + self.describe('first message', + it().should.contain('Mind your words, they are important.'), + it().should.contain('test'), + it().should_not.contain('zen') + ) + + + # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: -- cgit v1.2.3