{"action":"created","comment":{"url":"https://api.github.com/repos/zendesk/samson/pulls/comments/77217449","id":77217449,"diff_hunk":"@@ -52,46 +53,47 @@ def destroy\n   end\n \n   def deploy_all\n-    @stages = Project.all.flat_map do |project|\n-      environment = Environment.find(params[:environment_id]) if params[:environment_id]\n+    environment = deploy_group.environment\n+    deploys = deploy_group.stages.map do |stage|\n+      template_stage = environment.template_stages.where(project: stage.project).first\n+      next unless template_stage\n \n-      stages = stages_in_same_environment(project, environment)\n-      next unless deploy = stages.map(&:last_successful_deploy).compact.sort_by(&:created_at).last\n-      stages.map { |s| [s, deploy] }\n-    end.compact\n-  end\n+      last_success_deploy = template_stage.last_successful_deploy\n+      next unless last_success_deploy\n \n-  def deploy_all_now\n-    deploys = params.require(:stages).map do |stage|\n-      stage_id, reference = stage.split(\"-\", 2)\n-      stage = Stage.find(stage_id)\n-      stage = new_stage_with_group(stage) unless only_to_current_group?(stage)\n       deploy_service = DeployService.new(current_user)\n-      deploy_service.deploy!(stage, reference: reference)\n-    end\n-    redirect_to deploys_path(ids: deploys.map(&:id))\n-  end\n-\n-  private\n+      deploy_service.deploy!(stage, reference: last_success_deploy.reference)\n+    end.compact\n \n-  def only_to_current_group?(stage)\n-    stage.deploy_groups.map(&:id) == [deploy_group.id]\n+    if deploys.empty?\n+      flash[:error] = \"There were no stages ready for deploy.\"\n+      redirect_to deploys_path\n+    else\n+      redirect_to deploys_path(ids: deploys.map(&:id))\n+    end\n   end\n \n-  def stages_in_same_environment(project, environment)\n-    environment ||= deploy_group.environment\n-    stages = project.stages.select do |stage|\n-      stage.script.include?(\"$DEPLOY_GROUPS\") && # is dynamic\n-        stage.deploy_groups.where(environment: environment).exists? # is made to go to this environment\n+  def create_all_stages\n+    # No more than one stage, per project, per deploy_group\n+    # Note: you can call this multiple times, and it will create missing stages, but no redundant stages.\n+    environment = deploy_group.environment\n+    Project.where(include_new_deploy_groups: true).each do |project|\n+      template_stage = environment.template_stages.where(project: project).first\n+      deploy_group_stage = deploy_group.stages.where(project: project).first","path":"app/controllers/admin/deploy_groups_controller.rb","position":67,"original_position":67,"commit_id":"7b59271957830dba318c44b294f16b2ae686a0f1","original_commit_id":"7b59271957830dba318c44b294f16b2ae686a0f1","user":{"login":"grosser","id":11367,"avatar_url":"https://avatars.githubusercontent.com/u/11367?v=3","gravatar_id":"","url":"https://api.github.com/users/grosser","html_url":"https://github.com/grosser","followers_url":"https://api.github.com/users/grosser/followers","following_url":"https://api.github.com/users/grosser/following{/other_user}","gists_url":"https://api.github.com/users/grosser/gists{/gist_id}","starred_url":"https://api.github.com/users/grosser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grosser/subscriptions","organizations_url":"https://api.github.com/users/grosser/orgs","repos_url":"https://api.github.com/users/grosser/repos","events_url":"https://api.github.com/users/grosser/events{/privacy}","received_events_url":"https://api.github.com/users/grosser/received_events","type":"User","site_admin":false},"body":"could avoid N+1 here and fetch all the stages upfront ... same for the line above","created_at":"2016-09-01T17:28:19Z","updated_at":"2016-09-01T17:28:19Z","html_url":"https://github.com/zendesk/samson/pull/1242#discussion_r77217449","pull_request_url":"https://api.github.com/repos/zendesk/samson/pulls/1242","_links":{"self":{"href":"https://api.github.com/repos/zendesk/samson/pulls/comments/77217449"},"html":{"href":"https://github.com/zendesk/samson/pull/1242#discussion_r77217449"},"pull_request":{"href":"https://api.github.com/repos/zendesk/samson/pulls/1242"}}},"pull_request":{"url":"https://api.github.com/repos/zendesk/samson/pulls/1242","id":82997134,"html_url":"https://github.com/zendesk/samson/pull/1242","diff_url":"https://github.com/zendesk/samson/pull/1242.diff","patch_url":"https://github.com/zendesk/samson/pull/1242.patch","issue_url":"https://api.github.com/repos/zendesk/samson/issues/1242","number":1242,"state":"open","locked":false,"title":"Pod-o-matic: Create new stages for deploy group.","user":{"login":"dragonfax","id":933806,"avatar_url":"https://avatars.githubusercontent.com/u/933806?v=3","gravatar_id":"","url":"https://api.github.com/users/dragonfax","html_url":"https://github.com/dragonfax","followers_url":"https://api.github.com/users/dragonfax/followers","following_url":"https://api.github.com/users/dragonfax/following{/other_user}","gists_url":"https://api.github.com/users/dragonfax/gists{/gist_id}","starred_url":"https://api.github.com/users/dragonfax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dragonfax/subscriptions","organizations_url":"https://api.github.com/users/dragonfax/orgs","repos_url":"https://api.github.com/users/dragonfax/repos","events_url":"https://api.github.com/users/dragonfax/events{/privacy}","received_events_url":"https://api.github.com/users/dragonfax/received_events","type":"User","site_admin":false},"body":"Migrations and UI for managing automatic pod creation.\r\n\r\n? should this attribute be `environment_template` rather than `template_environment`?\r\n\r\n### Screenshots\r\n\r\n## Template status show in stages list\r\n\r\nOn project view page\r\n\r\n![test_project](https://cloud.githubusercontent.com/assets/933806/18070787/244f13aa-6e05-11e6-939c-ec984cd31a9f.png)\r\n\r\n## Project Setting for Including in New Pods\r\n\r\n![samson](https://cloud.githubusercontent.com/assets/933806/18070816/6265948e-6e05-11e6-86d3-b27144434e59.png)\r\n\r\n## Stage Settings, choose the template environment\r\n\r\n![editing_master__test_project_](https://cloud.githubusercontent.com/assets/933806/18070848/9044898c-6e05-11e6-92a8-76a3828b07e5.png)\r\n\r\n## Deploy Group page, \r\n\r\nButton for creating missing stages, and a dialog for verification before doing so.\r\n\r\n![fullscreen_8_29_16__4_29_pm](https://cloud.githubusercontent.com/assets/933806/18070898/f1799f08-6e05-11e6-9efc-a49ff8adf8c7.png)\r\n\r\n\r\n### References\r\n - Jira link: https://zendesk.atlassian.net/browse/TOOLS-791\r\n\r\n### Risks\r\n- Level: Low\r\n\r\nWe're adding funcionality, not removing or changing it. But this does involve database migrations and new fields in existing forms.\r\n","created_at":"2016-08-27T20:01:45Z","updated_at":"2016-09-01T17:28:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b53bec939197af1083441dfd342a1ca7c1c17310","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/zendesk/samson/pulls/1242/commits","review_comments_url":"https://api.github.com/repos/zendesk/samson/pulls/1242/comments","review_comment_url":"https://api.github.com/repos/zendesk/samson/pulls/comments{/number}","comments_url":"https://api.github.com/repos/zendesk/samson/issues/1242/comments","statuses_url":"https://api.github.com/repos/zendesk/samson/statuses/7b59271957830dba318c44b294f16b2ae686a0f1","head":{"label":"zendesk:jstillwell/podomatic_ui","ref":"jstillwell/podomatic_ui","sha":"7b59271957830dba318c44b294f16b2ae686a0f1","user":{"login":"zendesk","id":11525,"avatar_url":"https://avatars.githubusercontent.com/u/11525?v=3","gravatar_id":"","url":"https://api.github.com/users/zendesk","html_url":"https://github.com/zendesk","followers_url":"https://api.github.com/users/zendesk/followers","following_url":"https://api.github.com/users/zendesk/following{/other_user}","gists_url":"https://api.github.com/users/zendesk/gists{/gist_id}","starred_url":"https://api.github.com/users/zendesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zendesk/subscriptions","organizations_url":"https://api.github.com/users/zendesk/orgs","repos_url":"https://api.github.com/users/zendesk/repos","events_url":"https://api.github.com/users/zendesk/events{/privacy}","received_events_url":"https://api.github.com/users/zendesk/received_events","type":"Organization","site_admin":false},"repo":{"id":20208662,"name":"samson","full_name":"zendesk/samson","owner":{"login":"zendesk","id":11525,"avatar_url":"https://avatars.githubusercontent.com/u/11525?v=3","gravatar_id":"","url":"https://api.github.com/users/zendesk","html_url":"https://github.com/zendesk","followers_url":"https://api.github.com/users/zendesk/followers","following_url":"https://api.github.com/users/zendesk/following{/other_user}","gists_url":"https://api.github.com/users/zendesk/gists{/gist_id}","starred_url":"https://api.github.com/users/zendesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zendesk/subscriptions","organizations_url":"https://api.github.com/users/zendesk/orgs","repos_url":"https://api.github.com/users/zendesk/repos","events_url":"https://api.github.com/users/zendesk/events{/privacy}","received_events_url":"https://api.github.com/users/zendesk/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zendesk/samson","description":"Web interface for deployments","fork":false,"url":"https://api.github.com/repos/zendesk/samson","forks_url":"https://api.github.com/repos/zendesk/samson/forks","keys_url":"https://api.github.com/repos/zendesk/samson/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zendesk/samson/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zendesk/samson/teams","hooks_url":"https://api.github.com/repos/zendesk/samson/hooks","issue_events_url":"https://api.github.com/repos/zendesk/samson/issues/events{/number}","events_url":"https://api.github.com/repos/zendesk/samson/events","assignees_url":"https://api.github.com/repos/zendesk/samson/assignees{/user}","branches_url":"https://api.github.com/repos/zendesk/samson/branches{/branch}","tags_url":"https://api.github.com/repos/zendesk/samson/tags","blobs_url":"https://api.github.com/repos/zendesk/samson/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zendesk/samson/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zendesk/samson/git/refs{/sha}","trees_url":"https://api.github.com/repos/zendesk/samson/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zendesk/samson/statuses/{sha}","languages_url":"https://api.github.com/repos/zendesk/samson/languages","stargazers_url":"https://api.github.com/repos/zendesk/samson/stargazers","contributors_url":"https://api.github.com/repos/zendesk/samson/contributors","subscribers_url":"https://api.github.com/repos/zendesk/samson/subscribers","subscription_url":"https://api.github.com/repos/zendesk/samson/subscription","commits_url":"https://api.github.com/repos/zendesk/samson/commits{/sha}","git_commits_url":"https://api.github.com/repos/zendesk/samson/git/commits{/sha}","comments_url":"https://api.github.com/repos/zendesk/samson/comments{/number}","issue_comment_url":"https://api.github.com/repos/zendesk/samson/issues/comments{/number}","contents_url":"https://api.github.com/repos/zendesk/samson/contents/{+path}","compare_url":"https://api.github.com/repos/zendesk/samson/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zendesk/samson/merges","archive_url":"https://api.github.com/repos/zendesk/samson/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zendesk/samson/downloads","issues_url":"https://api.github.com/repos/zendesk/samson/issues{/number}","pulls_url":"https://api.github.com/repos/zendesk/samson/pulls{/number}","milestones_url":"https://api.github.com/repos/zendesk/samson/milestones{/number}","notifications_url":"https://api.github.com/repos/zendesk/samson/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zendesk/samson/labels{/name}","releases_url":"https://api.github.com/repos/zendesk/samson/releases{/id}","deployments_url":"https://api.github.com/repos/zendesk/samson/deployments","created_at":"2014-05-27T05:55:57Z","updated_at":"2016-09-01T16:40:37Z","pushed_at":"2016-09-01T17:14:26Z","git_url":"git://github.com/zendesk/samson.git","ssh_url":"git@github.com:zendesk/samson.git","clone_url":"https://github.com/zendesk/samson.git","svn_url":"https://github.com/zendesk/samson","homepage":null,"size":207193,"stargazers_count":736,"watchers_count":736,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":141,"mirror_url":null,"open_issues_count":65,"forks":141,"open_issues":65,"watchers":736,"default_branch":"master"}},"base":{"label":"zendesk:master","ref":"master","sha":"15ab6494dbedbc1449c645a6e2a4ff70cc8bf8b8","user":{"login":"zendesk","id":11525,"avatar_url":"https://avatars.githubusercontent.com/u/11525?v=3","gravatar_id":"","url":"https://api.github.com/users/zendesk","html_url":"https://github.com/zendesk","followers_url":"https://api.github.com/users/zendesk/followers","following_url":"https://api.github.com/users/zendesk/following{/other_user}","gists_url":"https://api.github.com/users/zendesk/gists{/gist_id}","starred_url":"https://api.github.com/users/zendesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zendesk/subscriptions","organizations_url":"https://api.github.com/users/zendesk/orgs","repos_url":"https://api.github.com/users/zendesk/repos","events_url":"https://api.github.com/users/zendesk/events{/privacy}","received_events_url":"https://api.github.com/users/zendesk/received_events","type":"Organization","site_admin":false},"repo":{"id":20208662,"name":"samson","full_name":"zendesk/samson","owner":{"login":"zendesk","id":11525,"avatar_url":"https://avatars.githubusercontent.com/u/11525?v=3","gravatar_id":"","url":"https://api.github.com/users/zendesk","html_url":"https://github.com/zendesk","followers_url":"https://api.github.com/users/zendesk/followers","following_url":"https://api.github.com/users/zendesk/following{/other_user}","gists_url":"https://api.github.com/users/zendesk/gists{/gist_id}","starred_url":"https://api.github.com/users/zendesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zendesk/subscriptions","organizations_url":"https://api.github.com/users/zendesk/orgs","repos_url":"https://api.github.com/users/zendesk/repos","events_url":"https://api.github.com/users/zendesk/events{/privacy}","received_events_url":"https://api.github.com/users/zendesk/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zendesk/samson","description":"Web interface for deployments","fork":false,"url":"https://api.github.com/repos/zendesk/samson","forks_url":"https://api.github.com/repos/zendesk/samson/forks","keys_url":"https://api.github.com/repos/zendesk/samson/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zendesk/samson/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zendesk/samson/teams","hooks_url":"https://api.github.com/repos/zendesk/samson/hooks","issue_events_url":"https://api.github.com/repos/zendesk/samson/issues/events{/number}","events_url":"https://api.github.com/repos/zendesk/samson/events","assignees_url":"https://api.github.com/repos/zendesk/samson/assignees{/user}","branches_url":"https://api.github.com/repos/zendesk/samson/branches{/branch}","tags_url":"https://api.github.com/repos/zendesk/samson/tags","blobs_url":"https://api.github.com/repos/zendesk/samson/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zendesk/samson/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zendesk/samson/git/refs{/sha}","trees_url":"https://api.github.com/repos/zendesk/samson/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zendesk/samson/statuses/{sha}","languages_url":"https://api.github.com/repos/zendesk/samson/languages","stargazers_url":"https://api.github.com/repos/zendesk/samson/stargazers","contributors_url":"https://api.github.com/repos/zendesk/samson/contributors","subscribers_url":"https://api.github.com/repos/zendesk/samson/subscribers","subscription_url":"https://api.github.com/repos/zendesk/samson/subscription","commits_url":"https://api.github.com/repos/zendesk/samson/commits{/sha}","git_commits_url":"https://api.github.com/repos/zendesk/samson/git/commits{/sha}","comments_url":"https://api.github.com/repos/zendesk/samson/comments{/number}","issue_comment_url":"https://api.github.com/repos/zendesk/samson/issues/comments{/number}","contents_url":"https://api.github.com/repos/zendesk/samson/contents/{+path}","compare_url":"https://api.github.com/repos/zendesk/samson/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zendesk/samson/merges","archive_url":"https://api.github.com/repos/zendesk/samson/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zendesk/samson/downloads","issues_url":"https://api.github.com/repos/zendesk/samson/issues{/number}","pulls_url":"https://api.github.com/repos/zendesk/samson/pulls{/number}","milestones_url":"https://api.github.com/repos/zendesk/samson/milestones{/number}","notifications_url":"https://api.github.com/repos/zendesk/samson/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zendesk/samson/labels{/name}","releases_url":"https://api.github.com/repos/zendesk/samson/releases{/id}","deployments_url":"https://api.github.com/repos/zendesk/samson/deployments","created_at":"2014-05-27T05:55:57Z","updated_at":"2016-09-01T16:40:37Z","pushed_at":"2016-09-01T17:14:26Z","git_url":"git://github.com/zendesk/samson.git","ssh_url":"git@github.com:zendesk/samson.git","clone_url":"https://github.com/zendesk/samson.git","svn_url":"https://github.com/zendesk/samson","homepage":null,"size":207193,"stargazers_count":736,"watchers_count":736,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":141,"mirror_url":null,"open_issues_count":65,"forks":141,"open_issues":65,"watchers":736,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/zendesk/samson/pulls/1242"},"html":{"href":"https://github.com/zendesk/samson/pull/1242"},"issue":{"href":"https://api.github.com/repos/zendesk/samson/issues/1242"},"comments":{"href":"https://api.github.com/repos/zendesk/samson/issues/1242/comments"},"review_comments":{"href":"https://api.github.com/repos/zendesk/samson/pulls/1242/comments"},"review_comment":{"href":"https://api.github.com/repos/zendesk/samson/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/zendesk/samson/pulls/1242/commits"},"statuses":{"href":"https://api.github.com/repos/zendesk/samson/statuses/7b59271957830dba318c44b294f16b2ae686a0f1"}}}}
{"actor":{"display_login":"grosser"}}