From 7f46f55d67c50f50dc51a00d2487250c4c1e5e94 Mon Sep 17 00:00:00 2001 From: kongr45gpen Date: Wed, 4 Jan 2017 00:27:19 +0200 Subject: Note when a push is forced --- local/handler/PushHandler.py | 16 +--- local/theme/DefaultTheme.py | 5 +- local/utility.py | 7 +- samples/push-forced.json | 183 +++++++++++++++++++++++++++++++++++++++++++ test.py | 24 ++++++ 5 files changed, 218 insertions(+), 17 deletions(-) create mode 100644 samples/push-forced.json diff --git a/local/handler/PushHandler.py b/local/handler/PushHandler.py index e40aa64..13052a3 100644 --- a/local/handler/PushHandler.py +++ b/local/handler/PushHandler.py @@ -29,17 +29,6 @@ def handle(data, theme): action = "re-tagged" else: action = "re-created" - elif data['created'] and not data['forced']: - if isTag: - action = "tagged" - else: - action = "created" - elif data['deleted'] and not data['forced']: - if isTag: - action = "deleted tag" - else: - action = "deleted" - urls = '' elif data['created']: if isTag: action = "tagged" @@ -62,9 +51,12 @@ def handle(data, theme): branch = branch, actor = data['pusher']['name'], url = getShortURL(data['compare']), - count = commitno + count = commitno, + forced = data['forced'] ) elif branched: + action = "force %s" % (action,) + if isTag: theme.tag( actor = data['pusher']['name'], diff --git a/local/theme/DefaultTheme.py b/local/theme/DefaultTheme.py index 3442383..96259d0 100644 --- a/local/theme/DefaultTheme.py +++ b/local/theme/DefaultTheme.py @@ -3,10 +3,11 @@ from Theme import Theme from ..utility import * class DefaultTheme(Theme): - def push(self, branch, actor, count, url): - self.msgs.append( "%s: %s pushed %s %s %s%s" % ( + def push(self, branch, actor, count, forced, url): + self.msgs.append( "%s: %s %s %s %s %s%s" % ( self.repo(branch), ircutils.mircColor(actor, "green"), + colorAction("force pushed") if forced else "pushed", ircutils.bold(str(count)), plural(count, "commit", "commits"), self.enclose(url), diff --git a/local/utility.py b/local/utility.py index 59dfd91..321637e 100644 --- a/local/utility.py +++ b/local/utility.py @@ -76,7 +76,7 @@ def maxLen(msg, maxn=400, splitLines=True): if splitLines is True: lines = msg.splitlines() - line = lines[0] + line = lines[0] if lines else "" else: line = msg @@ -90,6 +90,7 @@ 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", "published", "completed" ]: return ircutils.bold(ircutils.mircColor(action, "green")) @@ -101,8 +102,8 @@ def colorAction(action): return ircutils.bold(ircutils.mircColor(action, "light blue")) if action in [ "reopened", "pending" ]: return ircutils.bold(ircutils.mircColor(action, "blue")) - if action in [ "forced the creation of", "forced the deletion of" ]: - return ircutils.bold(ircutils.mircColor(action,"brown")) + if action[0:5] in [ "force" ]: + return ircutils.bold(ircutils.mircColor(action, "brown")) return action def getShortURL(longurl): diff --git a/samples/push-forced.json b/samples/push-forced.json new file mode 100644 index 0000000..d9198ba --- /dev/null +++ b/samples/push-forced.json @@ -0,0 +1,183 @@ +{ + "after": "12121ad459e0ae12ec91928949aab27a84a0478f", + "base_ref": null, + "before": "3be0d004b9d93e080d0ad355a4b8e9c151ed5bd1", + "commits": [ + { + "added": [], + "author": { + "email": "kongr45gpen@example.com", + "name": "alezakos", + "username": "kongr45gpen" + }, + "committer": { + "email": "kongr45gpen@example.com", + "name": "kongr45gpen", + "username": "kongr45gpen" + }, + "distinct": true, + "id": "726b044d600a19ce10eccf1014f7dd19b6efddf6", + "message": "Update README.md", + "modified": [ + "README.md" + ], + "removed": [], + "timestamp": "2017-01-03T23:39:49+02:00", + "tree_id": "6099cb6646a90a7f18d95b2e0ccb1202b7963e9a", + "url": "https://github.com/kongr45gpen/test/commit/726b044d600a19ce10eccf1014f7dd19b6efddf6" + }, + { + "added": [], + "author": { + "email": "Padiaten@example.com", + "name": "Padiaten", + "username": "Padiaten" + }, + "committer": { + "email": "kongr45gpen@example.com", + "name": "kongr45gpen", + "username": "kongr45gpen" + }, + "distinct": true, + "id": "12121ad459e0ae12ec91928949aab27a84a0478f", + "message": "Do it! (#9)\n\n* Update README.md\r\n\r\n* Update README\r\n\r\n* Update test", + "modified": [ + "README", + "README.md", + "test" + ], + "removed": [], + "timestamp": "2017-01-03T23:39:49+02:00", + "tree_id": "8d7d7eba922037605eb0e6d94b8f51b9160d6cbf", + "url": "https://github.com/kongr45gpen/test/commit/12121ad459e0ae12ec91928949aab27a84a0478f" + } + ], + "compare": "https://github.com/kongr45gpen/test/compare/3be0d004b9d9...12121ad459e0", + "created": false, + "deleted": false, + "forced": true, + "head_commit": { + "added": [], + "author": { + "email": "Padiaten@example.com", + "name": "Padiaten", + "username": "Padiaten" + }, + "committer": { + "email": "kongr45gpen@example.com", + "name": "kongr45gpen", + "username": "kongr45gpen" + }, + "distinct": true, + "id": "12121ad459e0ae12ec91928949aab27a84a0478f", + "message": "Do it! (#9)\n\n* Update README.md\r\n\r\n* Update README\r\n\r\n* Update test", + "modified": [ + "README", + "README.md", + "test" + ], + "removed": [], + "timestamp": "2017-01-03T23:39:49+02:00", + "tree_id": "8d7d7eba922037605eb0e6d94b8f51b9160d6cbf", + "url": "https://github.com/kongr45gpen/test/commit/12121ad459e0ae12ec91928949aab27a84a0478f" + }, + "pusher": { + "email": "kongr45gpen@example.com", + "name": "kongr45gpen" + }, + "ref": "refs/heads/pullr1", + "repository": { + "archive_url": "https://api.github.com/repos/kongr45gpen/test/{archive_format}{/ref}", + "assignees_url": "https://api.github.com/repos/kongr45gpen/test/assignees{/user}", + "blobs_url": "https://api.github.com/repos/kongr45gpen/test/git/blobs{/sha}", + "branches_url": "https://api.github.com/repos/kongr45gpen/test/branches{/branch}", + "clone_url": "https://github.com/kongr45gpen/test.git", + "collaborators_url": "https://api.github.com/repos/kongr45gpen/test/collaborators{/collaborator}", + "comments_url": "https://api.github.com/repos/kongr45gpen/test/comments{/number}", + "commits_url": "https://api.github.com/repos/kongr45gpen/test/commits{/sha}", + "compare_url": "https://api.github.com/repos/kongr45gpen/test/compare/{base}...{head}", + "contents_url": "https://api.github.com/repos/kongr45gpen/test/contents/{+path}", + "contributors_url": "https://api.github.com/repos/kongr45gpen/test/contributors", + "created_at": 1357130000, + "default_branch": "pullr1", + "deployments_url": "https://api.github.com/repos/kongr45gpen/test/deployments", + "description": "You can safely ignore this repo :)", + "downloads_url": "https://api.github.com/repos/kongr45gpen/test/downloads", + "events_url": "https://api.github.com/repos/kongr45gpen/test/events", + "fork": false, + "forks": 1, + "forks_count": 1, + "forks_url": "https://api.github.com/repos/kongr45gpen/test/forks", + "full_name": "kongr45gpen/test", + "git_commits_url": "https://api.github.com/repos/kongr45gpen/test/git/commits{/sha}", + "git_refs_url": "https://api.github.com/repos/kongr45gpen/test/git/refs{/sha}", + "git_tags_url": "https://api.github.com/repos/kongr45gpen/test/git/tags{/sha}", + "git_url": "git://github.com/kongr45gpen/test.git", + "has_downloads": true, + "has_issues": true, + "has_pages": false, + "has_wiki": true, + "homepage": "", + "hooks_url": "https://api.github.com/repos/kongr45gpen/test/hooks", + "html_url": "https://github.com/kongr45gpen/test", + "id": 7406434, + "issue_comment_url": "https://api.github.com/repos/kongr45gpen/test/issues/comments{/number}", + "issue_events_url": "https://api.github.com/repos/kongr45gpen/test/issues/events{/number}", + "issues_url": "https://api.github.com/repos/kongr45gpen/test/issues{/number}", + "keys_url": "https://api.github.com/repos/kongr45gpen/test/keys{/key_id}", + "labels_url": "https://api.github.com/repos/kongr45gpen/test/labels{/name}", + "language": null, + "languages_url": "https://api.github.com/repos/kongr45gpen/test/languages", + "master_branch": "pullr1", + "merges_url": "https://api.github.com/repos/kongr45gpen/test/merges", + "milestones_url": "https://api.github.com/repos/kongr45gpen/test/milestones{/number}", + "mirror_url": null, + "name": "test", + "notifications_url": "https://api.github.com/repos/kongr45gpen/test/notifications{?since,all,participating}", + "open_issues": 5, + "open_issues_count": 5, + "owner": { + "email": "kongr45gpen@example.com", + "name": "kongr45gpen" + }, + "private": false, + "pulls_url": "https://api.github.com/repos/kongr45gpen/test/pulls{/number}", + "pushed_at": 1483479604, + "releases_url": "https://api.github.com/repos/kongr45gpen/test/releases{/id}", + "size": 22, + "ssh_url": "git@github.com:kongr45gpen/test.git", + "stargazers": 0, + "stargazers_count": 0, + "stargazers_url": "https://api.github.com/repos/kongr45gpen/test/stargazers", + "statuses_url": "https://api.github.com/repos/kongr45gpen/test/statuses/{sha}", + "subscribers_url": "https://api.github.com/repos/kongr45gpen/test/subscribers", + "subscription_url": "https://api.github.com/repos/kongr45gpen/test/subscription", + "svn_url": "https://github.com/kongr45gpen/test", + "tags_url": "https://api.github.com/repos/kongr45gpen/test/tags", + "teams_url": "https://api.github.com/repos/kongr45gpen/test/teams", + "trees_url": "https://api.github.com/repos/kongr45gpen/test/git/trees{/sha}", + "updated_at": "2016-02-07T12:41:16Z", + "url": "https://github.com/kongr45gpen/test", + "watchers": 0, + "watchers_count": 0 + }, + "sender": { + "avatar_url": "https://avatars.githubusercontent.com/u/720678?v=3", + "events_url": "https://api.github.com/users/kongr45gpen/events{/privacy}", + "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}", + "gravatar_id": "", + "html_url": "https://github.com/kongr45gpen", + "id": 720678, + "login": "kongr45gpen", + "organizations_url": "https://api.github.com/users/kongr45gpen/orgs", + "received_events_url": "https://api.github.com/users/kongr45gpen/received_events", + "repos_url": "https://api.github.com/users/kongr45gpen/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/kongr45gpen/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/kongr45gpen/subscriptions", + "type": "User", + "url": "https://api.github.com/users/kongr45gpen" + } +} diff --git a/test.py b/test.py index e52e099..f711595 100644 --- a/test.py +++ b/test.py @@ -55,6 +55,30 @@ class GithubTestCase(ExpectationPluginTestCase): it().should.contain('Trigger pages build') ) + def testForcePush(self): + self.sendRequest('push-forced') + + self.describe('first message', + it().should.contain('force pushed'), + it().should.contain('2 commits'), + it().should.contain('kongr45gpen'), + it().should.contain('pullr1'), + it().should.contain('test'), + it().should.contain('https://github.com/kongr45gpen/test/compare/3be0d004b9d9...12121ad459e0') + ) + + self.describe('second message', + it().should.contain('kongr45gpen'), + it().should.contain('726'), + it().should.contain('https://github.com/kongr45gpen/test/commit/726b044d600a19ce10eccf1014f7dd19b6efddf6') + ) + + self.describe('fourth message', + it().should.contain('Padiaten'), + it().should.contain('121'), + it().should.contain('https://github.com/kongr45gpen/test/commit/12121ad459e0ae12ec91928949aab27a84a0478f') + ) + def testNewWikiPage(self): self.sendRequest('wiki-new-page') -- cgit v1.2.3