{"action":"created","comment":{"url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/pulls/comments/91797093","pull_request_review_id":12310130,"id":91797093,"diff_hunk":"@@ -22,6 +24,35 @@ const STATE_MAP = {\n     FAILURE: 'FAILED',\n     ABORTED: 'STOPPED'\n };\n+const WEBHOOK_PAGE_SIZE = 30;\n+\n+/**\n+ * Check the status code of the server's response.\n+ *\n+ * If there was an error encountered with the request, this will format a human-readable\n+ * error message.\n+ * @method checkResponseError\n+ * @param  {HTTPResponse}   response                               HTTP Response from `request` call\n+ * @param  {Number}         response.statusCode                    HTTP status code of the HTTP request\n+ * @param  {String}         [response.body.error.message]          Error message from the server\n+ * @param  {String}         [response.body.error.detail.required]  Error resolution message\n+ * @return {Promise}                                               Resolves when no error encountered.\n+ *                                                                 Rejects when status code is non-200\n+ */\n+function checkResponseError(response) {\n+    if (response.statusCode >= 200 && response.statusCode < 300) {\n+        return;\n+    }\n+\n+    const errorMessage = hoek.reach(response, 'body.error.message', {\n+        default: `SCM service unavailable (${response.statusCode}).`\n+    });\n+    const errorReason = hoek.reach(response, 'body.error.detail.required', {\n+        default: 'unknown'","path":"index.js","position":34,"original_position":34,"commit_id":"76a968c5ed4edac78a92ac8e7b50d3435402f75c","original_commit_id":"76a968c5ed4edac78a92ac8e7b50d3435402f75c","user":{"login":"FenrirUnbound","id":721148,"avatar_url":"https://avatars.githubusercontent.com/u/721148?v=3","gravatar_id":"","url":"https://api.github.com/users/FenrirUnbound","html_url":"https://github.com/FenrirUnbound","followers_url":"https://api.github.com/users/FenrirUnbound/followers","following_url":"https://api.github.com/users/FenrirUnbound/following{/other_user}","gists_url":"https://api.github.com/users/FenrirUnbound/gists{/gist_id}","starred_url":"https://api.github.com/users/FenrirUnbound/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FenrirUnbound/subscriptions","organizations_url":"https://api.github.com/users/FenrirUnbound/orgs","repos_url":"https://api.github.com/users/FenrirUnbound/repos","events_url":"https://api.github.com/users/FenrirUnbound/events{/privacy}","received_events_url":"https://api.github.com/users/FenrirUnbound/received_events","type":"User","site_admin":false},"body":"If the body is missing, it'll be *undefined*.\r\n\r\nI feel like that's a simpler method. Whether it says *undefined* or *unknown*, it still does its best to clarify the reason why there was a failure","created_at":"2016-12-09T21:19:04Z","updated_at":"2016-12-09T21:19:04Z","html_url":"https://github.com/screwdriver-cd/scm-bitbucket/pull/29#discussion_r91797093","pull_request_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/pulls/29","_links":{"self":{"href":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/pulls/comments/91797093"},"html":{"href":"https://github.com/screwdriver-cd/scm-bitbucket/pull/29#discussion_r91797093"},"pull_request":{"href":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/pulls/29"}}},"pull_request":{"url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/pulls/29","id":96820310,"html_url":"https://github.com/screwdriver-cd/scm-bitbucket/pull/29","diff_url":"https://github.com/screwdriver-cd/scm-bitbucket/pull/29.diff","patch_url":"https://github.com/screwdriver-cd/scm-bitbucket/pull/29.patch","issue_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/issues/29","number":29,"state":"open","locked":false,"title":"feat(379): addWebhook to attach a webhook URL to a repo","user":{"login":"FenrirUnbound","id":721148,"avatar_url":"https://avatars.githubusercontent.com/u/721148?v=3","gravatar_id":"","url":"https://api.github.com/users/FenrirUnbound","html_url":"https://github.com/FenrirUnbound","followers_url":"https://api.github.com/users/FenrirUnbound/followers","following_url":"https://api.github.com/users/FenrirUnbound/following{/other_user}","gists_url":"https://api.github.com/users/FenrirUnbound/gists{/gist_id}","starred_url":"https://api.github.com/users/FenrirUnbound/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FenrirUnbound/subscriptions","organizations_url":"https://api.github.com/users/FenrirUnbound/orgs","repos_url":"https://api.github.com/users/FenrirUnbound/repos","events_url":"https://api.github.com/users/FenrirUnbound/events{/privacy}","received_events_url":"https://api.github.com/users/FenrirUnbound/received_events","type":"User","site_admin":false},"body":"A mirror of screwdriver-cd/scm-github#45. This PR implements a non-public(ish) method that adds a webhook to a Bitbucket.org repository. If the repo already has a Screwdriver webhook, it will also update the webhook to ensure that it has all the correct information(e.g., permission scope).\r\n\r\nContributes to screwdriver-cd/screwdriver#379\r\n\r\nEDIT: Link to the correct issue","created_at":"2016-12-06T22:31:40Z","updated_at":"2016-12-09T21:19:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"47208874374d5f61d0d3e4f2f1896f94bbc9c31e","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/pulls/29/commits","review_comments_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/pulls/29/comments","review_comment_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/pulls/comments{/number}","comments_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/issues/29/comments","statuses_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/statuses/76a968c5ed4edac78a92ac8e7b50d3435402f75c","head":{"label":"screwdriver-cd:addWebhook","ref":"addWebhook","sha":"76a968c5ed4edac78a92ac8e7b50d3435402f75c","user":{"login":"screwdriver-cd","id":19417863,"avatar_url":"https://avatars.githubusercontent.com/u/19417863?v=3","gravatar_id":"","url":"https://api.github.com/users/screwdriver-cd","html_url":"https://github.com/screwdriver-cd","followers_url":"https://api.github.com/users/screwdriver-cd/followers","following_url":"https://api.github.com/users/screwdriver-cd/following{/other_user}","gists_url":"https://api.github.com/users/screwdriver-cd/gists{/gist_id}","starred_url":"https://api.github.com/users/screwdriver-cd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/screwdriver-cd/subscriptions","organizations_url":"https://api.github.com/users/screwdriver-cd/orgs","repos_url":"https://api.github.com/users/screwdriver-cd/repos","events_url":"https://api.github.com/users/screwdriver-cd/events{/privacy}","received_events_url":"https://api.github.com/users/screwdriver-cd/received_events","type":"Organization","site_admin":false},"repo":{"id":70520169,"name":"scm-bitbucket","full_name":"screwdriver-cd/scm-bitbucket","owner":{"login":"screwdriver-cd","id":19417863,"avatar_url":"https://avatars.githubusercontent.com/u/19417863?v=3","gravatar_id":"","url":"https://api.github.com/users/screwdriver-cd","html_url":"https://github.com/screwdriver-cd","followers_url":"https://api.github.com/users/screwdriver-cd/followers","following_url":"https://api.github.com/users/screwdriver-cd/following{/other_user}","gists_url":"https://api.github.com/users/screwdriver-cd/gists{/gist_id}","starred_url":"https://api.github.com/users/screwdriver-cd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/screwdriver-cd/subscriptions","organizations_url":"https://api.github.com/users/screwdriver-cd/orgs","repos_url":"https://api.github.com/users/screwdriver-cd/repos","events_url":"https://api.github.com/users/screwdriver-cd/events{/privacy}","received_events_url":"https://api.github.com/users/screwdriver-cd/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/screwdriver-cd/scm-bitbucket","description":"Bitbucket implementation of the scm-base class","fork":false,"url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket","forks_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/forks","keys_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/keys{/key_id}","collaborators_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/teams","hooks_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/hooks","issue_events_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/issues/events{/number}","events_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/events","assignees_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/assignees{/user}","branches_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/branches{/branch}","tags_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/tags","blobs_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/git/refs{/sha}","trees_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/git/trees{/sha}","statuses_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/statuses/{sha}","languages_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/languages","stargazers_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/stargazers","contributors_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/contributors","subscribers_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/subscribers","subscription_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/subscription","commits_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/commits{/sha}","git_commits_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/git/commits{/sha}","comments_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/comments{/number}","issue_comment_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/issues/comments{/number}","contents_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/contents/{+path}","compare_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/compare/{base}...{head}","merges_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/merges","archive_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/downloads","issues_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/issues{/number}","pulls_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/pulls{/number}","milestones_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/milestones{/number}","notifications_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/labels{/name}","releases_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/releases{/id}","deployments_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/deployments","created_at":"2016-10-10T19:12:13Z","updated_at":"2016-10-26T06:43:41Z","pushed_at":"2016-12-08T19:41:23Z","git_url":"git://github.com/screwdriver-cd/scm-bitbucket.git","ssh_url":"git@github.com:screwdriver-cd/scm-bitbucket.git","clone_url":"https://github.com/screwdriver-cd/scm-bitbucket.git","svn_url":"https://github.com/screwdriver-cd/scm-bitbucket","homepage":null,"size":57,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"screwdriver-cd:master","ref":"master","sha":"c52156e6049d59a0a4b018b004131136b442ce2f","user":{"login":"screwdriver-cd","id":19417863,"avatar_url":"https://avatars.githubusercontent.com/u/19417863?v=3","gravatar_id":"","url":"https://api.github.com/users/screwdriver-cd","html_url":"https://github.com/screwdriver-cd","followers_url":"https://api.github.com/users/screwdriver-cd/followers","following_url":"https://api.github.com/users/screwdriver-cd/following{/other_user}","gists_url":"https://api.github.com/users/screwdriver-cd/gists{/gist_id}","starred_url":"https://api.github.com/users/screwdriver-cd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/screwdriver-cd/subscriptions","organizations_url":"https://api.github.com/users/screwdriver-cd/orgs","repos_url":"https://api.github.com/users/screwdriver-cd/repos","events_url":"https://api.github.com/users/screwdriver-cd/events{/privacy}","received_events_url":"https://api.github.com/users/screwdriver-cd/received_events","type":"Organization","site_admin":false},"repo":{"id":70520169,"name":"scm-bitbucket","full_name":"screwdriver-cd/scm-bitbucket","owner":{"login":"screwdriver-cd","id":19417863,"avatar_url":"https://avatars.githubusercontent.com/u/19417863?v=3","gravatar_id":"","url":"https://api.github.com/users/screwdriver-cd","html_url":"https://github.com/screwdriver-cd","followers_url":"https://api.github.com/users/screwdriver-cd/followers","following_url":"https://api.github.com/users/screwdriver-cd/following{/other_user}","gists_url":"https://api.github.com/users/screwdriver-cd/gists{/gist_id}","starred_url":"https://api.github.com/users/screwdriver-cd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/screwdriver-cd/subscriptions","organizations_url":"https://api.github.com/users/screwdriver-cd/orgs","repos_url":"https://api.github.com/users/screwdriver-cd/repos","events_url":"https://api.github.com/users/screwdriver-cd/events{/privacy}","received_events_url":"https://api.github.com/users/screwdriver-cd/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/screwdriver-cd/scm-bitbucket","description":"Bitbucket implementation of the scm-base class","fork":false,"url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket","forks_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/forks","keys_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/keys{/key_id}","collaborators_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/teams","hooks_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/hooks","issue_events_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/issues/events{/number}","events_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/events","assignees_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/assignees{/user}","branches_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/branches{/branch}","tags_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/tags","blobs_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/git/refs{/sha}","trees_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/git/trees{/sha}","statuses_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/statuses/{sha}","languages_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/languages","stargazers_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/stargazers","contributors_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/contributors","subscribers_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/subscribers","subscription_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/subscription","commits_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/commits{/sha}","git_commits_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/git/commits{/sha}","comments_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/comments{/number}","issue_comment_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/issues/comments{/number}","contents_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/contents/{+path}","compare_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/compare/{base}...{head}","merges_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/merges","archive_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/downloads","issues_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/issues{/number}","pulls_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/pulls{/number}","milestones_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/milestones{/number}","notifications_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/labels{/name}","releases_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/releases{/id}","deployments_url":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/deployments","created_at":"2016-10-10T19:12:13Z","updated_at":"2016-10-26T06:43:41Z","pushed_at":"2016-12-08T19:41:23Z","git_url":"git://github.com/screwdriver-cd/scm-bitbucket.git","ssh_url":"git@github.com:screwdriver-cd/scm-bitbucket.git","clone_url":"https://github.com/screwdriver-cd/scm-bitbucket.git","svn_url":"https://github.com/screwdriver-cd/scm-bitbucket","homepage":null,"size":57,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/pulls/29"},"html":{"href":"https://github.com/screwdriver-cd/scm-bitbucket/pull/29"},"issue":{"href":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/issues/29"},"comments":{"href":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/issues/29/comments"},"review_comments":{"href":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/pulls/29/comments"},"review_comment":{"href":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/pulls/29/commits"},"statuses":{"href":"https://api.github.com/repos/screwdriver-cd/scm-bitbucket/statuses/76a968c5ed4edac78a92ac8e7b50d3435402f75c"}}}}
{"actor":{"display_login":"FenrirUnbound"}}