{"action":"created","comment":{"url":"https://api.github.com/repos/codice/ddf-support/pulls/comments/36796914","id":36796914,"diff_hunk":"@@ -30,34 +48,83 @@ module.exports = (robot) ->\n \n     try\n       if event_type in event_types && action_type in action_types\n+        # Determine which modules have modified files and trigger the appropriate PR build\n+        # Cases:\n+        #   1. Files change in the root\n+        #     - trigger ROOT (full repo) PR build\n+        #   2. Files change in multiple submodules\n+        #     - trigger ROOT (full repo) PR build\n+        #   3. Files change in only the distribution module\n+        #     - trigger the DISTRO PR build\n+        #   4. Files change in only one submodule that is not distribution (e.g. platform)\n+        #     - trigger MODULE PR build\n+        # The MODULE PR build will take a parameter that indicates the submodule to build\n+        # and includes distro + integration tasks.\n+        # The ROOT PR build builds from the reactor root with one maven task.\n+        # The DISTRO PR build builds the distro + integration tests with separate tasks.\n+\n+        repoDeltas = (base_url, pr_num, callback) ->\n+          robot.http(base_url + \"/pulls/\" + pr_num + \"/files\")\n+            .header('Authorization', \"token #{github_api_token}\")\n+            .get() (err, res, body) ->\n+              if err\n+                console.log \"Encountered an error: #{err}\"\n+              else\n+                files_body = JSON.parse body\n+                files = (obj.filename.split(\"/\") for obj in files_body)\n+\n+                root_delta = files.some((el) -> el.length == 1)\n+                redFunc = (acc, val) ->\n+                  if val.length > 1 and val[0] not in acc and val[0] != \"distribution\"\n+                    acc.concat(val[0])\n+                  else\n+                    acc\n+                directories = files.reduce(redFunc, [])\n+                console.log \"Submodules to build - \" + directories.toString()\n+\n+                if root_delta or directories.length > 1\n+                  callback(root_pr_plan)\n+                else if directories.length == 0\n+                  callback(distro_pr_plan)\n+                else\n+                  callback(module_pr_plan, directories[0])\n \n         # Webhook was generated by valid pull request. Attempt to queue Bamboo PR build\n         console.log \"Processing #{event_type} event in repo #{payload.pull_request.html_url}. Action: #{action_type}\"\n-        robot.http(\"#{bamboo_url}/rest/api/latest/queue/#{build_key}?\" +\n-                   \"bamboo.variable.pull_ref=#{payload.pull_request.head.ref}&\" +\n-                   \"bamboo.variable.pull_sha=#{payload.pull_request.head.sha}&\" +\n-                   \"bamboo.variable.pull_num=#{payload.number}&\" +\n-                   \"bamboo.variable.git_repo_url=#{payload.repository.clone_url}\")\n-          .auth(bamboo_user, bamboo_pass)\n-          .header('Accept', 'application/json')\n-          .post() (err, res, body) ->\n-            if err\n-              console.log \"Encountered an error :( #{err}\"\n-            else\n-              json_body = JSON.parse body\n-\n-              # Determine whether build was successfully queued and update GitHub PR status accordingly\n-              if !json_body.hasOwnProperty(\"status-code\")\n-                robot.http(payload.pull_request.statuses_url)\n-                  .header('Authorization', \"token #{github_api_token}\")\n-                  .post('{\"state\": \"pending\", \"context\": \"bamboo\", \"description\": \"A Bamboo build has been queued\", \"target_url\": \"' +\n-                        \"#{bamboo_url}/browse/#{json_body.buildResultKey}\\\"}\")\n+        bamboo_post = (build_plan, submodule) ->\n+          bamboo_query = \"#{bamboo_url}/rest/api/latest/queue/#{build_plan}?\" +\n+            \"bamboo.variable.pull_ref=#{payload.pull_request.head.ref}&\" +\n+            \"bamboo.variable.pull_sha=#{payload.pull_request.head.sha}&\" +\n+            \"bamboo.variable.pull_num=#{payload.number}&\" +\n+            \"bamboo.variable.git_repo_url=#{payload.repository.clone_url}\"\n+          if (submodule?)\n+            bamboo_query = bamboo_query + \"&bamboo.variable.submodule=#{submodule}\"\n+\n+          robot.http(bamboo_query)\n+            .auth(bamboo_user, bamboo_pass)\n+            .header('Accept', 'application/json')\n+            .post() (err, res, body) ->\n+              if err\n+                console.log \"Encountered an error :( #{err}\"\n               else\n-                console.log body\n-                robot.http(payload.pull_request.statuses_url)\n-                  .header('Authorization', \"token #{github_api_token}\")\n-                  .post('{\"state\": \"failure\", \"context\": \"bamboo\", \"description\": \"' + \"#{json_body.message}\" + '\", \"target_url\": \"' +\n-                        \"#{bamboo_url}/browse/#{build_key}\\\"}\")\n+                json_body = JSON.parse body\n+\n+                # Determine whether build was successfully queued and update GitHub PR status accordingly\n+                if !json_body.hasOwnProperty(\"status-code\")\n+                  robot.http(payload.pull_request.statuses_url)\n+                    .header('Authorization', \"token #{github_api_token}\")\n+                    .post('{\"state\": \"pending\", \"context\": \"bamboo\", \"description\": \"A Bamboo build has been queued\", \"target_url\": \"' +\n+                          \"#{bamboo_url}/browse/#{json_body.buildResultKey}\\\"}\")\n+                else\n+                  console.log body\n+                  robot.http(payload.pull_request.statuses_url)\n+                    .header('Authorization', \"token #{github_api_token}\")\n+                    .post('{\"state\": \"failure\", \"context\": \"bamboo\", \"description\": \"' + \"#{json_body.message}\" + '\", \"target_url\": \"' +\n+                          \"#{bamboo_url}/browse/#{build_key}\\\"}\")","path":"support-hubot/hubot-bamboo-prbuild/index.coffee","position":140,"original_position":140,"commit_id":"3b31e0f807c82a96bef43e5c439dc876ea6a6018","original_commit_id":"3b31e0f807c82a96bef43e5c439dc876ea6a6018","user":{"login":"SmithJosh","id":3878142,"avatar_url":"https://avatars.githubusercontent.com/u/3878142?v=3","gravatar_id":"","url":"https://api.github.com/users/SmithJosh","html_url":"https://github.com/SmithJosh","followers_url":"https://api.github.com/users/SmithJosh/followers","following_url":"https://api.github.com/users/SmithJosh/following{/other_user}","gists_url":"https://api.github.com/users/SmithJosh/gists{/gist_id}","starred_url":"https://api.github.com/users/SmithJosh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SmithJosh/subscriptions","organizations_url":"https://api.github.com/users/SmithJosh/orgs","repos_url":"https://api.github.com/users/SmithJosh/repos","events_url":"https://api.github.com/users/SmithJosh/events{/privacy}","received_events_url":"https://api.github.com/users/SmithJosh/received_events","type":"User","site_admin":false},"body":"The build_key variable here no longer exists.","created_at":"2015-08-11T20:49:20Z","updated_at":"2015-08-11T20:49:20Z","html_url":"https://github.com/codice/ddf-support/pull/20#discussion_r36796914","pull_request_url":"https://api.github.com/repos/codice/ddf-support/pulls/20","_links":{"self":{"href":"https://api.github.com/repos/codice/ddf-support/pulls/comments/36796914"},"html":{"href":"https://github.com/codice/ddf-support/pull/20#discussion_r36796914"},"pull_request":{"href":"https://api.github.com/repos/codice/ddf-support/pulls/20"}}},"pull_request":{"url":"https://api.github.com/repos/codice/ddf-support/pulls/20","id":42168238,"html_url":"https://github.com/codice/ddf-support/pull/20","diff_url":"https://github.com/codice/ddf-support/pull/20.diff","patch_url":"https://github.com/codice/ddf-support/pull/20.patch","issue_url":"https://api.github.com/repos/codice/ddf-support/issues/20","number":20,"state":"open","locked":false,"title":"DDF-1405 Changes github-to-bamboo hubot script to pick appropriate PR build plans based on file deltas","user":{"login":"coyotesqrl","id":1469860,"avatar_url":"https://avatars.githubusercontent.com/u/1469860?v=3","gravatar_id":"","url":"https://api.github.com/users/coyotesqrl","html_url":"https://github.com/coyotesqrl","followers_url":"https://api.github.com/users/coyotesqrl/followers","following_url":"https://api.github.com/users/coyotesqrl/following{/other_user}","gists_url":"https://api.github.com/users/coyotesqrl/gists{/gist_id}","starred_url":"https://api.github.com/users/coyotesqrl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coyotesqrl/subscriptions","organizations_url":"https://api.github.com/users/coyotesqrl/orgs","repos_url":"https://api.github.com/users/coyotesqrl/repos","events_url":"https://api.github.com/users/coyotesqrl/events{/privacy}","received_events_url":"https://api.github.com/users/coyotesqrl/received_events","type":"User","site_admin":false},"body":"With the repositories merged, our PR builds will now provisionally build only the submodule changed and run the distro + integration tests builds. If a PR has changes that span multiple submodules, we will build the entire repository; likewise, any change to the root of the repository (the reactor pom, in most cases) will result in a full build.\r\n\r\nChanges to the distribution submodule will only run a build of that single submodule.\r\n\r\nTightly coupled to this PR are the three new PR build plans (when we are finished, they should be the only remaining PR build plans)\r\n\r\n+ https://codice.atlassian.net/builds/browse/DDFPR-DIS\r\n+ https://codice.atlassian.net/builds/browse/DDFPR-MOD\r\n+ https://codice.atlassian.net/builds/browse/DDFPR-ROOT\r\n\r\nA final change will be removing the superseded `buildKey` query param on the webhook. It won't hurt us by being there, but holds no value anymore.\r\n\r\n@lessarderic \r\n@SmithJosh \r\n@pklinef ","created_at":"2015-08-11T19:34:16Z","updated_at":"2015-08-11T20:49:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ab1143d7f0d6281cbc96b74ce5cefcefa6c913aa","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/codice/ddf-support/pulls/20/commits","review_comments_url":"https://api.github.com/repos/codice/ddf-support/pulls/20/comments","review_comment_url":"https://api.github.com/repos/codice/ddf-support/pulls/comments{/number}","comments_url":"https://api.github.com/repos/codice/ddf-support/issues/20/comments","statuses_url":"https://api.github.com/repos/codice/ddf-support/statuses/3b31e0f807c82a96bef43e5c439dc876ea6a6018","head":{"label":"coyotesqrl:DDF-1405","ref":"DDF-1405","sha":"3b31e0f807c82a96bef43e5c439dc876ea6a6018","user":{"login":"coyotesqrl","id":1469860,"avatar_url":"https://avatars.githubusercontent.com/u/1469860?v=3","gravatar_id":"","url":"https://api.github.com/users/coyotesqrl","html_url":"https://github.com/coyotesqrl","followers_url":"https://api.github.com/users/coyotesqrl/followers","following_url":"https://api.github.com/users/coyotesqrl/following{/other_user}","gists_url":"https://api.github.com/users/coyotesqrl/gists{/gist_id}","starred_url":"https://api.github.com/users/coyotesqrl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coyotesqrl/subscriptions","organizations_url":"https://api.github.com/users/coyotesqrl/orgs","repos_url":"https://api.github.com/users/coyotesqrl/repos","events_url":"https://api.github.com/users/coyotesqrl/events{/privacy}","received_events_url":"https://api.github.com/users/coyotesqrl/received_events","type":"User","site_admin":false},"repo":{"id":40561026,"name":"ddf-support","full_name":"coyotesqrl/ddf-support","owner":{"login":"coyotesqrl","id":1469860,"avatar_url":"https://avatars.githubusercontent.com/u/1469860?v=3","gravatar_id":"","url":"https://api.github.com/users/coyotesqrl","html_url":"https://github.com/coyotesqrl","followers_url":"https://api.github.com/users/coyotesqrl/followers","following_url":"https://api.github.com/users/coyotesqrl/following{/other_user}","gists_url":"https://api.github.com/users/coyotesqrl/gists{/gist_id}","starred_url":"https://api.github.com/users/coyotesqrl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coyotesqrl/subscriptions","organizations_url":"https://api.github.com/users/coyotesqrl/orgs","repos_url":"https://api.github.com/users/coyotesqrl/repos","events_url":"https://api.github.com/users/coyotesqrl/events{/privacy}","received_events_url":"https://api.github.com/users/coyotesqrl/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/coyotesqrl/ddf-support","description":"DDF Support project","fork":true,"url":"https://api.github.com/repos/coyotesqrl/ddf-support","forks_url":"https://api.github.com/repos/coyotesqrl/ddf-support/forks","keys_url":"https://api.github.com/repos/coyotesqrl/ddf-support/keys{/key_id}","collaborators_url":"https://api.github.com/repos/coyotesqrl/ddf-support/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/coyotesqrl/ddf-support/teams","hooks_url":"https://api.github.com/repos/coyotesqrl/ddf-support/hooks","issue_events_url":"https://api.github.com/repos/coyotesqrl/ddf-support/issues/events{/number}","events_url":"https://api.github.com/repos/coyotesqrl/ddf-support/events","assignees_url":"https://api.github.com/repos/coyotesqrl/ddf-support/assignees{/user}","branches_url":"https://api.github.com/repos/coyotesqrl/ddf-support/branches{/branch}","tags_url":"https://api.github.com/repos/coyotesqrl/ddf-support/tags","blobs_url":"https://api.github.com/repos/coyotesqrl/ddf-support/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/coyotesqrl/ddf-support/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/coyotesqrl/ddf-support/git/refs{/sha}","trees_url":"https://api.github.com/repos/coyotesqrl/ddf-support/git/trees{/sha}","statuses_url":"https://api.github.com/repos/coyotesqrl/ddf-support/statuses/{sha}","languages_url":"https://api.github.com/repos/coyotesqrl/ddf-support/languages","stargazers_url":"https://api.github.com/repos/coyotesqrl/ddf-support/stargazers","contributors_url":"https://api.github.com/repos/coyotesqrl/ddf-support/contributors","subscribers_url":"https://api.github.com/repos/coyotesqrl/ddf-support/subscribers","subscription_url":"https://api.github.com/repos/coyotesqrl/ddf-support/subscription","commits_url":"https://api.github.com/repos/coyotesqrl/ddf-support/commits{/sha}","git_commits_url":"https://api.github.com/repos/coyotesqrl/ddf-support/git/commits{/sha}","comments_url":"https://api.github.com/repos/coyotesqrl/ddf-support/comments{/number}","issue_comment_url":"https://api.github.com/repos/coyotesqrl/ddf-support/issues/comments{/number}","contents_url":"https://api.github.com/repos/coyotesqrl/ddf-support/contents/{+path}","compare_url":"https://api.github.com/repos/coyotesqrl/ddf-support/compare/{base}...{head}","merges_url":"https://api.github.com/repos/coyotesqrl/ddf-support/merges","archive_url":"https://api.github.com/repos/coyotesqrl/ddf-support/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/coyotesqrl/ddf-support/downloads","issues_url":"https://api.github.com/repos/coyotesqrl/ddf-support/issues{/number}","pulls_url":"https://api.github.com/repos/coyotesqrl/ddf-support/pulls{/number}","milestones_url":"https://api.github.com/repos/coyotesqrl/ddf-support/milestones{/number}","notifications_url":"https://api.github.com/repos/coyotesqrl/ddf-support/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/coyotesqrl/ddf-support/labels{/name}","releases_url":"https://api.github.com/repos/coyotesqrl/ddf-support/releases{/id}","created_at":"2015-08-11T19:30:20Z","updated_at":"2015-08-11T19:30:21Z","pushed_at":"2015-08-11T20:30:08Z","git_url":"git://github.com/coyotesqrl/ddf-support.git","ssh_url":"git@github.com:coyotesqrl/ddf-support.git","clone_url":"https://github.com/coyotesqrl/ddf-support.git","svn_url":"https://github.com/coyotesqrl/ddf-support","homepage":null,"size":424,"stargazers_count":0,"watchers_count":0,"language":"Groovy","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":"codice:master","ref":"master","sha":"6d3fe76184466877e7bf2888b340376cdf540440","user":{"login":"codice","id":2386734,"avatar_url":"https://avatars.githubusercontent.com/u/2386734?v=3","gravatar_id":"","url":"https://api.github.com/users/codice","html_url":"https://github.com/codice","followers_url":"https://api.github.com/users/codice/followers","following_url":"https://api.github.com/users/codice/following{/other_user}","gists_url":"https://api.github.com/users/codice/gists{/gist_id}","starred_url":"https://api.github.com/users/codice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codice/subscriptions","organizations_url":"https://api.github.com/users/codice/orgs","repos_url":"https://api.github.com/users/codice/repos","events_url":"https://api.github.com/users/codice/events{/privacy}","received_events_url":"https://api.github.com/users/codice/received_events","type":"Organization","site_admin":false},"repo":{"id":15775344,"name":"ddf-support","full_name":"codice/ddf-support","owner":{"login":"codice","id":2386734,"avatar_url":"https://avatars.githubusercontent.com/u/2386734?v=3","gravatar_id":"","url":"https://api.github.com/users/codice","html_url":"https://github.com/codice","followers_url":"https://api.github.com/users/codice/followers","following_url":"https://api.github.com/users/codice/following{/other_user}","gists_url":"https://api.github.com/users/codice/gists{/gist_id}","starred_url":"https://api.github.com/users/codice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codice/subscriptions","organizations_url":"https://api.github.com/users/codice/orgs","repos_url":"https://api.github.com/users/codice/repos","events_url":"https://api.github.com/users/codice/events{/privacy}","received_events_url":"https://api.github.com/users/codice/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/codice/ddf-support","description":"DDF Support project","fork":false,"url":"https://api.github.com/repos/codice/ddf-support","forks_url":"https://api.github.com/repos/codice/ddf-support/forks","keys_url":"https://api.github.com/repos/codice/ddf-support/keys{/key_id}","collaborators_url":"https://api.github.com/repos/codice/ddf-support/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/codice/ddf-support/teams","hooks_url":"https://api.github.com/repos/codice/ddf-support/hooks","issue_events_url":"https://api.github.com/repos/codice/ddf-support/issues/events{/number}","events_url":"https://api.github.com/repos/codice/ddf-support/events","assignees_url":"https://api.github.com/repos/codice/ddf-support/assignees{/user}","branches_url":"https://api.github.com/repos/codice/ddf-support/branches{/branch}","tags_url":"https://api.github.com/repos/codice/ddf-support/tags","blobs_url":"https://api.github.com/repos/codice/ddf-support/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/codice/ddf-support/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/codice/ddf-support/git/refs{/sha}","trees_url":"https://api.github.com/repos/codice/ddf-support/git/trees{/sha}","statuses_url":"https://api.github.com/repos/codice/ddf-support/statuses/{sha}","languages_url":"https://api.github.com/repos/codice/ddf-support/languages","stargazers_url":"https://api.github.com/repos/codice/ddf-support/stargazers","contributors_url":"https://api.github.com/repos/codice/ddf-support/contributors","subscribers_url":"https://api.github.com/repos/codice/ddf-support/subscribers","subscription_url":"https://api.github.com/repos/codice/ddf-support/subscription","commits_url":"https://api.github.com/repos/codice/ddf-support/commits{/sha}","git_commits_url":"https://api.github.com/repos/codice/ddf-support/git/commits{/sha}","comments_url":"https://api.github.com/repos/codice/ddf-support/comments{/number}","issue_comment_url":"https://api.github.com/repos/codice/ddf-support/issues/comments{/number}","contents_url":"https://api.github.com/repos/codice/ddf-support/contents/{+path}","compare_url":"https://api.github.com/repos/codice/ddf-support/compare/{base}...{head}","merges_url":"https://api.github.com/repos/codice/ddf-support/merges","archive_url":"https://api.github.com/repos/codice/ddf-support/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/codice/ddf-support/downloads","issues_url":"https://api.github.com/repos/codice/ddf-support/issues{/number}","pulls_url":"https://api.github.com/repos/codice/ddf-support/pulls{/number}","milestones_url":"https://api.github.com/repos/codice/ddf-support/milestones{/number}","notifications_url":"https://api.github.com/repos/codice/ddf-support/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/codice/ddf-support/labels{/name}","releases_url":"https://api.github.com/repos/codice/ddf-support/releases{/id}","created_at":"2014-01-09T18:27:46Z","updated_at":"2015-05-05T18:33:26Z","pushed_at":"2015-08-11T20:30:09Z","git_url":"git://github.com/codice/ddf-support.git","ssh_url":"git@github.com:codice/ddf-support.git","clone_url":"https://github.com/codice/ddf-support.git","svn_url":"https://github.com/codice/ddf-support","homepage":null,"size":424,"stargazers_count":0,"watchers_count":0,"language":"Groovy","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":16,"mirror_url":null,"open_issues_count":1,"forks":16,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/codice/ddf-support/pulls/20"},"html":{"href":"https://github.com/codice/ddf-support/pull/20"},"issue":{"href":"https://api.github.com/repos/codice/ddf-support/issues/20"},"comments":{"href":"https://api.github.com/repos/codice/ddf-support/issues/20/comments"},"review_comments":{"href":"https://api.github.com/repos/codice/ddf-support/pulls/20/comments"},"review_comment":{"href":"https://api.github.com/repos/codice/ddf-support/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/codice/ddf-support/pulls/20/commits"},"statuses":{"href":"https://api.github.com/repos/codice/ddf-support/statuses/3b31e0f807c82a96bef43e5c439dc876ea6a6018"}}}}