shipit-engine 0.32.0 → 0.33.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/magic-solid.svg +1 -0
  3. data/app/assets/javascripts/shipit/repositories_search.js.coffee +60 -0
  4. data/app/assets/javascripts/shipit/{search.js.coffee → stack_search.js.coffee} +0 -0
  5. data/app/assets/stylesheets/_pages/_repositories.scss +148 -0
  6. data/app/assets/stylesheets/_pages/_stacks.scss +19 -0
  7. data/app/assets/stylesheets/shipit.scss +1 -0
  8. data/app/controllers/shipit/api/{pull_requests_controller.rb → merge_requests_controller.rb} +8 -8
  9. data/app/controllers/shipit/api/stacks_controller.rb +14 -1
  10. data/app/controllers/shipit/deploys_controller.rb +2 -2
  11. data/app/controllers/shipit/merge_requests_controller.rb +31 -0
  12. data/app/controllers/shipit/merge_status_controller.rb +15 -15
  13. data/app/controllers/shipit/repositories_controller.rb +74 -0
  14. data/app/controllers/shipit/tasks_controller.rb +4 -4
  15. data/app/helpers/shipit/chunks_helper.rb +2 -2
  16. data/app/helpers/shipit/github_url_helper.rb +8 -0
  17. data/app/helpers/shipit/stacks_helper.rb +4 -0
  18. data/app/jobs/shipit/create_on_github_job.rb +1 -0
  19. data/app/jobs/shipit/destroy_repository_job.rb +24 -0
  20. data/app/jobs/shipit/destroy_stack_job.rb +2 -2
  21. data/app/jobs/shipit/perform_task_job.rb +4 -98
  22. data/app/jobs/shipit/process_merge_requests_job.rb +32 -0
  23. data/app/jobs/shipit/refresh_merge_request_job.rb +11 -0
  24. data/app/models/shipit/anonymous_user.rb +4 -0
  25. data/app/models/shipit/check_run.rb +2 -2
  26. data/app/models/shipit/command_line_user.rb +4 -0
  27. data/app/models/shipit/commit.rb +11 -11
  28. data/app/models/shipit/commit_checks.rb +1 -0
  29. data/app/models/shipit/deploy.rb +1 -0
  30. data/app/models/shipit/deploy_spec.rb +16 -4
  31. data/app/models/shipit/deploy_spec/file_system.rb +11 -5
  32. data/app/models/shipit/hook.rb +2 -0
  33. data/app/models/shipit/merge_request.rb +302 -0
  34. data/app/models/shipit/provisioning_handler.rb +32 -0
  35. data/app/models/shipit/provisioning_handler/base.rb +30 -0
  36. data/app/models/shipit/provisioning_handler/unregistered_provisioning_handler.rb +35 -0
  37. data/app/models/shipit/pull_request.rb +25 -264
  38. data/app/models/shipit/pull_request_assignment.rb +10 -0
  39. data/app/models/shipit/repository.rb +54 -0
  40. data/app/models/shipit/review_stack.rb +116 -0
  41. data/app/models/shipit/review_stack_provisioning_queue.rb +39 -0
  42. data/app/models/shipit/stack.rb +22 -8
  43. data/app/models/shipit/task.rb +56 -7
  44. data/app/models/shipit/task_execution_strategy/base.rb +20 -0
  45. data/app/models/shipit/task_execution_strategy/default.rb +110 -0
  46. data/app/models/shipit/user.rb +6 -1
  47. data/app/models/shipit/webhooks.rb +10 -0
  48. data/app/models/shipit/webhooks/handlers/pull_request/assigned_handler.rb +74 -0
  49. data/app/models/shipit/webhooks/handlers/pull_request/closed_handler.rb +68 -0
  50. data/app/models/shipit/webhooks/handlers/pull_request/edited_handler.rb +74 -0
  51. data/app/models/shipit/webhooks/handlers/pull_request/label_capturing_handler.rb +127 -0
  52. data/app/models/shipit/webhooks/handlers/pull_request/labeled_handler.rb +106 -0
  53. data/app/models/shipit/webhooks/handlers/pull_request/opened_handler.rb +83 -0
  54. data/app/models/shipit/webhooks/handlers/pull_request/reopened_handler.rb +88 -0
  55. data/app/models/shipit/webhooks/handlers/pull_request/review_stack_adapter.rb +103 -0
  56. data/app/models/shipit/webhooks/handlers/pull_request/unlabeled_handler.rb +107 -0
  57. data/app/serializers/shipit/deploy_serializer.rb +6 -0
  58. data/app/serializers/shipit/merge_request_serializer.rb +21 -0
  59. data/app/serializers/shipit/pull_request_serializer.rb +5 -8
  60. data/app/serializers/shipit/review_stack_serializer.rb +7 -0
  61. data/app/serializers/shipit/stack_serializer.rb +7 -6
  62. data/app/serializers/shipit/tail_task_serializer.rb +10 -2
  63. data/app/serializers/shipit/task_serializer.rb +1 -1
  64. data/app/views/shipit/merge_requests/_merge_request.html.erb +29 -0
  65. data/app/views/shipit/{pull_requests → merge_requests}/index.html.erb +2 -2
  66. data/app/views/shipit/merge_requests/merge_requests/_pull_request.html.erb +29 -0
  67. data/app/views/shipit/merge_requests/merge_requests/index.html.erb +20 -0
  68. data/app/views/shipit/merge_status/_merge_queue_button.html.erb +3 -3
  69. data/app/views/shipit/merge_status/backlogged.html.erb +1 -1
  70. data/app/views/shipit/merge_status/failure.html.erb +1 -1
  71. data/app/views/shipit/merge_status/locked.html.erb +1 -1
  72. data/app/views/shipit/merge_status/success.html.erb +2 -2
  73. data/app/views/shipit/repositories/_header.html.erb +19 -0
  74. data/app/views/shipit/repositories/index.html.erb +31 -0
  75. data/app/views/shipit/repositories/new.html.erb +23 -0
  76. data/app/views/shipit/repositories/settings.html.erb +53 -0
  77. data/app/views/shipit/repositories/show.html.erb +30 -0
  78. data/app/views/shipit/stacks/_banners.html.erb +13 -0
  79. data/app/views/shipit/stacks/_header.html.erb +5 -2
  80. data/app/views/shipit/stacks/_stack.html.erb +8 -0
  81. data/app/views/shipit/stacks/index.html.erb +2 -1
  82. data/app/views/shipit/stacks/settings.html.erb +5 -5
  83. data/app/views/shipit/stacks/show.html.erb +1 -1
  84. data/app/views/shipit/tasks/_task_output.html.erb +1 -1
  85. data/config/routes.rb +15 -5
  86. data/db/migrate/20200706145406_add_review_stacks.rb +12 -0
  87. data/db/migrate/20200804144639_rename_pull_request_to_merge_request.rb +7 -0
  88. data/db/migrate/20200804161512_rename_commits_pull_request_id_to_merge_request_id.rb +5 -0
  89. data/db/migrate/20200813134712_recreate_shipit_pull_requests.rb +22 -0
  90. data/db/migrate/20200813194056_create_pull_request_assignments.rb +8 -0
  91. data/db/migrate/20201001125502_add_provision_pr_stacks_flag_to_repositories.rb +7 -0
  92. data/db/migrate/20201008145809_add_retry_attempt_to_tasks.rb +5 -0
  93. data/db/migrate/20201008152744_add_max_retries_to_tasks.rb +5 -0
  94. data/lib/shipit.rb +11 -1
  95. data/lib/shipit/github_app.rb +1 -1
  96. data/lib/shipit/review_stack_commands.rb +8 -0
  97. data/lib/shipit/stack_commands.rb +6 -1
  98. data/lib/shipit/task_commands.rb +1 -0
  99. data/lib/shipit/version.rb +1 -1
  100. data/lib/tasks/cron.rake +11 -2
  101. data/test/controllers/api/{pull_requests_controller_test.rb → merge_requests_controller_test.rb} +12 -12
  102. data/test/controllers/api/outputs_controller_test.rb +1 -0
  103. data/test/controllers/api/rollback_controller_test.rb +1 -1
  104. data/test/controllers/api/stacks_controller_test.rb +21 -1
  105. data/test/controllers/{pull_requests_controller_test.rb → merge_requests_controller_test.rb} +6 -6
  106. data/test/controllers/repositories_controller_test.rb +71 -0
  107. data/test/controllers/stacks_controller_test.rb +9 -1
  108. data/test/controllers/tasks_controller_test.rb +14 -2
  109. data/test/controllers/webhooks_controller_test.rb +1 -1
  110. data/test/dummy/config/application.rb +6 -1
  111. data/test/dummy/config/environments/development.rb +0 -3
  112. data/test/dummy/config/environments/test.rb +0 -5
  113. data/test/dummy/db/schema.rb +52 -14
  114. data/test/dummy/db/seeds.rb +1 -1
  115. data/test/fixtures/payloads/check_suite_master.json +2 -2
  116. data/test/fixtures/payloads/invalid_pull_request.json +117 -0
  117. data/test/fixtures/payloads/provision_disabled_pull_request.json +454 -0
  118. data/test/fixtures/payloads/pull_request_assigned.json +480 -0
  119. data/test/fixtures/payloads/pull_request_closed.json +454 -0
  120. data/test/fixtures/payloads/pull_request_labeled.json +461 -0
  121. data/test/fixtures/payloads/pull_request_opened.json +454 -0
  122. data/test/fixtures/payloads/pull_request_reopened.json +454 -0
  123. data/test/fixtures/payloads/pull_request_unlabeled.json +454 -0
  124. data/test/fixtures/payloads/pull_request_with_no_repo.json +454 -0
  125. data/test/fixtures/shipit/commits.yml +15 -2
  126. data/test/fixtures/shipit/merge_requests.yml +141 -0
  127. data/test/fixtures/shipit/pull_request_assignments.yml +3 -0
  128. data/test/fixtures/shipit/pull_requests.yml +10 -131
  129. data/test/fixtures/shipit/repositories.yml +1 -0
  130. data/test/fixtures/shipit/stacks.yml +145 -0
  131. data/test/fixtures/shipit/statuses.yml +9 -0
  132. data/test/fixtures/shipit/tasks.yml +3 -0
  133. data/test/fixtures/shipit/users.yml +7 -0
  134. data/test/helpers/payloads_helper.rb +4 -0
  135. data/test/jobs/chunk_rollup_job_test.rb +15 -1
  136. data/test/jobs/destroy_repository_job_test.rb +27 -0
  137. data/test/jobs/perform_task_job_test.rb +8 -8
  138. data/test/jobs/{merge_pull_requests_job_test.rb → process_merge_requests_job_test.rb} +18 -18
  139. data/test/lib/shipit/deploy_commands_test.rb +16 -0
  140. data/test/lib/shipit/task_commands_test.rb +17 -0
  141. data/test/models/commits_test.rb +22 -13
  142. data/test/models/deploy_spec_test.rb +57 -24
  143. data/test/models/deploys_test.rb +148 -14
  144. data/test/models/{pull_request_test.rb → merge_request_test.rb} +30 -30
  145. data/test/models/pull_request_assignment_test.rb +16 -0
  146. data/test/models/shipit/provisioning_handler/base_test.rb +33 -0
  147. data/test/models/shipit/provisioning_handler/unregistered_provisioning_handler_test.rb +49 -0
  148. data/test/models/shipit/provisioning_handler_test.rb +64 -0
  149. data/test/models/shipit/pull_request_test.rb +52 -0
  150. data/test/models/shipit/repository_test.rb +5 -1
  151. data/test/models/shipit/review_stack_provision_status_test.rb +77 -0
  152. data/test/models/shipit/review_stack_provisioning_queue_test.rb +63 -0
  153. data/test/models/shipit/review_stack_test.rb +59 -0
  154. data/test/models/{stacks_test.rb → shipit/stacks_test.rb} +10 -4
  155. data/test/models/shipit/webhooks/handlers/pull_request/assigned_handler_test.rb +45 -0
  156. data/test/models/shipit/webhooks/handlers/pull_request/closed_handler_test.rb +192 -0
  157. data/test/models/shipit/webhooks/handlers/pull_request/edited_handler_test.rb +47 -0
  158. data/test/models/shipit/webhooks/handlers/pull_request/label_capturing_handler_test.rb +209 -0
  159. data/test/models/shipit/webhooks/handlers/pull_request/labeled_handler_test.rb +332 -0
  160. data/test/models/shipit/webhooks/handlers/pull_request/opened_handler_test.rb +238 -0
  161. data/test/models/shipit/webhooks/handlers/pull_request/reopened_handler_test.rb +282 -0
  162. data/test/models/shipit/webhooks/handlers/pull_request/review_stack_adapter_test.rb +83 -0
  163. data/test/models/shipit/webhooks/handlers/pull_request/unlabeled_handler_test.rb +324 -0
  164. data/test/models/shipit/{wehbooks → webhooks}/handlers_test.rb +0 -0
  165. data/test/models/tasks_test.rb +44 -3
  166. data/test/serializers/shipit/pull_request_serializer_test.rb +29 -0
  167. data/test/unit/command_test.rb +3 -3
  168. data/test/unit/github_url_helper_test.rb +5 -0
  169. data/test/unit/shipit_task_execution_strategy_test.rb +47 -0
  170. metadata +260 -154
  171. data/app/controllers/shipit/pull_requests_controller.rb +0 -31
  172. data/app/jobs/shipit/merge_pull_requests_job.rb +0 -32
  173. data/app/jobs/shipit/refresh_pull_request_job.rb +0 -11
  174. data/app/views/shipit/pull_requests/_pull_request.html.erb +0 -29
  175. data/test/fixtures/shipit/output_chunks.yml +0 -47
  176. data/test/models/output_chunk_test.rb +0 -21
@@ -0,0 +1,8 @@
1
+ <li class="search-item <%= stack.archived? ? 'archived' : '' %> <%= stack.undeployed_commits? ? 'undeployed' : '' %> <%= contributor_class(current_user.stacks_contributed_to, stack.id) %>" data-search="<%= stack.repo_name %> <%= stack.environment %> <%= stack.deploy_url %>" data-stack-id="<%= stack.id %>">
2
+ <%= link_to stack_path(stack), class: 'commits-path' do %>
3
+ <span class="col"><%= stack.repo_name %></span>
4
+ <small class="col"><%= stack.environment.capitalize %></small>
5
+ <small class="col"><%= stack.branch %></small>
6
+ <small class="col"><%= stack.deploy_url %></small>
7
+ <% end %>
8
+ </li>
@@ -2,6 +2,7 @@
2
2
  <h1><%= Shipit.app_name %></h1>
3
3
  <% end %>
4
4
  <% content_for :primary_navigation do %>
5
+ <%= link_to 'Repositories', repositories_path, class: 'btn secondary' %>
5
6
  <%= link_to 'Add a stack', new_stack_path, class: 'btn secondary' %>
6
7
  <% end %>
7
8
 
@@ -21,7 +22,7 @@
21
22
  <li class="stack search-item <%= stack.archived? ? 'archived' : '' %> <%= stack.undeployed_commits? ? 'undeployed' : '' %> <%= @user_stacks.include?(stack.id) ? 'contributor' : 'not-matching' %>" data-search="<%= stack.repo_name %> <%= stack.environment %> <%= stack.deploy_url %>" data-stack-id="<%= stack.id %>">
22
23
  <%= link_to stack_path(stack), class: 'commits-path' do %>
23
24
  <span class="col"><%= stack.repo_name %></span>
24
- <small class="col"><%= stack.environment.capitalize %></small>
25
+ <small class="col"><%= stack.environment %></small>
25
26
  <small class="col"><%= stack.branch %></small>
26
27
  <small class="col"><%= stack.deploy_url %></small>
27
28
  <% end %>
@@ -7,7 +7,7 @@
7
7
  </header>
8
8
 
9
9
  <div class="setting-section">
10
- <%= form_for @stack do |f| %>
10
+ <%= form_with scope: :stack, url: stack_path(@stack), method: :patch do |f| %>
11
11
  <div class="field-wrapper">
12
12
  <%= f.label :environment %>
13
13
  <%= f.text_field :environment, placeholder: 'production' %>
@@ -43,7 +43,7 @@
43
43
 
44
44
  <div class="setting-section">
45
45
  <h5>Lock deploys</h5>
46
- <%= form_for @stack do |f| %>
46
+ <%= form_with scope: :stack, url: stack_path(@stack), method: :patch do |f| %>
47
47
  <div class="field-wrapper">
48
48
  <%= f.label :lock_reason, 'Reason for lock' %>
49
49
  <%= f.text_area :lock_reason %>
@@ -55,7 +55,7 @@
55
55
  <% end %>
56
56
  <% end %>
57
57
  <% if @stack.locked? %>
58
- <%= form_for @stack do |f| %>
58
+ <%= form_with scope: :stack, url: stack_path(@stack), method: :patch do |f| %>
59
59
  <%= f.hidden_field :lock_reason, value: nil %>
60
60
  <%= f.submit class: "btn btn--primary", value: "Unlock" %>
61
61
  <%- end -%>
@@ -85,14 +85,14 @@
85
85
  <% if @stack.archived? %>
86
86
  <h5>Restore Stack</h5>
87
87
  <p>This action will de-archive the Stack, restoring it in the stack list and unlocking it.</p>
88
- <%= form_for @stack do |f| %>
88
+ <%= form_with scope: :stack, url: stack_path(@stack), method: :patch do |f| %>
89
89
  <%= f.hidden_field :archived, value: false %>
90
90
  <%= f.submit class: "btn", value: "Restore" %>
91
91
  <% end %>
92
92
  <% else %>
93
93
  <h5>Archive Stack</h5>
94
94
  <p>This action will archive the Stack, hiding it from the stack list and locking it. It can still be found if you know the URL and de-archived.</p>
95
- <%= form_for @stack do |f| %>
95
+ <%= form_with scope: :stack, url: stack_path(@stack), method: :patch do |f| %>
96
96
  <%= f.hidden_field :archived, value: true %>
97
97
  <%= f.submit class: "btn", value: "Archive" %>
98
98
  <% end %>
@@ -12,7 +12,7 @@
12
12
  <% if params[:force] %>
13
13
  <%= link_to t('emergency_mode.disable'), stack_path(@stack) %>
14
14
  <% else %>
15
- <%= link_to t('emergency_mode.enable'), stack_path(@stack, force: 1), title: t('emergency_mode.enable_description') %>
15
+ <%= link_to t('emergency_mode.enable'), stack_path(@stack, force: 1, noredirect: 1), title: t('emergency_mode.enable_description') %>
16
16
  <% end %>
17
17
  </div>
18
18
  </header>
@@ -43,6 +43,6 @@
43
43
  </div>
44
44
 
45
45
  <div class="clusterize-scroll task-output-container task-output-container-main-page">
46
- <pre class="nowrap" data-status="<%= task.status %>"><code class="clusterize-content" data-output="<%= task.chunk_output %>" data-next-chunks-url="<%= next_chunks_url(task) %>"></code></pre>
46
+ <pre class="nowrap" data-status="<%= task.status %>"><code class="clusterize-content" data-output="<%= task.chunk_output %>" data-next-chunks-url="<%= next_chunks_url(task, last_byte: task.chunk_output_size) %>"></code></pre>
47
47
  </div>
48
48
  </div>
data/config/routes.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  Shipit::Engine.routes.draw do
3
3
  stack_id_format = %r{[^/]+/[^/]+/[^/]+}
4
+ repository_id_format = %r{[^/]+/[^/]+}
4
5
  sha_format = /[\da-f]{6,40}/
5
6
  root to: 'stacks#index'
6
7
 
@@ -32,7 +33,7 @@ Shipit::Engine.routes.draw do
32
33
  end
33
34
  resources :rollbacks, only: %i(create)
34
35
  resources :commits, only: %i(index)
35
- resources :pull_requests, only: %i(index show update destroy)
36
+ resources :merge_requests, only: %i(index show update destroy)
36
37
  post '/task/:task_name' => 'tasks#trigger', as: :trigger_task
37
38
  resources :hooks, only: %i(index create show update destroy)
38
39
  end
@@ -46,12 +47,20 @@ Shipit::Engine.routes.draw do
46
47
 
47
48
  # Browser extension
48
49
  get '/merge_status', action: :show, controller: :merge_status, as: :merge_status
49
- put '/merge_status/*stack_id/pull/:number', action: :enqueue, controller: :merge_status, id: stack_id_format, as: :enqueue_pull_request
50
- delete '/merge_status/*stack_id/pull/:number', action: :dequeue, controller: :merge_status, id: stack_id_format, as: :dequeue_pull_request
50
+ put '/merge_status/*stack_id/pull/:number', action: :enqueue, controller: :merge_status, id: stack_id_format, as: :enqueue_merge_request
51
+ delete '/merge_status/*stack_id/pull/:number', action: :dequeue, controller: :merge_status, id: stack_id_format, as: :dequeue_merge_request
51
52
 
52
53
  # Humans
53
54
  resources :api_clients
54
- resources :stacks, only: %i(new create index)
55
+
56
+ resources :repositories, only: %i(new index create)
57
+ scope '/repositories/*id', id: repository_id_format, as: :repository do
58
+ get '/' => 'repositories#show'
59
+ patch '/' => 'repositories#update'
60
+ delete '/' => 'repositories#destroy'
61
+ get :settings, controller: :repositories
62
+ get 'stacks/new' => 'repositories#new_stack'
63
+ end
55
64
 
56
65
  scope '/github/auth/github', as: :github_authentication, controller: :github_authentication do
57
66
  get '/', action: :request
@@ -60,6 +69,7 @@ Shipit::Engine.routes.draw do
60
69
  get :logout
61
70
  end
62
71
 
72
+ resources :stacks, only: %i(new create index)
63
73
  scope '/*id', id: stack_id_format, as: :stack do
64
74
  get '/' => 'stacks#show'
65
75
  patch '/' => 'stacks#update'
@@ -107,7 +117,7 @@ Shipit::Engine.routes.draw do
107
117
  resources :release_statuses, only: %i(create)
108
118
  end
109
119
 
110
- resources :pull_requests, only: %i(index destroy create)
120
+ resources :merge_requests, only: %i(index destroy create)
111
121
  end
112
122
  get '/stacks/:id' => 'stacks#lookup'
113
123
 
@@ -0,0 +1,12 @@
1
+ class AddReviewStacks < ActiveRecord::Migration[6.0]
2
+ def change
3
+ add_column :stacks, :provision_status, :string, null: false, default: :deprovisioned
4
+ add_index :stacks, :provision_status
5
+
6
+ add_column :stacks, :type, :string, default: "Shipit::Stack"
7
+ add_index :stacks, :type
8
+
9
+ add_column :stacks, :awaiting_provision, :boolean, null: false, default: false
10
+ add_index :stacks, :awaiting_provision
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RenamePullRequestToMergeRequest < ActiveRecord::Migration[6.0]
4
+ def change
5
+ rename_table :pull_requests, :merge_requests
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ class RenameCommitsPullRequestIdToMergeRequestId < ActiveRecord::Migration[6.0]
2
+ def change
3
+ rename_column :commits, :pull_request_id, :merge_request_id
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ class RecreateShipitPullRequests < ActiveRecord::Migration[6.0]
3
+ def change
4
+ create_table :pull_requests do |t|
5
+ t.references :stack, null: false
6
+ t.integer :number, null: false
7
+ t.string :title, limit: 256
8
+ t.integer :github_id, limit: 8
9
+ t.string :api_url, limit: 1024
10
+ t.string :state
11
+ t.integer :additions, null: false, default: 0
12
+ t.integer :deletions, null: false, default: 0
13
+ t.integer :user_id
14
+ t.text :labels
15
+ t.references :head
16
+ t.timestamps
17
+
18
+ t.index [:stack_id, :number], unique: true
19
+ t.index [:stack_id, :github_id], unique: true
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,8 @@
1
+ class CreatePullRequestAssignments < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :pull_request_assignments do |t|
4
+ t.references :pull_request
5
+ t.references :user
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ class AddProvisionPrStacksFlagToRepositories < ActiveRecord::Migration[6.0]
2
+ def change
3
+ add_column :repositories, :review_stacks_enabled, :boolean, default: false
4
+ add_column :repositories, :provisioning_behavior, :string, default: :allow_all
5
+ add_column :repositories, :provisioning_label_name, :string
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ class AddRetryAttemptToTasks < ActiveRecord::Migration[6.0]
2
+ def change
3
+ add_column :tasks, :retry_attempt, :integer, null: false, default: 0
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddMaxRetriesToTasks < ActiveRecord::Migration[6.0]
2
+ def change
3
+ add_column :tasks, :max_retries, :integer, null: true
4
+ end
5
+ end
data/lib/shipit.rb CHANGED
@@ -43,6 +43,7 @@ require 'shipit/simple_message_verifier'
43
43
  require 'shipit/command'
44
44
  require 'shipit/commands'
45
45
  require 'shipit/stack_commands'
46
+ require 'shipit/review_stack_commands'
46
47
  require 'shipit/task_commands'
47
48
  require 'shipit/deploy_commands'
48
49
  require 'shipit/rollback_commands'
@@ -62,7 +63,16 @@ module Shipit
62
63
  delegate :table_name_prefix, to: :secrets
63
64
 
64
65
  attr_accessor :disable_api_authentication, :timeout_exit_codes
65
- attr_writer :internal_hook_receivers, :task_logger, :preferred_org_emails
66
+ attr_writer(
67
+ :internal_hook_receivers,
68
+ :preferred_org_emails,
69
+ :task_execution_strategy,
70
+ :task_logger,
71
+ )
72
+
73
+ def task_execution_strategy
74
+ @task_execution_strategy ||= Shipit::TaskExecutionStrategy::Default
75
+ end
66
76
 
67
77
  self.timeout_exit_codes = [].freeze
68
78
 
@@ -52,7 +52,7 @@ module Shipit
52
52
  oauth = (@config[:oauth] || {}).with_indifferent_access
53
53
  @oauth_id = oauth[:id]
54
54
  @oauth_secret = oauth[:secret]
55
- @oauth_teams = Array.wrap(oauth[:teams] || oauth[:teams])
55
+ @oauth_teams = Array.wrap(oauth[:teams])
56
56
  end
57
57
 
58
58
  def login
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'shipit/stack_commands'
4
+
5
+ module Shipit
6
+ class ReviewStackCommands < Shipit::StackCommands
7
+ end
8
+ end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # rubocop:disable Lint/MissingSuper
2
3
  require 'pathname'
3
4
  require 'fileutils'
4
5
 
@@ -8,6 +9,10 @@ module Shipit
8
9
  @stack = stack
9
10
  end
10
11
 
12
+ def env
13
+ super.merge(@stack.env)
14
+ end
15
+
11
16
  def fetch
12
17
  create_directories
13
18
  if Dir.exist?(@stack.git_path)
@@ -56,7 +61,7 @@ module Shipit
56
61
  Dir.mktmpdir do |dir|
57
62
  git(
58
63
  'clone', @stack.git_path, @stack.repo_name,
59
- '--origin', 'cache',
64
+ '--recursive', '--origin', 'cache',
60
65
  chdir: dir
61
66
  ).run!
62
67
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # rubocop:disable Lint/MissingSuper
2
3
  module Shipit
3
4
  class TaskCommands < Commands
4
5
  delegate :fetch, :fetched?, to: :stack_commands
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Shipit
3
- VERSION = '0.32.0'
3
+ VERSION = '0.33.0'
4
4
  end
data/lib/tasks/cron.rake CHANGED
@@ -5,11 +5,12 @@ namespace :cron do
5
5
  Shipit::Stack.refresh_deployed_revisions
6
6
  Shipit::Stack.schedule_continuous_delivery
7
7
  Shipit::GithubStatus.refresh_status
8
- Shipit::PullRequest.schedule_merges
8
+ Shipit::MergeRequest.schedule_merges
9
9
  Shipit::ReapDeadTasksJob.perform_later
10
+ Shipit::ReviewStackProvisioningQueue.work
10
11
  end
11
12
 
12
- task hourly: %i(rollup refresh_users)
13
+ task hourly: %i(rollup refresh_users clear_stale_caches delete_old_deployment_directories)
13
14
 
14
15
  desc "Rolls-up output chunks for completed deploys older than an hour"
15
16
  task rollup: :environment do
@@ -19,4 +20,12 @@ namespace :cron do
19
20
  task refresh_users: :environment do
20
21
  Shipit::User.refresh_shard(Time.now.hour % 24, 24)
21
22
  end
23
+
24
+ task clear_stale_caches: :environment do
25
+ Shipit::ReviewStack.clear_stale_caches
26
+ end
27
+
28
+ task delete_old_deployment_directories: :environment do
29
+ Shipit::ReviewStack.delete_old_deployment_directories
30
+ end
22
31
  end
@@ -3,52 +3,52 @@ require 'test_helper'
3
3
 
4
4
  module Shipit
5
5
  module Api
6
- class PullRequestsControllerTest < ActionController::TestCase
6
+ class MergeRequestsControllerTest < ActionController::TestCase
7
7
  setup do
8
8
  @stack = shipit_stacks(:shipit)
9
- @pull_request = shipit_pull_requests(:shipit_pending)
9
+ @merge_request = shipit_merge_requests(:shipit_pending)
10
10
  authenticate!
11
11
  end
12
12
 
13
13
  test "#index returns a list of pull requests" do
14
- pull_request = @stack.pull_requests.last
14
+ merge_request = @stack.merge_requests.last
15
15
 
16
16
  get :index, params: { stack_id: @stack.to_param }
17
17
  assert_response :ok
18
- assert_json '0.id', pull_request.id
18
+ assert_json '0.id', merge_request.id
19
19
  end
20
20
 
21
21
  test "#show returns a single pull requests" do
22
- get :show, params: { stack_id: @stack.to_param, id: @pull_request.number.to_s }
22
+ get :show, params: { stack_id: @stack.to_param, id: @merge_request.number.to_s }
23
23
  assert_response :ok
24
- assert_json 'id', @pull_request.id
24
+ assert_json 'id', @merge_request.id
25
25
  end
26
26
 
27
27
  test "#update responds with Accepted if the pull request was queued" do
28
- assert_enqueued_with(job: RefreshPullRequestJob) do
28
+ assert_enqueued_with(job: RefreshMergeRequestJob) do
29
29
  put :update, params: { stack_id: @stack.to_param, id: '64' }
30
30
  end
31
31
  assert_response :accepted
32
32
  end
33
33
 
34
34
  test "#update responds with Accepted if the pull request was already queued" do
35
- assert_enqueued_with(job: RefreshPullRequestJob) do
35
+ assert_enqueued_with(job: RefreshMergeRequestJob) do
36
36
  put :update, params: { stack_id: @stack.to_param, id: '65' }
37
37
  end
38
38
  assert_response :accepted
39
39
  end
40
40
 
41
41
  test "#update responds with method not allowed if the pull request was already merged" do
42
- @pull_request.complete!
43
- put :update, params: { stack_id: @stack.to_param, id: @pull_request.number.to_s }
42
+ @merge_request.complete!
43
+ put :update, params: { stack_id: @stack.to_param, id: @merge_request.number.to_s }
44
44
  assert_response :method_not_allowed
45
45
  assert_json 'message', 'This pull request was already merged.'
46
46
  end
47
47
 
48
48
  test "#destroy cancels the merge if the pull request was waiting" do
49
- delete :destroy, params: { stack_id: @stack.to_param, id: @pull_request.number.to_s }
49
+ delete :destroy, params: { stack_id: @stack.to_param, id: @merge_request.number.to_s }
50
50
  assert_response :no_content
51
- assert_predicate @pull_request.reload, :canceled?
51
+ assert_predicate @merge_request.reload, :canceled?
52
52
  end
53
53
 
54
54
  test "#destroy silently fail if the pull request was unknown" do
@@ -11,6 +11,7 @@ module Shipit
11
11
 
12
12
  test "#show returns the task output as plain text" do
13
13
  task = @stack.tasks.last
14
+ task.write("dummy output")
14
15
 
15
16
  get :show, params: { stack_id: @stack.to_param, task_id: task.id }
16
17
  assert_response :ok
@@ -106,7 +106,7 @@ module Shipit
106
106
  last_deploy.reload
107
107
  assert_response :accepted
108
108
  refute_predicate last_deploy, :active?
109
- assert_json 'rollback_once_aborted_to.until_commit_id', @commit.id
109
+ assert_json 'rollback_once_aborted_to.revision.sha', @commit.sha
110
110
  end
111
111
  end
112
112
  end
@@ -84,7 +84,6 @@ module Shipit
84
84
 
85
85
  test "#index returns a list of stacks" do
86
86
  stack = Stack.last
87
-
88
87
  get :index
89
88
  assert_response :ok
90
89
  assert_json '0.id', stack.id
@@ -93,6 +92,27 @@ module Shipit
93
92
  end
94
93
  end
95
94
 
95
+ test "#index returns a list of stacks filtered by repo if name and owner given" do
96
+ repo = shipit_repositories(:shipit)
97
+ get :index, params: { repo_owner: repo.owner, repo_name: repo.name }
98
+ assert_response :ok
99
+ assert_json do |stacks|
100
+ assert_equal stacks.size, repo.stacks.size
101
+ end
102
+ end
103
+
104
+ test "#index returns a list of stacks filtered by repo and api client" do
105
+ authenticate!(:here_come_the_walrus)
106
+
107
+ repo = shipit_repositories(:soc)
108
+
109
+ get :index, params: { repo_owner: repo.owner, repo_name: repo.name }
110
+ assert_response :ok
111
+ assert_json do |stacks|
112
+ assert_equal 0, stacks.size
113
+ end
114
+ end
115
+
96
116
  test "#index is paginable" do
97
117
  get :index, params: { page_size: 1 }
98
118
  assert_json do |list|