shipit-engine 0.33.0 → 0.34.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -2
  3. data/app/assets/stylesheets/_pages/_deploy.scss +0 -2
  4. data/app/controllers/shipit/api/ccmenu_controller.rb +1 -1
  5. data/app/controllers/shipit/api/deploys_controller.rb +2 -0
  6. data/app/controllers/shipit/api/rollbacks_controller.rb +2 -1
  7. data/app/controllers/shipit/api/stacks_controller.rb +1 -0
  8. data/app/controllers/shipit/deploys_controller.rb +1 -1
  9. data/app/controllers/shipit/stacks_controller.rb +2 -2
  10. data/app/controllers/shipit/tasks_controller.rb +2 -2
  11. data/app/controllers/shipit/webhooks_controller.rb +23 -4
  12. data/app/helpers/shipit/shipit_helper.rb +0 -1
  13. data/app/jobs/shipit/deliver_hook_job.rb +1 -1
  14. data/app/jobs/shipit/github_sync_job.rb +13 -9
  15. data/app/jobs/shipit/update_github_last_deployed_ref_job.rb +1 -1
  16. data/app/models/shipit/anonymous_user.rb +6 -2
  17. data/app/models/shipit/check_run.rb +36 -0
  18. data/app/models/shipit/commit.rb +20 -9
  19. data/app/models/shipit/commit_checks.rb +13 -13
  20. data/app/models/shipit/commit_deployment.rb +3 -3
  21. data/app/models/shipit/commit_deployment_status.rb +3 -3
  22. data/app/models/shipit/deploy.rb +16 -11
  23. data/app/models/shipit/deploy_spec/lerna_discovery.rb +12 -4
  24. data/app/models/shipit/duration.rb +2 -0
  25. data/app/models/shipit/hook.rb +26 -2
  26. data/app/models/shipit/merge_request.rb +9 -7
  27. data/app/models/shipit/pull_request.rb +1 -1
  28. data/app/models/shipit/release_status.rb +1 -1
  29. data/app/models/shipit/repository.rb +9 -3
  30. data/app/models/shipit/review_stack.rb +16 -2
  31. data/app/models/shipit/stack.rb +59 -25
  32. data/app/models/shipit/status/group.rb +1 -1
  33. data/app/models/shipit/task.rb +6 -2
  34. data/app/models/shipit/task_execution_strategy/default.rb +4 -5
  35. data/app/models/shipit/team.rb +4 -2
  36. data/app/models/shipit/user.rb +4 -0
  37. data/app/models/shipit/webhooks/handlers/pull_request/review_stack_adapter.rb +1 -1
  38. data/app/models/shipit/webhooks/handlers/push_handler.rb +4 -1
  39. data/app/serializers/shipit/merge_request_serializer.rb +1 -1
  40. data/app/validators/subset_validator.rb +1 -1
  41. data/app/views/layouts/merge_status.html.erb +1 -1
  42. data/app/views/shipit/stacks/_banners.html.erb +2 -1
  43. data/app/views/shipit/stacks/new.html.erb +1 -1
  44. data/config/secrets.development.example.yml +24 -0
  45. data/config/secrets.development.shopify.yml +20 -9
  46. data/db/migrate/20210325194053_remove_stacks_branch_default.rb +5 -0
  47. data/db/migrate/20210504200438_add_github_updated_at_to_check_runs.rb +5 -0
  48. data/lib/shipit.rb +39 -15
  49. data/lib/shipit/command.rb +7 -6
  50. data/lib/shipit/commands.rb +9 -2
  51. data/lib/shipit/engine.rb +2 -0
  52. data/lib/shipit/flock.rb +8 -1
  53. data/lib/shipit/github_app.rb +7 -5
  54. data/lib/shipit/octokit_iterator.rb +3 -3
  55. data/lib/shipit/simple_message_verifier.rb +2 -2
  56. data/lib/shipit/stack_commands.rb +28 -4
  57. data/lib/shipit/task_commands.rb +6 -0
  58. data/lib/shipit/version.rb +1 -1
  59. data/lib/snippets/publish-lerna-independent-packages +35 -34
  60. data/lib/snippets/publish-lerna-independent-packages-legacy +39 -0
  61. data/test/controllers/api/ccmenu_controller_test.rb +1 -1
  62. data/test/controllers/api/deploys_controller_test.rb +17 -0
  63. data/test/controllers/api/stacks_controller_test.rb +21 -7
  64. data/test/controllers/webhooks_controller_test.rb +26 -11
  65. data/test/dummy/app/assets/config/manifest.js +3 -0
  66. data/test/dummy/config/application.rb +1 -1
  67. data/test/dummy/config/database.yml +9 -0
  68. data/test/dummy/config/environments/development.rb +1 -1
  69. data/test/dummy/config/secrets_double_github_app.yml +79 -0
  70. data/test/dummy/db/schema.rb +5 -4
  71. data/test/dummy/db/seeds.rb +1 -0
  72. data/test/fixtures/payloads/check_suite_master.json +2 -30
  73. data/test/fixtures/payloads/push_master.json +1 -1
  74. data/test/fixtures/payloads/push_not_master.json +1 -1
  75. data/test/fixtures/shipit/commits.yml +2 -2
  76. data/test/fixtures/shipit/hooks.yml +1 -0
  77. data/test/fixtures/shipit/tasks.yml +1 -1
  78. data/test/helpers/json_helper.rb +5 -1
  79. data/test/jobs/github_sync_job_test.rb +2 -1
  80. data/test/models/commit_deployment_status_test.rb +3 -3
  81. data/test/models/commits_test.rb +2 -0
  82. data/test/models/deploy_spec_test.rb +7 -0
  83. data/test/models/deploys_test.rb +18 -0
  84. data/test/models/hook_test.rb +30 -1
  85. data/test/models/merge_request_test.rb +19 -4
  86. data/test/models/shipit/check_run_test.rb +124 -5
  87. data/test/models/shipit/review_stack_test.rb +38 -6
  88. data/test/models/shipit/stacks_test.rb +42 -4
  89. data/test/models/shipit/webhooks/handlers/pull_request/review_stack_adapter_test.rb +24 -0
  90. data/test/models/tasks_test.rb +22 -0
  91. data/test/test_helper.rb +15 -0
  92. data/test/unit/anonymous_user_serializer_test.rb +1 -1
  93. data/test/unit/command_test.rb +5 -0
  94. data/test/unit/commit_serializer_test.rb +1 -1
  95. data/test/unit/deploy_commands_test.rb +70 -14
  96. data/test/unit/deploy_serializer_test.rb +1 -1
  97. data/test/unit/github_app_test.rb +2 -3
  98. data/test/unit/github_apps_test.rb +416 -0
  99. data/test/unit/shipit_deployment_checks_test.rb +77 -0
  100. data/test/unit/shipit_test.rb +14 -0
  101. data/test/unit/user_serializer_test.rb +1 -1
  102. metadata +202 -191
@@ -0,0 +1,3 @@
1
+ //= link_tree ../images
2
+ //= link_directory ../javascripts .js
3
+ //= link_directory ../stylesheets .css
@@ -17,7 +17,7 @@ end
17
17
 
18
18
  module Shipit
19
19
  class Application < Rails::Application
20
- config.load_defaults 6.0
20
+ config.load_defaults 6.1
21
21
  end
22
22
  end
23
23
 
@@ -1,3 +1,11 @@
1
+ <% if ENV['DATABASE_URL'].present? %>
2
+ development:
3
+ database: shipit_engine_development
4
+
5
+ test:
6
+ database: shipit_engine_test
7
+
8
+ <% else %>
1
9
  default: &default
2
10
  adapter: sqlite3
3
11
 
@@ -8,3 +16,4 @@ development:
8
16
  test:
9
17
  <<: *default
10
18
  database: db/test.sqlite3
19
+ <% end %>
@@ -50,7 +50,7 @@ Rails.application.configure do
50
50
 
51
51
  # Raises error for missing translations
52
52
  # config.action_view.raise_on_missing_translations = true
53
- if Rails.application.config_for(:database)['adapter'] == 'sqlite3'
53
+ if Rails.application.config_for(:database)&.dig('adapter') == 'sqlite3'
54
54
  config.to_prepare do
55
55
  Shipit::DeferredTouch.enabled = false
56
56
  end
@@ -0,0 +1,79 @@
1
+ github:
2
+ OrgOne:
3
+ domain: # defaults to github.com
4
+ app_id: 42
5
+ installation_id: 43
6
+ bot_login: "shipit[bot]"
7
+ webhook_secret: # nil
8
+ # Randomly generated
9
+ private_key: |
10
+ -----BEGIN RSA PRIVATE KEY-----
11
+ MIIEpAIBAAKCAQEA7iUQC2uUq/gtQg0gxtyaccuicYgmq1LUr1mOWbmwM1Cv63+S
12
+ 73qo8h87FX+YyclY5fZF6SMXIys02JOkImGgbnvEOLcHnImCYrWs03msOzEIO/pG
13
+ M0YedAPtQ2MEiLIu4y8htosVxeqfEOPiq9kQgFxNKyETzjdIA9q1md8sofuJUmPv
14
+ ibacW1PecuAMnn+P8qf0XIDp7uh6noB751KvhCaCNTAPtVE9NZ18OmNG9GOyX/pu
15
+ pQHIrPgTpTG6KlAe3r6LWvemzwsMtuRGU+K+KhK9dFIlSE+v9rA32KScO8efOh6s
16
+ Gu3rWorV4iDu14U62rzEfdzzc63YL94sUbZxbwIDAQABAoIBADLJ8r8MxZtbhYN1
17
+ u0zOFZ45WL6v09dsBfITvnlCUeLPzYUDIzoxxcBFittN6C744x3ARS6wjimw+EdM
18
+ TZALlCSb/sA9wMDQzt7wchhz9Zh2H5RzDu+2f54sjDh38KqancdT8PO2fAFGxX/b
19
+ qicOVyeZB9gv6MJtJc20olBbuXAeBNfcDABF9oxF+0i+Ssg7B4VXiqgcjtGbr/Og
20
+ qRll7AqyTArVx2xEcVfZxeZ4zGnigzcJq4te7yYpxzwk+RxblkPh54Yt4WxZ+8DI
21
+ Rsn3r6ajlpwzpwvsJFU2Txq7xBTzGQMFmy/Pnjk83kP2cogxB2+tRyjITGqTwD8b
22
+ gg9PFCkCgYEA+7u8A0l0Cz6p0SI6c7ftVePVRiIhpawWN7og/wEmI6zUjm/3rA+R
23
+ hrhaVKuOD8QF/HdDsqTck5gjGAjTmJz6r33/cl1Tz+pr62znsrB4r0yMKvQbKN81
24
+ WGaWOsi2+ZXqLNv5h5wpUF0MTKlXHeKnwP5kuEvGwVn6WURFCh6PhLMCgYEA8i5e
25
+ JjulJVGyd5HuoY3xyO7E6DjidsqRnVRq+hYpORjnHvTmSwe4+tH4ha2p9Kv2Y6k3
26
+ C1NYY/fSMQoYCCRaYyJleI+la/9tsZqAmtms4ZB8KhFmPHf9fW75i6G0xKWyZ8K+
27
+ E2Ft/UaEiM282593cguV6+Kt5uExnyPxLLK4FlUCgYEAwRJ/JGI8/7bjFkTTYheq
28
+ j5q75BufhOrU6471acAe2XPgXxLfefdC3Xodxh0CS3NESBvNL4Ikr4sbN37lk4Kq
29
+ /th7iOKtuqUIeru/hZy2I3VpeDRbdGCmEJQ2GwYA2LKztg5Nd0Y9paaIHXAwIfrK
30
+ QUqcQ4HTAk8ZpUeoUBeaaeMCgYANLmbjb9WiPVsYVPIHCwHA7PX8qbPxwT7BsGmO
31
+ KQyfVfKmZa/vH4F67Vi4deZNMdrcO8aKMEQcVM2065a5QrlEsgeR00eupB1lUEJ1
32
+ qylUsZeAdqf43JMIc7TTW77KATa/nQLZbTEeWus1wvTngztuEqFbUGAks9cOkVc8
33
+ FpIcbQKBgQDVIL8gPLmn0f+4oLF8MBC+oxtKpz14X5iJ1saGFkzW5I+nIEskpS0S
34
+ qtirnTCnJFGdCrFwctnxiuiCmyGwpBYdjIfHyvYAHnqAtMnESzCUyeSFZiquVW5W
35
+ MvbMmDPoV27XOHU9kIq6NXtfrkpufiyo6/VEYWozXalxKLNuqLYfPQ==
36
+ -----END RSA PRIVATE KEY-----
37
+ oauth:
38
+ id: Iv1.bf2c2c45b449bfd9
39
+ secret: ef694cd6e45223075d78d138ef014049052665f1
40
+ teams:
41
+ OrgTwo:
42
+ domain: # defaults to github.com
43
+ app_id: 42
44
+ installation_id: 43
45
+ bot_login: "shipit[bot]"
46
+ webhook_secret: # nil
47
+ # Randomly generated
48
+ private_key: |
49
+ -----BEGIN RSA PRIVATE KEY-----
50
+ MIIEpAIBAAKCAQEA7iUQC2uUq/gtQg0gxtyaccuicYgmq1LUr1mOWbmwM1Cv63+S
51
+ 73qo8h87FX+YyclY5fZF6SMXIys02JOkImGgbnvEOLcHnImCYrWs03msOzEIO/pG
52
+ M0YedAPtQ2MEiLIu4y8htosVxeqfEOPiq9kQgFxNKyETzjdIA9q1md8sofuJUmPv
53
+ ibacW1PecuAMnn+P8qf0XIDp7uh6noB751KvhCaCNTAPtVE9NZ18OmNG9GOyX/pu
54
+ pQHIrPgTpTG6KlAe3r6LWvemzwsMtuRGU+K+KhK9dFIlSE+v9rA32KScO8efOh6s
55
+ Gu3rWorV4iDu14U62rzEfdzzc63YL94sUbZxbwIDAQABAoIBADLJ8r8MxZtbhYN1
56
+ u0zOFZ45WL6v09dsBfITvnlCUeLPzYUDIzoxxcBFittN6C744x3ARS6wjimw+EdM
57
+ TZALlCSb/sA9wMDQzt7wchhz9Zh2H5RzDu+2f54sjDh38KqancdT8PO2fAFGxX/b
58
+ qicOVyeZB9gv6MJtJc20olBbuXAeBNfcDABF9oxF+0i+Ssg7B4VXiqgcjtGbr/Og
59
+ qRll7AqyTArVx2xEcVfZxeZ4zGnigzcJq4te7yYpxzwk+RxblkPh54Yt4WxZ+8DI
60
+ Rsn3r6ajlpwzpwvsJFU2Txq7xBTzGQMFmy/Pnjk83kP2cogxB2+tRyjITGqTwD8b
61
+ gg9PFCkCgYEA+7u8A0l0Cz6p0SI6c7ftVePVRiIhpawWN7og/wEmI6zUjm/3rA+R
62
+ hrhaVKuOD8QF/HdDsqTck5gjGAjTmJz6r33/cl1Tz+pr62znsrB4r0yMKvQbKN81
63
+ WGaWOsi2+ZXqLNv5h5wpUF0MTKlXHeKnwP5kuEvGwVn6WURFCh6PhLMCgYEA8i5e
64
+ JjulJVGyd5HuoY3xyO7E6DjidsqRnVRq+hYpORjnHvTmSwe4+tH4ha2p9Kv2Y6k3
65
+ C1NYY/fSMQoYCCRaYyJleI+la/9tsZqAmtms4ZB8KhFmPHf9fW75i6G0xKWyZ8K+
66
+ E2Ft/UaEiM282593cguV6+Kt5uExnyPxLLK4FlUCgYEAwRJ/JGI8/7bjFkTTYheq
67
+ j5q75BufhOrU6471acAe2XPgXxLfefdC3Xodxh0CS3NESBvNL4Ikr4sbN37lk4Kq
68
+ /th7iOKtuqUIeru/hZy2I3VpeDRbdGCmEJQ2GwYA2LKztg5Nd0Y9paaIHXAwIfrK
69
+ QUqcQ4HTAk8ZpUeoUBeaaeMCgYANLmbjb9WiPVsYVPIHCwHA7PX8qbPxwT7BsGmO
70
+ KQyfVfKmZa/vH4F67Vi4deZNMdrcO8aKMEQcVM2065a5QrlEsgeR00eupB1lUEJ1
71
+ qylUsZeAdqf43JMIc7TTW77KATa/nQLZbTEeWus1wvTngztuEqFbUGAks9cOkVc8
72
+ FpIcbQKBgQDVIL8gPLmn0f+4oLF8MBC+oxtKpz14X5iJ1saGFkzW5I+nIEskpS0S
73
+ qtirnTCnJFGdCrFwctnxiuiCmyGwpBYdjIfHyvYAHnqAtMnESzCUyeSFZiquVW5W
74
+ MvbMmDPoV27XOHU9kIq6NXtfrkpufiyo6/VEYWozXalxKLNuqLYfPQ==
75
+ -----END RSA PRIVATE KEY-----
76
+ oauth:
77
+ id: Iv1.bf2c2c45b449bfd9
78
+ secret: ef694cd6e45223075d78d138ef014049052665f1
79
+ teams:
@@ -2,15 +2,15 @@
2
2
  # of editing this file, please use the migrations feature of Active Record to
3
3
  # incrementally modify your database, and then regenerate this schema definition.
4
4
  #
5
- # This file is the source Rails uses to define your schema when running `rails
6
- # db:schema:load`. When creating a new database, `rails db:schema:load` tends to
5
+ # This file is the source Rails uses to define your schema when running `bin/rails
6
+ # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7
7
  # be faster and is potentially less error prone than running all of your
8
8
  # migrations from scratch. Old migrations may fail to apply correctly if those
9
9
  # migrations use external dependencies or application code.
10
10
  #
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema.define(version: 2020_10_08_152744) do
13
+ ActiveRecord::Schema.define(version: 2021_05_04_200438) do
14
14
 
15
15
  create_table "api_clients", force: :cascade do |t|
16
16
  t.text "permissions", limit: 65535
@@ -33,6 +33,7 @@ ActiveRecord::Schema.define(version: 2020_10_08_152744) do
33
33
  t.string "html_url"
34
34
  t.datetime "created_at", null: false
35
35
  t.datetime "updated_at", null: false
36
+ t.datetime "github_updated_at"
36
37
  t.index ["commit_id"], name: "index_check_runs_on_commit_id"
37
38
  t.index ["github_id", "commit_id"], name: "index_check_runs_on_github_id_and_commit_id", unique: true
38
39
  t.index ["stack_id"], name: "index_check_runs_on_stack_id"
@@ -234,7 +235,7 @@ ActiveRecord::Schema.define(version: 2020_10_08_152744) do
234
235
  t.string "environment", limit: 50, default: "production", null: false
235
236
  t.datetime "created_at"
236
237
  t.datetime "updated_at"
237
- t.string "branch", limit: 255, default: "master", null: false
238
+ t.string "branch", limit: 255, null: false
238
239
  t.string "deploy_url", limit: 255
239
240
  t.string "lock_reason", limit: 4096
240
241
  t.integer "tasks_count", limit: 4, default: 0, null: false
@@ -31,6 +31,7 @@ module Shipit
31
31
  name: Faker::Internet.domain_name.parameterize,
32
32
  owner: Faker::Company.name.parameterize
33
33
  ),
34
+ branch: "main",
34
35
  deploy_url: "https://#{Faker::Internet.domain_name.parameterize}.#{Faker::Internet.domain_suffix}/",
35
36
  cached_deploy_spec: DeploySpec.load(%(
36
37
  {
@@ -67,24 +67,7 @@
67
67
  "name": "shipit-engine",
68
68
  "full_name": "Shopify/shipit-engine",
69
69
  "owner": {
70
- "login": "github",
71
- "id": 340,
72
- "node_id": "MDQ6VXNlcjIxMDMxMDY3",
73
- "avatar_url": "http://alambic.github.com/avatars/u/340?",
74
- "gravatar_id": "",
75
- "url": "https://api.github.com/users/github",
76
- "html_url": "http://github.com/github",
77
- "followers_url": "https://api.github.com/users/github/followers",
78
- "following_url": "https://api.github.com/users/github/following{/other_user}",
79
- "gists_url": "https://api.github.com/users/github/gists{/gist_id}",
80
- "starred_url": "https://api.github.com/users/github/starred{/owner}{/repo}",
81
- "subscriptions_url": "https://api.github.com/users/github/subscriptions",
82
- "organizations_url": "https://api.github.com/users/github/orgs",
83
- "repos_url": "https://api.github.com/users/github/repos",
84
- "events_url": "https://api.github.com/users/github/events{/privacy}",
85
- "received_events_url": "https://api.github.com/users/github/received_events",
86
- "type": "Organization",
87
- "site_admin": false
70
+ "login": "Shopify"
88
71
  },
89
72
  "private": false,
90
73
  "html_url": "http://github.com/Shopify/shipit-engine",
@@ -155,18 +138,7 @@
155
138
  "default_branch": "master"
156
139
  },
157
140
  "organization": {
158
- "login": "github",
159
- "id": 340,
160
- "node_id": "MDEyOk9yZ2FuaXphdGlvbjM4MzAyODk5",
161
- "url": "https://api.github.com/orgs/github",
162
- "repos_url": "https://api.github.com/orgs/github/repos",
163
- "events_url": "https://api.github.com/orgs/github/events",
164
- "hooks_url": "https://api.github.com/orgs/github/hooks",
165
- "issues_url": "https://api.github.com/orgs/github/issues",
166
- "members_url": "https://api.github.com/orgs/github/members{/member}",
167
- "public_members_url": "https://api.github.com/orgs/github/public_members{/member}",
168
- "avatar_url": "http://alambic.github.com/avatars/u/340?",
169
- "description": "How people build software."
141
+ "login": "Shopify"
170
142
  },
171
143
  "sender": {
172
144
  "login": "octocat",
@@ -64,7 +64,7 @@
64
64
  "fork": false,
65
65
  "size": 0,
66
66
  "owner": {
67
- "name": "Shopify",
67
+ "login": "Shopify",
68
68
  "email": "jean.boussier@gmail.com"
69
69
  },
70
70
  "private": false,
@@ -64,7 +64,7 @@
64
64
  "fork": false,
65
65
  "size": 0,
66
66
  "owner": {
67
- "name": "Shopify",
67
+ "login": "Shopify",
68
68
  "email": "jean.boussier@gmail.com"
69
69
  },
70
70
  "private": false,
@@ -45,8 +45,8 @@ fourth:
45
45
  sha: 467578b362bf2b4df5903e1c7960929361c3435a
46
46
  message: "Merge pull request #7 from shipit-engine/yoloshipit\n\nyoloshipit!"
47
47
  stack: shipit
48
- author: walrus
49
- committer: walrus
48
+ author: ~
49
+ committer: ~
50
50
  authored_at: <%= 4.days.ago.to_s(:db) %>
51
51
  committed_at: <%= 3.days.ago.to_s(:db) %>
52
52
  additions: 420
@@ -3,6 +3,7 @@ shipit_deploys:
3
3
  events: 'deploy,rollback'
4
4
  delivery_url: https://example.com/events/deploy
5
5
  content_type: json
6
+ secret: 'example-secret-key'
6
7
 
7
8
  all_deploys:
8
9
  events: 'deploy,rollback'
@@ -29,7 +29,7 @@ shipit2:
29
29
 
30
30
  shipit_restart:
31
31
  id: 3
32
- user: walrus
32
+ user: ~
33
33
  type: Shipit::Task
34
34
  stack: shipit
35
35
  status: success
@@ -3,7 +3,11 @@ module JSONHelper
3
3
  UNDEFINED = Object.new.freeze
4
4
  private_constant :UNDEFINED
5
5
 
6
- def assert_json(path = nil, expected_value = UNDEFINED, document: response.body)
6
+ def assert_json(path = nil, expected_value = UNDEFINED, &block)
7
+ assert_json_document(response.body, path, expected_value, &block)
8
+ end
9
+
10
+ def assert_json_document(document, path, expected_value = UNDEFINED)
7
11
  value = follow_path(path.to_s.split('.'), document: document)
8
12
  if block_given?
9
13
  yield value
@@ -91,7 +91,7 @@ module Shipit
91
91
  last = stub(sha: 123)
92
92
  first = stub(sha: 345)
93
93
  Shipit::FirstParentCommitsIterator.any_instance.stubs(:each).multiple_yields(last, first)
94
- @job.stubs(lookup_commit: nil)
94
+ @job.stubs(lookup_commit: nil, stack: @stack)
95
95
 
96
96
  commits, parent = @job.fetch_missing_commits { stub }
97
97
  assert_nil parent
@@ -104,6 +104,7 @@ module Shipit
104
104
  Shipit::FirstParentCommitsIterator.any_instance.stubs(:each).multiple_yields(last, first)
105
105
  @job.stubs(:lookup_commit).with(123).returns(nil)
106
106
  @job.stubs(:lookup_commit).with(345).returns(first)
107
+ @job.stubs(stack: @stack)
107
108
 
108
109
  commits, parent = @job.fetch_missing_commits { stub }
109
110
  assert_equal first, parent
@@ -12,7 +12,7 @@ module Shipit
12
12
 
13
13
  test 'creation on GitHub' do
14
14
  response = stub(id: 44, url: 'https://example.com')
15
- @author.github_api.expects(:create_deployment_status).with(
15
+ @author.github_api.class.any_instance.expects(:create_deployment_status).with(
16
16
  @deployment.api_url,
17
17
  'in_progress',
18
18
  accept: "application/vnd.github.flash-preview+json",
@@ -33,7 +33,7 @@ module Shipit
33
33
  status = deployment.statuses.create!(status: 'success')
34
34
  status.stubs(:description).returns('desc' * limit)
35
35
  create_status_response = stub(id: 'abcd', url: 'https://github.com/status/abcd')
36
- status.author.github_api.expects(:create_deployment_status).with do |*_args, **kwargs|
36
+ status.author.github_api.class.any_instance.expects(:create_deployment_status).with do |_url, _status, kwargs|
37
37
  kwargs[:description].size <= limit
38
38
  end.returns(create_status_response)
39
39
 
@@ -47,7 +47,7 @@ module Shipit
47
47
  stack = status.stack
48
48
  stack.deploy_url = "stack-deploy-url"
49
49
  create_status_response = stub(id: 'abcd', url: 'https://github.com/status/abcd')
50
- status.author.github_api.expects(:create_deployment_status).with do |*_args, **kwargs|
50
+ status.author.github_api.class.any_instance.expects(:create_deployment_status).with do |_url, _status, kwargs|
51
51
  kwargs[:environment_url] == 'stack-deploy-url'
52
52
  end.returns(create_status_response)
53
53
 
@@ -350,6 +350,8 @@ module Shipit
350
350
  output: mock(
351
351
  title: 'Tests build ran successfully',
352
352
  ),
353
+ completed_at: Time.now,
354
+ started_at: Time.now - 1.minute,
353
355
  )
354
356
  response = mock(
355
357
  check_runs: [check_run],
@@ -828,6 +828,13 @@ module Shipit
828
828
  @spec.stubs(:lerna?).returns(true)
829
829
  @spec.stubs(:lerna_config).returns('lerna' => '2.0.0', 'version' => 'independent')
830
830
  assert_equal 'assert-lerna-independent-version-tags', @spec.deploy_steps[0]
831
+ assert_equal 'publish-lerna-independent-packages-legacy', @spec.deploy_steps[1]
832
+ end
833
+
834
+ test '#publish_lerna_packages checks if independent version tags exist, checks if a newer version of lerna is used, and then invokes lerna deploy script' do
835
+ @spec.stubs(:lerna?).returns(true)
836
+ @spec.stubs(:lerna_config).returns('lerna' => '3.0.0', 'version' => 'independent')
837
+ assert_equal 'assert-lerna-independent-version-tags', @spec.deploy_steps[0]
831
838
  assert_equal 'publish-lerna-independent-packages', @spec.deploy_steps[1]
832
839
  end
833
840
 
@@ -802,6 +802,12 @@ module Shipit
802
802
  assert_equal @user, @stack.lock_author
803
803
  end
804
804
 
805
+ test "#trigger_rollback does not lock the stack if not requested" do
806
+ refute @stack.locked?
807
+ @deploy.trigger_rollback(@user, lock: false)
808
+ refute @stack.reload.locked?
809
+ end
810
+
805
811
  test "#trigger_rollback marks the rollback as `ignored_safeties` if the force option was used" do
806
812
  rollback = @deploy.trigger_rollback(@user, force: true)
807
813
  assert_predicate rollback, :ignored_safeties?
@@ -967,6 +973,18 @@ module Shipit
967
973
  end
968
974
  end
969
975
 
976
+ test "succeeding a deploy sets the release status as pending and does not schedule job if the status delay is negative (-1)" do
977
+ @deploy = shipit_deploys(:canaries_running)
978
+ @deploy.stack.expects(:release_status_delay).at_least_once.returns(Duration.parse(-1))
979
+
980
+ assert_difference -> { ReleaseStatus.count }, +1 do
981
+ assert_not_equal 'success', @deploy.last_release_status.state
982
+ @deploy.report_complete!
983
+ assert_equal 'validating', @deploy.status
984
+ assert_equal 'pending', @deploy.last_release_status.state
985
+ end
986
+ end
987
+
970
988
  test "triggering a rollback via abort! sets the release status as failure" do
971
989
  @deploy = shipit_deploys(:canaries_running)
972
990
  @deploy.ping
@@ -36,6 +36,35 @@ module Shipit
36
36
  end
37
37
  end
38
38
 
39
+ test ".deliver! sends request with correct method, headers, and body" do
40
+ stub_request(:post, @hook.delivery_url).to_return(body: 'OK')
41
+ body = { 'foo' => 42 }
42
+ expected_body = JSON.pretty_generate(body)
43
+ expected_signature = Hook::DeliverySigner.new(@hook.secret).sign(expected_body)
44
+
45
+ perform_enqueued_jobs(only: DeliverHookJob) do
46
+ @hook.deliver!(:deploy, body)
47
+ end
48
+ assert_performed_jobs 1
49
+ assert_requested :post, @hook.delivery_url do |req|
50
+ req.headers['X-Shipit-Signature'] == expected_signature
51
+ end
52
+ end
53
+
54
+ test ".deliver! sends without signature if no secret is configured" do
55
+ stub_request(:post, @hook.delivery_url).to_return(body: 'OK')
56
+ @hook.update!(secret: '')
57
+ body = { 'foo' => 42 }
58
+
59
+ perform_enqueued_jobs(only: DeliverHookJob) do
60
+ @hook.deliver!(:deploy, body)
61
+ end
62
+ assert_performed_jobs 1
63
+ assert_requested :post, @hook.delivery_url do |req|
64
+ !req.headers.key?('X-Shipit-Signature')
65
+ end
66
+ end
67
+
39
68
  test ".scoped? returns true if the hook has a stack_id" do
40
69
  @hook.stack_id = nil
41
70
  refute @hook.scoped?
@@ -73,7 +102,7 @@ module Shipit
73
102
  locked_stack = Stack.first
74
103
  locked_stack.lock("Some Reason", nil)
75
104
  serialized = Hook.coerce_payload(stack: locked_stack)
76
- assert_json("stack.lock_author.anonymous", true, document: serialized)
105
+ assert_json_document(serialized, "stack.lock_author.anonymous", true)
77
106
  end
78
107
  end
79
108
  end
@@ -60,7 +60,7 @@ module Shipit
60
60
 
61
61
  assert_nil MergeRequest.extract_number(@stack, 'https://github.com/ACME/shipit-engine/pull/42')
62
62
 
63
- Shipit.github.expects(:domain).returns('github.acme.com').at_least_once
63
+ Shipit.github.class.any_instance.expects(:domain).returns('github.acme.com').at_least_once
64
64
  assert_equal 42, MergeRequest.extract_number(@stack, 'https://github.acme.com/Shopify/shipit-engine/pull/42')
65
65
  assert_nil MergeRequest.extract_number(@stack, 'https://github.com/Shopify/shipit-engine/pull/42')
66
66
  end
@@ -125,6 +125,21 @@ module Shipit
125
125
  created_at: 1.day.ago,
126
126
  )])
127
127
 
128
+ Shipit.github.api.expects(:check_runs).with(@stack.github_repo_name, head_sha).returns(stub(
129
+ check_runs: [stub(
130
+ id: 123456,
131
+ name: 'check run',
132
+ conclusion: 'success',
133
+ output: stub(
134
+ title: 'a test checkrun',
135
+ ),
136
+ details_url: 'http://example.com',
137
+ html_url: 'http://example.com',
138
+ completed_at: Time.now,
139
+ started_at: 1.minute.ago,
140
+ )]
141
+ ))
142
+
128
143
  merge_request.refresh!
129
144
 
130
145
  assert_predicate merge_request, :mergeable?
@@ -233,9 +248,9 @@ module Shipit
233
248
  end
234
249
  params = job.arguments.first
235
250
  assert_equal 'merge', params[:event]
236
- assert_json 'status', 'rejected', document: params[:payload]
237
- assert_json 'merge_request.rejection_reason', 'merge_conflict', document: params[:payload]
238
- assert_json 'merge_request.number', @pr.number, document: params[:payload]
251
+ assert_json_document params[:payload], 'status', 'rejected'
252
+ assert_json_document params[:payload], 'merge_request.rejection_reason', 'merge_conflict'
253
+ assert_json_document params[:payload], 'merge_request.number', @pr.number
239
254
  end
240
255
 
241
256
  test "#merge! doesnt delete the branch if there are open PRs against it" do