{"action":"created","comment":{"url":"https://api.github.com/repos/screwdriver-cd/screwdriver/pulls/comments/145603450","pull_request_review_id":70426606,"id":145603450,"diff_hunk":"@@ -0,0 +1,108 @@\n+'use strict';\n+\n+const boom = require('boom');\n+const urlLib = require('url');\n+const validationSchema = require('screwdriver-data-schema');\n+\n+module.exports = () => ({\n+    method: 'POST',\n+    path: '/events',\n+    config: {\n+        description: 'Create and start a event',\n+        notes: 'Create and start a specific event',\n+        tags: ['api', 'events'],\n+        auth: {\n+            strategies: ['token', 'session'],\n+            scope: ['user']\n+        },\n+        plugins: {\n+            'hapi-swagger': {\n+                security: [{ token: [] }]\n+            }\n+        },\n+        handler: (request, reply) => {\n+            const eventFactory = request.server.app.eventFactory;\n+            const pipelineFactory = request.server.app.pipelineFactory;\n+            const userFactory = request.server.app.userFactory;\n+            const scm = eventFactory.scm;\n+            const pipelineId = request.payload.pipelineId;\n+            const scmContext = request.auth.credentials.scmContext;\n+            const startFrom = request.payload.startFrom;\n+            const username = request.auth.credentials.username;\n+            const payload = {\n+                pipelineId,\n+                scmContext,\n+                startFrom,\n+                type: 'pipeline',\n+                username\n+            };\n+            // Match PR-prNum, then extract prNum\n+            const prNumFullName = startFrom.match(validationSchema.config.regex.PR_JOB_NAME);\n+            const prNum = prNumFullName ? prNumFullName[1].split('-')[1] : null;\n+\n+            // Fetch the job and user models\n+            return Promise.all([\n+                pipelineFactory.get(pipelineId),\n+                userFactory.get({ username, scmContext })\n+            ])\n+                // Get scmUri\n+                .then(([pipeline, user]) =>\n+                    user.getPermissions(pipeline.scmUri)\n+                        // Check if user has push access\n+                        .then((permissions) => {\n+                            if (!permissions.push) {\n+                                throw boom.unauthorized(`User ${username} `\n+                            + 'does not have push permission for this repo');\n+                            }\n+                        })\n+                        // User has good permissions, create an event\n+                        .then(() => user.unsealToken())\n+                        .then((token) => {\n+                            const scmConfig = {\n+                                prNum,\n+                                scmContext,\n+                                scmUri: pipeline.scmUri,\n+                                token\n+                            };\n+\n+                            // Get commit sha\n+                            return scm.getCommitSha(scmConfig)\n+                                .then((sha) => {\n+                                    // For PRs\n+                                    if (prNum) {","path":"plugins/events/create.js","position":72,"original_position":72,"commit_id":"1fbd21be52049f2f0ddbb0a6c10ae9e537abd957","original_commit_id":"1fbd21be52049f2f0ddbb0a6c10ae9e537abd957","user":{"login":"jithin1987","id":193126,"avatar_url":"https://avatars2.githubusercontent.com/u/193126?v=4","gravatar_id":"","url":"https://api.github.com/users/jithin1987","html_url":"https://github.com/jithin1987","followers_url":"https://api.github.com/users/jithin1987/followers","following_url":"https://api.github.com/users/jithin1987/following{/other_user}","gists_url":"https://api.github.com/users/jithin1987/gists{/gist_id}","starred_url":"https://api.github.com/users/jithin1987/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jithin1987/subscriptions","organizations_url":"https://api.github.com/users/jithin1987/orgs","repos_url":"https://api.github.com/users/jithin1987/repos","events_url":"https://api.github.com/users/jithin1987/events{/privacy}","received_events_url":"https://api.github.com/users/jithin1987/received_events","type":"User","site_admin":false},"body":"what will trigger this flow ? Is'nt all PR event triggering happening via webhooks ?","created_at":"2017-10-19T05:37:59Z","updated_at":"2017-10-19T05:37:59Z","html_url":"https://github.com/screwdriver-cd/screwdriver/pull/762#discussion_r145603450","pull_request_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/pulls/762","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/screwdriver-cd/screwdriver/pulls/comments/145603450"},"html":{"href":"https://github.com/screwdriver-cd/screwdriver/pull/762#discussion_r145603450"},"pull_request":{"href":"https://api.github.com/repos/screwdriver-cd/screwdriver/pulls/762"}}},"pull_request":{"url":"https://api.github.com/repos/screwdriver-cd/screwdriver/pulls/762","id":147361123,"html_url":"https://github.com/screwdriver-cd/screwdriver/pull/762","diff_url":"https://github.com/screwdriver-cd/screwdriver/pull/762.diff","patch_url":"https://github.com/screwdriver-cd/screwdriver/pull/762.patch","issue_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/issues/762","number":762,"state":"open","locked":false,"title":"feat: Add POST route for creating events","user":{"login":"tkyi","id":3230529,"avatar_url":"https://avatars3.githubusercontent.com/u/3230529?v=4","gravatar_id":"","url":"https://api.github.com/users/tkyi","html_url":"https://github.com/tkyi","followers_url":"https://api.github.com/users/tkyi/followers","following_url":"https://api.github.com/users/tkyi/following{/other_user}","gists_url":"https://api.github.com/users/tkyi/gists{/gist_id}","starred_url":"https://api.github.com/users/tkyi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tkyi/subscriptions","organizations_url":"https://api.github.com/users/tkyi/orgs","repos_url":"https://api.github.com/users/tkyi/repos","events_url":"https://api.github.com/users/tkyi/events{/privacy}","received_events_url":"https://api.github.com/users/tkyi/received_events","type":"User","site_admin":false},"body":"## Context\r\n\r\nWith the new workflow implementation, users should be able to start a pipeline from any job (instead of only the first one).\r\n\r\n## Objective\r\n\r\nThis PR adds a `POST` route for creating events.\r\n\r\n## References\r\n\r\nRelated to: https://github.com/screwdriver-cd/screwdriver/issues/723\r\n\r\n","created_at":"2017-10-18T17:19:52Z","updated_at":"2017-10-19T05:37:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1291202460cfa74be7c8cea9e3e6c12463bebb81","assignee":{"login":"tkyi","id":3230529,"avatar_url":"https://avatars3.githubusercontent.com/u/3230529?v=4","gravatar_id":"","url":"https://api.github.com/users/tkyi","html_url":"https://github.com/tkyi","followers_url":"https://api.github.com/users/tkyi/followers","following_url":"https://api.github.com/users/tkyi/following{/other_user}","gists_url":"https://api.github.com/users/tkyi/gists{/gist_id}","starred_url":"https://api.github.com/users/tkyi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tkyi/subscriptions","organizations_url":"https://api.github.com/users/tkyi/orgs","repos_url":"https://api.github.com/users/tkyi/repos","events_url":"https://api.github.com/users/tkyi/events{/privacy}","received_events_url":"https://api.github.com/users/tkyi/received_events","type":"User","site_admin":false},"assignees":[{"login":"tkyi","id":3230529,"avatar_url":"https://avatars3.githubusercontent.com/u/3230529?v=4","gravatar_id":"","url":"https://api.github.com/users/tkyi","html_url":"https://github.com/tkyi","followers_url":"https://api.github.com/users/tkyi/followers","following_url":"https://api.github.com/users/tkyi/following{/other_user}","gists_url":"https://api.github.com/users/tkyi/gists{/gist_id}","starred_url":"https://api.github.com/users/tkyi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tkyi/subscriptions","organizations_url":"https://api.github.com/users/tkyi/orgs","repos_url":"https://api.github.com/users/tkyi/repos","events_url":"https://api.github.com/users/tkyi/events{/privacy}","received_events_url":"https://api.github.com/users/tkyi/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/pulls/762/commits","review_comments_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/pulls/762/comments","review_comment_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/pulls/comments{/number}","comments_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/issues/762/comments","statuses_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/statuses/1fbd21be52049f2f0ddbb0a6c10ae9e537abd957","head":{"label":"screwdriver-cd:createEvents","ref":"createEvents","sha":"1fbd21be52049f2f0ddbb0a6c10ae9e537abd957","user":{"login":"screwdriver-cd","id":19417863,"avatar_url":"https://avatars0.githubusercontent.com/u/19417863?v=4","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":59517730,"name":"screwdriver","full_name":"screwdriver-cd/screwdriver","owner":{"login":"screwdriver-cd","id":19417863,"avatar_url":"https://avatars0.githubusercontent.com/u/19417863?v=4","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/screwdriver","description":"An open source build platform designed for Continuous Delivery","fork":false,"url":"https://api.github.com/repos/screwdriver-cd/screwdriver","forks_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/forks","keys_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/keys{/key_id}","collaborators_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/teams","hooks_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/hooks","issue_events_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/issues/events{/number}","events_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/events","assignees_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/assignees{/user}","branches_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/branches{/branch}","tags_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/tags","blobs_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/git/refs{/sha}","trees_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/git/trees{/sha}","statuses_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/statuses/{sha}","languages_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/languages","stargazers_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/stargazers","contributors_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/contributors","subscribers_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/subscribers","subscription_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/subscription","commits_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/commits{/sha}","git_commits_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/git/commits{/sha}","comments_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/comments{/number}","issue_comment_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/issues/comments{/number}","contents_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/contents/{+path}","compare_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/compare/{base}...{head}","merges_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/merges","archive_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/downloads","issues_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/issues{/number}","pulls_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/pulls{/number}","milestones_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/milestones{/number}","notifications_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/labels{/name}","releases_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/releases{/id}","deployments_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/deployments","created_at":"2016-05-23T20:55:35Z","updated_at":"2017-10-17T03:57:54Z","pushed_at":"2017-10-19T00:40:33Z","git_url":"git://github.com/screwdriver-cd/screwdriver.git","ssh_url":"git@github.com:screwdriver-cd/screwdriver.git","clone_url":"https://github.com/screwdriver-cd/screwdriver.git","svn_url":"https://github.com/screwdriver-cd/screwdriver","homepage":"http://screwdriver.cd","size":1478,"stargazers_count":440,"watchers_count":440,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":60,"mirror_url":null,"open_issues_count":101,"forks":60,"open_issues":101,"watchers":440,"default_branch":"master"}},"base":{"label":"screwdriver-cd:master","ref":"master","sha":"bd00a7346860670eca9edf5ab45c6ce599b90860","user":{"login":"screwdriver-cd","id":19417863,"avatar_url":"https://avatars0.githubusercontent.com/u/19417863?v=4","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":59517730,"name":"screwdriver","full_name":"screwdriver-cd/screwdriver","owner":{"login":"screwdriver-cd","id":19417863,"avatar_url":"https://avatars0.githubusercontent.com/u/19417863?v=4","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/screwdriver","description":"An open source build platform designed for Continuous Delivery","fork":false,"url":"https://api.github.com/repos/screwdriver-cd/screwdriver","forks_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/forks","keys_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/keys{/key_id}","collaborators_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/teams","hooks_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/hooks","issue_events_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/issues/events{/number}","events_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/events","assignees_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/assignees{/user}","branches_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/branches{/branch}","tags_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/tags","blobs_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/git/refs{/sha}","trees_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/git/trees{/sha}","statuses_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/statuses/{sha}","languages_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/languages","stargazers_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/stargazers","contributors_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/contributors","subscribers_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/subscribers","subscription_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/subscription","commits_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/commits{/sha}","git_commits_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/git/commits{/sha}","comments_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/comments{/number}","issue_comment_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/issues/comments{/number}","contents_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/contents/{+path}","compare_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/compare/{base}...{head}","merges_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/merges","archive_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/downloads","issues_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/issues{/number}","pulls_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/pulls{/number}","milestones_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/milestones{/number}","notifications_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/labels{/name}","releases_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/releases{/id}","deployments_url":"https://api.github.com/repos/screwdriver-cd/screwdriver/deployments","created_at":"2016-05-23T20:55:35Z","updated_at":"2017-10-17T03:57:54Z","pushed_at":"2017-10-19T00:40:33Z","git_url":"git://github.com/screwdriver-cd/screwdriver.git","ssh_url":"git@github.com:screwdriver-cd/screwdriver.git","clone_url":"https://github.com/screwdriver-cd/screwdriver.git","svn_url":"https://github.com/screwdriver-cd/screwdriver","homepage":"http://screwdriver.cd","size":1478,"stargazers_count":440,"watchers_count":440,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":60,"mirror_url":null,"open_issues_count":101,"forks":60,"open_issues":101,"watchers":440,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/screwdriver-cd/screwdriver/pulls/762"},"html":{"href":"https://github.com/screwdriver-cd/screwdriver/pull/762"},"issue":{"href":"https://api.github.com/repos/screwdriver-cd/screwdriver/issues/762"},"comments":{"href":"https://api.github.com/repos/screwdriver-cd/screwdriver/issues/762/comments"},"review_comments":{"href":"https://api.github.com/repos/screwdriver-cd/screwdriver/pulls/762/comments"},"review_comment":{"href":"https://api.github.com/repos/screwdriver-cd/screwdriver/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/screwdriver-cd/screwdriver/pulls/762/commits"},"statuses":{"href":"https://api.github.com/repos/screwdriver-cd/screwdriver/statuses/1fbd21be52049f2f0ddbb0a6c10ae9e537abd957"}},"author_association":"OWNER"}}
{"actor":{"display_login":"jithin1987"}}