shipit-engine 0.31.0 → 0.32.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (290) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -2
  3. data/Rakefile +4 -2
  4. data/app/assets/stylesheets/_pages/_stacks.scss +0 -3
  5. data/app/assets/stylesheets/merge_status.scss +0 -3
  6. data/app/controllers/concerns/shipit/active_model_serializers_patch.rb +1 -0
  7. data/app/controllers/concerns/shipit/api/cacheable.rb +1 -0
  8. data/app/controllers/concerns/shipit/api/paginable.rb +3 -2
  9. data/app/controllers/concerns/shipit/api/rendering.rb +5 -4
  10. data/app/controllers/concerns/shipit/authentication.rb +3 -2
  11. data/app/controllers/concerns/shipit/pagination.rb +2 -1
  12. data/app/controllers/shipit/api/base_controller.rb +11 -6
  13. data/app/controllers/shipit/api/ccmenu_controller.rb +2 -1
  14. data/app/controllers/shipit/api/commits_controller.rb +2 -1
  15. data/app/controllers/shipit/api/deploys_controller.rb +4 -3
  16. data/app/controllers/shipit/api/hooks_controller.rb +6 -5
  17. data/app/controllers/shipit/api/locks_controller.rb +5 -4
  18. data/app/controllers/shipit/api/outputs_controller.rb +2 -1
  19. data/app/controllers/shipit/api/pull_requests_controller.rb +7 -6
  20. data/app/controllers/shipit/api/release_statuses_controller.rb +3 -2
  21. data/app/controllers/shipit/api/rollbacks_controller.rb +33 -0
  22. data/app/controllers/shipit/api/stacks_controller.rb +18 -5
  23. data/app/controllers/shipit/api/tasks_controller.rb +6 -5
  24. data/app/controllers/shipit/api_clients_controller.rb +4 -3
  25. data/app/controllers/shipit/ccmenu_url_controller.rb +4 -3
  26. data/app/controllers/shipit/commit_checks_controller.rb +2 -1
  27. data/app/controllers/shipit/commits_controller.rb +2 -1
  28. data/app/controllers/shipit/deploys_controller.rb +3 -2
  29. data/app/controllers/shipit/github_authentication_controller.rb +4 -3
  30. data/app/controllers/shipit/merge_status_controller.rb +17 -16
  31. data/app/controllers/shipit/pull_requests_controller.rb +3 -2
  32. data/app/controllers/shipit/release_statuses_controller.rb +3 -2
  33. data/app/controllers/shipit/rollbacks_controller.rb +3 -2
  34. data/app/controllers/shipit/shipit_controller.rb +2 -1
  35. data/app/controllers/shipit/stacks_controller.rb +22 -7
  36. data/app/controllers/shipit/status_controller.rb +2 -1
  37. data/app/controllers/shipit/tasks_controller.rb +6 -5
  38. data/app/controllers/shipit/webhooks_controller.rb +3 -2
  39. data/app/helpers/shipit/chunks_helper.rb +1 -0
  40. data/app/helpers/shipit/deploys_helper.rb +4 -3
  41. data/app/helpers/shipit/github_url_helper.rb +1 -0
  42. data/app/helpers/shipit/merge_status_helper.rb +1 -0
  43. data/app/helpers/shipit/shipit_helper.rb +1 -0
  44. data/app/helpers/shipit/stacks_helper.rb +1 -0
  45. data/app/helpers/shipit/tasks_helper.rb +1 -0
  46. data/app/jobs/shipit/background_job.rb +4 -0
  47. data/app/jobs/shipit/background_job/unique.rb +1 -0
  48. data/app/jobs/shipit/cache_deploy_spec_job.rb +1 -0
  49. data/app/jobs/shipit/chunk_rollup_job.rb +4 -0
  50. data/app/jobs/shipit/clear_git_cache_job.rb +1 -0
  51. data/app/jobs/shipit/continuous_delivery_job.rb +2 -1
  52. data/app/jobs/shipit/create_on_github_job.rb +6 -1
  53. data/app/jobs/shipit/create_release_statuses_job.rb +1 -0
  54. data/app/jobs/shipit/deferred_touch_job.rb +4 -0
  55. data/app/jobs/shipit/deliver_hook_job.rb +1 -0
  56. data/app/jobs/shipit/destroy_job.rb +1 -0
  57. data/app/jobs/shipit/destroy_stack_job.rb +1 -0
  58. data/app/jobs/shipit/emit_event_job.rb +2 -1
  59. data/app/jobs/shipit/fetch_commit_stats_job.rb +1 -0
  60. data/app/jobs/shipit/fetch_deployed_revision_job.rb +1 -0
  61. data/app/jobs/shipit/github_sync_job.rb +2 -1
  62. data/app/jobs/shipit/mark_deploy_healthy_job.rb +1 -0
  63. data/app/jobs/shipit/merge_pull_requests_job.rb +1 -0
  64. data/app/jobs/shipit/perform_commit_checks_job.rb +1 -0
  65. data/app/jobs/shipit/perform_task_job.rb +12 -5
  66. data/app/jobs/shipit/purge_old_deliveries_job.rb +1 -0
  67. data/app/jobs/shipit/reap_dead_tasks_job.rb +21 -0
  68. data/app/jobs/shipit/refresh_check_runs_job.rb +1 -0
  69. data/app/jobs/shipit/refresh_github_user_job.rb +1 -0
  70. data/app/jobs/shipit/refresh_pull_request_job.rb +1 -0
  71. data/app/jobs/shipit/refresh_statuses_job.rb +1 -0
  72. data/app/jobs/shipit/setup_github_hook_job.rb +1 -0
  73. data/app/jobs/shipit/update_estimated_deploy_duration_job.rb +1 -0
  74. data/app/jobs/shipit/update_github_last_deployed_ref_job.rb +4 -3
  75. data/app/models/concerns/shipit/deferred_touch.rb +4 -3
  76. data/app/models/shipit/anonymous_user.rb +5 -0
  77. data/app/models/shipit/api_client.rb +3 -2
  78. data/app/models/shipit/application_record.rb +2 -1
  79. data/app/models/shipit/check_run.rb +4 -3
  80. data/app/models/shipit/command_line_user.rb +1 -0
  81. data/app/models/shipit/commit.rb +11 -4
  82. data/app/models/shipit/commit_checks.rb +1 -0
  83. data/app/models/shipit/commit_deployment.rb +3 -2
  84. data/app/models/shipit/commit_deployment_status.rb +2 -1
  85. data/app/models/shipit/commit_message.rb +1 -0
  86. data/app/models/shipit/delivery.rb +4 -3
  87. data/app/models/shipit/deploy.rb +6 -17
  88. data/app/models/shipit/deploy_spec.rb +22 -3
  89. data/app/models/shipit/deploy_spec/bundler_discovery.rb +1 -0
  90. data/app/models/shipit/deploy_spec/capistrano_discovery.rb +1 -0
  91. data/app/models/shipit/deploy_spec/file_system.rb +10 -3
  92. data/app/models/shipit/deploy_spec/kubernetes_discovery.rb +1 -0
  93. data/app/models/shipit/deploy_spec/lerna_discovery.rb +1 -0
  94. data/app/models/shipit/deploy_spec/npm_discovery.rb +5 -4
  95. data/app/models/shipit/deploy_spec/pypi_discovery.rb +1 -0
  96. data/app/models/shipit/deploy_spec/rubygems_discovery.rb +1 -0
  97. data/app/models/shipit/deploy_stats.rb +2 -1
  98. data/app/models/shipit/duration.rb +3 -2
  99. data/app/models/shipit/ephemeral_commit_checks.rb +1 -0
  100. data/app/models/shipit/github_hook.rb +2 -1
  101. data/app/models/shipit/github_status.rb +2 -1
  102. data/app/models/shipit/hook.rb +6 -5
  103. data/app/models/shipit/membership.rb +3 -2
  104. data/app/models/shipit/output_chunk.rb +7 -2
  105. data/app/models/shipit/pull_request.rb +6 -5
  106. data/app/models/shipit/record.rb +18 -0
  107. data/app/models/shipit/release_status.rb +3 -2
  108. data/app/models/shipit/repository.rb +10 -5
  109. data/app/models/shipit/rollback.rb +1 -0
  110. data/app/models/shipit/stack.rb +50 -16
  111. data/app/models/shipit/status.rb +3 -2
  112. data/app/models/shipit/status/common.rb +7 -6
  113. data/app/models/shipit/status/group.rb +1 -0
  114. data/app/models/shipit/status/missing.rb +2 -1
  115. data/app/models/shipit/status/unknown.rb +2 -1
  116. data/app/models/shipit/task.rb +38 -5
  117. data/app/models/shipit/task_definition.rb +1 -0
  118. data/app/models/shipit/team.rb +2 -1
  119. data/app/models/shipit/undeployed_commit.rb +1 -0
  120. data/app/models/shipit/unlimited_api_client.rb +1 -0
  121. data/app/models/shipit/user.rb +10 -8
  122. data/app/models/shipit/variable_definition.rb +1 -0
  123. data/app/models/shipit/webhooks.rb +1 -0
  124. data/app/models/shipit/webhooks/handlers/check_suite_handler.rb +1 -0
  125. data/app/models/shipit/webhooks/handlers/handler.rb +1 -0
  126. data/app/models/shipit/webhooks/handlers/membership_handler.rb +1 -0
  127. data/app/models/shipit/webhooks/handlers/push_handler.rb +1 -0
  128. data/app/models/shipit/webhooks/handlers/status_handler.rb +1 -0
  129. data/app/serializers/concerns/shipit/conditional_attributes.rb +1 -0
  130. data/app/serializers/shipit/anonymous_user_serializer.rb +1 -0
  131. data/app/serializers/shipit/command_line_user_serializer.rb +1 -0
  132. data/app/serializers/shipit/commit_serializer.rb +1 -0
  133. data/app/serializers/shipit/deploy_serializer.rb +2 -1
  134. data/app/serializers/shipit/hook_serializer.rb +1 -0
  135. data/app/serializers/shipit/pull_request_serializer.rb +1 -0
  136. data/app/serializers/shipit/rollback_serializer.rb +1 -0
  137. data/app/serializers/shipit/short_commit_serializer.rb +1 -0
  138. data/app/serializers/shipit/stack_serializer.rb +1 -0
  139. data/app/serializers/shipit/tail_task_serializer.rb +1 -0
  140. data/app/serializers/shipit/task_serializer.rb +2 -17
  141. data/app/serializers/shipit/user_serializer.rb +6 -1
  142. data/app/validators/ascii_only_validator.rb +1 -0
  143. data/app/validators/subset_validator.rb +1 -0
  144. data/app/views/layouts/shipit.html.erb +1 -1
  145. data/app/views/shipit/_variables.html.erb +1 -1
  146. data/app/views/shipit/ccmenu/project.xml.builder +2 -1
  147. data/app/views/shipit/deploys/show.html.erb +2 -2
  148. data/app/views/shipit/stacks/_header.html.erb +3 -0
  149. data/app/views/shipit/stacks/all_tasks.html.erb +28 -0
  150. data/app/views/shipit/stacks/index.html.erb +1 -1
  151. data/app/views/shipit/tasks/show.html.erb +1 -1
  152. data/config/initializers/inflections.rb +2 -1
  153. data/config/locales/en.yml +3 -3
  154. data/config/routes.rb +10 -2
  155. data/db/migrate/20200226211925_add_index_to_tasks_status.rb +5 -0
  156. data/db/migrate/20200427135152_add_pull_request_head_sha_to_commit.rb +5 -0
  157. data/db/migrate/20200615181558_add_rollback_once_aborted_to.rb +5 -0
  158. data/lib/shipit.rb +12 -2
  159. data/lib/shipit/cast_value.rb +1 -0
  160. data/lib/shipit/command.rb +13 -12
  161. data/lib/shipit/commands.rb +5 -4
  162. data/lib/shipit/csv_serializer.rb +1 -0
  163. data/lib/shipit/deploy_commands.rb +1 -0
  164. data/lib/shipit/engine.rb +7 -2
  165. data/lib/shipit/environment_variables.rb +2 -1
  166. data/lib/shipit/first_parent_commits_iterator.rb +1 -0
  167. data/lib/shipit/flock.rb +1 -0
  168. data/lib/shipit/github_app.rb +7 -6
  169. data/lib/shipit/github_http_cache_middleware.rb +1 -0
  170. data/lib/shipit/null_serializer.rb +1 -0
  171. data/lib/shipit/octokit_check_runs.rb +3 -2
  172. data/lib/shipit/octokit_iterator.rb +3 -2
  173. data/lib/shipit/paginator.rb +3 -2
  174. data/lib/shipit/rollback_commands.rb +1 -0
  175. data/lib/shipit/same_site_cookie_middleware.rb +29 -0
  176. data/lib/shipit/simple_message_verifier.rb +1 -0
  177. data/lib/shipit/stack_commands.rb +3 -2
  178. data/lib/shipit/stat.rb +1 -0
  179. data/lib/shipit/task_commands.rb +2 -0
  180. data/lib/shipit/version.rb +2 -1
  181. data/lib/snippets/release-gem +5 -1
  182. data/lib/tasks/cron.rake +2 -0
  183. data/lib/tasks/dev.rake +3 -2
  184. data/lib/tasks/shipit.rake +15 -14
  185. data/lib/tasks/teams.rake +1 -0
  186. data/test/controllers/api/base_controller_test.rb +3 -2
  187. data/test/controllers/api/ccmenu_controller_test.rb +8 -7
  188. data/test/controllers/api/commits_controller_test.rb +3 -2
  189. data/test/controllers/api/deploys_controller_test.rb +15 -14
  190. data/test/controllers/api/hooks_controller_test.rb +8 -7
  191. data/test/controllers/api/locks_controller_test.rb +7 -6
  192. data/test/controllers/api/outputs_controller_test.rb +2 -1
  193. data/test/controllers/api/pull_requests_controller_test.rb +8 -7
  194. data/test/controllers/api/release_statuses_controller_test.rb +2 -1
  195. data/test/controllers/api/rollback_controller_test.rb +113 -0
  196. data/test/controllers/api/stacks_controller_test.rb +30 -9
  197. data/test/controllers/api/tasks_controller_test.rb +13 -12
  198. data/test/controllers/api_clients_controller_test.rb +5 -4
  199. data/test/controllers/ccmenu_controller_test.rb +4 -3
  200. data/test/controllers/commit_checks_controller_test.rb +4 -3
  201. data/test/controllers/commits_controller_test.rb +3 -2
  202. data/test/controllers/deploys_controller_test.rb +32 -21
  203. data/test/controllers/github_authentication_controller_test.rb +1 -0
  204. data/test/controllers/merge_status_controller_test.rb +7 -6
  205. data/test/controllers/pull_requests_controller_test.rb +4 -3
  206. data/test/controllers/release_statuses_controller_test.rb +3 -2
  207. data/test/controllers/rollbacks_controller_test.rb +9 -8
  208. data/test/controllers/stacks_controller_test.rb +33 -19
  209. data/test/controllers/status_controller_test.rb +1 -0
  210. data/test/controllers/tasks_controller_test.rb +19 -18
  211. data/test/controllers/webhooks_controller_test.rb +11 -10
  212. data/test/dummy/config/environments/development.rb +2 -0
  213. data/test/dummy/config/environments/test.rb +2 -0
  214. data/test/dummy/db/schema.rb +4 -1
  215. data/test/fixtures/shipit/commits.yml +15 -0
  216. data/test/fixtures/shipit/repositories.yml +4 -0
  217. data/test/fixtures/shipit/stacks.yml +90 -14
  218. data/test/fixtures/timeout +2 -1
  219. data/test/helpers/api_helper.rb +1 -0
  220. data/test/helpers/fixture_aliases_helper.rb +1 -0
  221. data/test/helpers/hooks_helper.rb +2 -1
  222. data/test/helpers/json_helper.rb +15 -11
  223. data/test/helpers/links_helper.rb +4 -3
  224. data/test/helpers/payloads_helper.rb +1 -0
  225. data/test/helpers/queries_helper.rb +3 -2
  226. data/test/jobs/cache_deploy_spec_job_test.rb +2 -1
  227. data/test/jobs/chunk_rollup_job_test.rb +1 -0
  228. data/test/jobs/deliver_hook_job_test.rb +1 -0
  229. data/test/jobs/destroy_stack_job_test.rb +1 -0
  230. data/test/jobs/emit_event_job_test.rb +2 -1
  231. data/test/jobs/fetch_commit_stats_job_test.rb +1 -0
  232. data/test/jobs/fetch_deployed_revision_job_test.rb +1 -0
  233. data/test/jobs/github_sync_job_test.rb +1 -0
  234. data/test/jobs/mark_deploy_healthy_job_test.rb +1 -0
  235. data/test/jobs/merge_pull_requests_job_test.rb +1 -0
  236. data/test/jobs/perform_task_job_test.rb +4 -3
  237. data/test/jobs/purge_old_deliveries_job_test.rb +1 -0
  238. data/test/jobs/reap_dead_tasks_job_test.rb +68 -0
  239. data/test/jobs/refresh_github_user_job_test.rb +1 -0
  240. data/test/jobs/refresh_status_job_test.rb +1 -0
  241. data/test/jobs/unique_job_test.rb +1 -0
  242. data/test/jobs/update_github_last_deployed_ref_job_test.rb +1 -0
  243. data/test/middleware/same_site_cookie_middleware_test.rb +52 -0
  244. data/test/models/api_client_test.rb +1 -0
  245. data/test/models/commit_checks_test.rb +1 -0
  246. data/test/models/commit_deployment_status_test.rb +1 -0
  247. data/test/models/commit_deployment_test.rb +2 -1
  248. data/test/models/commits_test.rb +72 -6
  249. data/test/models/delivery_test.rb +2 -1
  250. data/test/models/deploy_spec_test.rb +47 -42
  251. data/test/models/deploy_stats_test.rb +1 -0
  252. data/test/models/deploys_test.rb +31 -22
  253. data/test/models/duration_test.rb +1 -0
  254. data/test/models/github_hook_test.rb +1 -0
  255. data/test/models/hook_test.rb +18 -10
  256. data/test/models/membership_test.rb +1 -0
  257. data/test/models/output_chunk_test.rb +1 -0
  258. data/test/models/pull_request_test.rb +4 -3
  259. data/test/models/release_statuses_test.rb +1 -0
  260. data/test/models/rollbacks_test.rb +1 -0
  261. data/test/models/shipit/check_run_test.rb +1 -0
  262. data/test/models/shipit/repository_test.rb +1 -0
  263. data/test/models/shipit/wehbooks/handlers_test.rb +1 -0
  264. data/test/models/stacks_test.rb +30 -8
  265. data/test/models/status/group_test.rb +1 -0
  266. data/test/models/status/missing_test.rb +1 -0
  267. data/test/models/status_test.rb +1 -0
  268. data/test/models/task_definitions_test.rb +9 -8
  269. data/test/models/tasks_test.rb +18 -1
  270. data/test/models/team_test.rb +4 -2
  271. data/test/models/undeployed_commits_test.rb +1 -0
  272. data/test/models/users_test.rb +13 -5
  273. data/test/test_command_integration.rb +3 -2
  274. data/test/test_helper.rb +34 -31
  275. data/test/unit/anonymous_user_serializer_test.rb +14 -0
  276. data/test/unit/command_test.rb +8 -7
  277. data/test/unit/commands_test.rb +1 -0
  278. data/test/unit/commit_serializer_test.rb +16 -0
  279. data/test/unit/csv_serializer_test.rb +3 -2
  280. data/test/unit/deploy_commands_test.rb +5 -4
  281. data/test/unit/deploy_serializer_test.rb +17 -0
  282. data/test/unit/environment_variables_test.rb +5 -4
  283. data/test/unit/github_app_test.rb +1 -0
  284. data/test/unit/github_url_helper_test.rb +1 -0
  285. data/test/unit/rollback_commands_test.rb +2 -1
  286. data/test/unit/shipit_helper_test.rb +17 -0
  287. data/test/unit/shipit_test.rb +1 -0
  288. data/test/unit/user_serializer_test.rb +14 -0
  289. data/test/unit/variable_definition_test.rb +1 -0
  290. metadata +155 -130
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  module Shipit
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  module Shipit
@@ -247,6 +248,8 @@ module Shipit
247
248
  end
248
249
 
249
250
  test "transitioning to success enqueues a last-deployed git reference update" do
251
+ Shipit.stubs(:update_latest_deployed_ref).returns(true)
252
+
250
253
  @deploy = shipit_deploys(:shipit_running)
251
254
  assert_enqueued_with(job: UpdateGithubLastDeployedRefJob, args: [@deploy.stack]) do
252
255
  @deploy.complete!
@@ -301,6 +304,20 @@ module Shipit
301
304
  end
302
305
  end
303
306
 
307
+ test "transitioning to aborted schedule a rollback to the designated deploy if set" do
308
+ @rollback_to = shipit_deploys(:shipit_pending)
309
+ @deploy = shipit_deploys(:shipit_running)
310
+ @deploy.ping
311
+ @deploy.pid = 42
312
+ @deploy.abort!(rollback_once_aborted: true, rollback_once_aborted_to: @rollback_to, aborted_by: @user)
313
+
314
+ assert_difference -> { @stack.rollbacks.count }, 1 do
315
+ assert_enqueued_with(job: PerformTaskJob) do
316
+ @deploy.aborted!
317
+ end
318
+ end
319
+ end
320
+
304
321
  test "#build_rollback returns an unsaved record" do
305
322
  assert @deploy.build_rollback.new_record?
306
323
  end
@@ -429,6 +446,20 @@ module Shipit
429
446
  assert_equal "Shipit::Rollback", last_deploy.type
430
447
  end
431
448
 
449
+ test "#trigger_revert uses rollback_to if set" do
450
+ test_stack = create_test_stack
451
+ test_stack.save
452
+ test_stack.reload
453
+
454
+ running_deploy = shipit_deploys(:shipit_running)
455
+ rollback_to = shipit_deploys(:shipit_pending)
456
+
457
+ final_rollback = running_deploy.trigger_revert(rollback_to: rollback_to)
458
+
459
+ assert_equal "Shipit::Rollback", final_rollback.type
460
+ assert_equal 4, final_rollback.until_commit_id
461
+ end
462
+
432
463
  test "#trigger_revert skips unsuccessful deploys when reverting" do
433
464
  user_id = @user.id
434
465
  test_stack = create_test_stack
@@ -865,9 +896,6 @@ module Shipit
865
896
  until_commit: template_task.until_commit,
866
897
  )
867
898
 
868
- pull_request_response = stub(head: stub(sha: '6dcb09b5b57875f334f61aebed695e2e4193db5e'))
869
- Shipit.github.api.expects(:pull_request).with('shopify/shipit-engine', 7).returns(pull_request_response)
870
-
871
899
  expected_delta = deploy.commits.select(&:pull_request?).size + 1
872
900
  assert_difference -> { CommitDeployment.count }, expected_delta do
873
901
  assert_difference -> { CommitDeploymentStatus.count }, expected_delta do
@@ -879,25 +907,6 @@ module Shipit
879
907
  refute_nil CommitDeployment.find_by(sha: deploy.until_commit.sha)
880
908
  end
881
909
 
882
- test "#create_commit_deployments handles API errors when loading pull request details" do
883
- template_task = shipit_tasks(:shipit_pending)
884
- deploy = template_task.stack.deploys.build(
885
- since_commit: template_task.since_commit,
886
- until_commit: template_task.until_commit,
887
- )
888
-
889
- Shipit.github.api.expects(:pull_request).with('shopify/shipit-engine', 7).raises(Octokit::NotFound)
890
-
891
- expected_delta = 1 # Only the batch head
892
- assert_difference -> { CommitDeployment.count }, expected_delta do
893
- assert_difference -> { CommitDeploymentStatus.count }, expected_delta do
894
- deploy.save!
895
- end
896
- end
897
-
898
- refute_nil CommitDeployment.find_by(sha: deploy.until_commit.sha)
899
- end
900
-
901
910
  private
902
911
 
903
912
  def expect_event(deploy)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  module Shipit
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  module Shipit
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  module Shipit
@@ -50,22 +51,29 @@ module Shipit
50
51
  end
51
52
 
52
53
  test ".emit calls #deliver on internal hooks" do
53
- original_receivers = Shipit.internal_hook_receivers
54
- FakeReceiver = Module.new
55
- FakeReceiver.expects(:deliver).with(:deploy, @stack, 'foo' => 42)
54
+ original_receivers = Shipit.internal_hook_receivers
55
+ FakeReceiver = Module.new
56
+ FakeReceiver.expects(:deliver).with(:deploy, @stack, 'foo' => 42)
56
57
 
57
- Shipit.internal_hook_receivers << FakeReceiver
58
- Hook.emit(:deploy, @stack, 'foo' => 42)
58
+ Shipit.internal_hook_receivers << FakeReceiver
59
+ Hook.emit(:deploy, @stack, 'foo' => 42)
59
60
  ensure
60
- Shipit.internal_hook_receivers = original_receivers
61
+ Shipit.internal_hook_receivers = original_receivers
61
62
  end
62
63
 
63
64
  test ".emit calls no internal hooks if there are no internal_hook_receivers" do
64
- original_receivers = Shipit.internal_hook_receivers
65
- Shipit.internal_hook_receivers = nil
66
- Hook.emit(:deploy, @stack, 'foo' => 42)
65
+ original_receivers = Shipit.internal_hook_receivers
66
+ Shipit.internal_hook_receivers = nil
67
+ Hook.emit(:deploy, @stack, 'foo' => 42)
67
68
  ensure
68
- Shipit.internal_hook_receivers = original_receivers
69
+ Shipit.internal_hook_receivers = original_receivers
70
+ end
71
+
72
+ test ".coerce_payload coerces anonymous user correctly" do
73
+ locked_stack = Stack.first
74
+ locked_stack.lock("Some Reason", nil)
75
+ serialized = Hook.coerce_payload(stack: locked_stack)
76
+ assert_json("stack.lock_author.anonymous", true, document: serialized)
69
77
  end
70
78
  end
71
79
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  module Shipit
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  module Shipit
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  module Shipit
@@ -271,7 +272,7 @@ module Shipit
271
272
  behind_by: 10,
272
273
  ),
273
274
  )
274
- spec = {'merge' => {'max_divergence' => {'commits' => 1}}}
275
+ spec = { 'merge' => { 'max_divergence' => { 'commits' => 1 } } }
275
276
  @pr.stack.cached_deploy_spec = DeploySpec.new(spec)
276
277
  assert_predicate @pr, :stale?
277
278
  end
@@ -279,14 +280,14 @@ module Shipit
279
280
  test "#stale? returns true when the branch falls behind the maximum age" do
280
281
  @pr.base_commit = shipit_commits(:second)
281
282
  @pr.head.committed_at = 2.hours.ago
282
- spec = {'merge' => {'max_divergence' => {'age' => '1h'}}}
283
+ spec = { 'merge' => { 'max_divergence' => { 'age' => '1h' } } }
283
284
  @pr.stack.cached_deploy_spec = DeploySpec.new(spec)
284
285
  assert_predicate @pr, :stale?
285
286
  end
286
287
 
287
288
  test "#stale? is false when base_commit information is missing" do
288
289
  @pr.base_commit = nil
289
- spec = {'merge' => {'max_divergence' => {'age' => '1h', 'commits' => 10}}}
290
+ spec = { 'merge' => { 'max_divergence' => { 'age' => '1h', 'commits' => 10 } } }
290
291
  @pr.stack.cached_deploy_spec = DeploySpec.new(spec)
291
292
  refute_predicate @pr, :stale?
292
293
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  module Shipit
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  module Shipit
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  module Shipit
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  module Shipit
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  module Shipit
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
  require 'securerandom'
3
4
 
@@ -70,11 +71,11 @@ module Shipit
70
71
 
71
72
  last_commit = shipit_commits(:third)
72
73
  deploy = @stack.trigger_deploy(last_commit, AnonymousUser.new)
73
- assert_includes FakeReceiver.hooks, [
74
+ assert_includes(FakeReceiver.hooks, [
74
75
  :deploy,
75
76
  @stack,
76
- {deploy: deploy, status: "pending", stack: @stack},
77
- ]
77
+ { deploy: deploy, status: "pending", stack: @stack },
78
+ ])
78
79
  ensure
79
80
  Shipit.internal_hook_receivers = original_receivers
80
81
  end
@@ -306,7 +307,7 @@ module Shipit
306
307
  end
307
308
 
308
309
  test "#monitoring returns deploy_spec's content" do
309
- assert_equal [{'image' => 'https://example.com/monitor.png', 'width' => 200, 'height' => 300}], @stack.monitoring
310
+ assert_equal [{ 'image' => 'https://example.com/monitor.png', 'width' => 200, 'height' => 300 }], @stack.monitoring
310
311
  end
311
312
 
312
313
  test "#destroy deletes the related commits" do
@@ -338,7 +339,7 @@ module Shipit
338
339
  time = Time.current
339
340
  @stack.update(lock_reason: "Just for fun", lock_author: shipit_users(:walrus))
340
341
  travel 1.day
341
- expect_hook(:lock, @stack, locked: false, lock_details: {from: time, until: Time.current}, stack: @stack) do
342
+ expect_hook(:lock, @stack, locked: false, lock_details: { from: time, until: Time.current }, stack: @stack) do
342
343
  @stack.update(lock_reason: nil)
343
344
  end
344
345
  end
@@ -389,7 +390,7 @@ module Shipit
389
390
 
390
391
  test "updating the stack emit a hook" do
391
392
  expect_hook(:stack, @stack, action: :updated, stack: @stack) do
392
- @stack.update(repo_name: 'foo')
393
+ @stack.update(environment: 'foo')
393
394
  end
394
395
  end
395
396
 
@@ -483,7 +484,9 @@ module Shipit
483
484
 
484
485
  assert_no_enqueued_jobs do
485
486
  assert_no_difference -> { Deploy.count } do
486
- @stack.trigger_continuous_delivery
487
+ value = @stack.trigger_continuous_delivery
488
+
489
+ assert_nil value
487
490
  end
488
491
  end
489
492
  end
@@ -551,7 +554,24 @@ module Shipit
551
554
  end
552
555
  end
553
556
 
557
+ test "#trigger_continuous_delivery bails out if no DeploySpec has been cached" do
558
+ @stack = shipit_stacks(:check_deploy_spec)
559
+ deploy_spec = @stack.cached_deploy_spec
560
+
561
+ assert_predicate @stack, :deployable?
562
+ refute_predicate @stack, :deployed_too_recently?
563
+ assert(deploy_spec.blank?, "DeploySpec blank? returned false")
564
+
565
+ assert_no_enqueued_jobs(only: Shipit::PerformTaskJob) do
566
+ assert_no_difference -> { Deploy.count } do
567
+ @stack.trigger_continuous_delivery
568
+ end
569
+ end
570
+ end
571
+
554
572
  test "#trigger_continuous_delivery enqueues deployment ref update job" do
573
+ Shipit.stubs(:update_latest_deployed_ref).returns(true)
574
+
555
575
  @stack = shipit_stacks(:shipit_canaries)
556
576
  shipit_tasks(:canaries_running).delete
557
577
 
@@ -567,6 +587,8 @@ module Shipit
567
587
  end
568
588
 
569
589
  test "#trigger_continuous_delivery executes ref update job with correct sha" do
590
+ Shipit.stubs(:update_latest_deployed_ref).returns(true)
591
+
570
592
  @stack = shipit_stacks(:shipit_canaries)
571
593
  shipit_tasks(:canaries_running).delete
572
594
 
@@ -598,7 +620,7 @@ module Shipit
598
620
  @stack.tasks.delete_all
599
621
 
600
622
  deploy = @stack.trigger_continuous_delivery
601
- assert_equal({'SAFETY_DISABLED' => '0'}, deploy.env)
623
+ assert_equal({ 'SAFETY_DISABLED' => '0' }, deploy.env)
602
624
  end
603
625
 
604
626
  test "#continuous_delivery_delayed! bumps updated_at" do
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  module Shipit
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  module Shipit
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  module Shipit
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  module Shipit
@@ -11,10 +12,10 @@ module Shipit
11
12
  'steps' => ['touch tmp/restart'],
12
13
  'allow_concurrency' => true,
13
14
  'variables' => [
14
- {'name' => 'FOO', 'title' => 'Set to 0 to foo', 'default' => '1'},
15
- {'name' => 'BAR', 'title' => 'Set to 1 to bar', 'default' => '0'},
16
- {'name' => 'WALRUS', 'title' => 'Use with caution', 'default' => ' '},
17
- {'name' => 'NODEFAULT', 'title' => 'Variable without default'},
15
+ { 'name' => 'FOO', 'title' => 'Set to 0 to foo', 'default' => '1' },
16
+ { 'name' => 'BAR', 'title' => 'Set to 1 to bar', 'default' => '0' },
17
+ { 'name' => 'WALRUS', 'title' => 'Use with caution', 'default' => ' ' },
18
+ { 'name' => 'NODEFAULT', 'title' => 'Variable without default' },
18
19
  ],
19
20
  )
20
21
  end
@@ -43,10 +44,10 @@ module Shipit
43
44
  checklist: [],
44
45
  allow_concurrency: true,
45
46
  variables: [
46
- {'name' => 'FOO', 'title' => 'Set to 0 to foo', 'default' => '1', 'select' => nil},
47
- {'name' => 'BAR', 'title' => 'Set to 1 to bar', 'default' => '0', 'select' => nil},
48
- {'name' => 'WALRUS', 'title' => 'Use with caution', 'default' => ' ', 'select' => nil},
49
- {'name' => 'NODEFAULT', 'title' => 'Variable without default', 'default' => '', 'select' => nil},
47
+ { 'name' => 'FOO', 'title' => 'Set to 0 to foo', 'default' => '1', 'select' => nil },
48
+ { 'name' => 'BAR', 'title' => 'Set to 1 to bar', 'default' => '0', 'select' => nil },
49
+ { 'name' => 'WALRUS', 'title' => 'Use with caution', 'default' => ' ', 'select' => nil },
50
+ { 'name' => 'NODEFAULT', 'title' => 'Variable without default', 'default' => '', 'select' => nil },
50
51
  ],
51
52
  }
52
53
  assert_equal as_json, TaskDefinition.load(TaskDefinition.dump(@definition)).as_json
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  module Shipit
4
5
  class TasksTest < ActiveSupport::TestCase
5
6
  test "#title interpolates env" do
6
7
  task = shipit_tasks(:shipit_rendered_failover)
7
- assert_equal({'POD_ID' => '12'}, task.env)
8
+ assert_equal({ 'POD_ID' => '12' }, task.env)
8
9
  assert_equal 'Failover pod 12', task.title
9
10
  end
10
11
 
@@ -30,5 +31,21 @@ module Shipit
30
31
 
31
32
  task.write("hello\nworld")
32
33
  end
34
+
35
+ test "#chunk_output truncates output exceeding the storage limit" do
36
+ task = shipit_tasks(:shipit)
37
+ task.chunks.delete_all
38
+ # Dont persist the chunk to the DB, as it may exceed the MySQL max packet size on CI
39
+ task.chunks.build(text: 'a' * (Task::OUTPUT_SIZE_LIMIT * 1.1))
40
+
41
+ output = task.chunk_output
42
+
43
+ assert output.size <= Task::OUTPUT_SIZE_LIMIT, "Output was not truncated to the limit"
44
+ # We don't use assert_includes because it will print the whole message
45
+ assert(
46
+ output.include?(Task::OUTPUT_TRUNCATED_MESSAGE),
47
+ "'#{Task::OUTPUT_TRUNCATED_MESSAGE.chomp}' was not present in the output",
48
+ )
49
+ end
33
50
  end
34
51
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  module Shipit
@@ -11,16 +12,17 @@ module Shipit
11
12
  end
12
13
 
13
14
  test ".find_or_create_by_handle fetch the team from github if it's not in the db already" do
14
- Shipit.github.api.expects(:org_teams).with('shopify', per_page: 100)
15
15
  response = stub(rels: {}, data: [new_team])
16
+ Shipit.github.api.expects(:org_teams).with('shopify', per_page: 100).returns(response.data)
16
17
  Shipit.github.api.expects(:last_response).returns(response)
18
+
17
19
  assert_difference -> { Team.count }, 1 do
18
20
  Team.find_or_create_by_handle('Shopify/new-team')
19
21
  end
20
22
  end
21
23
 
22
24
  test "#refresh_members! fetch all the team members from github" do
23
- response = stub(rels: {members: members_resource})
25
+ response = stub(rels: { members: members_resource })
24
26
  Shipit.github.api.expects(:get).with(@team.api_url).returns(response)
25
27
  assert_difference -> { User.count }, 1 do
26
28
  @team.refresh_members!
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  module Shipit
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'test_helper'
2
3
 
3
4
  module Shipit
@@ -91,8 +92,8 @@ module Shipit
91
92
 
92
93
  stub_request(:get, @emails_url).to_return(
93
94
  status: %w(200 OK),
94
- body: [{email: expected_email}].to_json,
95
- headers: {"Content-Type" => "application/json"},
95
+ body: [{ email: expected_email }].to_json,
96
+ headers: { "Content-Type" => "application/json" },
96
97
  )
97
98
 
98
99
  user = User.find_or_create_from_github(@github_user)
@@ -119,7 +120,7 @@ module Shipit
119
120
  stub_request(:get, @emails_url).to_return(
120
121
  status: %w(200 OK),
121
122
  body: result_email_records.to_json,
122
- headers: {"Content-Type" => "application/json"},
123
+ headers: { "Content-Type" => "application/json" },
123
124
  )
124
125
 
125
126
  user = User.find_or_create_from_github(@github_user)
@@ -141,7 +142,7 @@ module Shipit
141
142
  stub_request(:get, @emails_url).to_return(
142
143
  status: %w(200 OK),
143
144
  body: result_email_records.to_json,
144
- headers: {"Content-Type" => "application/json"},
145
+ headers: { "Content-Type" => "application/json" },
145
146
  )
146
147
 
147
148
  user = User.find_or_create_from_github(@github_user)
@@ -162,9 +163,16 @@ module Shipit
162
163
  assert_nil user.email
163
164
  end
164
165
 
166
+ test "find_or_create_from_github handles user 401" do
167
+ Shipit.preferred_org_emails = [@org_domain]
168
+ Octokit::Client.any_instance.expects(:emails).raises(Octokit::Unauthorized)
169
+ user = User.find_or_create_from_github(@minimal_github_user)
170
+ assert_nil user.email
171
+ end
172
+
165
173
  test "#identifiers_for_ping returns a hash with the user's github_id, name, email and github_login" do
166
174
  user = shipit_users(:bob)
167
- expected_ouput = {github_id: user.github_id, name: user.name, email: user.email, github_login: user.login}
175
+ expected_ouput = { github_id: user.github_id, name: user.name, email: user.email, github_login: user.login }
168
176
  assert_equal expected_ouput, user.identifiers_for_ping
169
177
  end
170
178