shipit-engine 0.34.0 → 0.36.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -7
  3. data/app/assets/stylesheets/_pages/_deploy.scss +2 -1
  4. data/app/controllers/concerns/shipit/authentication.rb +5 -1
  5. data/app/controllers/shipit/api/base_controller.rb +13 -1
  6. data/app/controllers/shipit/api/rollbacks_controller.rb +1 -1
  7. data/app/controllers/shipit/api/stacks_controller.rb +8 -2
  8. data/app/controllers/shipit/api/tasks_controller.rb +19 -2
  9. data/app/helpers/shipit/stacks_helper.rb +11 -0
  10. data/app/models/concerns/shipit/deferred_touch.rb +3 -3
  11. data/app/models/shipit/anonymous_user.rb +4 -0
  12. data/app/models/shipit/commit_checks.rb +3 -3
  13. data/app/models/shipit/rollback.rb +5 -0
  14. data/app/models/shipit/task.rb +3 -3
  15. data/app/models/shipit/user.rb +23 -9
  16. data/app/serializers/shipit/stack_serializer.rb +1 -1
  17. data/app/views/shipit/deploys/_deploy.html.erb +1 -5
  18. data/app/views/shipit/stacks/_banners.html.erb +1 -1
  19. data/app/views/shipit/stacks/_settings_form.erb +55 -0
  20. data/app/views/shipit/stacks/settings.html.erb +1 -55
  21. data/app/views/shipit/stacks/show.html.erb +1 -1
  22. data/config/locales/en.yml +1 -1
  23. data/config/routes.rb +4 -0
  24. data/db/migrate/20210504200438_add_github_updated_at_to_check_runs.rb +1 -1
  25. data/db/migrate/20210823075617_change_check_runs_github_updated_at_default.rb +5 -0
  26. data/db/migrate/20211103154121_increase_github_team_slug_size.rb +5 -0
  27. data/lib/shipit/commands.rb +12 -6
  28. data/lib/shipit/engine.rb +13 -5
  29. data/lib/shipit/stack_commands.rb +3 -3
  30. data/lib/shipit/task_commands.rb +1 -1
  31. data/lib/shipit/version.rb +1 -1
  32. data/lib/shipit.rb +5 -2
  33. data/test/controllers/api/hooks_controller_test.rb +1 -1
  34. data/test/controllers/api/rollback_controller_test.rb +1 -0
  35. data/test/controllers/api/stacks_controller_test.rb +25 -0
  36. data/test/controllers/api/tasks_controller_test.rb +56 -0
  37. data/test/controllers/stacks_controller_test.rb +11 -0
  38. data/test/dummy/config/application.rb +1 -2
  39. data/test/dummy/db/schema.rb +2 -2
  40. data/test/fixtures/shipit/check_runs.yml +3 -3
  41. data/test/fixtures/shipit/commits.yml +101 -101
  42. data/test/fixtures/shipit/deliveries.yml +1 -1
  43. data/test/fixtures/shipit/merge_requests.yml +19 -19
  44. data/test/fixtures/shipit/stacks.yml +28 -28
  45. data/test/fixtures/shipit/statuses.yml +16 -16
  46. data/test/fixtures/shipit/tasks.yml +65 -65
  47. data/test/fixtures/shipit/users.yml +2 -5
  48. data/test/models/commits_test.rb +6 -6
  49. data/test/models/deploys_test.rb +22 -0
  50. data/test/models/tasks_test.rb +2 -2
  51. data/test/models/team_test.rb +21 -2
  52. data/test/models/users_test.rb +29 -9
  53. data/test/unit/deploy_commands_test.rb +7 -7
  54. metadata +170 -167
@@ -16,7 +16,7 @@ module Shipit
16
16
  def fetch
17
17
  create_directories
18
18
  if valid_git_repository?(@stack.git_path)
19
- git('fetch', 'origin', '--tags', @stack.branch, env: env, chdir: @stack.git_path)
19
+ git('fetch', 'origin', '--quiet', '--tags', @stack.branch, env: env, chdir: @stack.git_path)
20
20
  else
21
21
  @stack.clear_git_cache!
22
22
  git_clone(@stack.repo_git_url, @stack.git_path, branch: @stack.branch, env: env, chdir: @stack.deploys_path)
@@ -72,7 +72,7 @@ module Shipit
72
72
  ).run!
73
73
 
74
74
  git_dir = File.join(dir, @stack.repo_name)
75
- git('checkout', commit.sha, chdir: git_dir).run! if commit
75
+ git('-c', 'advice.detachedHead=false', 'checkout', commit.sha, chdir: git_dir).run! if commit
76
76
  yield Pathname.new(git_dir)
77
77
  end
78
78
  end
@@ -90,7 +90,7 @@ module Shipit
90
90
  end
91
91
 
92
92
  def git_clone(url, path, branch: 'master', **kwargs)
93
- git('clone', *modern_git_args, '--recursive', '--branch', branch, url, path, **kwargs)
93
+ git('clone', '--quiet', *modern_git_args, '--recursive', '--branch', branch, url, path, **kwargs)
94
94
  end
95
95
 
96
96
  def modern_git_args
@@ -47,7 +47,7 @@ module Shipit
47
47
  end
48
48
 
49
49
  def checkout(commit)
50
- git('checkout', commit.sha, chdir: @task.working_directory)
50
+ git('-c', 'advice.detachedHead=false', 'checkout', commit.sha, chdir: @task.working_directory)
51
51
  end
52
52
 
53
53
  def clone
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Shipit
3
- VERSION = '0.34.0'
3
+ VERSION = '0.36.0'
4
4
  end
data/lib/shipit.rb CHANGED
@@ -5,7 +5,6 @@ require 'state_machines-activerecord'
5
5
  require 'validate_url'
6
6
  require 'responders'
7
7
  require 'explicit-parameters'
8
- require 'attr_encrypted'
9
8
 
10
9
  require 'sass-rails'
11
10
  require 'coffee-rails'
@@ -153,7 +152,11 @@ module Shipit
153
152
  end
154
153
 
155
154
  def user_access_tokens_key
156
- (secrets.user_access_tokens_key.presence || secrets.secret_key_base).byteslice(0, 32)
155
+ if secrets.user_access_tokens_key.present?
156
+ secrets.user_access_tokens_key
157
+ elsif secrets.secret_key_base
158
+ Digest::SHA256.digest("user_access_tokens_key" + secrets.secret_key_base)
159
+ end
157
160
  end
158
161
 
159
162
  def host
@@ -61,7 +61,7 @@ module Shipit
61
61
  post :create, params: {
62
62
  delivery_url: 'https://example.com/hook',
63
63
  events: %w(deploy rollback),
64
- created_at: 2.months.ago.to_s(:db),
64
+ created_at: 2.months.ago.to_formatted_s(:db),
65
65
  }
66
66
  Hook.last.created_at > 2.seconds.ago
67
67
  end
@@ -107,6 +107,7 @@ module Shipit
107
107
  assert_response :accepted
108
108
  refute_predicate last_deploy, :active?
109
109
  assert_json 'rollback_once_aborted_to.revision.sha', @commit.sha
110
+ assert last_deploy.rollback_once_aborted?
110
111
  end
111
112
  end
112
113
  end
@@ -96,6 +96,24 @@ module Shipit
96
96
  assert_equal 'test', @stack.branch
97
97
  end
98
98
 
99
+ test "#update updates the stack when nil deploy_url" do
100
+ @stack.update(deploy_url: nil)
101
+ @stack.update(continuous_deployment: true)
102
+ assert_nil @stack.deploy_url
103
+ assert @stack.continuous_deployment
104
+
105
+ patch :update, params: {
106
+ id: @stack.to_param,
107
+ continuous_deployment: false,
108
+ }
109
+
110
+ assert_response :ok
111
+ @stack.reload
112
+
113
+ assert_nil @stack.deploy_url
114
+ refute @stack.continuous_deployment
115
+ end
116
+
99
117
  test "#index returns a list of stacks" do
100
118
  stack = Stack.last
101
119
  get :index
@@ -189,6 +207,13 @@ module Shipit
189
207
  assert_response :forbidden
190
208
  assert_json 'message', 'This operation requires the `write:stack` permission'
191
209
  end
210
+
211
+ test "#refresh queues a GithubSyncJob" do
212
+ assert_enqueued_with(job: GithubSyncJob, args: [id: @stack.id]) do
213
+ post :refresh, params: { id: @stack.to_param }
214
+ end
215
+ assert_response :accepted
216
+ end
192
217
  end
193
218
  end
194
219
  end
@@ -6,6 +6,7 @@ module Shipit
6
6
  class TasksControllerTest < ActionController::TestCase
7
7
  setup do
8
8
  @stack = shipit_stacks(:shipit)
9
+ @user = shipit_users(:walrus)
9
10
  authenticate!
10
11
  end
11
12
 
@@ -90,6 +91,61 @@ module Shipit
90
91
  assert_response :conflict
91
92
  assert_json 'message', 'A task is already running.'
92
93
  end
94
+
95
+ test "#trigger fails when user does not have deploy permission" do
96
+ @client.permissions.delete('deploy:stack')
97
+ @client.save!
98
+
99
+ assert_no_difference 'Task.count' do
100
+ post :trigger, params: { stack_id: @stack.to_param, task_name: 'restart' }
101
+ end
102
+
103
+ assert_response :forbidden
104
+ assert_json 'message', 'This operation requires the `deploy:stack` permission'
105
+ end
106
+
107
+ test "#abort aborts the task" do
108
+ task = shipit_deploys(:shipit_running)
109
+ task.ping
110
+
111
+ put :abort, params: { stack_id: @stack.to_param, id: task.id }
112
+
113
+ assert_response :accepted
114
+ assert_equal 'aborting', task.reload.status
115
+ end
116
+
117
+ test "#abort sets `aborted_by` to the current user" do
118
+ task = shipit_deploys(:shipit_running)
119
+ task.ping
120
+ request.headers['X-Shipit-User'] = @user.login
121
+
122
+ put :abort, params: { stack_id: @stack.to_param, id: task.id }
123
+
124
+ assert_equal task.reload.aborted_by, @user
125
+ end
126
+
127
+ test "#abort responds with method_not_allowed if the task is not currently running" do
128
+ task = shipit_deploys(:shipit_aborted)
129
+ task.ping
130
+ put :abort, params: { stack_id: @stack.to_param, id: task.id }
131
+
132
+ assert_response :method_not_allowed
133
+ assert_json 'message', 'This task is not currently running.'
134
+ end
135
+
136
+ test "#abort fails when user does not have deploy permission" do
137
+ @client.permissions.delete('deploy:stack')
138
+ @client.save!
139
+ task = shipit_deploys(:shipit_running)
140
+ task.ping
141
+
142
+ assert_no_difference 'Task.count' do
143
+ put :abort, params: { stack_id: @stack.to_param, id: task.id }
144
+ end
145
+
146
+ assert_response :forbidden
147
+ assert_json 'message', 'This operation requires the `deploy:stack` permission'
148
+ end
93
149
  end
94
150
  end
95
151
  end
@@ -36,6 +36,17 @@ module Shipit
36
36
  assert_redirected_to '/github/auth/github?origin=http%3A%2F%2Ftest.host%2F'
37
37
  end
38
38
 
39
+ test "users which require a fresh login are redirected" do
40
+ user = shipit_users(:walrus)
41
+ user.update!(github_access_token: 'some_legacy_value')
42
+ assert_predicate user, :requires_fresh_login?
43
+
44
+ get :index
45
+
46
+ assert_redirected_to '/github/auth/github?origin=http%3A%2F%2Ftest.host%2F'
47
+ assert_nil session[:user_id]
48
+ end
49
+
39
50
  test "current_user must be a member of at least a Shipit.github_teams" do
40
51
  session[:user_id] = shipit_users(:bob).id
41
52
  Shipit.stubs(:github_teams).returns([shipit_teams(:cyclimse_cooks), shipit_teams(:shopify_developers)])
@@ -17,7 +17,6 @@ end
17
17
 
18
18
  module Shipit
19
19
  class Application < Rails::Application
20
- config.load_defaults 6.1
20
+ config.load_defaults 7.0
21
21
  end
22
22
  end
23
-
@@ -10,7 +10,7 @@
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: 2021_05_04_200438) do
13
+ ActiveRecord::Schema.define(version: 2021_11_03_154121) do
14
14
 
15
15
  create_table "api_clients", force: :cascade do |t|
16
16
  t.text "permissions", limit: 65535
@@ -315,7 +315,7 @@ ActiveRecord::Schema.define(version: 2021_05_04_200438) do
315
315
  create_table "teams", force: :cascade do |t|
316
316
  t.integer "github_id", limit: 4
317
317
  t.string "api_url", limit: 255
318
- t.string "slug", limit: 50
318
+ t.string "slug", limit: 255
319
319
  t.string "name", limit: 255
320
320
  t.string "organization", limit: 39
321
321
  t.datetime "created_at", null: false
@@ -7,7 +7,7 @@ second_pending_travis:
7
7
  conclusion: success
8
8
  html_url: "http://www.example.com/run/424242"
9
9
  details_url: "http://www.example.com/build/424242"
10
- created_at: <%= 10.days.ago.to_s(:db) %>
10
+ created_at: <%= 10.days.ago.to_formatted_s(:db) %>
11
11
 
12
12
  check_runs_first_pending_coveralls:
13
13
  stack: check_runs
@@ -15,7 +15,7 @@ check_runs_first_pending_coveralls:
15
15
  github_id: 43
16
16
  title: lets go
17
17
  name: Coverage metrics
18
- created_at: <%= 10.days.ago.to_s(:db) %>
18
+ created_at: <%= 10.days.ago.to_formatted_s(:db) %>
19
19
  conclusion: pending
20
20
  html_url: "http://www.example.com/run/434343"
21
21
  details_url: "http://www.example.com/build/434343"
@@ -26,7 +26,7 @@ check_runs_first_success_coveralls:
26
26
  github_id: 434343
27
27
  title: lets go
28
28
  name: Coverage metrics
29
- created_at: <%= 9.days.ago.to_s(:db) %>
29
+ created_at: <%= 9.days.ago.to_formatted_s(:db) %>
30
30
  conclusion: success
31
31
  html_url: "http://www.example.com/run/434343"
32
32
  details_url: "http://www.example.com/build/434343"