{"action":"created","comment":{"url":"https://api.github.com/repos/buildbot/buildbot/pulls/comments/71644785","id":71644785,"diff_hunk":"@@ -0,0 +1,118 @@\n+# This file is part of Buildbot.  Buildbot is free software: you can\n+# redistribute it and/or modify it under the terms of the GNU General Public\n+# License as published by the Free Software Foundation, version 2.\n+#\n+# This program is distributed in the hope that it will be useful, but WITHOUT\n+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more\n+# details.\n+#\n+# You should have received a copy of the GNU General Public License along with\n+# this program; if not, write to the Free Software Foundation, Inc., 51\n+# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n+#\n+# Copyright Buildbot Team Members\n+\n+import json\n+from urlparse import urlparse\n+\n+from twisted.internet import defer\n+from twisted.python import log\n+\n+from buildbot.process.results import SUCCESS\n+from buildbot.reporters import http\n+\n+# Magic words understood by Butbucket REST API\n+BITBUCKET_INPROGRESS = 'INPROGRESS'\n+BITBUCKET_SUCCESSFUL = 'SUCCESSFUL'\n+BITBUCKET_FAILED = 'FAILED'\n+\n+_BASE_URL = 'https://api.bitbucket.org/2.0/repositories'\n+_OAUTH_URL = 'https://bitbucket.org/site/oauth2/access_token'\n+_GET_TOKEN_DATA = {\n+    'grant_type': 'client_credentials'\n+}\n+\n+\n+class BitbucketStatusPush(http.HttpStatusPushBase):\n+    name = \"BitbucketStatusPush\"\n+\n+    @defer.inlineCallbacks\n+    def reconfigService(self, oauth_key, oauth_secret,\n+                        base_url=_BASE_URL,\n+                        oauth_url=_OAUTH_URL,\n+                        **kwargs):\n+        yield http.HttpStatusPushBase.reconfigService(self, **kwargs)\n+\n+        if base_url.endswith('/'):\n+            base_url = base_url[:-1]\n+\n+        self._base_url = base_url\n+        self._oauth_url = oauth_url\n+        self._auth = (oauth_key, oauth_secret)\n+\n+    @defer.inlineCallbacks\n+    def send(self, build):\n+        results = build['results']\n+\n+        if build['complete']:\n+            status = BITBUCKET_SUCCESSFUL if results == SUCCESS else BITBUCKET_FAILED\n+        else:\n+            status = BITBUCKET_INPROGRESS\n+\n+        for sourcestamp in build['buildset']['sourcestamps']:\n+            sha = sourcestamp['revision']\n+            body = {\n+                'state': status,\n+                'key': build['builder']['name'],\n+                'name': build['builder']['name'],\n+                'url': build['url']\n+            }\n+\n+            owner, repo = self.get_owner_and_repo(sourcestamp['repository'])\n+            token = ''\n+\n+            oauth_request = yield self.session.post(self._oauth_url,\n+                                                    auth=self._auth,\n+                                                    data=_GET_TOKEN_DATA)\n+            if oauth_request.status_code == 200:\n+                token = json.loads(oauth_request.content)['access_token']\n+\n+            self.session.headers.update({'Authorization': 'Bearer ' + token})\n+\n+            bitbucket_uri = '/'.join([self._base_url, owner, repo, 'commit', sha, 'statuses', 'build'])\n+\n+            response = yield self.session.post(bitbucket_uri, json=body)\n+            if response.status_code != 201:\n+                log.msg(\"%s: unable to upload Bitbucket status: %s\" %\n+                        (response.status_code, response.content))\n+            else:","path":"master/buildbot/reporters/bitbucket.py","position":89,"original_position":89,"commit_id":"7738f926330ed4352ea7ce69b1f84dd6486c931a","original_commit_id":"7738f926330ed4352ea7ce69b1f84dd6486c931a","user":{"login":"faulteh","id":401338,"avatar_url":"https://avatars.githubusercontent.com/u/401338?v=3","gravatar_id":"","url":"https://api.github.com/users/faulteh","html_url":"https://github.com/faulteh","followers_url":"https://api.github.com/users/faulteh/followers","following_url":"https://api.github.com/users/faulteh/following{/other_user}","gists_url":"https://api.github.com/users/faulteh/gists{/gist_id}","starred_url":"https://api.github.com/users/faulteh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/faulteh/subscriptions","organizations_url":"https://api.github.com/users/faulteh/orgs","repos_url":"https://api.github.com/users/faulteh/repos","events_url":"https://api.github.com/users/faulteh/events{/privacy}","received_events_url":"https://api.github.com/users/faulteh/received_events","type":"User","site_admin":false},"body":"This else branch is no longer needed and was in the wrong place anyway.\r\nI've tested this on my production buildbot just now, minus this else branch and it works in production :)\r\n\r\nThanks for fixing the test for me.","created_at":"2016-07-21T04:15:54Z","updated_at":"2016-07-21T04:15:54Z","html_url":"https://github.com/buildbot/buildbot/pull/2323#discussion_r71644785","pull_request_url":"https://api.github.com/repos/buildbot/buildbot/pulls/2323","_links":{"self":{"href":"https://api.github.com/repos/buildbot/buildbot/pulls/comments/71644785"},"html":{"href":"https://github.com/buildbot/buildbot/pull/2323#discussion_r71644785"},"pull_request":{"href":"https://api.github.com/repos/buildbot/buildbot/pulls/2323"}}},"pull_request":{"url":"https://api.github.com/repos/buildbot/buildbot/pulls/2323","id":77938081,"html_url":"https://github.com/buildbot/buildbot/pull/2323","diff_url":"https://github.com/buildbot/buildbot/pull/2323.diff","patch_url":"https://github.com/buildbot/buildbot/pull/2323.patch","issue_url":"https://api.github.com/repos/buildbot/buildbot/issues/2323","number":2323,"state":"open","locked":false,"title":"add bitbucket reporter","user":{"login":"sa2ajj","id":447092,"avatar_url":"https://avatars.githubusercontent.com/u/447092?v=3","gravatar_id":"","url":"https://api.github.com/users/sa2ajj","html_url":"https://github.com/sa2ajj","followers_url":"https://api.github.com/users/sa2ajj/followers","following_url":"https://api.github.com/users/sa2ajj/following{/other_user}","gists_url":"https://api.github.com/users/sa2ajj/gists{/gist_id}","starred_url":"https://api.github.com/users/sa2ajj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sa2ajj/subscriptions","organizations_url":"https://api.github.com/users/sa2ajj/orgs","repos_url":"https://api.github.com/users/sa2ajj/repos","events_url":"https://api.github.com/users/sa2ajj/events{/privacy}","received_events_url":"https://api.github.com/users/sa2ajj/received_events","type":"User","site_admin":false},"body":"Checking #2322's coverage issues.","created_at":"2016-07-19T08:43:14Z","updated_at":"2016-07-21T04:15:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3e5dd38dccf30a8f4ae53de9039c8b3032df4fa4","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/buildbot/buildbot/pulls/2323/commits","review_comments_url":"https://api.github.com/repos/buildbot/buildbot/pulls/2323/comments","review_comment_url":"https://api.github.com/repos/buildbot/buildbot/pulls/comments{/number}","comments_url":"https://api.github.com/repos/buildbot/buildbot/issues/2323/comments","statuses_url":"https://api.github.com/repos/buildbot/buildbot/statuses/7738f926330ed4352ea7ce69b1f84dd6486c931a","head":{"label":"sa2ajj:bitbucket-reporter","ref":"bitbucket-reporter","sha":"7738f926330ed4352ea7ce69b1f84dd6486c931a","user":{"login":"sa2ajj","id":447092,"avatar_url":"https://avatars.githubusercontent.com/u/447092?v=3","gravatar_id":"","url":"https://api.github.com/users/sa2ajj","html_url":"https://github.com/sa2ajj","followers_url":"https://api.github.com/users/sa2ajj/followers","following_url":"https://api.github.com/users/sa2ajj/following{/other_user}","gists_url":"https://api.github.com/users/sa2ajj/gists{/gist_id}","starred_url":"https://api.github.com/users/sa2ajj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sa2ajj/subscriptions","organizations_url":"https://api.github.com/users/sa2ajj/orgs","repos_url":"https://api.github.com/users/sa2ajj/repos","events_url":"https://api.github.com/users/sa2ajj/events{/privacy}","received_events_url":"https://api.github.com/users/sa2ajj/received_events","type":"User","site_admin":false},"repo":{"id":21306128,"name":"buildbot","full_name":"sa2ajj/buildbot","owner":{"login":"sa2ajj","id":447092,"avatar_url":"https://avatars.githubusercontent.com/u/447092?v=3","gravatar_id":"","url":"https://api.github.com/users/sa2ajj","html_url":"https://github.com/sa2ajj","followers_url":"https://api.github.com/users/sa2ajj/followers","following_url":"https://api.github.com/users/sa2ajj/following{/other_user}","gists_url":"https://api.github.com/users/sa2ajj/gists{/gist_id}","starred_url":"https://api.github.com/users/sa2ajj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sa2ajj/subscriptions","organizations_url":"https://api.github.com/users/sa2ajj/orgs","repos_url":"https://api.github.com/users/sa2ajj/repos","events_url":"https://api.github.com/users/sa2ajj/events{/privacy}","received_events_url":"https://api.github.com/users/sa2ajj/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sa2ajj/buildbot","description":"Python-based continuous integration testing framework; send pull requests for your patches!","fork":true,"url":"https://api.github.com/repos/sa2ajj/buildbot","forks_url":"https://api.github.com/repos/sa2ajj/buildbot/forks","keys_url":"https://api.github.com/repos/sa2ajj/buildbot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sa2ajj/buildbot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sa2ajj/buildbot/teams","hooks_url":"https://api.github.com/repos/sa2ajj/buildbot/hooks","issue_events_url":"https://api.github.com/repos/sa2ajj/buildbot/issues/events{/number}","events_url":"https://api.github.com/repos/sa2ajj/buildbot/events","assignees_url":"https://api.github.com/repos/sa2ajj/buildbot/assignees{/user}","branches_url":"https://api.github.com/repos/sa2ajj/buildbot/branches{/branch}","tags_url":"https://api.github.com/repos/sa2ajj/buildbot/tags","blobs_url":"https://api.github.com/repos/sa2ajj/buildbot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sa2ajj/buildbot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sa2ajj/buildbot/git/refs{/sha}","trees_url":"https://api.github.com/repos/sa2ajj/buildbot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sa2ajj/buildbot/statuses/{sha}","languages_url":"https://api.github.com/repos/sa2ajj/buildbot/languages","stargazers_url":"https://api.github.com/repos/sa2ajj/buildbot/stargazers","contributors_url":"https://api.github.com/repos/sa2ajj/buildbot/contributors","subscribers_url":"https://api.github.com/repos/sa2ajj/buildbot/subscribers","subscription_url":"https://api.github.com/repos/sa2ajj/buildbot/subscription","commits_url":"https://api.github.com/repos/sa2ajj/buildbot/commits{/sha}","git_commits_url":"https://api.github.com/repos/sa2ajj/buildbot/git/commits{/sha}","comments_url":"https://api.github.com/repos/sa2ajj/buildbot/comments{/number}","issue_comment_url":"https://api.github.com/repos/sa2ajj/buildbot/issues/comments{/number}","contents_url":"https://api.github.com/repos/sa2ajj/buildbot/contents/{+path}","compare_url":"https://api.github.com/repos/sa2ajj/buildbot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sa2ajj/buildbot/merges","archive_url":"https://api.github.com/repos/sa2ajj/buildbot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sa2ajj/buildbot/downloads","issues_url":"https://api.github.com/repos/sa2ajj/buildbot/issues{/number}","pulls_url":"https://api.github.com/repos/sa2ajj/buildbot/pulls{/number}","milestones_url":"https://api.github.com/repos/sa2ajj/buildbot/milestones{/number}","notifications_url":"https://api.github.com/repos/sa2ajj/buildbot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sa2ajj/buildbot/labels{/name}","releases_url":"https://api.github.com/repos/sa2ajj/buildbot/releases{/id}","deployments_url":"https://api.github.com/repos/sa2ajj/buildbot/deployments","created_at":"2014-06-28T15:55:46Z","updated_at":"2016-03-20T07:03:36Z","pushed_at":"2016-07-20T07:28:03Z","git_url":"git://github.com/sa2ajj/buildbot.git","ssh_url":"git@github.com:sa2ajj/buildbot.git","clone_url":"https://github.com/sa2ajj/buildbot.git","svn_url":"https://github.com/sa2ajj/buildbot","homepage":"http://buildbot.net","size":43598,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":1,"default_branch":"upstream"}},"base":{"label":"buildbot:master","ref":"master","sha":"12328fc74a8f6fef273c811e60ccd7b1167b8b66","user":{"login":"buildbot","id":324515,"avatar_url":"https://avatars.githubusercontent.com/u/324515?v=3","gravatar_id":"","url":"https://api.github.com/users/buildbot","html_url":"https://github.com/buildbot","followers_url":"https://api.github.com/users/buildbot/followers","following_url":"https://api.github.com/users/buildbot/following{/other_user}","gists_url":"https://api.github.com/users/buildbot/gists{/gist_id}","starred_url":"https://api.github.com/users/buildbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/buildbot/subscriptions","organizations_url":"https://api.github.com/users/buildbot/orgs","repos_url":"https://api.github.com/users/buildbot/repos","events_url":"https://api.github.com/users/buildbot/events{/privacy}","received_events_url":"https://api.github.com/users/buildbot/received_events","type":"Organization","site_admin":false},"repo":{"id":760165,"name":"buildbot","full_name":"buildbot/buildbot","owner":{"login":"buildbot","id":324515,"avatar_url":"https://avatars.githubusercontent.com/u/324515?v=3","gravatar_id":"","url":"https://api.github.com/users/buildbot","html_url":"https://github.com/buildbot","followers_url":"https://api.github.com/users/buildbot/followers","following_url":"https://api.github.com/users/buildbot/following{/other_user}","gists_url":"https://api.github.com/users/buildbot/gists{/gist_id}","starred_url":"https://api.github.com/users/buildbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/buildbot/subscriptions","organizations_url":"https://api.github.com/users/buildbot/orgs","repos_url":"https://api.github.com/users/buildbot/repos","events_url":"https://api.github.com/users/buildbot/events{/privacy}","received_events_url":"https://api.github.com/users/buildbot/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/buildbot/buildbot","description":"Python-based continuous integration testing framework; your pull requests are more than welcome!","fork":false,"url":"https://api.github.com/repos/buildbot/buildbot","forks_url":"https://api.github.com/repos/buildbot/buildbot/forks","keys_url":"https://api.github.com/repos/buildbot/buildbot/keys{/key_id}","collaborators_url":"https://api.github.com/repos/buildbot/buildbot/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/buildbot/buildbot/teams","hooks_url":"https://api.github.com/repos/buildbot/buildbot/hooks","issue_events_url":"https://api.github.com/repos/buildbot/buildbot/issues/events{/number}","events_url":"https://api.github.com/repos/buildbot/buildbot/events","assignees_url":"https://api.github.com/repos/buildbot/buildbot/assignees{/user}","branches_url":"https://api.github.com/repos/buildbot/buildbot/branches{/branch}","tags_url":"https://api.github.com/repos/buildbot/buildbot/tags","blobs_url":"https://api.github.com/repos/buildbot/buildbot/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/buildbot/buildbot/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/buildbot/buildbot/git/refs{/sha}","trees_url":"https://api.github.com/repos/buildbot/buildbot/git/trees{/sha}","statuses_url":"https://api.github.com/repos/buildbot/buildbot/statuses/{sha}","languages_url":"https://api.github.com/repos/buildbot/buildbot/languages","stargazers_url":"https://api.github.com/repos/buildbot/buildbot/stargazers","contributors_url":"https://api.github.com/repos/buildbot/buildbot/contributors","subscribers_url":"https://api.github.com/repos/buildbot/buildbot/subscribers","subscription_url":"https://api.github.com/repos/buildbot/buildbot/subscription","commits_url":"https://api.github.com/repos/buildbot/buildbot/commits{/sha}","git_commits_url":"https://api.github.com/repos/buildbot/buildbot/git/commits{/sha}","comments_url":"https://api.github.com/repos/buildbot/buildbot/comments{/number}","issue_comment_url":"https://api.github.com/repos/buildbot/buildbot/issues/comments{/number}","contents_url":"https://api.github.com/repos/buildbot/buildbot/contents/{+path}","compare_url":"https://api.github.com/repos/buildbot/buildbot/compare/{base}...{head}","merges_url":"https://api.github.com/repos/buildbot/buildbot/merges","archive_url":"https://api.github.com/repos/buildbot/buildbot/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/buildbot/buildbot/downloads","issues_url":"https://api.github.com/repos/buildbot/buildbot/issues{/number}","pulls_url":"https://api.github.com/repos/buildbot/buildbot/pulls{/number}","milestones_url":"https://api.github.com/repos/buildbot/buildbot/milestones{/number}","notifications_url":"https://api.github.com/repos/buildbot/buildbot/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/buildbot/buildbot/labels{/name}","releases_url":"https://api.github.com/repos/buildbot/buildbot/releases{/id}","deployments_url":"https://api.github.com/repos/buildbot/buildbot/deployments","created_at":"2010-07-06T17:56:53Z","updated_at":"2016-07-21T02:16:17Z","pushed_at":"2016-07-20T07:28:04Z","git_url":"git://github.com/buildbot/buildbot.git","ssh_url":"git@github.com:buildbot/buildbot.git","clone_url":"https://github.com/buildbot/buildbot.git","svn_url":"https://github.com/buildbot/buildbot","homepage":"http://buildbot.net","size":93320,"stargazers_count":2243,"watchers_count":2243,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":927,"mirror_url":null,"open_issues_count":10,"forks":927,"open_issues":10,"watchers":2243,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/buildbot/buildbot/pulls/2323"},"html":{"href":"https://github.com/buildbot/buildbot/pull/2323"},"issue":{"href":"https://api.github.com/repos/buildbot/buildbot/issues/2323"},"comments":{"href":"https://api.github.com/repos/buildbot/buildbot/issues/2323/comments"},"review_comments":{"href":"https://api.github.com/repos/buildbot/buildbot/pulls/2323/comments"},"review_comment":{"href":"https://api.github.com/repos/buildbot/buildbot/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/buildbot/buildbot/pulls/2323/commits"},"statuses":{"href":"https://api.github.com/repos/buildbot/buildbot/statuses/7738f926330ed4352ea7ce69b1f84dd6486c931a"}}}}
{"actor":{"display_login":"faulteh"}}