{"action":"created","comment":{"url":"https://api.github.com/repos/Block8/PHPCI/pulls/comments/41066475","id":41066475,"diff_hunk":"@@ -80,11 +80,88 @@ public function handleAction($action, $actionParams)\n     }\n \n     /**\n-     * Called by Bitbucket POST service.\n+     * Called by Bitbucket.\n      */\n     public function bitbucket($projectId)\n     {\n         $project = $this->fetchProject($projectId, 'bitbucket');\n+\n+        if ($payload = $this->getParam('payload')) {\n+            return $this->bitbucketService(json_decode($payload, true), $project);\n+        }\n+\n+        $payload = json_decode(file_get_contents(\"php://input\"), true);\n+\n+        switch (true) {\n+            case isset($payload['pullrequest_created']):\n+                return $this->bitbucketCreatePullRequestWebhook($payload, $project);\n+                break;\n+            case isset($payload['push']['changes']):\n+                return $this->bitbucketPushWebhook($payload, $project);\n+                break;\n+            default:\n+                return array('status' => 'failed', 'commits' => array());\n+                break;\n+        }\n+    }\n+\n+    /**\n+     * Bitbucket webhooks for created \"pull request\".\n+     */\n+    protected function bitbucketCreatePullRequestWebhook($payload, $project)\n+    {\n+        $results = array();\n+        $status = 'failed';\n+        try {\n+            $results[] = $this->createBuild(\n+                    $project,\n+                    $payload['pullrequest_created']['source']['commit']['hash'],\n+                    $payload['pullrequest_created']['source']['branch']['name'],","path":"PHPCI/Controller/WebhookController.php","position":41,"original_position":41,"commit_id":"44d8ef56a12f7a744b32ae6818ac1a340a295164","original_commit_id":"44d8ef56a12f7a744b32ae6818ac1a340a295164","user":{"login":"phpcibot","id":11097145,"avatar_url":"https://avatars.githubusercontent.com/u/11097145?v=3","gravatar_id":"","url":"https://api.github.com/users/phpcibot","html_url":"https://github.com/phpcibot","followers_url":"https://api.github.com/users/phpcibot/followers","following_url":"https://api.github.com/users/phpcibot/following{/other_user}","gists_url":"https://api.github.com/users/phpcibot/gists{/gist_id}","starred_url":"https://api.github.com/users/phpcibot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phpcibot/subscriptions","organizations_url":"https://api.github.com/users/phpcibot/orgs","repos_url":"https://api.github.com/users/phpcibot/repos","events_url":"https://api.github.com/users/phpcibot/events{/privacy}","received_events_url":"https://api.github.com/users/phpcibot/received_events","type":"User","site_admin":false},"body":"PHPCS: Multi-line function call not indented correctly; expected 16 spaces but found 20","created_at":"2015-10-02T20:54:06Z","updated_at":"2015-10-02T20:54:06Z","html_url":"https://github.com/Block8/PHPCI/pull/1061#discussion_r41066475","pull_request_url":"https://api.github.com/repos/Block8/PHPCI/pulls/1061","_links":{"self":{"href":"https://api.github.com/repos/Block8/PHPCI/pulls/comments/41066475"},"html":{"href":"https://github.com/Block8/PHPCI/pull/1061#discussion_r41066475"},"pull_request":{"href":"https://api.github.com/repos/Block8/PHPCI/pulls/1061"}}},"pull_request":{"url":"https://api.github.com/repos/Block8/PHPCI/pulls/1061","id":45609976,"html_url":"https://github.com/Block8/PHPCI/pull/1061","diff_url":"https://github.com/Block8/PHPCI/pull/1061.diff","patch_url":"https://github.com/Block8/PHPCI/pull/1061.patch","issue_url":"https://api.github.com/repos/Block8/PHPCI/issues/1061","number":1061,"state":"open","locked":false,"title":"add webhook for created pull request, refactoring","user":{"login":"gansky-alexander","id":1111370,"avatar_url":"https://avatars.githubusercontent.com/u/1111370?v=3","gravatar_id":"","url":"https://api.github.com/users/gansky-alexander","html_url":"https://github.com/gansky-alexander","followers_url":"https://api.github.com/users/gansky-alexander/followers","following_url":"https://api.github.com/users/gansky-alexander/following{/other_user}","gists_url":"https://api.github.com/users/gansky-alexander/gists{/gist_id}","starred_url":"https://api.github.com/users/gansky-alexander/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gansky-alexander/subscriptions","organizations_url":"https://api.github.com/users/gansky-alexander/orgs","repos_url":"https://api.github.com/users/gansky-alexander/repos","events_url":"https://api.github.com/users/gansky-alexander/events{/privacy}","received_events_url":"https://api.github.com/users/gansky-alexander/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-09-21T22:47:33Z","updated_at":"2015-10-02T20:54:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0949d8a7cfc2060b4a83cb83e97a789e6a0ba0f4","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Block8/PHPCI/pulls/1061/commits","review_comments_url":"https://api.github.com/repos/Block8/PHPCI/pulls/1061/comments","review_comment_url":"https://api.github.com/repos/Block8/PHPCI/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Block8/PHPCI/issues/1061/comments","statuses_url":"https://api.github.com/repos/Block8/PHPCI/statuses/44d8ef56a12f7a744b32ae6818ac1a340a295164","head":{"label":"mindteam:master","ref":"master","sha":"44d8ef56a12f7a744b32ae6818ac1a340a295164","user":{"login":"mindteam","id":14143028,"avatar_url":"https://avatars.githubusercontent.com/u/14143028?v=3","gravatar_id":"","url":"https://api.github.com/users/mindteam","html_url":"https://github.com/mindteam","followers_url":"https://api.github.com/users/mindteam/followers","following_url":"https://api.github.com/users/mindteam/following{/other_user}","gists_url":"https://api.github.com/users/mindteam/gists{/gist_id}","starred_url":"https://api.github.com/users/mindteam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mindteam/subscriptions","organizations_url":"https://api.github.com/users/mindteam/orgs","repos_url":"https://api.github.com/users/mindteam/repos","events_url":"https://api.github.com/users/mindteam/events{/privacy}","received_events_url":"https://api.github.com/users/mindteam/received_events","type":"Organization","site_admin":false},"repo":{"id":42016223,"name":"PHPCI","full_name":"mindteam/PHPCI","owner":{"login":"mindteam","id":14143028,"avatar_url":"https://avatars.githubusercontent.com/u/14143028?v=3","gravatar_id":"","url":"https://api.github.com/users/mindteam","html_url":"https://github.com/mindteam","followers_url":"https://api.github.com/users/mindteam/followers","following_url":"https://api.github.com/users/mindteam/following{/other_user}","gists_url":"https://api.github.com/users/mindteam/gists{/gist_id}","starred_url":"https://api.github.com/users/mindteam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mindteam/subscriptions","organizations_url":"https://api.github.com/users/mindteam/orgs","repos_url":"https://api.github.com/users/mindteam/repos","events_url":"https://api.github.com/users/mindteam/events{/privacy}","received_events_url":"https://api.github.com/users/mindteam/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mindteam/PHPCI","description":"","fork":true,"url":"https://api.github.com/repos/mindteam/PHPCI","forks_url":"https://api.github.com/repos/mindteam/PHPCI/forks","keys_url":"https://api.github.com/repos/mindteam/PHPCI/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mindteam/PHPCI/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mindteam/PHPCI/teams","hooks_url":"https://api.github.com/repos/mindteam/PHPCI/hooks","issue_events_url":"https://api.github.com/repos/mindteam/PHPCI/issues/events{/number}","events_url":"https://api.github.com/repos/mindteam/PHPCI/events","assignees_url":"https://api.github.com/repos/mindteam/PHPCI/assignees{/user}","branches_url":"https://api.github.com/repos/mindteam/PHPCI/branches{/branch}","tags_url":"https://api.github.com/repos/mindteam/PHPCI/tags","blobs_url":"https://api.github.com/repos/mindteam/PHPCI/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mindteam/PHPCI/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mindteam/PHPCI/git/refs{/sha}","trees_url":"https://api.github.com/repos/mindteam/PHPCI/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mindteam/PHPCI/statuses/{sha}","languages_url":"https://api.github.com/repos/mindteam/PHPCI/languages","stargazers_url":"https://api.github.com/repos/mindteam/PHPCI/stargazers","contributors_url":"https://api.github.com/repos/mindteam/PHPCI/contributors","subscribers_url":"https://api.github.com/repos/mindteam/PHPCI/subscribers","subscription_url":"https://api.github.com/repos/mindteam/PHPCI/subscription","commits_url":"https://api.github.com/repos/mindteam/PHPCI/commits{/sha}","git_commits_url":"https://api.github.com/repos/mindteam/PHPCI/git/commits{/sha}","comments_url":"https://api.github.com/repos/mindteam/PHPCI/comments{/number}","issue_comment_url":"https://api.github.com/repos/mindteam/PHPCI/issues/comments{/number}","contents_url":"https://api.github.com/repos/mindteam/PHPCI/contents/{+path}","compare_url":"https://api.github.com/repos/mindteam/PHPCI/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mindteam/PHPCI/merges","archive_url":"https://api.github.com/repos/mindteam/PHPCI/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mindteam/PHPCI/downloads","issues_url":"https://api.github.com/repos/mindteam/PHPCI/issues{/number}","pulls_url":"https://api.github.com/repos/mindteam/PHPCI/pulls{/number}","milestones_url":"https://api.github.com/repos/mindteam/PHPCI/milestones{/number}","notifications_url":"https://api.github.com/repos/mindteam/PHPCI/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mindteam/PHPCI/labels{/name}","releases_url":"https://api.github.com/repos/mindteam/PHPCI/releases{/id}","created_at":"2015-09-06T19:32:35Z","updated_at":"2015-09-06T19:32:57Z","pushed_at":"2015-09-21T22:27:44Z","git_url":"git://github.com/mindteam/PHPCI.git","ssh_url":"git@github.com:mindteam/PHPCI.git","clone_url":"https://github.com/mindteam/PHPCI.git","svn_url":"https://github.com/mindteam/PHPCI","homepage":"","size":4651,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Block8:master","ref":"master","sha":"92ee90998a1b6b218656195a78366542d74a97a3","user":{"login":"Block8","id":2234295,"avatar_url":"https://avatars.githubusercontent.com/u/2234295?v=3","gravatar_id":"","url":"https://api.github.com/users/Block8","html_url":"https://github.com/Block8","followers_url":"https://api.github.com/users/Block8/followers","following_url":"https://api.github.com/users/Block8/following{/other_user}","gists_url":"https://api.github.com/users/Block8/gists{/gist_id}","starred_url":"https://api.github.com/users/Block8/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Block8/subscriptions","organizations_url":"https://api.github.com/users/Block8/orgs","repos_url":"https://api.github.com/users/Block8/repos","events_url":"https://api.github.com/users/Block8/events{/privacy}","received_events_url":"https://api.github.com/users/Block8/received_events","type":"Organization","site_admin":false},"repo":{"id":9982892,"name":"PHPCI","full_name":"Block8/PHPCI","owner":{"login":"Block8","id":2234295,"avatar_url":"https://avatars.githubusercontent.com/u/2234295?v=3","gravatar_id":"","url":"https://api.github.com/users/Block8","html_url":"https://github.com/Block8","followers_url":"https://api.github.com/users/Block8/followers","following_url":"https://api.github.com/users/Block8/following{/other_user}","gists_url":"https://api.github.com/users/Block8/gists{/gist_id}","starred_url":"https://api.github.com/users/Block8/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Block8/subscriptions","organizations_url":"https://api.github.com/users/Block8/orgs","repos_url":"https://api.github.com/users/Block8/repos","events_url":"https://api.github.com/users/Block8/events{/privacy}","received_events_url":"https://api.github.com/users/Block8/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Block8/PHPCI","description":"PHPCI is a free and open source continuous integration tool specifically designed for PHP.","fork":false,"url":"https://api.github.com/repos/Block8/PHPCI","forks_url":"https://api.github.com/repos/Block8/PHPCI/forks","keys_url":"https://api.github.com/repos/Block8/PHPCI/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Block8/PHPCI/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Block8/PHPCI/teams","hooks_url":"https://api.github.com/repos/Block8/PHPCI/hooks","issue_events_url":"https://api.github.com/repos/Block8/PHPCI/issues/events{/number}","events_url":"https://api.github.com/repos/Block8/PHPCI/events","assignees_url":"https://api.github.com/repos/Block8/PHPCI/assignees{/user}","branches_url":"https://api.github.com/repos/Block8/PHPCI/branches{/branch}","tags_url":"https://api.github.com/repos/Block8/PHPCI/tags","blobs_url":"https://api.github.com/repos/Block8/PHPCI/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Block8/PHPCI/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Block8/PHPCI/git/refs{/sha}","trees_url":"https://api.github.com/repos/Block8/PHPCI/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Block8/PHPCI/statuses/{sha}","languages_url":"https://api.github.com/repos/Block8/PHPCI/languages","stargazers_url":"https://api.github.com/repos/Block8/PHPCI/stargazers","contributors_url":"https://api.github.com/repos/Block8/PHPCI/contributors","subscribers_url":"https://api.github.com/repos/Block8/PHPCI/subscribers","subscription_url":"https://api.github.com/repos/Block8/PHPCI/subscription","commits_url":"https://api.github.com/repos/Block8/PHPCI/commits{/sha}","git_commits_url":"https://api.github.com/repos/Block8/PHPCI/git/commits{/sha}","comments_url":"https://api.github.com/repos/Block8/PHPCI/comments{/number}","issue_comment_url":"https://api.github.com/repos/Block8/PHPCI/issues/comments{/number}","contents_url":"https://api.github.com/repos/Block8/PHPCI/contents/{+path}","compare_url":"https://api.github.com/repos/Block8/PHPCI/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Block8/PHPCI/merges","archive_url":"https://api.github.com/repos/Block8/PHPCI/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Block8/PHPCI/downloads","issues_url":"https://api.github.com/repos/Block8/PHPCI/issues{/number}","pulls_url":"https://api.github.com/repos/Block8/PHPCI/pulls{/number}","milestones_url":"https://api.github.com/repos/Block8/PHPCI/milestones{/number}","notifications_url":"https://api.github.com/repos/Block8/PHPCI/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Block8/PHPCI/labels{/name}","releases_url":"https://api.github.com/repos/Block8/PHPCI/releases{/id}","created_at":"2013-05-10T14:17:41Z","updated_at":"2015-10-02T16:55:10Z","pushed_at":"2015-10-02T20:53:42Z","git_url":"git://github.com/Block8/PHPCI.git","ssh_url":"git@github.com:Block8/PHPCI.git","clone_url":"https://github.com/Block8/PHPCI.git","svn_url":"https://github.com/Block8/PHPCI","homepage":"https://www.phptesting.org/","size":10396,"stargazers_count":1686,"watchers_count":1686,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":360,"mirror_url":null,"open_issues_count":240,"forks":360,"open_issues":240,"watchers":1686,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Block8/PHPCI/pulls/1061"},"html":{"href":"https://github.com/Block8/PHPCI/pull/1061"},"issue":{"href":"https://api.github.com/repos/Block8/PHPCI/issues/1061"},"comments":{"href":"https://api.github.com/repos/Block8/PHPCI/issues/1061/comments"},"review_comments":{"href":"https://api.github.com/repos/Block8/PHPCI/pulls/1061/comments"},"review_comment":{"href":"https://api.github.com/repos/Block8/PHPCI/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Block8/PHPCI/pulls/1061/commits"},"statuses":{"href":"https://api.github.com/repos/Block8/PHPCI/statuses/44d8ef56a12f7a744b32ae6818ac1a340a295164"}}}}