{"action":"created","comment":{"url":"https://api.github.com/repos/screwdriver-cd/scm-github/pulls/comments/90752000","pull_request_review_id":11272571,"id":90752000,"diff_hunk":"@@ -149,6 +150,90 @@ class GithubScm extends Scm {\n     }\n \n     /**\n+     * Adds the Screwdriver webhook to the Github repository\n+     * @method _addWebhook\n+     * @param  {Object}    config            Config object\n+     * @param  {String}    config.scmUri     The SCM URI to add the webhook to\n+     * @param  {String}    config.token      Service token to authenticate with Github\n+     * @param  {String}    config.webhookUrl The URL to use for the webhook notifications\n+     * @return {Promise}                     Resolve means operation completed without failure.\n+     */\n+    _addWebhook(config) {\n+        const searchForHook = (scmInfo, url, page) => {\n+            const getHooks = this.breaker.runCommand({\n+                action: 'getHooks',\n+                token: config.token,\n+                params: {\n+                    owner: scmInfo.owner,\n+                    repo: scmInfo.repo,\n+                    page,\n+                    per_page: WEBHOOK_PAGE_SIZE\n+                }\n+            });\n+            const filterForHook = getHooks.then((hooks) => {\n+                let found = null;\n+\n+                hooks.some((hook) => {\n+                    const currentHook = hoek.reach(hook, 'config.url');\n+\n+                    if (currentHook === url) {\n+                        found = hook;\n+                    }\n+\n+                    return found;\n+                });\n+\n+                return found;\n+            });\n+\n+            return Promise.all([\n+                getHooks,\n+                filterForHook\n+            ]).then(([hooks, screwdriverHook]) => {\n+                if (!screwdriverHook && hooks.length === WEBHOOK_PAGE_SIZE) {\n+                    return searchForHook(scmInfo, url, page + 1);\n+                }\n+\n+                return screwdriverHook;\n+            });\n+        };\n+        const lookupScm = this.lookupScmUri({\n+            scmUri: config.scmUri,\n+            token: config.token\n+        });\n+\n+        return Promise.all([\n+            lookupScm,\n+            lookupScm.then(scmInfo => searchForHook(scmInfo, config.webhookUrl, 1))","path":"index.js","position":66,"original_position":66,"commit_id":"a35f9f289a5c047ca814c4fdc89db3ac4ec1e296","original_commit_id":"a35f9f289a5c047ca814c4fdc89db3ac4ec1e296","user":{"login":"d2lam","id":3401924,"avatar_url":"https://avatars.githubusercontent.com/u/3401924?v=3","gravatar_id":"","url":"https://api.github.com/users/d2lam","html_url":"https://github.com/d2lam","followers_url":"https://api.github.com/users/d2lam/followers","following_url":"https://api.github.com/users/d2lam/following{/other_user}","gists_url":"https://api.github.com/users/d2lam/gists{/gist_id}","starred_url":"https://api.github.com/users/d2lam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/d2lam/subscriptions","organizations_url":"https://api.github.com/users/d2lam/orgs","repos_url":"https://api.github.com/users/d2lam/repos","events_url":"https://api.github.com/users/d2lam/events{/privacy}","received_events_url":"https://api.github.com/users/d2lam/received_events","type":"User","site_admin":false},"body":"Hmm... I think Min is actually talking about the same comment that I commented above. ","created_at":"2016-12-03T06:26:10Z","updated_at":"2016-12-03T06:26:10Z","html_url":"https://github.com/screwdriver-cd/scm-github/pull/45#discussion_r90752000","pull_request_url":"https://api.github.com/repos/screwdriver-cd/scm-github/pulls/45","_links":{"self":{"href":"https://api.github.com/repos/screwdriver-cd/scm-github/pulls/comments/90752000"},"html":{"href":"https://github.com/screwdriver-cd/scm-github/pull/45#discussion_r90752000"},"pull_request":{"href":"https://api.github.com/repos/screwdriver-cd/scm-github/pulls/45"}}},"pull_request":{"url":"https://api.github.com/repos/screwdriver-cd/scm-github/pulls/45","id":96364232,"html_url":"https://github.com/screwdriver-cd/scm-github/pull/45","diff_url":"https://github.com/screwdriver-cd/scm-github/pull/45.diff","patch_url":"https://github.com/screwdriver-cd/scm-github/pull/45.patch","issue_url":"https://api.github.com/repos/screwdriver-cd/scm-github/issues/45","number":45,"state":"open","locked":false,"title":"refactor: internal addWebhook method","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":"Implement a non-public(ish) method that adds a webhook to a repository. If the repo already has a Screwdriver webhook, it will also update the webhook to ensure it has all the correct information (e.g., webhook API secret).\r\n\r\nRelated to screwdriver-cd/screwdriver#379","created_at":"2016-12-02T22:28:06Z","updated_at":"2016-12-03T06:26:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"339769b0a4174d903ce8f87f4e5ebb8f91f570d1","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/screwdriver-cd/scm-github/pulls/45/commits","review_comments_url":"https://api.github.com/repos/screwdriver-cd/scm-github/pulls/45/comments","review_comment_url":"https://api.github.com/repos/screwdriver-cd/scm-github/pulls/comments{/number}","comments_url":"https://api.github.com/repos/screwdriver-cd/scm-github/issues/45/comments","statuses_url":"https://api.github.com/repos/screwdriver-cd/scm-github/statuses/a35f9f289a5c047ca814c4fdc89db3ac4ec1e296","head":{"label":"screwdriver-cd:addWebhooks","ref":"addWebhooks","sha":"a35f9f289a5c047ca814c4fdc89db3ac4ec1e296","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":65842228,"name":"scm-github","full_name":"screwdriver-cd/scm-github","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-github","description":"Github implementation of the scm-base class","fork":false,"url":"https://api.github.com/repos/screwdriver-cd/scm-github","forks_url":"https://api.github.com/repos/screwdriver-cd/scm-github/forks","keys_url":"https://api.github.com/repos/screwdriver-cd/scm-github/keys{/key_id}","collaborators_url":"https://api.github.com/repos/screwdriver-cd/scm-github/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/screwdriver-cd/scm-github/teams","hooks_url":"https://api.github.com/repos/screwdriver-cd/scm-github/hooks","issue_events_url":"https://api.github.com/repos/screwdriver-cd/scm-github/issues/events{/number}","events_url":"https://api.github.com/repos/screwdriver-cd/scm-github/events","assignees_url":"https://api.github.com/repos/screwdriver-cd/scm-github/assignees{/user}","branches_url":"https://api.github.com/repos/screwdriver-cd/scm-github/branches{/branch}","tags_url":"https://api.github.com/repos/screwdriver-cd/scm-github/tags","blobs_url":"https://api.github.com/repos/screwdriver-cd/scm-github/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/screwdriver-cd/scm-github/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/screwdriver-cd/scm-github/git/refs{/sha}","trees_url":"https://api.github.com/repos/screwdriver-cd/scm-github/git/trees{/sha}","statuses_url":"https://api.github.com/repos/screwdriver-cd/scm-github/statuses/{sha}","languages_url":"https://api.github.com/repos/screwdriver-cd/scm-github/languages","stargazers_url":"https://api.github.com/repos/screwdriver-cd/scm-github/stargazers","contributors_url":"https://api.github.com/repos/screwdriver-cd/scm-github/contributors","subscribers_url":"https://api.github.com/repos/screwdriver-cd/scm-github/subscribers","subscription_url":"https://api.github.com/repos/screwdriver-cd/scm-github/subscription","commits_url":"https://api.github.com/repos/screwdriver-cd/scm-github/commits{/sha}","git_commits_url":"https://api.github.com/repos/screwdriver-cd/scm-github/git/commits{/sha}","comments_url":"https://api.github.com/repos/screwdriver-cd/scm-github/comments{/number}","issue_comment_url":"https://api.github.com/repos/screwdriver-cd/scm-github/issues/comments{/number}","contents_url":"https://api.github.com/repos/screwdriver-cd/scm-github/contents/{+path}","compare_url":"https://api.github.com/repos/screwdriver-cd/scm-github/compare/{base}...{head}","merges_url":"https://api.github.com/repos/screwdriver-cd/scm-github/merges","archive_url":"https://api.github.com/repos/screwdriver-cd/scm-github/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/screwdriver-cd/scm-github/downloads","issues_url":"https://api.github.com/repos/screwdriver-cd/scm-github/issues{/number}","pulls_url":"https://api.github.com/repos/screwdriver-cd/scm-github/pulls{/number}","milestones_url":"https://api.github.com/repos/screwdriver-cd/scm-github/milestones{/number}","notifications_url":"https://api.github.com/repos/screwdriver-cd/scm-github/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/screwdriver-cd/scm-github/labels{/name}","releases_url":"https://api.github.com/repos/screwdriver-cd/scm-github/releases{/id}","deployments_url":"https://api.github.com/repos/screwdriver-cd/scm-github/deployments","created_at":"2016-08-16T18:02:02Z","updated_at":"2016-10-29T05:34:32Z","pushed_at":"2016-12-02T22:28:06Z","git_url":"git://github.com/screwdriver-cd/scm-github.git","ssh_url":"git@github.com:screwdriver-cd/scm-github.git","clone_url":"https://github.com/screwdriver-cd/scm-github.git","svn_url":"https://github.com/screwdriver-cd/scm-github","homepage":null,"size":118,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"screwdriver-cd:master","ref":"master","sha":"909a2d87f72c74f5773794bca7f181706e13c1f9","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":65842228,"name":"scm-github","full_name":"screwdriver-cd/scm-github","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-github","description":"Github implementation of the scm-base class","fork":false,"url":"https://api.github.com/repos/screwdriver-cd/scm-github","forks_url":"https://api.github.com/repos/screwdriver-cd/scm-github/forks","keys_url":"https://api.github.com/repos/screwdriver-cd/scm-github/keys{/key_id}","collaborators_url":"https://api.github.com/repos/screwdriver-cd/scm-github/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/screwdriver-cd/scm-github/teams","hooks_url":"https://api.github.com/repos/screwdriver-cd/scm-github/hooks","issue_events_url":"https://api.github.com/repos/screwdriver-cd/scm-github/issues/events{/number}","events_url":"https://api.github.com/repos/screwdriver-cd/scm-github/events","assignees_url":"https://api.github.com/repos/screwdriver-cd/scm-github/assignees{/user}","branches_url":"https://api.github.com/repos/screwdriver-cd/scm-github/branches{/branch}","tags_url":"https://api.github.com/repos/screwdriver-cd/scm-github/tags","blobs_url":"https://api.github.com/repos/screwdriver-cd/scm-github/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/screwdriver-cd/scm-github/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/screwdriver-cd/scm-github/git/refs{/sha}","trees_url":"https://api.github.com/repos/screwdriver-cd/scm-github/git/trees{/sha}","statuses_url":"https://api.github.com/repos/screwdriver-cd/scm-github/statuses/{sha}","languages_url":"https://api.github.com/repos/screwdriver-cd/scm-github/languages","stargazers_url":"https://api.github.com/repos/screwdriver-cd/scm-github/stargazers","contributors_url":"https://api.github.com/repos/screwdriver-cd/scm-github/contributors","subscribers_url":"https://api.github.com/repos/screwdriver-cd/scm-github/subscribers","subscription_url":"https://api.github.com/repos/screwdriver-cd/scm-github/subscription","commits_url":"https://api.github.com/repos/screwdriver-cd/scm-github/commits{/sha}","git_commits_url":"https://api.github.com/repos/screwdriver-cd/scm-github/git/commits{/sha}","comments_url":"https://api.github.com/repos/screwdriver-cd/scm-github/comments{/number}","issue_comment_url":"https://api.github.com/repos/screwdriver-cd/scm-github/issues/comments{/number}","contents_url":"https://api.github.com/repos/screwdriver-cd/scm-github/contents/{+path}","compare_url":"https://api.github.com/repos/screwdriver-cd/scm-github/compare/{base}...{head}","merges_url":"https://api.github.com/repos/screwdriver-cd/scm-github/merges","archive_url":"https://api.github.com/repos/screwdriver-cd/scm-github/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/screwdriver-cd/scm-github/downloads","issues_url":"https://api.github.com/repos/screwdriver-cd/scm-github/issues{/number}","pulls_url":"https://api.github.com/repos/screwdriver-cd/scm-github/pulls{/number}","milestones_url":"https://api.github.com/repos/screwdriver-cd/scm-github/milestones{/number}","notifications_url":"https://api.github.com/repos/screwdriver-cd/scm-github/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/screwdriver-cd/scm-github/labels{/name}","releases_url":"https://api.github.com/repos/screwdriver-cd/scm-github/releases{/id}","deployments_url":"https://api.github.com/repos/screwdriver-cd/scm-github/deployments","created_at":"2016-08-16T18:02:02Z","updated_at":"2016-10-29T05:34:32Z","pushed_at":"2016-12-02T22:28:06Z","git_url":"git://github.com/screwdriver-cd/scm-github.git","ssh_url":"git@github.com:screwdriver-cd/scm-github.git","clone_url":"https://github.com/screwdriver-cd/scm-github.git","svn_url":"https://github.com/screwdriver-cd/scm-github","homepage":null,"size":118,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/screwdriver-cd/scm-github/pulls/45"},"html":{"href":"https://github.com/screwdriver-cd/scm-github/pull/45"},"issue":{"href":"https://api.github.com/repos/screwdriver-cd/scm-github/issues/45"},"comments":{"href":"https://api.github.com/repos/screwdriver-cd/scm-github/issues/45/comments"},"review_comments":{"href":"https://api.github.com/repos/screwdriver-cd/scm-github/pulls/45/comments"},"review_comment":{"href":"https://api.github.com/repos/screwdriver-cd/scm-github/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/screwdriver-cd/scm-github/pulls/45/commits"},"statuses":{"href":"https://api.github.com/repos/screwdriver-cd/scm-github/statuses/a35f9f289a5c047ca814c4fdc89db3ac4ec1e296"}}}}
{"actor":{"display_login":"d2lam"}}