diff --git a/.rubocop.yml b/.rubocop.yml
index 28f0bb2a6..5800ac789 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -13,9 +13,6 @@ AllCops:
- lib/shipit-engine.rb
- template.rb
-inherit_gem:
- rubocop-shopify: rubocop.yml
-
Layout/LineLength:
Exclude:
- config/routes.rb
@@ -66,6 +63,41 @@ Style/SymbolArray:
Naming/InclusiveLanguage:
Enabled: false
+Style/Documentation:
+ Enabled: false
+
+Metrics/ClassLength:
+ Enabled: false
+
+Metrics/BlockLength:
+ Enabled: false
+
+Metrics/ModuleLength:
+ Enabled: false
+
+Metrics/MethodLength:
+ Enabled: false
+
+Naming/MemoizedInstanceVariableName:
+ Enabled: false
+
+Lint/ConstantDefinitionInBlock:
+ Enabled: false
+
+Metrics/AbcSize:
+ Enabled: false
+
+Metrics/CyclomaticComplexity:
+ Enabled: false
+
+Metrics/PerceivedComplexity:
+ Enabled: false
+
+Style/NumericPredicate:
+ Enabled: false
+
+Style/ModuleFunction:
+ Enabled: false
# Crashing cops. We need to update rubocop at some point but better do it in its own PR.
Layout/BlockAlignment:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5b4cf78e5..cf5ccfd9f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,7 @@
# Unreleased
* Pass `Shipit::Stack` to `DeploySpec::FileSystem.new` and make it accessible through an accessor. (#1356)
+* Upgrade Rubocop to 1.48.0
# 0.39.0
diff --git a/Gemfile b/Gemfile
index b12bdc854..377200e65 100644
--- a/Gemfile
+++ b/Gemfile
@@ -13,8 +13,7 @@ end
group :development, :test do
gem 'faker'
gem 'webmock'
- gem 'rubocop', '1.18.3'
- gem 'rubocop-shopify', require: false
+ gem 'rubocop', '~> 1.48.0'
end
group :test do
diff --git a/Gemfile.lock b/Gemfile.lock
index 14e4a688f..6fd78b317 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -109,7 +109,7 @@ GEM
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
ansi_stream (0.0.6)
- ast (2.4.2)
+ ast (2.4.3)
autoprefixer-rails (6.4.1.1)
execjs
axiom-types (0.1.1)
@@ -195,6 +195,7 @@ GEM
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
+ json (2.10.2)
jwt (2.7.1)
lodash-rails (4.17.21)
railties (>= 3.1)
@@ -252,11 +253,12 @@ GEM
omniauth (>= 1.9, < 3)
paquito (0.10.0)
msgpack (>= 1.5.2)
- parallel (1.26.3)
- parser (3.3.4.2)
+ parallel (1.27.0)
+ parser (3.3.8.0)
ast (~> 2.4.1)
racc
pg (1.3.3)
+ prism (1.4.0)
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
@@ -318,26 +320,26 @@ GEM
redis (4.8.1)
redis-objects (1.7.0)
redis
- regexp_parser (2.9.2)
+ regexp_parser (2.10.0)
reline (0.5.8)
io-console (~> 0.5)
responders (3.1.0)
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.3.9)
- rubocop (1.18.3)
+ rubocop (1.48.1)
+ json (~> 2.3)
parallel (~> 1.10)
- parser (>= 3.0.0.0)
+ parser (>= 3.2.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
- rexml
- rubocop-ast (>= 1.7.0, < 2.0)
+ rexml (>= 3.2.5, < 4.0)
+ rubocop-ast (>= 1.26.0, < 2.0)
ruby-progressbar (~> 1.7)
- unicode-display_width (>= 1.4.0, < 3.0)
- rubocop-ast (1.32.1)
- parser (>= 3.3.1.0)
- rubocop-shopify (2.2.0)
- rubocop (~> 1.18)
+ unicode-display_width (>= 2.4.0, < 3.0)
+ rubocop-ast (1.44.1)
+ parser (>= 3.3.7.2)
+ prism (~> 1.4)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
safe_yaml (1.0.5)
@@ -390,7 +392,7 @@ GEM
timeout (0.4.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
- unicode-display_width (2.5.0)
+ unicode-display_width (2.6.0)
useragent (0.16.10)
validate_url (1.0.15)
activemodel (>= 3.0.0)
@@ -423,8 +425,7 @@ DEPENDENCIES
mysql2
pg
pry
- rubocop (= 1.18.3)
- rubocop-shopify
+ rubocop (~> 1.48.0)
shipit-engine!
simplecov
spy
diff --git a/Rakefile b/Rakefile
index 01a482cb1..dfd662856 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
@@ -8,7 +9,7 @@ begin
rescue LoadError
end
-APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
+APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
load('rails/tasks/engine.rake')
Bundler::GemHelper.install_tasks
diff --git a/app/controllers/concerns/shipit/active_model_serializers_patch.rb b/app/controllers/concerns/shipit/active_model_serializers_patch.rb
index e4e5c625b..81db56dd5 100644
--- a/app/controllers/concerns/shipit/active_model_serializers_patch.rb
+++ b/app/controllers/concerns/shipit/active_model_serializers_patch.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
module ActiveModelSerializersPatch
private
diff --git a/app/controllers/concerns/shipit/api/cacheable.rb b/app/controllers/concerns/shipit/api/cacheable.rb
index 963f82071..549a9a7b3 100644
--- a/app/controllers/concerns/shipit/api/cacheable.rb
+++ b/app/controllers/concerns/shipit/api/cacheable.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
module Api
module Cacheable
diff --git a/app/controllers/concerns/shipit/api/paginable.rb b/app/controllers/concerns/shipit/api/paginable.rb
index a77a795b5..8a5e339e3 100644
--- a/app/controllers/concerns/shipit/api/paginable.rb
+++ b/app/controllers/concerns/shipit/api/paginable.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
module Api
module Paginable
@@ -23,8 +24,8 @@ def render_resources(resource, *)
resource,
self,
order: default_order,
- max_page_size: max_page_size,
- default_page_size: default_page_size,
+ max_page_size:,
+ default_page_size:
)
headers[LINK] = render_links(paginator.links)
super(paginator.to_a)
diff --git a/app/controllers/concerns/shipit/api/rendering.rb b/app/controllers/concerns/shipit/api/rendering.rb
index 137e0b4d6..b7f28a5c7 100644
--- a/app/controllers/concerns/shipit/api/rendering.rb
+++ b/app/controllers/concerns/shipit/api/rendering.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
module Api
module Rendering
diff --git a/app/controllers/concerns/shipit/authentication.rb b/app/controllers/concerns/shipit/authentication.rb
index cc53e5860..e3bdf3469 100644
--- a/app/controllers/concerns/shipit/authentication.rb
+++ b/app/controllers/concerns/shipit/authentication.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
module Authentication
extend ActiveSupport::Concern
diff --git a/app/controllers/concerns/shipit/pagination.rb b/app/controllers/concerns/shipit/pagination.rb
index 937ecc571..483c781f2 100644
--- a/app/controllers/concerns/shipit/pagination.rb
+++ b/app/controllers/concerns/shipit/pagination.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
module Pagination
extend ActiveSupport::Concern
@@ -20,8 +21,8 @@ def paginate(relation)
relation,
self,
order: default_order,
- max_page_size: max_page_size,
- default_page_size: default_page_size,
+ max_page_size:,
+ default_page_size:
)
end
end
diff --git a/app/controllers/shipit/api/base_controller.rb b/app/controllers/shipit/api/base_controller.rb
index d7df8157a..aa49b36c8 100644
--- a/app/controllers/shipit/api/base_controller.rb
+++ b/app/controllers/shipit/api/base_controller.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
module Api
class BaseController < ActionController::Base
@@ -35,7 +36,7 @@ module BasicAuth
private
- def has_basic_credentials?(request)
+ def basic_credentials?(request)
request.authorization.present? && (auth_scheme(request).downcase == "basic")
end
end
@@ -46,14 +47,15 @@ def namespace_for_serializer
def authenticate_api_client
@current_api_client = if Shipit.disable_api_authentication
- UnlimitedApiClient.new
- else
- BasicAuth.authenticate(request) do |*parts|
- token = parts.select(&:present?).join('--')
- ApiClient.authenticate(token)
- end
- end
+ UnlimitedApiClient.new
+ else
+ BasicAuth.authenticate(request) do |*parts|
+ token = parts.select(&:present?).join('--')
+ ApiClient.authenticate(token)
+ end
+ end
return if @current_api_client
+
headers['WWW-Authenticate'] = 'Basic realm="Authentication token"'
render(status: :unauthorized, json: { message: 'Bad credentials' })
end
diff --git a/app/controllers/shipit/api/ccmenu_controller.rb b/app/controllers/shipit/api/ccmenu_controller.rb
index c42bb48cf..b67f4b79f 100644
--- a/app/controllers/shipit/api/ccmenu_controller.rb
+++ b/app/controllers/shipit/api/ccmenu_controller.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
module Api
class CCMenuController < BaseController
@@ -20,7 +21,7 @@ def running?
def show
latest_deploy = stack.deploys_and_rollbacks.last || NoDeploy.new
- render('shipit/ccmenu/project', formats: [:xml], locals: { stack: stack, deploy: latest_deploy })
+ render('shipit/ccmenu/project', formats: [:xml], locals: { stack:, deploy: latest_deploy })
end
private
diff --git a/app/controllers/shipit/api/commits_controller.rb b/app/controllers/shipit/api/commits_controller.rb
index b35e05dc7..e3838e2d8 100644
--- a/app/controllers/shipit/api/commits_controller.rb
+++ b/app/controllers/shipit/api/commits_controller.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
module Api
class CommitsController < BaseController
@@ -6,9 +7,7 @@ class CommitsController < BaseController
def index
commits = stack.commits.reachable.includes(:statuses)
- if params[:undeployed]
- commits = commits.newer_than(stack.last_deployed_commit)
- end
+ commits = commits.newer_than(stack.last_deployed_commit) if params[:undeployed]
render_resources(commits)
end
diff --git a/app/controllers/shipit/api/deploys_controller.rb b/app/controllers/shipit/api/deploys_controller.rb
index 3ccb3f077..a20360802 100644
--- a/app/controllers/shipit/api/deploys_controller.rb
+++ b/app/controllers/shipit/api/deploys_controller.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
module Api
class DeploysController < BaseController
@@ -22,7 +23,7 @@ def create
allow_concurrency = params.allow_concurrency.nil? ? params.force : params.allow_concurrency
deploy = stack.trigger_deploy(commit, current_user, env: params.env, force: params.force,
- allow_concurrency: allow_concurrency)
+ allow_concurrency:)
render_resource(deploy, status: :accepted)
end
end
diff --git a/app/controllers/shipit/api/hooks_controller.rb b/app/controllers/shipit/api/hooks_controller.rb
index 033615052..dd710ba94 100644
--- a/app/controllers/shipit/api/hooks_controller.rb
+++ b/app/controllers/shipit/api/hooks_controller.rb
@@ -1,9 +1,10 @@
# frozen_string_literal: true
+
module Shipit
module Api
class HooksController < BaseController
- require_permission :read, :hook, only: %i(index show)
- require_permission :write, :hook, only: %i(create update destroy)
+ require_permission :read, :hook, only: %i[index show]
+ require_permission :write, :hook, only: %i[create update destroy]
def index
render_resources(hooks)
@@ -43,7 +44,7 @@ def hook
end
def hooks
- Hook.where(stack_id: stack_id)
+ Hook.where(stack_id:)
end
def stack_id
diff --git a/app/controllers/shipit/api/locks_controller.rb b/app/controllers/shipit/api/locks_controller.rb
index 29668a414..f04010c13 100644
--- a/app/controllers/shipit/api/locks_controller.rb
+++ b/app/controllers/shipit/api/locks_controller.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
module Api
class LocksController < BaseController
diff --git a/app/controllers/shipit/api/merge_requests_controller.rb b/app/controllers/shipit/api/merge_requests_controller.rb
index b676db243..e1d664cbb 100644
--- a/app/controllers/shipit/api/merge_requests_controller.rb
+++ b/app/controllers/shipit/api/merge_requests_controller.rb
@@ -1,9 +1,10 @@
# frozen_string_literal: true
+
module Shipit
module Api
class MergeRequestsController < BaseController
require_permission :read, :stack
- require_permission :deploy, :stack, only: %i(update destroy)
+ require_permission :deploy, :stack, only: %i[update destroy]
def index
render_resources(stack.merge_requests.includes(:head).order(id: :desc))
@@ -19,16 +20,16 @@ def update
head(:accepted)
elsif merge_request.merged?
render(status: :method_not_allowed, json: {
- message: "This pull request was already merged.",
- })
+ message: "This pull request was already merged."
+ })
else
raise "Pull Request is neither waiting nor merged, this should be impossible"
end
end
def destroy
- if merge_request = stack.merge_requests.where(number: params[:id]).first
- merge_request.cancel! if merge_request.waiting?
+ if (merge_request = stack.merge_requests.where(number: params[:id]).first) && merge_request.waiting?
+ merge_request.cancel!
end
head(:no_content)
end
diff --git a/app/controllers/shipit/api/outputs_controller.rb b/app/controllers/shipit/api/outputs_controller.rb
index 041e7c716..851f380ec 100644
--- a/app/controllers/shipit/api/outputs_controller.rb
+++ b/app/controllers/shipit/api/outputs_controller.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
module Api
class OutputsController < BaseController
diff --git a/app/controllers/shipit/api/release_statuses_controller.rb b/app/controllers/shipit/api/release_statuses_controller.rb
index 7a10c381d..79740af7e 100644
--- a/app/controllers/shipit/api/release_statuses_controller.rb
+++ b/app/controllers/shipit/api/release_statuses_controller.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
module Api
class ReleaseStatusesController < BaseController
@@ -6,7 +7,7 @@ class ReleaseStatusesController < BaseController
params do
requires :status, String
- validates :status, inclusion: { in: %w(success failure) }
+ validates :status, inclusion: { in: %w[success failure] }
end
def create
deploy = stack.deploys_and_rollbacks.find(params[:deploy_id])
diff --git a/app/controllers/shipit/api/rollbacks_controller.rb b/app/controllers/shipit/api/rollbacks_controller.rb
index 0c954bd23..94bcffc9b 100644
--- a/app/controllers/shipit/api/rollbacks_controller.rb
+++ b/app/controllers/shipit/api/rollbacks_controller.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
module Api
class RollbacksController < BaseController
diff --git a/app/controllers/shipit/api/stacks_controller.rb b/app/controllers/shipit/api/stacks_controller.rb
index ffcec1215..a483a5e3a 100644
--- a/app/controllers/shipit/api/stacks_controller.rb
+++ b/app/controllers/shipit/api/stacks_controller.rb
@@ -1,9 +1,10 @@
# frozen_string_literal: true
+
module Shipit
module Api
class StacksController < BaseController
- require_permission :read, :stack, only: %i(index show)
- require_permission :write, :stack, only: %i(create update destroy)
+ require_permission :read, :stack, only: %i[index show]
+ require_permission :write, :stack, only: %i[create update destroy]
params do
accepts :repo_owner, String
@@ -14,10 +15,10 @@ def index
if params[:repo_owner] && params[:repo_name]
full_repo_name = [repo_owner, repo_name].join('/')
@stacks = if (repository = Repository.from_github_repo_name(full_repo_name))
- stacks.where(repository: repository)
- else
- Stack.none
- end
+ stacks.where(repository:)
+ else
+ Stack.none
+ end
end
render_resources(@stacks)
end
@@ -75,7 +76,7 @@ def refresh
private
def create_params
- params.reject { |key, _| %i(repo_owner repo_name).include?(key) }
+ params.reject { |key, _| %i[repo_owner repo_name].include?(key) }
end
def stack
@@ -83,12 +84,12 @@ def stack
end
def update_archived
- if key?(:archived)
- if params[:archived]
- stack.archive!(nil)
- elsif stack.archived?
- stack.unarchive!
- end
+ return unless key?(:archived)
+
+ if params[:archived]
+ stack.archive!(nil)
+ elsif stack.archived?
+ stack.unarchive!
end
end
@@ -98,7 +99,7 @@ def key?(key)
def update_params
params.select do |key, _|
- %i(environment branch deploy_url ignore_ci merge_queue_enabled continuous_deployment).include?(key)
+ %i[environment branch deploy_url ignore_ci merge_queue_enabled continuous_deployment].include?(key)
end
end
diff --git a/app/controllers/shipit/api/tasks_controller.rb b/app/controllers/shipit/api/tasks_controller.rb
index 345e9d1b5..6d7ae4004 100644
--- a/app/controllers/shipit/api/tasks_controller.rb
+++ b/app/controllers/shipit/api/tasks_controller.rb
@@ -1,9 +1,10 @@
# frozen_string_literal: true
+
module Shipit
module Api
class TasksController < BaseController
require_permission :read, :stack
- require_permission :deploy, :stack, only: %i(trigger abort)
+ require_permission :deploy, :stack, only: %i[trigger abort]
def index
render_resources(stack.tasks)
@@ -20,8 +21,8 @@ def trigger
render_resource(stack.trigger_task(params[:task_name], current_user, env: params.env), status: :accepted)
rescue Shipit::Task::ConcurrentTaskRunning
render(status: :conflict, json: {
- message: 'A task is already running.',
- })
+ message: 'A task is already running.'
+ })
end
def abort
@@ -30,8 +31,8 @@ def abort
head(:accepted)
else
render(status: :method_not_allowed, json: {
- message: "This task is not currently running.",
- })
+ message: "This task is not currently running."
+ })
end
end
diff --git a/app/controllers/shipit/api_clients_controller.rb b/app/controllers/shipit/api_clients_controller.rb
index efa503ee3..b4c0dc3e7 100644
--- a/app/controllers/shipit/api_clients_controller.rb
+++ b/app/controllers/shipit/api_clients_controller.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class ApiClientsController < ShipitController
include Pagination
@@ -15,9 +16,7 @@ def new
def create
@api_client = ApiClient.new(create_params.merge(creator_id: current_user.id))
- unless @api_client.save
- flash[:warning] = @api_client.errors.full_messages.to_sentence
- end
+ flash[:warning] = @api_client.errors.full_messages.to_sentence unless @api_client.save
respond_with(@api_client)
end
@@ -29,10 +28,10 @@ def show
def update
@api_client = ApiClient.find(params[:id])
options = if @api_client.update(update_params)
- { flash: { success: 'Successfully updated' } }
- else
- { flash: { warning: @stack.errors.full_messages.to_sentence } }
- end
+ { flash: { success: 'Successfully updated' } }
+ else
+ { flash: { warning: @stack.errors.full_messages.to_sentence } }
+ end
redirect_to(params[:return_to].presence || api_client_path(@api_client), options)
end
diff --git a/app/controllers/shipit/ccmenu_url_controller.rb b/app/controllers/shipit/ccmenu_url_controller.rb
index aedc32283..aafed86d0 100644
--- a/app/controllers/shipit/ccmenu_url_controller.rb
+++ b/app/controllers/shipit/ccmenu_url_controller.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'uri'
module Shipit
@@ -12,8 +13,8 @@ def fetch
private
def client
- @client ||= ApiClient.create_with(permissions: %w(read:stack))
- .find_or_create_by!(creator: current_user, name: 'CCMenu Client')
+ @client ||= ApiClient.create_with(permissions: %w[read:stack])
+ .find_or_create_by!(creator: current_user, name: 'CCMenu Client')
end
def stack
diff --git a/app/controllers/shipit/commit_checks_controller.rb b/app/controllers/shipit/commit_checks_controller.rb
index f8cce55de..422111ef7 100644
--- a/app/controllers/shipit/commit_checks_controller.rb
+++ b/app/controllers/shipit/commit_checks_controller.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class CommitChecksController < ShipitController
def show
@@ -16,7 +17,7 @@ def tail
url = stack_tail_commit_checks_path(stack, sha: commit.sha, since: next_offset)
end
- render(json: { url: url, output: output, status: checks.status })
+ render(json: { url:, output:, status: checks.status })
end
private
diff --git a/app/controllers/shipit/commits_controller.rb b/app/controllers/shipit/commits_controller.rb
index 716f33523..e9358573b 100644
--- a/app/controllers/shipit/commits_controller.rb
+++ b/app/controllers/shipit/commits_controller.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class CommitsController < ShipitController
def update
diff --git a/app/controllers/shipit/continuous_delivery_schedules_controller.rb b/app/controllers/shipit/continuous_delivery_schedules_controller.rb
index 4efa02521..6b284f960 100644
--- a/app/controllers/shipit/continuous_delivery_schedules_controller.rb
+++ b/app/controllers/shipit/continuous_delivery_schedules_controller.rb
@@ -33,7 +33,7 @@ def continuous_delivery_schedule_params
[
"#{day}_start",
"#{day}_end",
- "#{day}_enabled",
+ "#{day}_enabled"
]
end
)
diff --git a/app/controllers/shipit/deploys_controller.rb b/app/controllers/shipit/deploys_controller.rb
index 730c5d6c3..bd126b128 100644
--- a/app/controllers/shipit/deploys_controller.rb
+++ b/app/controllers/shipit/deploys_controller.rb
@@ -1,10 +1,11 @@
# frozen_string_literal: true
+
module Shipit
class DeploysController < ShipitController
include ChunksHelper
before_action :load_stack
- before_action :load_deploy, only: %i(show rollback revert)
+ before_action :load_deploy, only: %i[show rollback revert]
before_action :load_until_commit, only: :create
helper_method :short_commit_sha
@@ -26,7 +27,7 @@ def create
@until_commit,
current_user,
env: deploy_params[:env],
- force: params[:force].present?,
+ force: params[:force].present?
)
respond_with(@deploy.stack, @deploy)
rescue Task::ConcurrentTaskRunning
@@ -43,9 +44,9 @@ def revert
end
def short_commit_sha(task)
- if previous_successful_deploy_commit(task)
- @short_commit_sha ||= @previous_successful_deploy_commit&.short_sha
- end
+ return unless previous_successful_deploy_commit(task)
+
+ @short_commit_sha ||= @previous_successful_deploy_commit&.short_sha
end
private
diff --git a/app/controllers/shipit/github_authentication_controller.rb b/app/controllers/shipit/github_authentication_controller.rb
index d263db525..0d5345c95 100644
--- a/app/controllers/shipit/github_authentication_controller.rb
+++ b/app/controllers/shipit/github_authentication_controller.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class GithubAuthenticationController < ActionController::Base
include Shipit::Engine.routes.url_helpers
diff --git a/app/controllers/shipit/merge_requests_controller.rb b/app/controllers/shipit/merge_requests_controller.rb
index c0ff7801f..a6a3f8f15 100644
--- a/app/controllers/shipit/merge_requests_controller.rb
+++ b/app/controllers/shipit/merge_requests_controller.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class MergeRequestsController < ShipitController
def index
diff --git a/app/controllers/shipit/merge_status_controller.rb b/app/controllers/shipit/merge_status_controller.rb
index 9e07b15db..271f65f49 100644
--- a/app/controllers/shipit/merge_status_controller.rb
+++ b/app/controllers/shipit/merge_status_controller.rb
@@ -1,7 +1,8 @@
# frozen_string_literal: true
+
module Shipit
class MergeStatusController < ShipitController
- skip_authentication only: %i(check show)
+ skip_authentication only: %i[check show]
etag { cache_seed }
layout 'merge_status'
@@ -12,6 +13,7 @@ def show
if stack
return render('logged_out') unless current_user.logged_in?
+
if stale?(last_modified: [stack.updated_at, merge_request.updated_at].max, template: false)
render(stack_status, layout: !request.xhr?)
end
@@ -28,8 +30,8 @@ def enqueue
end
def dequeue
- if merge_request = stack.merge_requests.find_by_number(params[:number])
- merge_request.cancel! if merge_request.waiting?
+ if (merge_request = stack.merge_requests.find_by_number(params[:number])) && merge_request.waiting?
+ merge_request.cancel!
end
render(stack_status, layout: !request.xhr?)
end
@@ -43,7 +45,7 @@ def check
render(plain: stack_status, status: 503)
end
end
- format.json { render(json: { stack_status: stack_status }) }
+ format.json { render(json: { stack_status: }) }
end
end
@@ -59,23 +61,23 @@ def stack_status
def stack
@stack ||= if params[:stack_id]
- Stack.from_param!(params[:stack_id])
- else
- # Null ordering is inconsistent across DBMS's, this case statement is ugly but supported universally
- scope = Stack.order(Arel.sql('CASE WHEN locked_since IS NULL THEN 1 ELSE 0 END, locked_since'))
- .order(merge_queue_enabled: :desc, id: :asc).includes(:repository).where(
- repositories: {
- owner: referrer_parser.repo_owner,
- name: referrer_parser.repo_name,
- },
- )
- scope = if params[:branch]
- scope.where(branch: params[:branch])
- else
- scope.where(environment: 'production')
- end
- scope.first
- end
+ Stack.from_param!(params[:stack_id])
+ else
+ # Null ordering is inconsistent across DBMS's, this case statement is ugly but supported universally
+ scope = Stack.order(Arel.sql('CASE WHEN locked_since IS NULL THEN 1 ELSE 0 END, locked_since'))
+ .order(merge_queue_enabled: :desc, id: :asc).includes(:repository).where(
+ repositories: {
+ owner: referrer_parser.repo_owner,
+ name: referrer_parser.repo_name
+ }
+ )
+ scope = if params[:branch]
+ scope.where(branch: params[:branch])
+ else
+ scope.where(environment: 'production')
+ end
+ scope.first
+ end
end
def referrer_parser
@@ -84,12 +86,14 @@ def referrer_parser
def merge_request
return @merge_request if defined?(@merge_request)
+
@merge_request = pull_request_number && stack.merge_requests.find_by_number(pull_request_number)
@merge_request ||= UnknownMergeRequest.new
end
def pull_request_number
return @pull_request_number if defined?(@pull_request_number)
+
@pull_request_number = referrer_parser.pull_request_number
end
@@ -113,13 +117,13 @@ class ReferrerParser
attr_reader :repo_owner, :repo_name, :pull_request_number
def initialize(referrer)
- if (match_info = URL_PATTERN.match(referrer.to_s))
- @repo_owner = match_info[1].downcase
- @repo_name = match_info[2].downcase
- @pull_request_number = match_info[3].to_i
- else
+ unless (match_info = URL_PATTERN.match(referrer.to_s))
raise ArgumentError, "Invalid referrer: #{referrer.inspect}"
end
+
+ @repo_owner = match_info[1].downcase
+ @repo_name = match_info[2].downcase
+ @pull_request_number = match_info[3].to_i
end
end
diff --git a/app/controllers/shipit/release_statuses_controller.rb b/app/controllers/shipit/release_statuses_controller.rb
index ecf94f406..d84e119d1 100644
--- a/app/controllers/shipit/release_statuses_controller.rb
+++ b/app/controllers/shipit/release_statuses_controller.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class ReleaseStatusesController < ShipitController
before_action :load_stack
diff --git a/app/controllers/shipit/repositories_controller.rb b/app/controllers/shipit/repositories_controller.rb
index 3a01995b7..bb629e465 100644
--- a/app/controllers/shipit/repositories_controller.rb
+++ b/app/controllers/shipit/repositories_controller.rb
@@ -2,7 +2,7 @@
module Shipit
class RepositoriesController < ShipitController
- before_action :load_repository, only: %i(destroy settings update new_stack)
+ before_action :load_repository, only: %i[destroy settings update new_stack]
def index
@user_repositories = current_user.repositories_contributed_to
@@ -21,9 +21,7 @@ def show
def create
@repository = Repository.new(create_params)
- unless @repository.save
- flash[:warning] = @repository.errors.full_messages.to_sentence
- end
+ flash[:warning] = @repository.errors.full_messages.to_sentence unless @repository.save
respond_with(@repository)
end
@@ -45,8 +43,7 @@ def update
redirect_to(params[:return_to].presence || repository_settings_path(@repository), options)
end
- def settings
- end
+ def settings; end
def new_stack
@stack = @repository.stacks.new
@@ -63,7 +60,7 @@ def update_params
params.require(:repository).permit(
:review_stacks_enabled,
:provisioning_behavior,
- :provisioning_label_name,
+ :provisioning_label_name
)
end
diff --git a/app/controllers/shipit/rollbacks_controller.rb b/app/controllers/shipit/rollbacks_controller.rb
index 62b33df7d..e6b98b7b1 100644
--- a/app/controllers/shipit/rollbacks_controller.rb
+++ b/app/controllers/shipit/rollbacks_controller.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class RollbacksController < ShipitController
before_action :load_stack
@@ -8,7 +9,7 @@ def create
@rollback = @deploy.trigger_rollback(
current_user,
env: rollback_params[:env]&.to_unsafe_hash,
- force: params[:force].present?,
+ force: params[:force].present?
)
redirect_to(stack_deploy_path(@stack, @rollback))
rescue Task::ConcurrentTaskRunning
diff --git a/app/controllers/shipit/shipit_controller.rb b/app/controllers/shipit/shipit_controller.rb
index c80655123..88237ef53 100644
--- a/app/controllers/shipit/shipit_controller.rb
+++ b/app/controllers/shipit/shipit_controller.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class ShipitController < ApplicationController
layout 'shipit'
diff --git a/app/controllers/shipit/stacks_controller.rb b/app/controllers/shipit/stacks_controller.rb
index f2cc2ebcb..fcef6eed9 100644
--- a/app/controllers/shipit/stacks_controller.rb
+++ b/app/controllers/shipit/stacks_controller.rb
@@ -1,7 +1,8 @@
# frozen_string_literal: true
+
module Shipit
class StacksController < ShipitController
- before_action :load_stack, only: %i(update destroy settings statistics clear_git_cache refresh)
+ before_action :load_stack, only: %i[update destroy settings statistics clear_git_cache refresh]
def new
@stack = Stack.new
@@ -13,10 +14,10 @@ def index
@stacks = Stack.all
if params[:repo]
@stacks = if (repository = Repository.from_github_repo_name(params[:repo]))
- repository.stacks
- else
- Stack.none
- end
+ repository.stacks
+ else
+ Stack.none
+ end
end
@stacks = @stacks.order(Arel.sql('(undeployed_commits_count > 0) desc'), tasks_count: :desc)
@@ -37,7 +38,7 @@ def show
scope.preload(:author, :statuses, :check_runs, :lock_author)
end
- next_expected_commit_to_deploy = @stack.next_expected_commit_to_deploy(commits: commits)
+ next_expected_commit_to_deploy = @stack.next_expected_commit_to_deploy(commits:)
@active_commits = []
@undeployed_commits = []
@@ -48,11 +49,11 @@ def show
@active_commits = map_to_undeployed_commit(
@active_commits,
- next_expected_commit_to_deploy: next_expected_commit_to_deploy,
+ next_expected_commit_to_deploy:
)
@undeployed_commits = map_to_undeployed_commit(
@undeployed_commits,
- next_expected_commit_to_deploy: next_expected_commit_to_deploy,
+ next_expected_commit_to_deploy:
)
end
@@ -64,9 +65,7 @@ def lookup
def create
@stack = Stack.new(create_params)
@stack.repository = repository
- unless @stack.save
- flash[:warning] = @stack.errors.full_messages.to_sentence
- end
+ flash[:warning] = @stack.errors.full_messages.to_sentence unless @stack.save
respond_with(@stack)
end
@@ -75,8 +74,7 @@ def destroy
redirect_to(stacks_url)
end
- def settings
- end
+ def settings; end
def all_tasks
@stack = Stack.from_param!(params[:id])
@@ -103,9 +101,7 @@ def refresh
def update
options = {}
- unless @stack.update(update_params)
- options = { flash: { warning: @stack.errors.full_messages.to_sentence } }
- end
+ options = { flash: { warning: @stack.errors.full_messages.to_sentence } } unless @stack.update(update_params)
update_lock
update_archived
@@ -122,30 +118,30 @@ def clear_git_cache
private
def update_lock
- if params[:stack].key?(:lock_reason)
- reason = params[:stack][:lock_reason]
- if reason.present?
- @stack.lock(reason, current_user)
- elsif @stack.locked?
- @stack.unlock
- end
+ return unless params[:stack].key?(:lock_reason)
+
+ reason = params[:stack][:lock_reason]
+ if reason.present?
+ @stack.lock(reason, current_user)
+ elsif @stack.locked?
+ @stack.unlock
end
end
def update_archived
- if params[:stack][:archived].present?
- if params[:stack][:archived] == "true"
- @stack.archive!(current_user)
- elsif @stack.archived?
- @stack.unarchive!
- end
+ return unless params[:stack][:archived].present?
+
+ if params[:stack][:archived] == "true"
+ @stack.archive!(current_user)
+ elsif @stack.archived?
+ @stack.unarchive!
end
end
def map_to_undeployed_commit(commits, next_expected_commit_to_deploy:)
commits.map.with_index do |c, i|
index = commits.size - i - 1
- UndeployedCommit.new(c, index: index, next_expected_commit_to_deploy: next_expected_commit_to_deploy)
+ UndeployedCommit.new(c, index:, next_expected_commit_to_deploy:)
end
end
@@ -163,7 +159,7 @@ def update_params
:environment,
:continuous_deployment,
:ignore_ci,
- :merge_queue_enabled,
+ :merge_queue_enabled
)
end
diff --git a/app/controllers/shipit/status_controller.rb b/app/controllers/shipit/status_controller.rb
index a8b46dc1b..c626bdbd6 100644
--- a/app/controllers/shipit/status_controller.rb
+++ b/app/controllers/shipit/status_controller.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class StatusController < ActionController::Base
def version
diff --git a/app/controllers/shipit/tasks_controller.rb b/app/controllers/shipit/tasks_controller.rb
index 6a95d84b7..b440114c5 100644
--- a/app/controllers/shipit/tasks_controller.rb
+++ b/app/controllers/shipit/tasks_controller.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class TasksController < ShipitController
include Pagination
@@ -34,7 +35,7 @@ def create
params[:definition_id],
current_user,
env: task_params[:env],
- force: params[:force].present?,
+ force: params[:force].present?
)
redirect_to([stack, @task])
rescue Task::ConcurrentTaskRunning
@@ -75,6 +76,7 @@ def stack
def task_params
return {} unless params[:task]
+
@definition = stack.find_task_definition(params[:definition_id])
@task_params ||= params.require(:task).permit(env: @definition.variables.map(&:name))
end
diff --git a/app/controllers/shipit/webhooks_controller.rb b/app/controllers/shipit/webhooks_controller.rb
index eb2a152cb..cf5e92fd0 100644
--- a/app/controllers/shipit/webhooks_controller.rb
+++ b/app/controllers/shipit/webhooks_controller.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class WebhooksController < ActionController::Base
skip_before_action :verify_authenticity_token, raise: false
@@ -33,7 +34,7 @@ def verify_signature
"event=#{event}",
"repository_owner=#{repository_owner}",
"signature=#{request.headers['X-Hub-Signature']}",
- "status=#{status}",
+ "status=#{status}"
].join(' '))
end
diff --git a/app/helpers/shipit/api_clients_helper.rb b/app/helpers/shipit/api_clients_helper.rb
index 1b55fc169..d0e0a94ae 100644
--- a/app/helpers/shipit/api_clients_helper.rb
+++ b/app/helpers/shipit/api_clients_helper.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
module ApiClientsHelper
def api_client_token(api_client)
diff --git a/app/helpers/shipit/chunks_helper.rb b/app/helpers/shipit/chunks_helper.rb
index a37f1db31..61ba3d240 100644
--- a/app/helpers/shipit/chunks_helper.rb
+++ b/app/helpers/shipit/chunks_helper.rb
@@ -1,9 +1,11 @@
# frozen_string_literal: true
+
module Shipit
module ChunksHelper
def next_chunks_url(task, last_byte: 0)
return if task.finished?
- tail_stack_task_path(task.stack, task, last_byte: last_byte)
+
+ tail_stack_task_path(task.stack, task, last_byte:)
end
end
end
diff --git a/app/helpers/shipit/deploys_helper.rb b/app/helpers/shipit/deploys_helper.rb
index 8a525c72a..c9fb6aa47 100644
--- a/app/helpers/shipit/deploys_helper.rb
+++ b/app/helpers/shipit/deploys_helper.rb
@@ -1,19 +1,23 @@
# frozen_string_literal: true
+
module Shipit
module DeploysHelper
def render_checklist(checklist)
return if checklist.blank?
- render('shipit/deploys/checklist', checklist: checklist)
+
+ render('shipit/deploys/checklist', checklist:)
end
def render_monitoring(stack)
return unless stack.monitoring?
- render('shipit/deploys/monitoring', stack: stack)
+
+ render('shipit/deploys/monitoring', stack:)
end
def render_checks(commit)
return unless commit.stack.checks?
- render('shipit/commit_checks/checks', commit: commit)
+
+ render('shipit/commit_checks/checks', commit:)
end
def render_monitoring_panel(panel_spec)
diff --git a/app/helpers/shipit/github_url_helper.rb b/app/helpers/shipit/github_url_helper.rb
index 9dadcbd77..ae8862aa9 100644
--- a/app/helpers/shipit/github_url_helper.rb
+++ b/app/helpers/shipit/github_url_helper.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
module GithubUrlHelper
private
@@ -44,10 +45,10 @@ def github_commit_url(commit)
def github_pull_request_url(pull_request_or_commit)
stack = pull_request_or_commit.stack
number = if pull_request_or_commit.respond_to?(:pull_request_number)
- pull_request_or_commit.pull_request_number
- else
- pull_request_or_commit.number
- end
+ pull_request_or_commit.pull_request_number
+ else
+ pull_request_or_commit.number
+ end
github_repo_url(stack.repo_owner, stack.repo_name, 'pull', number)
end
diff --git a/app/helpers/shipit/merge_status_helper.rb b/app/helpers/shipit/merge_status_helper.rb
index c55f0f19a..1830d30dc 100644
--- a/app/helpers/shipit/merge_status_helper.rb
+++ b/app/helpers/shipit/merge_status_helper.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
module MergeStatusHelper
def display_commit_count_warning?(commits)
diff --git a/app/helpers/shipit/shipit_helper.rb b/app/helpers/shipit/shipit_helper.rb
index 03df4bd0e..06245ec87 100644
--- a/app/helpers/shipit/shipit_helper.rb
+++ b/app/helpers/shipit/shipit_helper.rb
@@ -1,20 +1,22 @@
# frozen_string_literal: true
+
module Shipit
module ShipitHelper
def subscribe(url, *selectors)
content_for(:update_subscription) do
[
tag('meta', name: 'subscription-channel', content: url),
- *selectors.map { |s| tag('meta', name: 'subscription-selector', content: s) },
+ *selectors.map { |s| tag('meta', name: 'subscription-selector', content: s) }
].join("\n").html_safe
end
end
def emojify(content)
- if content.present?
- h(content).to_str.gsub(/:([\w+-]+):/) do |match|
- if emoji = Emoji.find_by_alias($1)
- %(
+ return unless content.present?
+
+ h(content).to_str.gsub(/:([\w+-]+):/) do |match|
+ if emoji = Emoji.find_by_alias($1)
+ %(
)
- else
- match
- end
- end.html_safe
- end
+ else
+ match
+ end
+ end.html_safe
end
def include_plugins(stack)
diff --git a/app/helpers/shipit/stacks_helper.rb b/app/helpers/shipit/stacks_helper.rb
index a44c6bb0e..73877cea1 100644
--- a/app/helpers/shipit/stacks_helper.rb
+++ b/app/helpers/shipit/stacks_helper.rb
@@ -1,10 +1,11 @@
# frozen_string_literal: true
+
module Shipit
module StacksHelper
def redeploy_button(deployed_commit)
commit = UndeployedCommit.new(deployed_commit, index: 0)
url = new_stack_deploy_path(commit.stack, sha: commit.sha)
- classes = %W(btn btn--primary deploy-action #{commit.state})
+ classes = %W[btn btn--primary deploy-action #{commit.state}]
unless commit.stack.deployable?
classes.push(bypass_safeties? ? 'btn--warning' : 'btn--disabled')
@@ -19,21 +20,19 @@ def bypass_safeties?
def deploy_button(commit)
url = new_stack_deploy_path(commit.stack, sha: commit.sha)
- classes = %W(btn btn--primary deploy-action #{commit.state})
+ classes = %W[btn btn--primary deploy-action #{commit.state}]
deploy_state = commit.deploy_state(bypass_safeties?)
data = {}
if commit.deploy_disallowed?
classes.push(bypass_safeties? ? 'btn--warning' : 'btn--disabled')
- if deploy_state == 'blocked'
- data[:tooltip] = t('deploy_button.hint.blocked')
- end
+ data[:tooltip] = t('deploy_button.hint.blocked') if deploy_state == 'blocked'
elsif commit.deploy_discouraged?
classes.push('btn--warning')
data[:tooltip] = t('deploy_button.hint.max_commits', maximum: commit.stack.maximum_commits_per_deploy)
end
- link_to(t("deploy_button.caption.#{deploy_state}"), url, class: classes, data: data)
+ link_to(t("deploy_button.caption.#{deploy_state}"), url, class: classes, data:)
end
def rollback_button(deploy)
@@ -41,7 +40,7 @@ def rollback_button(deploy)
link_to('Deploy in progress...', '#', class: 'btn disabled deploy-action')
else
url = rollback_stack_deploy_path(deploy.stack, deploy)
- classes = %w(btn btn--delete deploy-action rollback-action)
+ classes = %w[btn btn--delete deploy-action rollback-action]
link_to('Rollback to this deploy...', url, class: classes)
end
@@ -80,10 +79,10 @@ def render_commit_id_link(commit)
def pull_request_link(pull_request_or_commit)
number = if pull_request_or_commit.respond_to?(:pull_request_number)
- pull_request_or_commit.pull_request_number
- else
- pull_request_or_commit.number
- end
+ pull_request_or_commit.pull_request_number
+ else
+ pull_request_or_commit.number
+ end
link_to("##{number}", github_pull_request_url(pull_request_or_commit), target: '_blank', class: 'number')
end
diff --git a/app/helpers/shipit/tasks_helper.rb b/app/helpers/shipit/tasks_helper.rb
index 358a4abcb..06ac850ab 100644
--- a/app/helpers/shipit/tasks_helper.rb
+++ b/app/helpers/shipit/tasks_helper.rb
@@ -1,8 +1,9 @@
# frozen_string_literal: true
+
module Shipit
module TasksHelper
def task_description(task)
- if task.class == Task
+ if task.instance_of?(Task)
task.definition.action
else
t("#{task.class.name.demodulize.underscore.pluralize}.description", sha: task.until_commit.short_sha)
diff --git a/app/jobs/shipit/background_job.rb b/app/jobs/shipit/background_job.rb
index 0426792c5..cef3c3cff 100644
--- a/app/jobs/shipit/background_job.rb
+++ b/app/jobs/shipit/background_job.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class BackgroundJob < ActiveJob::Base
class << self
@@ -24,6 +25,7 @@ def perform(*)
def with_timeout(&block)
return yield unless timeout
+
Timeout.timeout(timeout, &block)
end
diff --git a/app/jobs/shipit/background_job/unique.rb b/app/jobs/shipit/background_job/unique.rb
index 3d334cda8..6d9215ca4 100644
--- a/app/jobs/shipit/background_job/unique.rb
+++ b/app/jobs/shipit/background_job/unique.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class BackgroundJob
module Unique
@@ -18,7 +19,7 @@ def acquire_lock(&block)
lock_key(*arguments),
Shipit.redis,
expiration: self.class.timeout || DEFAULT_TIMEOUT,
- timeout: self.class.lock_timeout || 0,
+ timeout: self.class.lock_timeout || 0
)
mutex.lock(&block)
rescue Redis::Lock::LockTimeout
@@ -30,7 +31,7 @@ def lock_key(*args)
end
module ClassMethods
- ACTIONS = %i(retry drop).freeze
+ ACTIONS = %i[retry drop].freeze
ACTIONS_LIST = ACTIONS.map(&:inspect).join(', ').freeze
def on_duplicate(action)
unless ACTIONS.include?(action)
diff --git a/app/jobs/shipit/cache_deploy_spec_job.rb b/app/jobs/shipit/cache_deploy_spec_job.rb
index d239d00b5..8c97631d8 100644
--- a/app/jobs/shipit/cache_deploy_spec_job.rb
+++ b/app/jobs/shipit/cache_deploy_spec_job.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class CacheDeploySpecJob < BackgroundJob
include BackgroundJob::Unique
diff --git a/app/jobs/shipit/chunk_rollup_job.rb b/app/jobs/shipit/chunk_rollup_job.rb
index 5bfe6500b..2aec61ea4 100644
--- a/app/jobs/shipit/chunk_rollup_job.rb
+++ b/app/jobs/shipit/chunk_rollup_job.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class ChunkRollupJob < BackgroundJob
include BackgroundJob::Unique
diff --git a/app/jobs/shipit/clear_git_cache_job.rb b/app/jobs/shipit/clear_git_cache_job.rb
index e3ea4e2c2..dd5aeeae0 100644
--- a/app/jobs/shipit/clear_git_cache_job.rb
+++ b/app/jobs/shipit/clear_git_cache_job.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class ClearGitCacheJob < BackgroundJob
queue_as :deploys
diff --git a/app/jobs/shipit/continuous_delivery_job.rb b/app/jobs/shipit/continuous_delivery_job.rb
index e9f2af982..1aecb909d 100644
--- a/app/jobs/shipit/continuous_delivery_job.rb
+++ b/app/jobs/shipit/continuous_delivery_job.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class ContinuousDeliveryJob < BackgroundJob
include BackgroundJob::Unique
@@ -11,9 +12,7 @@ def perform(stack)
# If there is a schedule defined for this stack, make sure we are within a
# deployment window before proceeding.
- if stack.continuous_delivery_schedule
- return unless stack.continuous_delivery_schedule.can_deploy?
- end
+ return if stack.continuous_delivery_schedule && !stack.continuous_delivery_schedule.can_deploy?
# checks if there are any tasks running, including concurrent tasks
return if stack.occupied?
diff --git a/app/jobs/shipit/create_on_github_job.rb b/app/jobs/shipit/create_on_github_job.rb
index 6f6b74f40..2d75616e6 100644
--- a/app/jobs/shipit/create_on_github_job.rb
+++ b/app/jobs/shipit/create_on_github_job.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class CreateOnGithubJob < BackgroundJob
include BackgroundJob::Unique
diff --git a/app/jobs/shipit/create_release_statuses_job.rb b/app/jobs/shipit/create_release_statuses_job.rb
index d632eb4ef..7c0bd3c7e 100644
--- a/app/jobs/shipit/create_release_statuses_job.rb
+++ b/app/jobs/shipit/create_release_statuses_job.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class CreateReleaseStatusesJob < BackgroundJob
include BackgroundJob::Unique
diff --git a/app/jobs/shipit/deferred_touch_job.rb b/app/jobs/shipit/deferred_touch_job.rb
index e36bafa50..fe3db9889 100644
--- a/app/jobs/shipit/deferred_touch_job.rb
+++ b/app/jobs/shipit/deferred_touch_job.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class DeferredTouchJob < BackgroundJob
include BackgroundJob::Unique
diff --git a/app/jobs/shipit/deliver_hook_job.rb b/app/jobs/shipit/deliver_hook_job.rb
index 4f6bfe974..c4a52dc4e 100644
--- a/app/jobs/shipit/deliver_hook_job.rb
+++ b/app/jobs/shipit/deliver_hook_job.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class DeliverHookJob < BackgroundJob
queue_as :hooks
diff --git a/app/jobs/shipit/destroy_job.rb b/app/jobs/shipit/destroy_job.rb
index 43d8e2020..6d0d997aa 100644
--- a/app/jobs/shipit/destroy_job.rb
+++ b/app/jobs/shipit/destroy_job.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class DestroyJob < BackgroundJob
queue_as :default
diff --git a/app/jobs/shipit/destroy_repository_job.rb b/app/jobs/shipit/destroy_repository_job.rb
index 07aea7fc5..ef5cacb6a 100644
--- a/app/jobs/shipit/destroy_repository_job.rb
+++ b/app/jobs/shipit/destroy_repository_job.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class DestroyRepositoryJob < BackgroundJob
queue_as :default
diff --git a/app/jobs/shipit/destroy_stack_job.rb b/app/jobs/shipit/destroy_stack_job.rb
index 23c137b60..df4e39cc1 100644
--- a/app/jobs/shipit/destroy_stack_job.rb
+++ b/app/jobs/shipit/destroy_stack_job.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class DestroyStackJob < BackgroundJob
queue_as :default
diff --git a/app/jobs/shipit/emit_event_job.rb b/app/jobs/shipit/emit_event_job.rb
index 88e14615f..15c0b37f6 100644
--- a/app/jobs/shipit/emit_event_job.rb
+++ b/app/jobs/shipit/emit_event_job.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class EmitEventJob < BackgroundJob
queue_as :hooks
diff --git a/app/jobs/shipit/fetch_commit_stats_job.rb b/app/jobs/shipit/fetch_commit_stats_job.rb
index 868c18960..4970aa4f7 100644
--- a/app/jobs/shipit/fetch_commit_stats_job.rb
+++ b/app/jobs/shipit/fetch_commit_stats_job.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class FetchCommitStatsJob < BackgroundJob
queue_as :default
diff --git a/app/jobs/shipit/fetch_deployed_revision_job.rb b/app/jobs/shipit/fetch_deployed_revision_job.rb
index 072bb73be..0909e6bb6 100644
--- a/app/jobs/shipit/fetch_deployed_revision_job.rb
+++ b/app/jobs/shipit/fetch_deployed_revision_job.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class FetchDeployedRevisionJob < BackgroundJob
queue_as :deploys
diff --git a/app/jobs/shipit/github_sync_job.rb b/app/jobs/shipit/github_sync_job.rb
index 0cb6abd45..6dd7ecc5a 100644
--- a/app/jobs/shipit/github_sync_job.rb
+++ b/app/jobs/shipit/github_sync_job.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class GithubSyncJob < BackgroundJob
include BackgroundJob::Unique
@@ -36,13 +37,14 @@ def append_commit(gh_commit)
def fetch_missing_commits(&block)
commits = []
github_api = stack&.github_api
- iterator = Shipit::FirstParentCommitsIterator.new(github_api: github_api, &block)
+ iterator = Shipit::FirstParentCommitsIterator.new(github_api:, &block)
iterator.each_with_index do |commit, index|
break if index >= MAX_FETCHED_COMMITS
if shared_parent = lookup_commit(commit.sha)
return commits, shared_parent
end
+
commits.unshift(commit)
end
[commits, nil]
@@ -59,7 +61,7 @@ def handle_github_errors
end
def lookup_commit(sha)
- stack.commits.find_by(sha: sha)
+ stack.commits.find_by(sha:)
end
end
end
diff --git a/app/jobs/shipit/mark_deploy_healthy_job.rb b/app/jobs/shipit/mark_deploy_healthy_job.rb
index 6e2ac3e72..d483a5c3a 100644
--- a/app/jobs/shipit/mark_deploy_healthy_job.rb
+++ b/app/jobs/shipit/mark_deploy_healthy_job.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class MarkDeployHealthyJob < BackgroundJob
include BackgroundJob::Unique
diff --git a/app/jobs/shipit/perform_commit_checks_job.rb b/app/jobs/shipit/perform_commit_checks_job.rb
index 540819dbb..502989c15 100644
--- a/app/jobs/shipit/perform_commit_checks_job.rb
+++ b/app/jobs/shipit/perform_commit_checks_job.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class PerformCommitChecksJob < BackgroundJob
include BackgroundJob::Unique
diff --git a/app/jobs/shipit/perform_task_job.rb b/app/jobs/shipit/perform_task_job.rb
index 090c587f1..709d6ed27 100644
--- a/app/jobs/shipit/perform_task_job.rb
+++ b/app/jobs/shipit/perform_task_job.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class PerformTaskJob < BackgroundJob
queue_as :deploys
diff --git a/app/jobs/shipit/process_merge_requests_job.rb b/app/jobs/shipit/process_merge_requests_job.rb
index ba0009ca8..fb3864e22 100644
--- a/app/jobs/shipit/process_merge_requests_job.rb
+++ b/app/jobs/shipit/process_merge_requests_job.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class ProcessMergeRequestsJob < BackgroundJob
include BackgroundJob::Unique
@@ -20,6 +21,7 @@ def perform(stack)
merge_requests.select(&:pending?).each do |merge_request|
merge_request.refresh!
next unless merge_request.all_status_checks_passed?
+
begin
merge_request.merge!
rescue MergeRequest::NotReady
diff --git a/app/jobs/shipit/purge_old_deliveries_job.rb b/app/jobs/shipit/purge_old_deliveries_job.rb
index 6e7c1719e..93682ff53 100644
--- a/app/jobs/shipit/purge_old_deliveries_job.rb
+++ b/app/jobs/shipit/purge_old_deliveries_job.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class PurgeOldDeliveriesJob < BackgroundJob
include BackgroundJob::Unique
diff --git a/app/jobs/shipit/reap_dead_tasks_job.rb b/app/jobs/shipit/reap_dead_tasks_job.rb
index 648314e0a..f15b6d2b0 100644
--- a/app/jobs/shipit/reap_dead_tasks_job.rb
+++ b/app/jobs/shipit/reap_dead_tasks_job.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class ReapDeadTasksJob < BackgroundJob
include BackgroundJob::Unique
diff --git a/app/jobs/shipit/refresh_check_runs_job.rb b/app/jobs/shipit/refresh_check_runs_job.rb
index 885783112..f34580c0f 100644
--- a/app/jobs/shipit/refresh_check_runs_job.rb
+++ b/app/jobs/shipit/refresh_check_runs_job.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class RefreshCheckRunsJob < BackgroundJob
queue_as :default
diff --git a/app/jobs/shipit/refresh_github_user_job.rb b/app/jobs/shipit/refresh_github_user_job.rb
index 4f817e6a5..c88b367b1 100644
--- a/app/jobs/shipit/refresh_github_user_job.rb
+++ b/app/jobs/shipit/refresh_github_user_job.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class RefreshGithubUserJob < BackgroundJob
queue_as :default
diff --git a/app/jobs/shipit/refresh_merge_request_job.rb b/app/jobs/shipit/refresh_merge_request_job.rb
index ef5ee3951..94d3939e7 100644
--- a/app/jobs/shipit/refresh_merge_request_job.rb
+++ b/app/jobs/shipit/refresh_merge_request_job.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class RefreshMergeRequestJob < BackgroundJob
queue_as :default
diff --git a/app/jobs/shipit/refresh_statuses_job.rb b/app/jobs/shipit/refresh_statuses_job.rb
index 0a94b5733..0cb439ac3 100644
--- a/app/jobs/shipit/refresh_statuses_job.rb
+++ b/app/jobs/shipit/refresh_statuses_job.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class RefreshStatusesJob < BackgroundJob
queue_as :default
diff --git a/app/jobs/shipit/setup_github_hook_job.rb b/app/jobs/shipit/setup_github_hook_job.rb
index e4accd56a..c6f34cb14 100644
--- a/app/jobs/shipit/setup_github_hook_job.rb
+++ b/app/jobs/shipit/setup_github_hook_job.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class SetupGithubHookJob < BackgroundJob
queue_as :default
diff --git a/app/jobs/shipit/update_estimated_deploy_duration_job.rb b/app/jobs/shipit/update_estimated_deploy_duration_job.rb
index 6d4fe2951..04845df19 100644
--- a/app/jobs/shipit/update_estimated_deploy_duration_job.rb
+++ b/app/jobs/shipit/update_estimated_deploy_duration_job.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class UpdateEstimatedDeployDurationJob < BackgroundJob
queue_as :default
diff --git a/app/jobs/shipit/update_github_last_deployed_ref_job.rb b/app/jobs/shipit/update_github_last_deployed_ref_job.rb
index 66a601694..f82cf9ee0 100644
--- a/app/jobs/shipit/update_github_last_deployed_ref_job.rb
+++ b/app/jobs/shipit/update_github_last_deployed_ref_job.rb
@@ -1,11 +1,12 @@
# frozen_string_literal: true
+
module Shipit
class UpdateGithubLastDeployedRefJob < BackgroundJob
queue_as :default
# We do not prefix 'refs/' because Octokit methods will do this automatically.
BRANCH_REF_PREFIX = 'heads'
- DEPLOY_PREFIX = "#{Shipit.app_name.downcase}-deploy"
+ DEPLOY_PREFIX = "#{Shipit.app_name.downcase}-deploy".freeze
def perform(stack)
stack_sha = stack.last_successful_deploy_commit&.sha
@@ -17,7 +18,7 @@ def perform(stack)
full_repo_name = stack.github_repo_name
- update_or_create_ref(client: client, repo_name: full_repo_name, ref: stack_ref, new_sha: stack_sha)
+ update_or_create_ref(client:, repo_name: full_repo_name, ref: stack_ref, new_sha: stack_sha)
end
private
@@ -34,11 +35,9 @@ def update_or_create_ref(client:, repo_name:, ref:, new_sha:)
client.update_ref(repo_name, ref, new_sha)
rescue Octokit::UnprocessableEntity => e
error_msg = e.message
- if error_msg.include?("Reference does not exist")
- create_ref(client: client, repo_name: repo_name, ref: ref, sha: new_sha)
- else
- raise
- end
+ raise unless error_msg.include?("Reference does not exist")
+
+ create_ref(client:, repo_name:, ref:, sha: new_sha)
end
end
end
diff --git a/app/models/concerns/shipit/deferred_touch.rb b/app/models/concerns/shipit/deferred_touch.rb
index 2117a5f74..64925f510 100644
--- a/app/models/concerns/shipit/deferred_touch.rb
+++ b/app/models/concerns/shipit/deferred_touch.rb
@@ -1,11 +1,12 @@
# frozen_string_literal: true
+
module Shipit
module DeferredTouch
extend ActiveSupport::Concern
SET_KEY = 'shipit:deferred_touches'
- TMP_KEY = "#{SET_KEY}:updating"
- CACHE_KEY = "#{SET_KEY}:scheduled"
+ TMP_KEY = "#{SET_KEY}:updating".freeze
+ CACHE_KEY = "#{SET_KEY}:scheduled".freeze
THROTTLE_TTL = 1.second
included do
@@ -39,6 +40,7 @@ def touch_now!
def fetch
fetch_members do |records|
return if records.empty?
+
records = records.each_with_object({}) do |(model, id, attribute), hash|
attributes = (hash[model] ||= {})
ids = (attributes[attribute] ||= [])
@@ -78,6 +80,7 @@ def deferred_touch(touches)
def schedule_touches
return unless self.class.deferred_touches
+
deferred_touches = self.class.deferred_touches.reject do |m, _fk, _a|
ActiveRecord::NoTouching.applied_to?(m.constantize)
end
diff --git a/app/models/shipit/anonymous_user.rb b/app/models/shipit/anonymous_user.rb
index c6c9d206e..f6c959427 100644
--- a/app/models/shipit/anonymous_user.rb
+++ b/app/models/shipit/anonymous_user.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class AnonymousUser
def blank?
@@ -21,11 +22,9 @@ def avatar_url
'https://github.com/images/error/octocat_happy.gif'
end
- def id
- end
+ def id; end
- def github_id
- end
+ def github_id; end
def logged_in?
false
@@ -54,7 +53,7 @@ def avatar_uri
def created_at
Time.at(0).utc
end
- alias_method :updated_at, :created_at
+ alias updated_at created_at
def read_attribute_for_serialization(attr)
public_send(attr)
diff --git a/app/models/shipit/api_client.rb b/app/models/shipit/api_client.rb
index 18f5b73c7..27ff3b29b 100644
--- a/app/models/shipit/api_client.rb
+++ b/app/models/shipit/api_client.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class ApiClient < Record
InsufficientPermission = Class.new(StandardError)
@@ -9,14 +10,14 @@ class ApiClient < Record
validates :creator, :name, presence: true
serialize :permissions, coder: Shipit.serialized_column(:permissions, type: Array)
- PERMISSIONS = %w(
+ PERMISSIONS = %w[
read:stack
write:stack
deploy:stack
lock:stack
read:hook
write:hook
- ).freeze
+ ].freeze
validates :permissions, subset: { of: PERMISSIONS }
class << self
@@ -39,6 +40,7 @@ def check_permissions!(operation, scope)
unless permissions.include?(required_permission)
raise InsufficientPermission, "This operation requires the `#{required_permission}` permission"
end
+
true
end
end
diff --git a/app/models/shipit/application_record.rb b/app/models/shipit/application_record.rb
index 3e8a6ee54..5198356ea 100644
--- a/app/models/shipit/application_record.rb
+++ b/app/models/shipit/application_record.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class ApplicationRecord < Record
self.abstract_class = true
diff --git a/app/models/shipit/check_run.rb b/app/models/shipit/check_run.rb
index d0b27d926..c2b91db75 100644
--- a/app/models/shipit/check_run.rb
+++ b/app/models/shipit/check_run.rb
@@ -1,7 +1,8 @@
# frozen_string_literal: true
+
module Shipit
class CheckRun < ApplicationRecord
- CONCLUSIONS = %w(success failure neutral cancelled timed_out action_required stale skipped).freeze
+ CONCLUSIONS = %w[success failure neutral cancelled timed_out action_required stale skipped].freeze
include DeferredTouch
include Status::Common
@@ -41,23 +42,23 @@ def create_or_update_from_github!(stack_id, github_check_run)
unless checkrun_date
Rails.logger.warn("No valid timestamp found in checkrun data. Checkrun id: #{github_check_run.id}.")
- RefreshCheckRunsJob.set(wait: CHECK_RUN_REFRESH_DELAY).perform_later(stack_id: stack_id)
+ RefreshCheckRunsJob.set(wait: CHECK_RUN_REFRESH_DELAY).perform_later(stack_id:)
return
end
create_or_update_by!(
selector: {
- github_id: github_check_run.id,
+ github_id: github_check_run.id
},
attributes: {
- stack_id: stack_id,
+ stack_id:,
name: github_check_run.name,
conclusion: github_check_run.conclusion,
title: github_check_run.output.title.to_s.truncate(1_000),
details_url: github_check_run.details_url,
html_url: github_check_run.html_url,
- github_updated_at: checkrun_date,
- },
+ github_updated_at: checkrun_date
+ }
)
end
diff --git a/app/models/shipit/command_line_user.rb b/app/models/shipit/command_line_user.rb
index 9cac72196..abc73b7b8 100644
--- a/app/models/shipit/command_line_user.rb
+++ b/app/models/shipit/command_line_user.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class CommandLineUser
def present?
@@ -21,11 +22,9 @@ def avatar_url
'https://github.com/images/error/octocat_happy.gif'
end
- def id
- end
+ def id; end
- def github_id
- end
+ def github_id; end
def logged_in?
false
@@ -50,7 +49,7 @@ def avatar_uri
def created_at
Time.at(0).utc
end
- alias_method :updated_at, :created_at
+ alias updated_at created_at
def read_attribute_for_serialization(attr)
public_send(attr)
diff --git a/app/models/shipit/commit.rb b/app/models/shipit/commit.rb
index 9e152b2ed..554202e9b 100644
--- a/app/models/shipit/commit.rb
+++ b/app/models/shipit/commit.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class Commit < Record
include DeferredTouch
@@ -21,7 +22,7 @@ class Commit < Record
after_create { stack.update_undeployed_commits_count }
after_commit :schedule_refresh_statuses!, :schedule_refresh_check_runs!, :schedule_fetch_stats!,
- :schedule_continuous_delivery, on: :create
+ :schedule_continuous_delivery, on: :create
belongs_to :author, class_name: 'User', optional: true, inverse_of: :authored_commits
belongs_to :committer, class_name: 'User', optional: true, inverse_of: :commits
@@ -54,25 +55,29 @@ def lock_author=(user)
scope :reachable, -> { where(detached: false) }
delegate :broadcast_update, :github_repo_name, :hidden_statuses, :required_statuses, :blocking_statuses,
- :soft_failing_statuses, to: :stack
+ :soft_failing_statuses, to: :stack
def self.newer_than(commit)
return all unless commit
+
where('id > ?', commit.try(:id) || commit)
end
def self.older_than(commit)
return all unless commit
+
where('id < ?', commit.try(:id) || commit)
end
def self.since(commit)
return all unless commit
+
where('id >= ?', commit.try(:id) || commit)
end
def self.until(commit)
return all unless commit
+
where('id <= ?', commit.try(:id) || commit)
end
@@ -85,12 +90,11 @@ def self.detach!
end
def self.by_sha(sha)
- if sha.to_s.size < 6
- raise AmbiguousRevision, "Short SHA1 #{sha} is ambiguous (too short)"
- end
+ raise AmbiguousRevision, "Short SHA1 #{sha} is ambiguous (too short)" if sha.to_s.size < 6
commits = where('sha like ?', "#{sha}%").take(2)
raise AmbiguousRevision, "Short SHA1 #{sha} is ambiguous (matches multiple commits)" if commits.size > 1
+
commits.first
end
@@ -107,26 +111,22 @@ def self.from_github(commit)
record = new(
sha: commit.sha,
message: commit.commit.message,
- author: author,
- committer: committer,
+ author:,
+ committer:,
committed_at: commit.commit.committer.date,
authored_at: commit.commit.author.date,
additions: commit.stats&.additions,
- deletions: commit.stats&.deletions,
+ deletions: commit.stats&.deletions
)
- if record.pull_request?
- record.pull_request_head_sha = commit.parents.last.sha
- end
+ record.pull_request_head_sha = commit.parents.last.sha if record.pull_request?
record
end
def message=(message)
limit = self.class.columns_hash['message'].limit
- if limit && message && message.bytesize > limit
- message = message.truncate_bytes(limit)
- end
+ message = message.truncate_bytes(limit) if limit && message && message.bytesize > limit
super(message)
end
@@ -206,11 +206,11 @@ def create_release_status!(state, user: nil, target_url: nil, description: nil)
@last_release_status = nil
release_statuses.create!(
- stack: stack,
- user: user,
- state: state,
- target_url: target_url,
- description: description,
+ stack:,
+ user:,
+ state:,
+ target_url:,
+ description:
)
end
@@ -239,7 +239,7 @@ def blocked?
end
def children
- self.class.where(stack_id: stack_id).newer_than(self)
+ self.class.where(stack_id:).newer_than(self)
end
def detach_children!
@@ -282,6 +282,7 @@ def short_sha
def schedule_continuous_delivery
return unless deployable? && stack.continuous_deployment? && stack.deployable?
+
# This buffer is to allow for statuses and checks to be refreshed before evaluating if the commit is deployable
# - e.g. if the commit was fast-forwarded with already passing CI.
ContinuousDeliveryJob.set(wait: RECENT_COMMIT_THRESHOLD).perform_later(stack)
@@ -298,7 +299,7 @@ def schedule_fetch_stats!
def fetch_stats!
update!(
additions: github_commit.stats&.additions,
- deletions: github_commit.stats&.deletions,
+ deletions: github_commit.stats&.deletions
)
end
@@ -316,6 +317,7 @@ def deploy_failed?
def identify_merge_request
return unless message_parser.pull_request?
+
if merge_request = stack.merge_requests.find_by(number: message_parser.pull_request_number)
self.merge_request = merge_request
self.pull_request_number = merge_request.number
@@ -338,14 +340,14 @@ def deploy_requested_at
def lock(user)
update!(
locked: true,
- lock_author_id: user.id,
+ lock_author_id: user.id
)
end
def self.lock_all(user)
update_all(
locked: true,
- lock_author_id: user.id,
+ lock_author_id: user.id
)
end
@@ -372,19 +374,15 @@ def add_status
new_status = status
unless already_deployed
- payload = { commit: self, stack: stack, status: new_status.state }
- if previous_status != new_status
- Hook.emit(:commit_status, stack, payload.merge(commit_status: new_status))
- end
+ payload = { commit: self, stack:, status: new_status.state }
+ Hook.emit(:commit_status, stack, payload.merge(commit_status: new_status)) if previous_status != new_status
end
if previous_status.simple_state != new_status.simple_state
if !already_deployed && (!new_status.pending? || previous_status.unknown?)
Hook.emit(:deployable_status, stack, payload.merge(deployable_status: new_status))
end
- if new_status.pending? || new_status.success?
- stack.schedule_merges
- end
+ stack.schedule_merges if new_status.pending? || new_status.success?
end
new_status
end
diff --git a/app/models/shipit/commit_checks.rb b/app/models/shipit/commit_checks.rb
index 70eeba8a1..0c63ec9a8 100644
--- a/app/models/shipit/commit_checks.rb
+++ b/app/models/shipit/commit_checks.rb
@@ -1,8 +1,9 @@
# frozen_string_literal: true
+
module Shipit
class CommitChecks < EphemeralCommitChecks
OUTPUT_TTL = 10.minutes.to_i
- FINAL_STATUSES = %w(failed error success).freeze
+ FINAL_STATUSES = %w[failed error success].freeze
def initialize(commit)
@commit = commit
@@ -16,12 +17,13 @@ def synchronize(&block)
def schedule
return false if Shipit.redis.get(key('status')).present?
+
synchronize do
return false if Shipit.redis.get(key('status')).present?
initialize_redis_state
end
- PerformCommitChecksJob.perform_later(commit: commit)
+ PerformCommitChecksJob.perform_later(commit:)
true
end
diff --git a/app/models/shipit/commit_deployment.rb b/app/models/shipit/commit_deployment.rb
index 08bc30542..19d40803f 100644
--- a/app/models/shipit/commit_deployment.rb
+++ b/app/models/shipit/commit_deployment.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class CommitDeployment < Record
belongs_to :task
@@ -11,8 +12,8 @@ class CommitDeployment < Record
def create_on_github!
create_deployment_on_github!
statuses.order(id: :asc).each(&:create_on_github!)
- rescue Octokit::NotFound, Octokit::Forbidden => error
- Rails.logger.warn("Got #{error.class.name} creating deployment or statuses: #{error.message}")
+ rescue Octokit::NotFound, Octokit::Forbidden => e
+ Rails.logger.warn("Got #{e.class.name} creating deployment or statuses: #{e.message}")
# If no one can create the deployment we can only give up
end
@@ -23,6 +24,7 @@ def create_deployment_on_github!
create_deployment_on_github(stack.github_api)
rescue Octokit::ClientError
raise if Shipit.github(organization: stack.repository.owner).api == stack.github_api
+
# If the deploy author didn't gave us the permission to create the deployment we falback the the main shipit
# user.
#
@@ -55,9 +57,9 @@ def create_deployment_on_github(client)
shipit: {
task_id: task.id,
from_sha: task.since_commit.sha,
- to_sha: task.until_commit.sha,
- },
- }.to_json,
+ to_sha: task.until_commit.sha
+ }
+ }.to_json
)
end
end
diff --git a/app/models/shipit/commit_deployment_status.rb b/app/models/shipit/commit_deployment_status.rb
index 6be2693f5..da3bdb60b 100644
--- a/app/models/shipit/commit_deployment_status.rb
+++ b/app/models/shipit/commit_deployment_status.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class CommitDeploymentStatus < Record
DESCRIPTION_CHARACTER_LIMIT_ON_GITHUB = 140
@@ -11,10 +12,12 @@ class CommitDeploymentStatus < Record
def create_on_github!
return if github_id?
+
response = begin
create_status_on_github(stack.github_api)
rescue Octokit::ClientError
raise if Shipit.github(organization: stack.repository.owner).api == stack.github_api
+
# If the deploy author didn't gave us the permission to create the deployment we falback the the main shipit
# user.
#
@@ -30,7 +33,7 @@ def description
"deployment_description.#{task_type}.#{status}",
sha: task.until_commit.short_sha,
author: task.author.login,
- stack: stack.to_param,
+ stack: stack.to_param
)
end
@@ -50,7 +53,7 @@ def create_status_on_github(client)
status,
target_url: url_helpers.stack_deploy_url(stack, task),
description: description.truncate(DESCRIPTION_CHARACTER_LIMIT_ON_GITHUB),
- environment_url: stack.deploy_url,
+ environment_url: stack.deploy_url
)
end
diff --git a/app/models/shipit/commit_message.rb b/app/models/shipit/commit_message.rb
index 337b053be..fb00022cd 100644
--- a/app/models/shipit/commit_message.rb
+++ b/app/models/shipit/commit_message.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class CommitMessage
GITHUB_MERGE_COMMIT_PATTERN = /\AMerge pull request #(?\d+) from \S+\n\n(?.*)/
@@ -27,6 +28,7 @@ def to_s
def parsed
return @parsed if defined?(@parsed)
+
@parsed = to_s.match(GITHUB_MERGE_COMMIT_PATTERN)
end
end
diff --git a/app/models/shipit/continuous_delivery_schedule.rb b/app/models/shipit/continuous_delivery_schedule.rb
index 52e700ea9..2ee9a1cb0 100644
--- a/app/models/shipit/continuous_delivery_schedule.rb
+++ b/app/models/shipit/continuous_delivery_schedule.rb
@@ -8,7 +8,7 @@ class ContinuousDeliverySchedule < Record
validates(
*DAYS.map { |day| "#{day}_enabled" },
- inclusion: [true, false],
+ inclusion: [true, false]
)
validates(
@@ -51,7 +51,7 @@ def get_deployment_window(date)
date.month,
date.day,
raw_time.hour,
- raw_time.min,
+ raw_time.min
)
end
@@ -61,7 +61,7 @@ def get_deployment_window(date)
# that a window configured to end at 17:59 actually ends at 17:59:59
# instead of 17:59:00.
ends_at.at_end_of_minute,
- enabled,
+ enabled
)
end
diff --git a/app/models/shipit/delivery.rb b/app/models/shipit/delivery.rb
index 61fd8f1bb..ef174a359 100644
--- a/app/models/shipit/delivery.rb
+++ b/app/models/shipit/delivery.rb
@@ -1,7 +1,8 @@
# frozen_string_literal: true
+
module Shipit
class Delivery < Record
- STATUSES = %w(pending scheduled sent).freeze
+ STATUSES = %w[pending scheduled sent].freeze
enum :status, STATUSES.zip(STATUSES).to_h
belongs_to :hook
@@ -47,7 +48,7 @@ def headers
'Content-Type' => content_type,
'X-Shipit-Event' => event,
'X-Shipit-Delivery' => id.to_s,
- 'Accept' => '*/*',
+ 'Accept' => '*/*'
}
end
end
diff --git a/app/models/shipit/deploy.rb b/app/models/shipit/deploy.rb
index 52c9bdf12..311a8041b 100644
--- a/app/models/shipit/deploy.rb
+++ b/app/models/shipit/deploy.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'fileutils'
module Shipit
@@ -26,7 +27,7 @@ class Deploy < Task
'success' => 'success',
'faulty' => 'error',
'error' => 'error',
- 'aborted' => 'error',
+ 'aborted' => 'error'
}.freeze
def append_status(task_status)
@@ -37,7 +38,7 @@ def append_status(task_status)
"Creating #{github_status} deploy status for deployment #{deployment.id}. "\
"Commit: #{deployment.sha}, Github id: #{deployment.github_id}, "\
"Repo: #{deployment.stack.repo_name}, Environment: #{deployment.stack.environment}, "\
- "API Url: #{deployment.api_url}.",
+ "API Url: #{deployment.api_url}."
)
deployment.statuses.create!(status: github_status)
end
@@ -47,7 +48,7 @@ def append_status(task_status)
"No GitHub status for task status #{task_status}. "\
"Commit: #{deployment.sha}, Github id: #{deployment.github_id}, "\
"Repo: #{deployment.stack.repo_name}, Environment: #{deployment.stack.environment}, "\
- "API Url: #{deployment.api_url}.",
+ "API Url: #{deployment.api_url}."
)
end
end
@@ -64,48 +65,52 @@ def append_status(task_status)
def self.newer_than(deploy)
return all unless deploy
+
where('id > ?', deploy.try(:id) || deploy)
end
def self.older_than(deploy)
return all unless deploy
+
where('id < ?', deploy.try(:id) || deploy)
end
def self.since(deploy)
return all unless deploy
+
where('id >= ?', deploy.try(:id) || deploy)
end
def self.until(deploy)
return all unless deploy
+
where('id <= ?', deploy.try(:id) || deploy)
end
def build_rollback(user = nil, env: nil, force: false)
Rollback.new(
user_id: user&.id,
- stack_id: stack_id,
+ stack_id:,
parent_id: id,
since_commit: stack.last_deployed_commit,
- until_commit: until_commit,
- env: env&.to_h || {},
+ until_commit:,
+ env: env.to_h,
allow_concurrency: force,
ignored_safeties: force,
- max_retries: stack.retries_on_rollback,
+ max_retries: stack.retries_on_rollback
)
end
# Rolls the stack back to this deploy
def trigger_rollback(user = AnonymousUser.new, env: nil, force: false, lock: true)
- rollback = build_rollback(user, env: env, force: force)
+ rollback = build_rollback(user, env:, force:)
rollback.save!
rollback.enqueue
if lock
lock_reason = "A rollback for #{rollback.since_commit.sha} has been triggered. " \
"Please make sure the reason for the rollback has been addressed before deploying again."
- stack.update!(lock_reason: lock_reason, lock_author_id: user.id)
+ stack.update!(lock_reason:, lock_author_id: user.id)
end
rollback
@@ -116,18 +121,18 @@ def trigger_revert(force: false, rollback_to: nil)
previous_successful_commit = rollback_to&.until_commit || commit_to_rollback_to
rollback = Rollback.create!(
- user_id: user_id,
- stack_id: stack_id,
+ user_id:,
+ stack_id:,
parent_id: id,
since_commit: until_commit,
until_commit: previous_successful_commit,
- allow_concurrency: force,
+ allow_concurrency: force
)
rollback.enqueue
lock_reason = "A rollback for #{until_commit.sha} has been triggered. " \
"Please make sure the reason for the rollback has been addressed before deploying again."
- stack.update!(lock_reason: lock_reason, lock_author_id: user_id)
+ stack.update!(lock_reason:, lock_author_id: user_id)
stack.emit_lock_hooks
rollback
end
@@ -176,6 +181,7 @@ def variables
def reject!
return if failed? || aborted?
+
transaction do
flap! unless flapping?
update!(confirmations: [confirmations - 1, -1].min)
@@ -185,6 +191,7 @@ def reject!
def accept!
return if success?
+
transaction do
flap! unless flapping?
update!(confirmations: [confirmations + 1, 1].max)
@@ -198,13 +205,12 @@ def confirmed?
delegate :last_release_status, to: :until_commit
def append_release_status(state, description, user: self.user)
- status = until_commit.create_release_status!(
+ until_commit.create_release_status!(
state,
user: user.presence,
target_url: permalink,
- description: description,
+ description:
)
- status
end
def permalink
@@ -225,7 +231,7 @@ def report_healthy!(user: self.user, description: "@#{user.login} signaled this
append_release_status(
'success',
description,
- user: user,
+ user:
)
end
end
@@ -236,7 +242,7 @@ def report_faulty!(user: self.user, description: "@#{user.login} signaled this r
append_release_status(
'failure',
description,
- user: user,
+ user:
)
end
end
@@ -254,6 +260,7 @@ def create_commit_deployments
# Create one for each pull request in the batch, to give feedback on the PR timeline
commits.select(&:pull_request?).each do |commit|
next if commit.pull_request_head_sha.blank? # This attribute was not always populated
+
commit_deployments.create!(sha: commit.pull_request_head_sha)
end
@@ -272,13 +279,17 @@ def update_release_status
when 'aborted', 'aborting'
append_release_status('failure', "The deploy on #{stack.environment} was canceled")
when 'validating'
- append_release_status(
- 'pending',
- "The deploy on #{stack.environment} succeeded"
- ) unless stack.release_status_delay.zero?
+ unless stack.release_status_delay.zero?
+ append_release_status(
+ 'pending',
+ "The deploy on #{stack.environment} succeeded"
+ )
+ end
- MarkDeployHealthyJob.set(wait: stack.release_status_delay)
- .perform_later(self) if stack.release_status_delay.positive?
+ if stack.release_status_delay.positive?
+ MarkDeployHealthyJob.set(wait: stack.release_status_delay)
+ .perform_later(self)
+ end
when 'success'
if stack.release_status_delay.zero?
append_release_status('success', "The deploy on #{stack.environment} succeeded")
@@ -289,11 +300,13 @@ def update_release_status
def trigger_revert_if_required
return unless rollback_once_aborted?
return unless supports_rollback?
+
trigger_revert(rollback_to: rollback_once_aborted_to)
end
def default_since_commit_id
return unless stack
+
@default_since_commit_id ||= stack.last_completed_deploy&.until_commit_id
end
@@ -308,6 +321,7 @@ def schedule_merges
def schedule_continuous_delivery
return unless stack.continuous_deployment?
+
ContinuousDeliveryJob.perform_later(stack)
end
@@ -321,6 +335,7 @@ def update_last_deploy_time
def update_latest_deployed_ref
return unless previous_changes.include?(:status)
+
stack.update_latest_deployed_ref if previous_changes[:status].last == 'success'
end
end
diff --git a/app/models/shipit/deploy_spec.rb b/app/models/shipit/deploy_spec.rb
index 0d10da807..a2faf19a1 100644
--- a/app/models/shipit/deploy_spec.rb
+++ b/app/models/shipit/deploy_spec.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'pathname'
module Shipit
@@ -47,11 +48,9 @@ def cacheable
def config(*keys, &default)
default ||= -> { nil }
keys.flatten.reduce(@config) do |hash, key|
- if hash.is_a?(Hash)
- hash.fetch(key) { return default.call }
- else
- return default.call
- end
+ return default.call unless hash.is_a?(Hash)
+
+ hash.fetch(key) { return default.call }
end
end
@@ -80,7 +79,7 @@ def dependencies_steps
config('dependencies', 'override') { discover_dependencies_steps || [] }
end
end
- alias_method :dependencies_steps!, :dependencies_steps
+ alias dependencies_steps! dependencies_steps
def maximum_commits_per_deploy
config('deploy', 'max_commits') { 8 }
@@ -95,9 +94,9 @@ def release_status_context
end
def release_status_delay
- if delay = config('status', 'delay') { config('deploy', 'interval') { 0 } }
- Duration.parse(delay)
- end
+ return unless delay = config('status', 'delay') { config('deploy', 'interval') { 0 } }
+
+ Duration.parse(delay)
end
def pause_between_deploys
@@ -193,7 +192,7 @@ def blocking_statuses
def merge_request_merge_method
method = config('merge', 'method')
- method if %w(merge rebase squash).include?(method)
+ method if %w[merge rebase squash].include?(method)
end
def merge_request_required_statuses
@@ -213,11 +212,11 @@ def merge_request_ignored_statuses
end
def revalidate_merge_requests_after
- if timeout = config('merge', 'revalidate_after')
- begin
- Duration.parse(timeout)
- rescue Duration::ParseError
- end
+ return unless timeout = config('merge', 'revalidate_after')
+
+ begin
+ Duration.parse(timeout)
+ rescue Duration::ParseError
end
end
@@ -226,11 +225,11 @@ def max_divergence_commits
end
def max_divergence_age
- if timeout = config('merge', 'max_divergence', 'age')
- begin
- Duration.parse(timeout)
- rescue Duration::ParseError
- end
+ return unless timeout = config('merge', 'max_divergence', 'age')
+
+ begin
+ Duration.parse(timeout)
+ rescue Duration::ParseError
end
end
@@ -255,6 +254,7 @@ def links
def around_steps(section)
steps = yield
return unless steps
+
config(section, 'pre') { [] } + steps + config(section, 'post') { [] }
end
@@ -262,24 +262,19 @@ def coerce_task_definition(config)
config
end
- def discover_review_checklist
- end
+ def discover_review_checklist; end
def discover_task_definitions
config('tasks') || {}
end
- def discover_dependencies_steps
- end
+ def discover_dependencies_steps; end
- def discover_deploy_steps
- end
+ def discover_deploy_steps; end
- def discover_rollback_steps
- end
+ def discover_rollback_steps; end
- def discover_fetch_deployed_revision_steps
- end
+ def discover_fetch_deployed_revision_steps; end
def discover_machine_env
{}
diff --git a/app/models/shipit/deploy_spec/bundler_discovery.rb b/app/models/shipit/deploy_spec/bundler_discovery.rb
index cbd59fe66..0312935bc 100644
--- a/app/models/shipit/deploy_spec/bundler_discovery.rb
+++ b/app/models/shipit/deploy_spec/bundler_discovery.rb
@@ -1,8 +1,9 @@
# frozen_string_literal: true
+
module Shipit
class DeploySpec
module BundlerDiscovery
- DEFAULT_BUNDLER_WITHOUT = %w(default production development test staging benchmark debug).freeze
+ DEFAULT_BUNDLER_WITHOUT = %w[default production development test staging benchmark debug].freeze
def discover_dependencies_steps
discover_bundler || super
@@ -43,6 +44,7 @@ def remove_ruby_version_from_gemfile
def frozen_flag
return unless gemfile_lock_exists?
return if config('dependencies', 'bundler', 'frozen') == false
+
'--frozen'
end
diff --git a/app/models/shipit/deploy_spec/capistrano_discovery.rb b/app/models/shipit/deploy_spec/capistrano_discovery.rb
index ff6522254..0f1759bb7 100644
--- a/app/models/shipit/deploy_spec/capistrano_discovery.rb
+++ b/app/models/shipit/deploy_spec/capistrano_discovery.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class DeploySpec
module CapistranoDiscovery
diff --git a/app/models/shipit/deploy_spec/file_system.rb b/app/models/shipit/deploy_spec/file_system.rb
index e5efe2491..8850ddbfb 100644
--- a/app/models/shipit/deploy_spec/file_system.rb
+++ b/app/models/shipit/deploy_spec/file_system.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class DeploySpec
class FileSystem < DeploySpec
@@ -42,29 +43,29 @@ def cacheable_config
'method' => merge_request_merge_method,
'max_divergence' => {
'commits' => max_divergence_commits&.to_i,
- 'age' => max_divergence_age&.to_i,
- },
+ 'age' => max_divergence_age&.to_i
+ }
},
'ci' => {
'hide' => hidden_statuses,
'allow_failures' => soft_failing_statuses,
'require' => required_statuses,
- 'blocking' => blocking_statuses,
+ 'blocking' => blocking_statuses
},
'machine' => {
'environment' => discover_machine_env.merge(machine_env),
'directory' => directory,
- 'cleanup' => true,
+ 'cleanup' => true
},
'review' => {
'checklist' => review_checklist,
'monitoring' => review_monitoring,
- 'checks' => review_checks,
+ 'checks' => review_checks
},
'plugins' => plugins,
'status' => {
'context' => release_status_context,
- 'delay' => release_status_delay,
+ 'delay' => release_status_delay
},
'dependencies' => { 'override' => dependencies_steps },
'provision' => { 'handler_name' => provisioning_handler_name },
@@ -73,19 +74,19 @@ def cacheable_config
'variables' => deploy_variables.map(&:to_h),
'max_commits' => maximum_commits_per_deploy,
'interval' => pause_between_deploys,
- 'retries' => retries_on_deploy,
+ 'retries' => retries_on_deploy
},
'rollback' => {
'override' => rollback_steps,
- 'retries' => retries_on_rollback,
+ 'retries' => retries_on_rollback
},
'fetch' => fetch_deployed_revision_steps,
- 'tasks' => cacheable_tasks,
+ 'tasks' => cacheable_tasks
)
end
def cacheable_tasks
- discover_task_definitions.map { |k, c| [k, coerce_task_definition(c)] }.to_h
+ discover_task_definitions.transform_values { |c| coerce_task_definition(c) }
end
def config(*)
@@ -115,7 +116,7 @@ def shipit_file_names_in_priority_order
".shipit/#{@env}.yml",
"shipit.yml",
- ".shipit/shipit.yml",
+ ".shipit/shipit.yml"
].uniq
end
@@ -141,11 +142,11 @@ def read_config(path)
end
def shipit_not_obeying_bare_file_echo_command
- <<~EOM
+ <<~WARNING_MESSAGE
echo \"\e[1;31mShipit is configured to ignore the bare '#{app_name}.yml' file.
Please rename this file to more specifically include the environment name.
Deployments will fail until a valid '#{app_name}.#{@env}.yml' file is found.\e[0m\"
- EOM
+ WARNING_MESSAGE
end
end
end
diff --git a/app/models/shipit/deploy_spec/kubernetes_discovery.rb b/app/models/shipit/deploy_spec/kubernetes_discovery.rb
index b41c10968..0dc126999 100644
--- a/app/models/shipit/deploy_spec/kubernetes_discovery.rb
+++ b/app/models/shipit/deploy_spec/kubernetes_discovery.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class DeploySpec
module KubernetesDiscovery
@@ -16,8 +17,8 @@ def discover_task_definitions
'restart' => {
'action' => "Restart application",
'description' => "Simulates a rollout of Kubernetes deployments by using kubernetes-restart utility",
- 'steps' => [kubernetes_restart_cmd],
- },
+ 'steps' => [kubernetes_restart_cmd]
+ }
}.merge!(super)
else
super
@@ -55,7 +56,7 @@ def kubernetes_restart_cmd
cmd = [
"kubernetes-restart",
kube_config.fetch('namespace'),
- kube_config.fetch('context'),
+ kube_config.fetch('context')
]
cmd += ["--max-watch-seconds", timeout_duration] if timeout_duration
Shellwords.join(cmd)
diff --git a/app/models/shipit/deploy_spec/lerna_discovery.rb b/app/models/shipit/deploy_spec/lerna_discovery.rb
index 5a60a6e7d..2b068ebe1 100644
--- a/app/models/shipit/deploy_spec/lerna_discovery.rb
+++ b/app/models/shipit/deploy_spec/lerna_discovery.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'json'
module Shipit
@@ -23,23 +24,23 @@ def discover_review_checklist
end
def discover_lerna_checklist
- if lerna?
- command = if lerna_lerna >= LATEST_MAJOR_VERSION
- 'lerna version'
- else
- %(
+ return unless lerna?
+
+ command = if lerna_lerna >= LATEST_MAJOR_VERSION
+ 'lerna version'
+ else
+ %(
lerna publish --skip-npm
&& git add -A
&& git push --follow-tags
)
- end
+ end
- [%(
+ [%(
Don't forget version and tag before publishing!
You can do this with:
#{command}
)]
- end
end
def lerna?
@@ -72,47 +73,47 @@ def discover_deploy_steps
def publish_lerna_packages
return publish_independent_packages if lerna_version == 'independent'
+
publish_fixed_version_packages
end
def publish_independent_packages
- command = if lerna_lerna >= LATEST_MAJOR_VERSION
+ if lerna_lerna >= LATEST_MAJOR_VERSION
[
'assert-lerna-independent-version-tags',
- 'publish-lerna-independent-packages',
+ 'publish-lerna-independent-packages'
]
else
[
'assert-lerna-independent-version-tags',
- 'publish-lerna-independent-packages-legacy',
+ 'publish-lerna-independent-packages-legacy'
]
end
- command
end
def publish_fixed_version_packages
check_tags = 'assert-lerna-fixed-version-tag'
version = lerna_version
publish = if lerna_lerna >= LATEST_MAJOR_VERSION
- %W(
- node_modules/.bin/lerna publish
- from-git
- --yes
- --dist-tag #{dist_tag(version)}
- ).join(" ")
- else
- # `yarn publish` requires user input, so always use npm.
- %W(
- node_modules/.bin/lerna publish
- --yes
- --skip-git
- --repo-version #{version}
- --force-publish=*
- --npm-tag #{dist_tag(version)}
- --npm-client=npm
- --skip-npm=false
- ).join(" ")
- end
+ %W[
+ node_modules/.bin/lerna publish
+ from-git
+ --yes
+ --dist-tag #{dist_tag(version)}
+ ].join(" ")
+ else
+ # `yarn publish` requires user input, so always use npm.
+ %W[
+ node_modules/.bin/lerna publish
+ --yes
+ --skip-git
+ --repo-version #{version}
+ --force-publish=*
+ --npm-tag #{dist_tag(version)}
+ --npm-client=npm
+ --skip-npm=false
+ ].join(" ")
+ end
[check_tags, publish]
end
diff --git a/app/models/shipit/deploy_spec/npm_discovery.rb b/app/models/shipit/deploy_spec/npm_discovery.rb
index 714d7416e..52682e591 100644
--- a/app/models/shipit/deploy_spec/npm_discovery.rb
+++ b/app/models/shipit/deploy_spec/npm_discovery.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'json'
module Shipit
@@ -27,19 +28,19 @@ def discover_review_checklist
end
def discover_yarn_checklist
- if yarn?
- [%(Don't forget version and tag before publishing! You can do this with:
+ return unless yarn?
+
+ [%(Don't forget version and tag before publishing! You can do this with:
yarn version --new-version <major|minor|patch>
&& git push --follow-tags)]
- end
end
def discover_npm_checklist
- if npm?
- [%(Don't forget version and tag before publishing! You can do this with:
+ return unless npm?
+
+ [%(Don't forget version and tag before publishing! You can do this with:
npm version <major|minor|patch>
&& git push --follow-tags)]
- end
end
def npm?
@@ -59,6 +60,7 @@ def dist_tag(version)
# An 1.0.0-beta.1 would be installable using both:
# `yarn add package@1.0.0-beta.1` and `yarn add package@next`
return 'next' if ['-beta', '-alpha', '-rc', '-next'].any? { |tag| version.include?(tag) }
+
'latest'
end
@@ -104,21 +106,25 @@ def publish_config_access
# default to private deploy when we enforce a publishConfig
if enforce_publish_config?
return PRIVATE if config.blank?
+
config['access'] || PRIVATE
end
return PUBLIC if config.blank?
+
config['access'] || PUBLIC
end
def scoped_package?
return false if Shipit.npm_org_scope.nil?
+
package_name.start_with?(Shipit.npm_org_scope)
end
def enforce_publish_config?
enforce = Shipit.enforce_publish_config
return false if enforce.nil? || enforce.to_s == "0"
+
true
end
@@ -148,9 +154,7 @@ def registry
scope = Shipit.npm_org_scope
prefix = scoped_package? ? "#{scope}:registry" : "registry"
- if publish_config_access == PUBLIC
- return "#{prefix}=#{NPM_REGISTRY}"
- end
+ return "#{prefix}=#{NPM_REGISTRY}" if publish_config_access == PUBLIC
"#{prefix}=#{Shipit.private_npm_registry}"
end
@@ -164,15 +168,16 @@ def publish_npm_package
publish = "npm publish --tag #{dist_tag(package_version)} --access #{publish_config_access}"
return [check_tags, generate_npmrc, publish] if enforce_publish_config?
+
[check_tags, publish]
end
def js_command(command_args)
runner = if yarn?
- 'yarn'
- else
- 'npm'
- end
+ 'yarn'
+ else
+ 'npm'
+ end
"#{runner} #{command_args}"
end
diff --git a/app/models/shipit/deploy_spec/pypi_discovery.rb b/app/models/shipit/deploy_spec/pypi_discovery.rb
index 93a0645a9..ef3745b47 100644
--- a/app/models/shipit/deploy_spec/pypi_discovery.rb
+++ b/app/models/shipit/deploy_spec/pypi_discovery.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class DeploySpec
module PypiDiscovery
@@ -15,10 +16,10 @@ def discover_review_checklist
end
def discover_pypi_checklist
- if egg?
- [%(Don't forget to add a tag before deploying! You can do this with:
+ return unless egg?
+
+ [%(Don't forget to add a tag before deploying! You can do this with:
git tag -a -m "Version x.y.z" vx.y.z && git push --tags)]
- end
end
def egg?
@@ -33,7 +34,7 @@ def publish_egg
[
"assert-egg-version-tag #{setup_dot_py}",
'python setup.py register sdist',
- 'twine upload dist/*',
+ 'twine upload dist/*'
]
end
end
diff --git a/app/models/shipit/deploy_spec/rubygems_discovery.rb b/app/models/shipit/deploy_spec/rubygems_discovery.rb
index 8eb2ab3c5..c7fabd58f 100644
--- a/app/models/shipit/deploy_spec/rubygems_discovery.rb
+++ b/app/models/shipit/deploy_spec/rubygems_discovery.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class DeploySpec
module RubygemsDiscovery
diff --git a/app/models/shipit/deploy_stats.rb b/app/models/shipit/deploy_stats.rb
index 1f4d94848..fd3f03a96 100644
--- a/app/models/shipit/deploy_stats.rb
+++ b/app/models/shipit/deploy_stats.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class DeployStats
delegate :empty?, to: :@deploys
@@ -14,6 +15,7 @@ def count
def average_duration
return if empty?
+
@durations.sum / @durations.length.to_f
end
@@ -27,11 +29,13 @@ def min_duration
def median_duration
return if @durations.empty?
+
(sorted_durations[(@durations.length - 1) / 2] + sorted_durations[@durations.length / 2]) / 2.0
end
def success_rate
return if empty?
+
(@deploys.count(&:success?) / @deploys.length.to_f) * 100
end
@@ -39,7 +43,7 @@ def compare(compare_stats)
{
count: percent_change(compare_stats.count, count),
average_duration: percent_change(compare_stats.average_duration, average_duration),
- median_duration: percent_change(compare_stats.median_duration, median_duration),
+ median_duration: percent_change(compare_stats.median_duration, median_duration)
}
end
@@ -52,6 +56,7 @@ def sorted_durations
def percent_change(from, to)
return if to.nil? || from.nil?
return to * 100 if from.zero?
+
((to - from) / from.to_f) * 100
end
end
diff --git a/app/models/shipit/duration.rb b/app/models/shipit/duration.rb
index 51856909c..fc520d0d5 100644
--- a/app/models/shipit/duration.rb
+++ b/app/models/shipit/duration.rb
@@ -1,21 +1,22 @@
# frozen_string_literal: true
+
module Shipit
class Duration < ActiveSupport::Duration
ParseError = Class.new(ArgumentError)
- FORMAT = %r{
+ FORMAT = /
\A
(?\d+d)?
(?\d+h)?
(?\d+m)?
(?\d+s?)?
\z
- }x
+ /x
UNITS = {
's' => :seconds,
'm' => :minutes,
'h' => :hours,
- 'd' => :days,
+ 'd' => :days
}.freeze
class << self
@@ -25,6 +26,7 @@ def parse(value)
unless match = FORMAT.match(value.to_s)
raise ParseError, "not a duration: #{value.inspect}"
end
+
parts = []
UNITS.each_value do |unit|
if value = match[unit]
diff --git a/app/models/shipit/ephemeral_commit_checks.rb b/app/models/shipit/ephemeral_commit_checks.rb
index 7bb7fbf5c..ca3795645 100644
--- a/app/models/shipit/ephemeral_commit_checks.rb
+++ b/app/models/shipit/ephemeral_commit_checks.rb
@@ -1,7 +1,8 @@
# frozen_string_literal: true
+
module Shipit
class EphemeralCommitChecks
- FINAL_STATUSES = %w(failed error success).freeze
+ FINAL_STATUSES = %w[failed error success].freeze
def initialize(commit)
@commit = commit
@@ -13,7 +14,7 @@ def initialize(commit)
def run
self.status = 'running'
commands = StackCommands.new(stack)
- commands.with_temporary_working_directory(commit: commit) do |directory|
+ commands.with_temporary_working_directory(commit:) do |directory|
deploy_spec = DeploySpec::FileSystem.new(directory, stack)
capture_all(build_commands(deploy_spec.dependencies_steps, chdir: directory))
capture_all(build_commands(deploy_spec.review_checks, chdir: directory))
@@ -22,7 +23,7 @@ def run
rescue Command::Error
self.status = 'failed'
self
- rescue
+ rescue StandardError
self.status = 'error'
raise
else
@@ -46,7 +47,7 @@ def write(output)
private
def build_commands(commands, chdir:)
- commands.map { |c| Command.new(c, env: Shipit.env, chdir: chdir) }
+ commands.map { |c| Command.new(c, env: Shipit.env, chdir:) }
end
def capture_all(commands)
@@ -59,8 +60,8 @@ def capture(command)
command.stream! do |line|
write(line)
end
- rescue Command::Error => error
- write(error.message)
+ rescue Command::Error => e
+ write(e.message)
raise
ensure
write("\n")
diff --git a/app/models/shipit/github_hook.rb b/app/models/shipit/github_hook.rb
index e3dac614f..69228e091 100644
--- a/app/models/shipit/github_hook.rb
+++ b/app/models/shipit/github_hook.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class GithubHook < Record
# TODO: app-migration, delete class
diff --git a/app/models/shipit/github_status.rb b/app/models/shipit/github_status.rb
index 339941e66..713eead4c 100644
--- a/app/models/shipit/github_status.rb
+++ b/app/models/shipit/github_status.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
module GithubStatus
CACHE_KEY = 'github::status'
diff --git a/app/models/shipit/hook.rb b/app/models/shipit/hook.rb
index 5b20ddeda..7843ca54d 100644
--- a/app/models/shipit/hook.rb
+++ b/app/models/shipit/hook.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class Hook < Record
class DeliverySigner
@@ -46,7 +47,7 @@ def headers
'Content-Type' => content_type,
'X-Shipit-Event' => event,
'X-Shipit-Signature' => signature,
- 'Accept' => '*/*',
+ 'Accept' => '*/*'
}
end
@@ -63,10 +64,10 @@ def signature
CONTENT_TYPES = {
'json' => 'application/json',
- 'form' => 'application/x-www-form-urlencoded',
+ 'form' => 'application/x-www-form-urlencoded'
}.freeze
- EVENTS = %w(
+ EVENTS = %w[
stack
review_stack
task
@@ -78,7 +79,7 @@ def signature
merge_status
merge
pull_request
- ).freeze
+ ].freeze
belongs_to :stack, required: false
has_many :deliveries
@@ -96,10 +97,11 @@ def signature
class << self
def emit(event, stack, payload)
raise "#{event} is not declared in Shipit::Hook::EVENTS" unless EVENTS.include?(event.to_s)
+
Shipit::EmitEventJob.perform_later(
event: event.to_s,
stack_id: stack&.id,
- payload: coerce_payload(payload),
+ payload: coerce_payload(payload)
)
deliver_internal_hooks(event, stack, payload)
end
@@ -142,7 +144,7 @@ def deliver!(event, payload)
url: delivery_url,
content_type: CONTENT_TYPES[content_type],
payload: serialize_payload(payload),
- secret: secret,
+ secret:
)
end
diff --git a/app/models/shipit/membership.rb b/app/models/shipit/membership.rb
index fa2907761..22948bf92 100644
--- a/app/models/shipit/membership.rb
+++ b/app/models/shipit/membership.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class Membership < Record
belongs_to :team, required: true
diff --git a/app/models/shipit/merge_request.rb b/app/models/shipit/merge_request.rb
index 3ce283311..fb03dcc98 100644
--- a/app/models/shipit/merge_request.rb
+++ b/app/models/shipit/merge_request.rb
@@ -1,13 +1,14 @@
# frozen_string_literal: true
+
module Shipit
class MergeRequest < ApplicationRecord
include DeferredTouch
MERGE_REQUEST_FIELD = 'Merge-Requested-By'
- WAITING_STATUSES = %w(fetching pending).freeze
- QUEUED_STATUSES = %w(pending revalidating).freeze
- REJECTION_REASONS = %w(ci_missing ci_failing merge_conflict requires_rebase).freeze
+ WAITING_STATUSES = %w[fetching pending].freeze
+ QUEUED_STATUSES = %w[pending revalidating].freeze
+ REJECTION_REASONS = %w[ci_missing ci_failing merge_conflict requires_rebase].freeze
InvalidTransition = Class.new(StandardError)
NotReady = Class.new(StandardError)
@@ -85,14 +86,14 @@ def required_statuses
end
event :retry do
- transition %i(rejected canceled revalidating) => :pending
+ transition %i[rejected canceled revalidating] => :pending
end
before_transition rejected: any do |pr|
pr.rejection_reason = nil
end
- before_transition %i(fetching rejected canceled) => :pending do |pr|
+ before_transition %i[fetching rejected canceled] => :pending do |pr|
pr.merge_requested_at = Time.now.utc
end
@@ -100,7 +101,7 @@ def required_statuses
pr.revalidated_at = Time.now.utc
end
- before_transition %i(pending) => :merged do |pr|
+ before_transition %i[pending] => :merged do |pr|
Stack.increment_counter(:undeployed_commits_count, pr.stack_id)
end
end
@@ -117,6 +118,7 @@ def self.extract_number(stack, number_or_url)
when %r{\Ahttps://#{Regexp.escape(Shipit.github(organization: org).domain)}/([^/]+)/([^/]+)/pull/(\d+)}
return unless $1.downcase == stack.repo_owner.downcase
return unless $2.downcase == stack.repo_name.downcase
+
$3.to_i
end
end
@@ -126,10 +128,10 @@ def self.request_merge!(stack, number, user)
merge_request = begin
create_with(
merge_requested_at: now,
- merge_requested_by: user.presence,
+ merge_requested_by: user.presence
).find_or_create_by!(
- stack: stack,
- number: number,
+ stack:,
+ number:
)
rescue ActiveRecord::RecordNotUnique
retry
@@ -144,6 +146,7 @@ def reject!(reason)
unless REJECTION_REASONS.include?(reason)
raise ArgumentError, "invalid reason: #{reason.inspect}, must be one of: #{REJECTION_REASONS.inspect}"
end
+
self.rejection_reason = reason.presence
super()
true
@@ -154,6 +157,7 @@ def reject_unless_mergeable!
return reject!('ci_missing') if any_status_checks_missing?
return reject!('ci_failing') if any_status_checks_failed?
return reject!('requires_rebase') if stale?
+
false
end
@@ -168,7 +172,7 @@ def merge!
merge_message,
sha: head.sha,
commit_message: 'Merged by Shipit',
- merge_method: stack.merge_method,
+ merge_method: stack.merge_method
)
begin
if stack.github_api.pull_requests(stack.github_repo_name, base: branch).empty?
@@ -188,6 +192,7 @@ def merge!
def all_status_checks_passed?
return false unless head
+
StatusChecker.new(head, head.statuses_and_check_runs, stack.cached_deploy_spec).success?
end
@@ -207,6 +212,7 @@ def waiting?
def need_revalidation?
timeout = stack.cached_deploy_spec&.revalidate_merge_requests_after
return false unless timeout
+
(revalidated_at + timeout).past?
end
@@ -255,18 +261,21 @@ def github_pull_request=(github_pull_request)
def merge_message
return title unless merge_requested_by
+
"#{title}\n\n#{MERGE_REQUEST_FIELD}: #{merge_requested_by.login}\n"
end
def stale?
return false unless base_commit
+
spec = stack.cached_deploy_spec
- if max_branch_age = spec.max_divergence_age
- return true if Time.now.utc - head.committed_at > max_branch_age
+ if (max_branch_age = spec.max_divergence_age) && (Time.now.utc - head.committed_at > max_branch_age)
+ return true
end
- if commit_count_limit = spec.max_divergence_commits
- return true if comparison.behind_by > commit_count_limit
+ if (commit_count_limit = spec.max_divergence_commits) && (comparison.behind_by > commit_count_limit)
+ return true
end
+
false
end
@@ -274,7 +283,7 @@ def comparison
@comparison ||= stack.github_api.compare(
stack.github_repo_name,
base_ref,
- head.sha,
+ head.sha
)
end
@@ -286,8 +295,9 @@ def record_merge_status_change
def emit_hooks
return unless @merge_status_changed
+
@merge_status_changed = nil
- Hook.emit('merge', stack, merge_request: self, status: merge_status, stack: stack)
+ Hook.emit('merge', stack, merge_request: self, status: merge_status, stack:)
end
def find_or_create_commit_from_github_by_sha!(sha, attributes)
diff --git a/app/models/shipit/output_chunk.rb b/app/models/shipit/output_chunk.rb
index 1e673006b..3070fb7df 100644
--- a/app/models/shipit/output_chunk.rb
+++ b/app/models/shipit/output_chunk.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class OutputChunk < Record
belongs_to :task
diff --git a/app/models/shipit/provisioning_handler.rb b/app/models/shipit/provisioning_handler.rb
index c6255cbc3..05bbba35b 100644
--- a/app/models/shipit/provisioning_handler.rb
+++ b/app/models/shipit/provisioning_handler.rb
@@ -17,6 +17,7 @@ def register(handler_class)
def fetch(name)
return default if name.blank?
+
registry.fetch(name) { ProvisioningHandler::UnregisteredProvisioningHandler }
end
diff --git a/app/models/shipit/pull_request.rb b/app/models/shipit/pull_request.rb
index 8e993af82..b5ad60698 100644
--- a/app/models/shipit/pull_request.rb
+++ b/app/models/shipit/pull_request.rb
@@ -30,7 +30,7 @@ def emit_update_hooks
end
def emit_hooks(reason)
- Hook.emit('pull_request', stack, action: reason, pull_request: self, stack: stack)
+ Hook.emit('pull_request', stack, action: reason, pull_request: self, stack:)
end
def github_pull_request=(github_pull_request)
diff --git a/app/models/shipit/record.rb b/app/models/shipit/record.rb
index 4b98b9909..9cb1ba3a4 100644
--- a/app/models/shipit/record.rb
+++ b/app/models/shipit/record.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class Record < ActiveRecord::Base
self.abstract_class = true
diff --git a/app/models/shipit/release_status.rb b/app/models/shipit/release_status.rb
index 3bbd38130..4c8991413 100644
--- a/app/models/shipit/release_status.rb
+++ b/app/models/shipit/release_status.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class ReleaseStatus < Record
MAX_DESCRIPTION_LENGTH = 140
@@ -13,7 +14,7 @@ class ReleaseStatus < Record
scope :to_be_created, -> { where(github_id: nil).order(id: :asc) }
- STATES = %w(pending success failure error).freeze
+ STATES = %w[pending success failure error].freeze
validates :state, presence: true, inclusion: { in: STATES }
def create_status_on_github!
@@ -30,8 +31,8 @@ def create_status_on_github
commit.sha,
state,
context: stack.release_status_context,
- target_url: target_url,
- description: description&.truncate(MAX_DESCRIPTION_LENGTH),
+ target_url:,
+ description: description&.truncate(MAX_DESCRIPTION_LENGTH)
)
end
diff --git a/app/models/shipit/repository.rb b/app/models/shipit/repository.rb
index 83a79c508..92a6150e5 100644
--- a/app/models/shipit/repository.rb
+++ b/app/models/shipit/repository.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class NullRepository
def id
@@ -37,16 +38,16 @@ class Repository < ApplicationRecord
NAME_MAX_SIZE = 100
private_constant :NAME_MAX_SIZE
- validates :name, uniqueness: { scope: %i(owner), case_sensitive: false,
- message: 'cannot be used more than once', }
+ validates :name, uniqueness: { scope: %i[owner], case_sensitive: false,
+ message: 'cannot be used more than once' }
validates :owner, :name, presence: true, ascii_only: true
- validates :owner, format: { with: /\A[a-z0-9_\-\.]+\z/ }, length: { maximum: OWNER_MAX_SIZE }
- validates :name, format: { with: /\A[a-z0-9_\-\.]+\z/ }, length: { maximum: NAME_MAX_SIZE }
+ validates :owner, format: { with: /\A[a-z0-9_\-.]+\z/ }, length: { maximum: OWNER_MAX_SIZE }
+ validates :name, format: { with: /\A[a-z0-9_\-.]+\z/ }, length: { maximum: NAME_MAX_SIZE }
has_many :stacks, dependent: :destroy
has_many :review_stacks, dependent: :destroy
- PROVISIONING_BEHAVIORS = %w(allow_all allow_with_label prevent_with_label).freeze
+ PROVISIONING_BEHAVIORS = %w[allow_all allow_with_label prevent_with_label].freeze
enum :provisioning_behavior, PROVISIONING_BEHAVIORS.zip(PROVISIONING_BEHAVIORS).to_h, prefix: :provisioning_behavior
def self.from_github_repo_name(github_repo_name)
@@ -54,12 +55,12 @@ def self.from_github_repo_name(github_repo_name)
find_by(owner: repo_owner, name: repo_name)
end
- def name=(n)
- super(n&.downcase)
+ def name=(name_value)
+ super(name_value&.downcase)
end
- def owner=(o)
- super(o&.downcase)
+ def owner=(owner_value)
+ super(owner_value&.downcase)
end
def github_repo_name
@@ -90,7 +91,7 @@ def self.from_param!(param)
repo_owner, repo_name = param.split('/')
where(
owner: repo_owner.downcase,
- name: repo_name.downcase,
+ name: repo_name.downcase
).first!
end
diff --git a/app/models/shipit/review_stack.rb b/app/models/shipit/review_stack.rb
index 758ab54c0..ae21fa4d1 100644
--- a/app/models/shipit/review_stack.rb
+++ b/app/models/shipit/review_stack.rb
@@ -102,11 +102,13 @@ def provisioner_class
def enqueue_for_provisioning
return if awaiting_provision
+
update!(awaiting_provision: true)
end
def remove_from_provisioning_queue
return unless awaiting_provision
+
update!(awaiting_provision: false)
end
@@ -119,7 +121,7 @@ def emit_added_hooks
end
def emit_updated_hooks
- changed = !(previous_changes.keys - %w(updated_at)).empty?
+ changed = !(previous_changes.keys - %w[updated_at]).empty?
Hook.emit(:review_stack, self, action: :updated, review_stack: self) if changed
end
diff --git a/app/models/shipit/review_stack_provisioning_queue.rb b/app/models/shipit/review_stack_provisioning_queue.rb
index 23121da34..29c443102 100644
--- a/app/models/shipit/review_stack_provisioning_queue.rb
+++ b/app/models/shipit/review_stack_provisioning_queue.rb
@@ -20,8 +20,8 @@ def work
def queued_stacks
@queued_stacks ||= Shipit::ReviewStack
- .with_provision_status(:deprovisioned)
- .where(awaiting_provision: true)
+ .with_provision_status(:deprovisioned)
+ .where(awaiting_provision: true)
end
private
diff --git a/app/models/shipit/rollback.rb b/app/models/shipit/rollback.rb
index 261858bd2..dfa1f76e6 100644
--- a/app/models/shipit/rollback.rb
+++ b/app/models/shipit/rollback.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class Rollback < Deploy
belongs_to :deploy, foreign_key: :parent_id, inverse_of: false
@@ -45,6 +46,7 @@ def update_release_status
# When we rollback to a certain revision, assume that all later deploys were faulty
stack.deploys.newer_than(deploy.id).until(stack.last_completed_deploy.id).to_a.each do |deploy|
next if deploy.id == id
+
deploy.report_faulty!(description: "A rollback of #{stack.to_param} was triggered")
end
end
diff --git a/app/models/shipit/stack.rb b/app/models/shipit/stack.rb
index a48bad72a..6731d8775 100644
--- a/app/models/shipit/stack.rb
+++ b/app/models/shipit/stack.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'fileutils'
module Shipit
@@ -24,7 +25,7 @@ def blank?
end
ENVIRONMENT_MAX_SIZE = 50
- REQUIRED_HOOKS = %i(push status).freeze
+ REQUIRED_HOOKS = %i[push status].freeze
has_many :commits, dependent: :destroy
has_many :merge_requests, dependent: :destroy
@@ -32,9 +33,9 @@ def blank?
has_many :deploys
has_many :rollbacks
has_many :deploys_and_rollbacks,
- -> { where(type: %w(Shipit::Deploy Shipit::Rollback)) },
- class_name: 'Task',
- inverse_of: :stack
+ -> { where(type: %w[Shipit::Deploy Shipit::Rollback]) },
+ class_name: 'Task',
+ inverse_of: :stack
has_many :github_hooks, dependent: :destroy, class_name: 'Shipit::GithubHook::Repo'
has_many :hooks, dependent: :destroy
has_many :api_clients, dependent: :destroy
@@ -57,7 +58,7 @@ def env
'GITHUB_REPO_OWNER' => repository.owner,
'GITHUB_REPO_NAME' => repository.name,
'DEPLOY_URL' => deploy_url,
- 'BRANCH' => branch,
+ 'BRANCH' => branch
}
end
@@ -87,17 +88,17 @@ def lock_author=(user)
after_commit :sync_github_if_necessary, on: :update
def sync_github_if_necessary
- if (archived_since_previously_changed? && archived_since.nil?) || branch_previously_changed?
- sync_github
- end
+ return unless (archived_since_previously_changed? && archived_since.nil?) || branch_previously_changed?
+
+ sync_github
end
validates :repository, uniqueness: {
- scope: %i(environment), case_sensitive: false,
- message: 'cannot be used more than once with this environment. Check archived stacks.',
+ scope: %i[environment], case_sensitive: false,
+ message: 'cannot be used more than once with this environment. Check archived stacks.'
}
- validates :environment, format: { with: /\A[a-z0-9\-_\:]+\z/ }, length: { maximum: ENVIRONMENT_MAX_SIZE }
- validates :deploy_url, format: { with: URI.regexp(%w(http https ssh)) }, allow_blank: true
+ validates :environment, format: { with: /\A[a-z0-9\-_:]+\z/ }, length: { maximum: ENVIRONMENT_MAX_SIZE }
+ validates :deploy_url, format: { with: URI::DEFAULT_PARSER.make_regexp(%w[http https ssh]) }, allow_blank: true
validates :branch, presence: true
validates :lock_reason, length: { maximum: 4096 }
@@ -131,7 +132,7 @@ def undeployed_commits?
def trigger_task(definition_id, user, env: nil, force: false)
definition = find_task_definition(definition_id)
- env = env&.to_h || {}
+ env = env.to_h
definition.variables_with_defaults.each do |variable|
env[variable.name] ||= variable.default
@@ -140,12 +141,12 @@ def trigger_task(definition_id, user, env: nil, force: false)
commit = last_deployed_commit.presence || commits.first
task = tasks.create(
user_id: user.id,
- definition: definition,
+ definition:,
until_commit_id: commit.id,
since_commit_id: commit.id,
env: definition.filter_envs(env),
allow_concurrency: definition.allow_concurrency? || force,
- ignored_safeties: force,
+ ignored_safeties: force
)
task.enqueue
task
@@ -155,12 +156,12 @@ def build_deploy(until_commit, user, env: nil, force: false, allow_concurrency:
since_commit = last_deployed_commit.presence || commits.first
deploys.build(
user_id: user.id,
- until_commit: until_commit,
- since_commit: since_commit,
- env: filter_deploy_envs(env&.to_h || {}),
- allow_concurrency: allow_concurrency,
+ until_commit:,
+ since_commit:,
+ env: filter_deploy_envs(env.to_h),
+ allow_concurrency:,
ignored_safeties: force || !until_commit.deployable?,
- max_retries: retries_on_deploy,
+ max_retries: retries_on_deploy
)
end
@@ -236,17 +237,16 @@ def next_commit_to_deploy
end
def deployed_too_recently?
- if task = last_active_task
- return true if task.validating?
+ return unless task = last_active_task
+ return true if task.validating?
- task.ended_at? && (task.ended_at + pause_between_deploys).future?
- end
+ task.ended_at? && (task.ended_at + pause_between_deploys).future?
end
def async_refresh_deployed_revision
async_refresh_deployed_revision!
- rescue => error
- logger.warn("Failed to dispatch FetchDeployedRevisionJob: [#{error.class.name}] #{error.message}")
+ rescue StandardError => e
+ logger.warn("Failed to dispatch FetchDeployedRevisionJob: [#{e.class.name}] #{e.message}")
end
def async_refresh_deployed_revision!
@@ -268,7 +268,7 @@ def update_deployed_revision(sha)
deploys.create!(
until_commit: actual_deployed_commit,
since_commit: last_deployed_commit.presence || commits.first,
- status: 'success',
+ status: 'success'
)
end
end
@@ -279,8 +279,9 @@ def head
def merge_status(backlog_leniency_factor: 2.0)
return 'locked' if locked?
- return 'failure' if %w(failure error).freeze.include?(branch_status)
- return 'backlogged' if backlogged?(backlog_leniency_factor: backlog_leniency_factor)
+ return 'failure' if %w[failure error].freeze.include?(branch_status)
+ return 'backlogged' if backlogged?(backlog_leniency_factor:)
+
'success'
end
@@ -291,13 +292,14 @@ def backlogged?(backlog_leniency_factor: 2.0)
def branch_status
undeployed_commits.each do |commit|
state = commit.status.simple_state
- return state unless %w(pending unknown missing).freeze.include?(state)
+ return state unless %w[pending unknown missing].freeze.include?(state)
end
'pending'
end
def status
return :deploying if active_task?
+
:default
end
@@ -314,8 +316,8 @@ def lock_reverted_commits!
next if commits_to_lock.empty?
affected_rows += commits
- .where(id: commits_to_lock.map(&:id).uniq)
- .lock_all(revert.author)
+ .where(id: commits_to_lock.map(&:id).uniq)
+ .lock_all(revert.author)
end
touch if affected_rows > 1
@@ -397,13 +399,14 @@ def git_path
end
def acquire_git_cache_lock(timeout: 15, &block)
- @git_cache_lock ||= Flock.new(git_path.to_s + '.lock')
- @git_cache_lock.lock(timeout: timeout, &block)
+ @git_cache_lock ||= Flock.new("#{git_path}.lock")
+ @git_cache_lock.lock(timeout:, &block)
end
def clear_git_cache!
tmp_path = "#{git_path}-#{SecureRandom.hex}"
return unless git_path.exist?
+
acquire_git_cache_lock do
git_path.rename(tmp_path)
end
@@ -443,9 +446,7 @@ def handle_github_redirections
def refresh_repository!
resource = github_api.repo(github_repo_name)
- if resource.try(:message) == 'Moved Permanently'
- resource = github_api.get(resource.url)
- end
+ resource = github_api.get(resource.url) if resource.try(:message) == 'Moved Permanently'
repository.update!(owner: resource.owner.login, name: resource.name)
end
@@ -455,6 +456,7 @@ def active_task?
def active_task
return @active_task if defined?(@active_task)
+
@active_task ||= tasks.current
end
@@ -501,7 +503,7 @@ def self.run_deploy_in_foreground(stack:, revision:)
env = stack.cached_deploy_spec.default_deploy_env
current_user = Shipit::CommandLineUser.new
- stack.trigger_deploy(until_commit, current_user, env: env, force: true, run_now: true)
+ stack.trigger_deploy(until_commit, current_user, env:, force: true, run_now: true)
end
def self.from_param!(param)
@@ -510,16 +512,16 @@ def self.from_param!(param)
.where(
repositories: {
owner: repo_owner.downcase,
- name: repo_name.downcase,
+ name: repo_name.downcase
},
- environment: environment,
+ environment:
).first!
end
delegate :plugins, :task_definitions, :hidden_statuses, :required_statuses, :soft_failing_statuses,
- :blocking_statuses, :deploy_variables, :filter_task_envs, :filter_deploy_envs,
- :maximum_commits_per_deploy, :pause_between_deploys, :retries_on_deploy, :retries_on_rollback,
- to: :cached_deploy_spec
+ :blocking_statuses, :deploy_variables, :filter_task_envs, :filter_deploy_envs,
+ :maximum_commits_per_deploy, :pause_between_deploys, :retries_on_deploy, :retries_on_rollback,
+ to: :cached_deploy_spec
def monitoring?
monitoring.present?
@@ -544,16 +546,16 @@ def update_undeployed_commits_count(after_commit = nil)
end
def update_latest_deployed_ref
- if Shipit.update_latest_deployed_ref
- UpdateGithubLastDeployedRefJob.perform_later(self)
- end
+ return unless Shipit.update_latest_deployed_ref
+
+ UpdateGithubLastDeployedRefJob.perform_later(self)
end
def broadcast_update
Pubsubstub.publish(
"stack.#{id}",
- { id: id, updated_at: updated_at }.to_json,
- name: 'update',
+ { id:, updated_at: }.to_json,
+ name: 'update'
)
end
@@ -625,10 +627,10 @@ def emit_lock_hooks
return unless previous_changes.include?('lock_reason')
lock_details = if previous_changes['lock_reason'].last.blank?
- { from: previous_changes['locked_since'].first, until: Time.zone.now }
- end
+ { from: previous_changes['locked_since'].first, until: Time.zone.now }
+ end
- Hook.emit(:lock, self, locked: locked?, lock_details: lock_details, stack: self)
+ Hook.emit(:lock, self, locked: locked?, lock_details:, stack: self)
end
private
@@ -663,9 +665,9 @@ def set_locked_since
end
def schedule_merges_if_necessary
- if lock_reason_previously_changed? && lock_reason.blank?
- schedule_merges
- end
+ return unless lock_reason_previously_changed? && lock_reason.blank?
+
+ schedule_merges
end
def emit_added_hooks
@@ -673,7 +675,7 @@ def emit_added_hooks
end
def emit_updated_hooks
- changed = !(previous_changes.keys - %w(updated_at)).empty?
+ changed = !(previous_changes.keys - %w[updated_at]).empty?
Hook.emit(:stack, self, action: :updated, stack: self) if changed
end
@@ -682,7 +684,7 @@ def emit_removed_hooks
end
def emit_merge_status_hooks
- Hook.emit(:merge_status, self, merge_status: merge_status, stack: self)
+ Hook.emit(:merge_status, self, merge_status:, stack: self)
end
def ci_enabled_cache_key
diff --git a/app/models/shipit/status.rb b/app/models/shipit/status.rb
index 3527b5ea3..b32439913 100644
--- a/app/models/shipit/status.rb
+++ b/app/models/shipit/status.rb
@@ -1,10 +1,11 @@
# frozen_string_literal: true
+
module Shipit
class Status < Record
include Common
include DeferredTouch
- STATES = %w(pending success failure error).freeze
+ STATES = %w[pending success failure error].freeze
enum :state, STATES.zip(STATES).to_h
belongs_to :stack, required: true
@@ -22,12 +23,12 @@ class Status < Record
class << self
def replicate_from_github!(stack_id, github_status)
find_or_create_by!(
- stack_id: stack_id,
+ stack_id:,
state: github_status.state,
description: github_status.description,
target_url: github_status.target_url,
context: github_status.context,
- created_at: github_status.created_at,
+ created_at: github_status.created_at
)
end
end
diff --git a/app/models/shipit/status/common.rb b/app/models/shipit/status/common.rb
index 5f1951e86..d7f926fff 100644
--- a/app/models/shipit/status/common.rb
+++ b/app/models/shipit/status/common.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class Status
module Common
diff --git a/app/models/shipit/status/group.rb b/app/models/shipit/status/group.rb
index b057a445b..5d151ceb0 100644
--- a/app/models/shipit/status/group.rb
+++ b/app/models/shipit/status/group.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class Status
class Group
@@ -31,7 +32,7 @@ def initialize(commit, statuses)
end
delegate :pending?, :success?, :error?, :failure?, :unknown?, :missing?, :state, :simple_state,
- to: :significant_status
+ to: :significant_status
delegate :each, :size, :map, to: :statuses
delegate :required_statuses, to: :commit
@@ -43,8 +44,7 @@ def description
"#{success_count} / #{statuses.count} checks OK"
end
- def target_url
- end
+ def target_url; end
def to_partial_path
'statuses/group'
@@ -75,8 +75,10 @@ def significant_status
def select_significant_status(statuses)
statuses = reject_allowed_to_fail(statuses)
return Status::Unknown.new(commit) if statuses.empty?
+
non_success_statuses = statuses.reject(&:success?)
return statuses.first if non_success_statuses.empty?
+
non_success_statuses.reject(&:pending?).first || non_success_statuses.first || Status::Unknown.new(commit)
end
diff --git a/app/models/shipit/status/missing.rb b/app/models/shipit/status/missing.rb
index e6a2ab183..31b3f0327 100644
--- a/app/models/shipit/status/missing.rb
+++ b/app/models/shipit/status/missing.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class Status
class Missing
@@ -24,7 +25,7 @@ def missing?
end
def description
- I18n.t('missing_status.description', context: context)
+ I18n.t('missing_status.description', context:)
end
def to_partial_path
diff --git a/app/models/shipit/status/unknown.rb b/app/models/shipit/status/unknown.rb
index 9cea9089a..94165c241 100644
--- a/app/models/shipit/status/unknown.rb
+++ b/app/models/shipit/status/unknown.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class Status
class Unknown
diff --git a/app/models/shipit/task.rb b/app/models/shipit/task.rb
index 43a9e2bc6..2a23d4000 100644
--- a/app/models/shipit/task.rb
+++ b/app/models/shipit/task.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class Task < Record
include DeferredTouch
@@ -10,12 +11,12 @@ def message
end
PRESENCE_CHECK_TIMEOUT = 30
- ACTIVE_STATUSES = %w(pending running aborting).freeze
- COMPLETED_STATUSES = %w(success flapping faulty validating).freeze
- UNSUCCESSFUL_STATUSES = %w(error failed aborted flapping timedout faulty).freeze
+ ACTIVE_STATUSES = %w[pending running aborting].freeze
+ COMPLETED_STATUSES = %w[success flapping faulty validating].freeze
+ UNSUCCESSFUL_STATUSES = %w[error failed aborted flapping timedout faulty].freeze
OUTPUT_SIZE_LIMIT = 16.megabytes # A MySQL mediumblob
HUMAN_READABLE_OUTPUT_LIMIT = ActionController::Base.helpers.number_to_human_size(OUTPUT_SIZE_LIMIT)
- OUTPUT_TRUNCATED_MESSAGE = "Output exceeded the limit of #{HUMAN_READABLE_OUTPUT_LIMIT} and was truncated\n"
+ OUTPUT_TRUNCATED_MESSAGE = "Output exceeded the limit of #{HUMAN_READABLE_OUTPUT_LIMIT} and was truncated\n".freeze
attr_accessor :pid
@@ -35,6 +36,7 @@ module EnvHash
class << self
def dump(hash)
raise TypeError, "Task#env should be a Hash[String => String]" unless hash.is_a?(Hash)
+
hash = hash.to_h.stringify_keys
hash.transform_values! do |value|
case value
@@ -49,7 +51,7 @@ def dump(hash)
end
def load(hash)
- hash&.to_h || {} # cast back to a real hash
+ hash.to_h # cast back to a real hash
end
def new
@@ -104,11 +106,11 @@ def current
task.ended_at ||= Time.now.utc
end
- after_transition any => %i(success failed error timedout) do |task|
+ after_transition any => %i[success failed error timedout] do |task|
task.async_refresh_deployed_revision
end
- after_transition any => %i(aborted success failed error timedout) do |task|
+ after_transition any => %i[aborted success failed error timedout] do |task|
task.schedule_rollup_chunks
end
@@ -120,7 +122,7 @@ def current
task.async_update_estimated_deploy_duration
end
- after_transition any => %i(failed error timedout) do |task|
+ after_transition any => %i[failed error timedout] do |task|
task.retry_if_necessary
end
@@ -129,19 +131,19 @@ def current
end
event :failure do
- transition %i(running flapping) => :failed
+ transition %i[running flapping] => :failed
end
event :complete do
- transition %i(running flapping validating faulty) => :success
+ transition %i[running flapping validating faulty] => :success
end
event :enter_validation do
- transition %i(running flapping) => :validating
+ transition %i[running flapping] => :validating
end
event :mark_faulty do
- transition %i(validating success) => :faulty
+ transition %i[validating success] => :faulty
end
event :error do
@@ -153,7 +155,7 @@ def current
end
event :aborting do
- transition all - %i(aborted) => :aborting
+ transition all - %i[aborted] => :aborting
end
event :aborted do
@@ -161,7 +163,7 @@ def current
end
event :flap do
- transition %i(failed error timedout success) => :flapping
+ transition %i[failed error timedout success] => :flapping
end
state :pending
@@ -206,7 +208,7 @@ def report_error!(error)
end
delegate :acquire_git_cache_lock, :async_refresh_deployed_revision, :async_update_estimated_deploy_duration,
- to: :stack
+ to: :stack
delegate :checklist, to: :definition
@@ -224,11 +226,13 @@ def spec
def enqueue
raise "only persisted jobs can be enqueued" unless persisted?
+
PerformTaskJob.perform_later(self)
end
def run_now!
raise "only persisted jobs can be run" unless persisted?
+
PerformTaskJob.perform_now(self)
end
@@ -350,10 +354,10 @@ def request_abort
end
end
- def abort!(rollback_once_aborted: false, rollback_once_aborted_to: nil, aborted_by:)
+ def abort!(aborted_by:, rollback_once_aborted: false, rollback_once_aborted_to: nil)
update!(
- rollback_once_aborted: rollback_once_aborted,
- rollback_once_aborted_to: rollback_once_aborted_to,
+ rollback_once_aborted:,
+ rollback_once_aborted_to:,
aborted_by_id: aborted_by.id
)
@@ -383,12 +387,13 @@ def record_status_change
def emit_hooks_if_status_changed
return unless @status_changed
+
@status_changed = nil
emit_hooks
end
def emit_hooks
- Hook.emit(hook_event, stack, hook_event => self, status: status, stack: stack)
+ Hook.emit(hook_event, stack, hook_event => self, status:, stack:)
end
def hook_event
@@ -427,13 +432,13 @@ def self.recently_created_at
5.minutes.ago
end
- ZOMBIE_STATES = %w(running aborting).freeze
+ ZOMBIE_STATES = %w[running aborting].freeze
private_constant :ZOMBIE_STATES
def self.zombies
where(status: ZOMBIE_STATES)
.where(
"created_at <= :recently",
- recently: recently_created_at,
+ recently: recently_created_at
)
.reject(&:alive?)
end
@@ -441,13 +446,13 @@ def self.zombies
def retry_if_necessary
return unless retries_configured? && !stack.reload.locked?
- if retry_attempt < max_retries
- retry_task = duplicate_task
- retry_task.retry_attempt = duplicate_task.retry_attempt + 1
- retry_task.save!
+ return unless retry_attempt < max_retries
- retry_task.enqueue
- end
+ retry_task = duplicate_task
+ retry_task.retry_attempt = duplicate_task.retry_attempt + 1
+ retry_task.save!
+
+ retry_task.enqueue
end
def retries_configured?
diff --git a/app/models/shipit/task_definition.rb b/app/models/shipit/task_definition.rb
index bc814709b..3de878f88 100644
--- a/app/models/shipit/task_definition.rb
+++ b/app/models/shipit/task_definition.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class TaskDefinition
NotFound = Class.new(StandardError)
@@ -6,18 +7,20 @@ class TaskDefinition
class << self
def load(payload)
return if payload.blank?
+
json = JSON.parse(payload)
new(json.delete('id'), json)
end
def dump(definition)
return if definition.blank?
+
JSON.dump(definition.as_json)
end
end
attr_reader :id, :action, :description, :steps, :checklist, :variables
- alias_method :to_param, :id
+ alias to_param id
def initialize(id, config)
@id = id
@@ -46,14 +49,14 @@ def allow_concurrency?
def as_json
{
- id: id,
- action: action,
+ id:,
+ action:,
title: @title,
- description: description,
- steps: steps,
+ description:,
+ steps:,
variables: variables.map(&:to_h),
- checklist: checklist,
- allow_concurrency: allow_concurrency?,
+ checklist:,
+ allow_concurrency: allow_concurrency?
}
end
diff --git a/app/models/shipit/task_execution_strategy/default.rb b/app/models/shipit/task_execution_strategy/default.rb
index 3cd2998b9..0b39ef0a9 100644
--- a/app/models/shipit/task_execution_strategy/default.rb
+++ b/app/models/shipit/task_execution_strategy/default.rb
@@ -21,16 +21,16 @@ def run
perform_task
@task.write("\nCompleted successfully\n")
@task.report_complete!
- rescue Command::TimedOut => error
- @task.write("\n#{error.message}\n")
- @task.report_timeout!(error)
- rescue Command::Error => error
- @task.write("\n#{error.message}\n")
- @task.report_failure!(error)
- rescue StandardError => error
- @task.report_error!(error)
- rescue Exception => error
- @task.report_error!(error)
+ rescue Command::TimedOut => e
+ @task.write("\n#{e.message}\n")
+ @task.report_timeout!(e)
+ rescue Command::Error => e
+ @task.write("\n#{e.message}\n")
+ @task.report_failure!(e)
+ rescue StandardError => e
+ @task.report_error!(e)
+ rescue Exception => e
+ @task.report_error!(e)
raise
end
@@ -42,8 +42,8 @@ def abort!(signal: 'TERM')
else
@task.write("Can't abort, no recorded pid, WTF?\n")
end
- rescue SystemCallError => error
- @task.write("kill: (#{pid}) - #{error.message}\n")
+ rescue SystemCallError => e
+ @task.write("kill: (#{pid}) - #{e.message}\n")
end
def check_for_abort
diff --git a/app/models/shipit/team.rb b/app/models/shipit/team.rb
index bcdaee20c..d07ef9796 100644
--- a/app/models/shipit/team.rb
+++ b/app/models/shipit/team.rb
@@ -1,32 +1,33 @@
# frozen_string_literal: true
+
module Shipit
class Team < Record
- REQUIRED_HOOKS = %i(membership).freeze
+ REQUIRED_HOOKS = %i[membership].freeze
has_many :memberships
has_many :members, class_name: :User, through: :memberships, source: :user
has_many :github_hooks,
- -> { where(event: REQUIRED_HOOKS) },
- foreign_key: :organization,
- primary_key: :organization,
- class_name: 'GithubHook::Organization',
- inverse_of: false
+ -> { where(event: REQUIRED_HOOKS) },
+ foreign_key: :organization,
+ primary_key: :organization,
+ class_name: 'GithubHook::Organization',
+ inverse_of: false
class << self
def find_or_create_by_handle(handle)
organization, slug = handle.split('/').map(&:downcase)
- find_by(organization: organization, slug: slug) || fetch_and_create_from_github(organization, slug)
+ find_by(organization:, slug:) || fetch_and_create_from_github(organization, slug)
end
def fetch_and_create_from_github(organization, slug)
- if github_team = find_team_on_github(organization, slug)
- create!(github_team: github_team, organization: organization)
- end
+ return unless github_team = find_team_on_github(organization, slug)
+
+ create!(github_team:, organization:)
end
def find_team_on_github(organization, slug)
- gh_api = Shipit.github(organization: organization).api
+ gh_api = Shipit.github(organization:).api
teams = Shipit::OctokitIterator.new(github_api: gh_api) { gh_api.org_teams(organization, per_page: 100) }
teams.find { |t| t.slug == slug }
rescue Octokit::NotFound
@@ -42,7 +43,7 @@ def add_member(member)
end
def refresh_members!
- github_api = Shipit.github(organization: organization).api
+ github_api = Shipit.github(organization:).api
github_members = Shipit::OctokitIterator.new(github_api.get(api_url).rels[:members])
members = github_members.map { |u| User.find_or_create_from_github(u) }
self.members = members
diff --git a/app/models/shipit/undeployed_commit.rb b/app/models/shipit/undeployed_commit.rb
index d499c00f6..17f401bda 100644
--- a/app/models/shipit/undeployed_commit.rb
+++ b/app/models/shipit/undeployed_commit.rb
@@ -1,4 +1,10 @@
# frozen_string_literal: true
+
+# rubocop:disable Lint/MissingCopEnableDirective, Style/OptionalBooleanParameter
+# Disabling for now because we need to support the `bypass_safeties` parameter
+# in the `deploy_state` and `redeploy_state` methods. We can revisit this later.
+
+require 'delegate'
module Shipit
class UndeployedCommit < DelegateClass(Commit)
attr_reader :index
@@ -26,9 +32,7 @@ def deploy_state(bypass_safeties = false)
def redeploy_state(bypass_safeties = false)
state = 'allowed'
- unless bypass_safeties
- state = 'deploying' if stack.active_task?
- end
+ state = 'deploying' if !bypass_safeties && stack.active_task?
state
end
@@ -50,6 +54,7 @@ def expected_to_be_deployed?
def blocked?
return @blocked if defined?(@blocked)
+
@blocked = super
end
end
diff --git a/app/models/shipit/unlimited_api_client.rb b/app/models/shipit/unlimited_api_client.rb
index 495625873..66e4ca9a9 100644
--- a/app/models/shipit/unlimited_api_client.rb
+++ b/app/models/shipit/unlimited_api_client.rb
@@ -1,11 +1,11 @@
# frozen_string_literal: true
+
module Shipit
class UnlimitedApiClient
def stack_id?
false
end
- def check_permissions!(*)
- end
+ def check_permissions!(*); end
end
end
diff --git a/app/models/shipit/user.rb b/app/models/shipit/user.rb
index c94c29dfa..6de8fe8d6 100644
--- a/app/models/shipit/user.rb
+++ b/app/models/shipit/user.rb
@@ -1,9 +1,10 @@
# frozen_string_literal: true
+
module Shipit
class User < Record
DEFAULT_AVATAR = URI.parse('https://avatars.githubusercontent.com/u/583231?')
- self.ignored_columns = %w(encrypted_github_access_token_iv)
+ self.ignored_columns = %w[encrypted_github_access_token_iv]
has_many :memberships
has_many :teams, through: :memberships
@@ -19,7 +20,7 @@ class User < Record
after_find :discard_outdated_credentials!
def self.find_or_create_by_login!(login)
- find_or_create_by!(login: login) do |user|
+ find_or_create_by!(login:) do |user|
# Users are global, any app can be used
# This will not work for users that only exist in an Enterprise install
user.github_user = Shipit.github.api.user(login)
@@ -31,7 +32,7 @@ def self.find_or_create_committer_from_github_commit(github_commit)
end
def self.find_or_create_author_from_github_commit(github_commit)
- if (match_info = github_commit.commit.message.match(/^#{MergeRequest::MERGE_REQUEST_FIELD}: ([\w\-\.]+)$/))
+ if (match_info = github_commit.commit.message.match(/^#{MergeRequest::MERGE_REQUEST_FIELD}: ([\w\-.]+)$/))
begin
return find_or_create_by_login!(match_info[1])
rescue Octokit::NotFound
@@ -48,11 +49,12 @@ def self.find_or_create_from_github(github_user)
def self.find_from_github(github_user)
return unless github_user.id
+
find_by(github_id: github_user.id)
end
def self.create_from_github(github_user)
- create(github_user: github_user)
+ create(github_user:)
end
def self.refresh_shard(shard_index, shards_count)
@@ -68,7 +70,7 @@ def github_api
end
def identifiers_for_ping
- { github_id: github_id, name: name, email: email, github_login: login }
+ { github_id:, name:, email:, github_login: login }
end
def logged_in?
@@ -81,12 +83,14 @@ def authorized?
def repositories_contributed_to
return [] unless id
+
Stack.where(id: stacks_contributed_to).distinct.pluck(:repository_id)
end
def stacks_contributed_to
return [] unless id
- Commit.where('author_id = :id or committer_id = :id', id: id).distinct.pluck(:stack_id)
+
+ Commit.where('author_id = :id or committer_id = :id', id:).distinct.pluck(:stack_id)
end
def refresh_from_github!
@@ -112,7 +116,7 @@ def github_user=(github_user)
email: appropriate_email_for(github_user),
login: github_user.login,
avatar_url: github_user.avatar_url,
- api_url: github_user.url,
+ api_url: github_user.url
)
end
@@ -132,18 +136,19 @@ def requires_fresh_login?
private
def discard_outdated_credentials!
- if encrypted_github_access_token_before_type_cast.present?
- begin
- encrypted_github_access_token
- rescue ActiveRecord::Encryption::Errors::Decryption
- update_column(:encrypted_github_access_token, nil)
- end
+ return unless encrypted_github_access_token_before_type_cast.present?
+
+ begin
+ encrypted_github_access_token
+ rescue ActiveRecord::Encryption::Errors::Decryption
+ update_column(:encrypted_github_access_token, nil)
end
end
def identify_renamed_user!
last_commit = commits.last
return unless last_commit
+
github_author = last_commit.github_commit.author
update!(github_user: github_author)
rescue Octokit::NotFound
@@ -163,9 +168,9 @@ def appropriate_email_for(github_user)
begin
github_api.emails
- .sort_by { |e| e.primary ? 0 : 1 }
- .map(&:email)
- .find { |e| email_valid_and_preferred?(e) }
+ .sort_by { |e| e.primary ? 0 : 1 }
+ .map(&:email)
+ .find { |e| email_valid_and_preferred?(e) }
rescue Octokit::NotFound, Octokit::Forbidden, Octokit::Unauthorized
# If the user hasn't agreed to the necessary permission, we can't access their private emails.
Rails.logger.warn("Failed to retrieve emails for user '#{github_user.name || github_user.login}'")
diff --git a/app/models/shipit/variable_definition.rb b/app/models/shipit/variable_definition.rb
index 5093e81f2..bf9df0e8c 100644
--- a/app/models/shipit/variable_definition.rb
+++ b/app/models/shipit/variable_definition.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class VariableDefinition
attr_reader :name, :title, :default, :select
@@ -20,7 +21,7 @@ def to_h
'name' => @name,
'title' => @title,
'default' => @default,
- 'select' => @select,
+ 'select' => @select
}
end
end
diff --git a/app/models/shipit/webhooks.rb b/app/models/shipit/webhooks.rb
index d42c859bf..64a7c94a7 100644
--- a/app/models/shipit/webhooks.rb
+++ b/app/models/shipit/webhooks.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
module Webhooks
class << self
@@ -13,11 +14,11 @@ def default_handlers
Handlers::PullRequest::AssignedHandler,
Handlers::PullRequest::LabeledHandler,
Handlers::PullRequest::UnlabeledHandler,
- Handlers::PullRequest::LabelCapturingHandler,
+ Handlers::PullRequest::LabelCapturingHandler
],
'status' => [Handlers::StatusHandler],
'membership' => [Handlers::MembershipHandler],
- 'check_suite' => [Handlers::CheckSuiteHandler],
+ 'check_suite' => [Handlers::CheckSuiteHandler]
}
end
diff --git a/app/models/shipit/webhooks/handlers/check_suite_handler.rb b/app/models/shipit/webhooks/handlers/check_suite_handler.rb
index ac180d847..92bf68746 100644
--- a/app/models/shipit/webhooks/handlers/check_suite_handler.rb
+++ b/app/models/shipit/webhooks/handlers/check_suite_handler.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
module Webhooks
module Handlers
diff --git a/app/models/shipit/webhooks/handlers/handler.rb b/app/models/shipit/webhooks/handlers/handler.rb
index d9246f6ae..9057b39f2 100644
--- a/app/models/shipit/webhooks/handlers/handler.rb
+++ b/app/models/shipit/webhooks/handlers/handler.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
module Webhooks
module Handlers
diff --git a/app/models/shipit/webhooks/handlers/membership_handler.rb b/app/models/shipit/webhooks/handlers/membership_handler.rb
index f2db98060..e11f6c23d 100644
--- a/app/models/shipit/webhooks/handlers/membership_handler.rb
+++ b/app/models/shipit/webhooks/handlers/membership_handler.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
module Webhooks
module Handlers
diff --git a/app/models/shipit/webhooks/handlers/pull_request/assigned_handler.rb b/app/models/shipit/webhooks/handlers/pull_request/assigned_handler.rb
index a93757b2c..d5f8b08d2 100644
--- a/app/models/shipit/webhooks/handlers/pull_request/assigned_handler.rb
+++ b/app/models/shipit/webhooks/handlers/pull_request/assigned_handler.rb
@@ -52,16 +52,16 @@ def respond_to_assignee_change?
def pull_request
@pull_request ||= Shipit::PullRequest
- .joins(:stack, stack: :repository)
- .find_by(
- number: params.number,
- stacks: {
- repositories:
- {
- id: repository.id,
- },
- }
- )
+ .joins(:stack, stack: :repository)
+ .find_by(
+ number: params.number,
+ stacks: {
+ repositories:
+ {
+ id: repository.id
+ }
+ }
+ )
end
def repository
diff --git a/app/models/shipit/webhooks/handlers/pull_request/closed_handler.rb b/app/models/shipit/webhooks/handlers/pull_request/closed_handler.rb
index 89686016d..82153888a 100644
--- a/app/models/shipit/webhooks/handlers/pull_request/closed_handler.rb
+++ b/app/models/shipit/webhooks/handlers/pull_request/closed_handler.rb
@@ -55,7 +55,7 @@ def repository
def review_stack
@review_stack ||=
Shipit::Webhooks::Handlers::PullRequest::ReviewStackAdapter
- .new(params, scope: repository.review_stacks)
+ .new(params, scope: repository.review_stacks)
end
def respond_to_pull_request_closed?
diff --git a/app/models/shipit/webhooks/handlers/pull_request/edited_handler.rb b/app/models/shipit/webhooks/handlers/pull_request/edited_handler.rb
index db79583f6..b83ae28d8 100644
--- a/app/models/shipit/webhooks/handlers/pull_request/edited_handler.rb
+++ b/app/models/shipit/webhooks/handlers/pull_request/edited_handler.rb
@@ -48,16 +48,16 @@ def process
def pull_request
@pull_request ||= Shipit::PullRequest
- .joins(:stack, stack: :repository)
- .find_by(
- number: params.number,
- stacks: {
- repositories:
- {
- id: repository.id,
- },
- }
- )
+ .joins(:stack, stack: :repository)
+ .find_by(
+ number: params.number,
+ stacks: {
+ repositories:
+ {
+ id: repository.id
+ }
+ }
+ )
end
def repository
diff --git a/app/models/shipit/webhooks/handlers/pull_request/label_capturing_handler.rb b/app/models/shipit/webhooks/handlers/pull_request/label_capturing_handler.rb
index 361549cb2..76449f003 100644
--- a/app/models/shipit/webhooks/handlers/pull_request/label_capturing_handler.rb
+++ b/app/models/shipit/webhooks/handlers/pull_request/label_capturing_handler.rb
@@ -104,13 +104,13 @@ def capture_labels
def review_stack
@review_stack ||=
Shipit::Webhooks::Handlers::PullRequest::ReviewStackAdapter
- .new(params, scope: repository.review_stacks)
+ .new(params, scope: repository.review_stacks)
end
def repository
@repository ||=
Shipit::Repository
- .from_github_repo_name(params.repository.full_name) || NullRepository.new
+ .from_github_repo_name(params.repository.full_name) || NullRepository.new
end
def stack
diff --git a/app/models/shipit/webhooks/handlers/pull_request/labeled_handler.rb b/app/models/shipit/webhooks/handlers/pull_request/labeled_handler.rb
index 4e0e91d19..7bfa5ce61 100644
--- a/app/models/shipit/webhooks/handlers/pull_request/labeled_handler.rb
+++ b/app/models/shipit/webhooks/handlers/pull_request/labeled_handler.rb
@@ -59,12 +59,12 @@ def handle
def stack
@stack ||=
Shipit::Webhooks::Handlers::PullRequest::ReviewStackAdapter
- .new(params, scope: repository.review_stacks)
+ .new(params, scope: repository.review_stacks)
end
def repository
@repository ||= Shipit::Repository.from_github_repo_name(params.repository.full_name) ||
- Shipit::NullRepository.new
+ Shipit::NullRepository.new
end
def pull_request
diff --git a/app/models/shipit/webhooks/handlers/pull_request/reopened_handler.rb b/app/models/shipit/webhooks/handlers/pull_request/reopened_handler.rb
index d2d56825b..ee0549b18 100644
--- a/app/models/shipit/webhooks/handlers/pull_request/reopened_handler.rb
+++ b/app/models/shipit/webhooks/handlers/pull_request/reopened_handler.rb
@@ -55,7 +55,7 @@ def repository
def stack
@stack ||=
Shipit::Webhooks::Handlers::PullRequest::ReviewStackAdapter
- .new(params, scope: repository.review_stacks)
+ .new(params, scope: repository.review_stacks)
end
def pull_request
diff --git a/app/models/shipit/webhooks/handlers/pull_request/review_stack_adapter.rb b/app/models/shipit/webhooks/handlers/pull_request/review_stack_adapter.rb
index 56fd66610..b758734bc 100644
--- a/app/models/shipit/webhooks/handlers/pull_request/review_stack_adapter.rb
+++ b/app/models/shipit/webhooks/handlers/pull_request/review_stack_adapter.rb
@@ -13,7 +13,7 @@ def initialize(params, scope: Shipit::ReviewStack)
end
def stack
- @stack ||= scope.find_by(environment: environment)
+ @stack ||= scope.find_by(environment:)
end
def find_or_create!
@@ -87,9 +87,9 @@ def create!
def stack_attributes
{
branch: params.pull_request.head.ref,
- environment: environment,
+ environment:,
ignore_ci: false,
- continuous_deployment: false,
+ continuous_deployment: false
}
end
diff --git a/app/models/shipit/webhooks/handlers/pull_request/unlabeled_handler.rb b/app/models/shipit/webhooks/handlers/pull_request/unlabeled_handler.rb
index ebfb7d502..42767ae98 100644
--- a/app/models/shipit/webhooks/handlers/pull_request/unlabeled_handler.rb
+++ b/app/models/shipit/webhooks/handlers/pull_request/unlabeled_handler.rb
@@ -65,7 +65,7 @@ def repository
def stack
@stack ||=
Shipit::Webhooks::Handlers::PullRequest::ReviewStackAdapter
- .new(params, scope: repository.review_stacks)
+ .new(params, scope: repository.review_stacks)
end
def pull_request
diff --git a/app/models/shipit/webhooks/handlers/push_handler.rb b/app/models/shipit/webhooks/handlers/push_handler.rb
index 3f4663843..7464dbff1 100644
--- a/app/models/shipit/webhooks/handlers/push_handler.rb
+++ b/app/models/shipit/webhooks/handlers/push_handler.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
module Webhooks
module Handlers
@@ -9,7 +10,7 @@ class PushHandler < Handler
def process
stacks
.not_archived
- .where(branch: branch)
+ .where(branch:)
.find_each(&:sync_github)
end
diff --git a/app/models/shipit/webhooks/handlers/status_handler.rb b/app/models/shipit/webhooks/handlers/status_handler.rb
index f285fbdb8..b19e9af1f 100644
--- a/app/models/shipit/webhooks/handlers/status_handler.rb
+++ b/app/models/shipit/webhooks/handlers/status_handler.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
module Webhooks
module Handlers
diff --git a/app/serializers/concerns/shipit/conditional_attributes.rb b/app/serializers/concerns/shipit/conditional_attributes.rb
index 588f56fbf..c8f734c48 100644
--- a/app/serializers/concerns/shipit/conditional_attributes.rb
+++ b/app/serializers/concerns/shipit/conditional_attributes.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
module ConditionalAttributes
extend ActiveSupport::Concern
diff --git a/app/serializers/shipit/anonymous_user_serializer.rb b/app/serializers/shipit/anonymous_user_serializer.rb
index 470764957..039150815 100644
--- a/app/serializers/shipit/anonymous_user_serializer.rb
+++ b/app/serializers/shipit/anonymous_user_serializer.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class AnonymousUserSerializer < UserSerializer
end
diff --git a/app/serializers/shipit/command_line_user_serializer.rb b/app/serializers/shipit/command_line_user_serializer.rb
index 3cb7df90e..cf919cedd 100644
--- a/app/serializers/shipit/command_line_user_serializer.rb
+++ b/app/serializers/shipit/command_line_user_serializer.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class CommandLineUserSerializer < UserSerializer
end
diff --git a/app/serializers/shipit/commit_serializer.rb b/app/serializers/shipit/commit_serializer.rb
index e215720a5..3f89691cb 100644
--- a/app/serializers/shipit/commit_serializer.rb
+++ b/app/serializers/shipit/commit_serializer.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class CommitSerializer < ShortCommitSerializer
include GithubUrlHelper
@@ -24,7 +25,7 @@ def html_url
def pull_request
{
number: object.pull_request_number,
- html_url: github_pull_request_url(object),
+ html_url: github_pull_request_url(object)
}
end
diff --git a/app/serializers/shipit/deploy_serializer.rb b/app/serializers/shipit/deploy_serializer.rb
index 7b13376e4..61fab9f56 100644
--- a/app/serializers/shipit/deploy_serializer.rb
+++ b/app/serializers/shipit/deploy_serializer.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class DeploySerializer < TaskSerializer
include GithubUrlHelper
diff --git a/app/serializers/shipit/hook_serializer.rb b/app/serializers/shipit/hook_serializer.rb
index e81362151..e48218c09 100644
--- a/app/serializers/shipit/hook_serializer.rb
+++ b/app/serializers/shipit/hook_serializer.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class HookSerializer < ActiveModel::Serializer
include ConditionalAttributes
diff --git a/app/serializers/shipit/merge_request_serializer.rb b/app/serializers/shipit/merge_request_serializer.rb
index 1b9e91803..7f9b7d7d8 100644
--- a/app/serializers/shipit/merge_request_serializer.rb
+++ b/app/serializers/shipit/merge_request_serializer.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class MergeRequestSerializer < ActiveModel::Serializer
include GithubUrlHelper
@@ -8,7 +9,7 @@ class MergeRequestSerializer < ActiveModel::Serializer
has_one :head, serializer: ShortCommitSerializer
attributes :id, :number, :title, :github_id, :additions, :deletions, :state, :merge_status, :mergeable,
- :merge_requested_at, :rejection_reason, :html_url, :branch, :base_ref
+ :merge_requested_at, :rejection_reason, :html_url, :branch, :base_ref
def html_url
github_pull_request_url(object)
diff --git a/app/serializers/shipit/rollback_serializer.rb b/app/serializers/shipit/rollback_serializer.rb
index 5efddf1d0..abc8cd2e2 100644
--- a/app/serializers/shipit/rollback_serializer.rb
+++ b/app/serializers/shipit/rollback_serializer.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class RollbackSerializer < DeploySerializer
def type
diff --git a/app/serializers/shipit/short_commit_serializer.rb b/app/serializers/shipit/short_commit_serializer.rb
index 6f70609fa..a55bd6450 100644
--- a/app/serializers/shipit/short_commit_serializer.rb
+++ b/app/serializers/shipit/short_commit_serializer.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class ShortCommitSerializer < ActiveModel::Serializer
attributes :sha, :message
diff --git a/app/serializers/shipit/stack_serializer.rb b/app/serializers/shipit/stack_serializer.rb
index c08869f5f..43d7b46cd 100644
--- a/app/serializers/shipit/stack_serializer.rb
+++ b/app/serializers/shipit/stack_serializer.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class StackSerializer < ActiveModel::Serializer
include ConditionalAttributes
@@ -6,9 +7,9 @@ class StackSerializer < ActiveModel::Serializer
has_one :lock_author
attributes :id, :repo_owner, :repo_name, :environment, :html_url, :url, :tasks_url, :deploy_url,
- :merge_requests_url, :deploy_spec, :undeployed_commits_count, :is_locked, :lock_reason, :continuous_deployment,
- :created_at, :updated_at, :locked_since, :last_deployed_at, :branch, :merge_queue_enabled, :is_archived,
- :archived_since, :ignore_ci
+ :merge_requests_url, :deploy_spec, :undeployed_commits_count, :is_locked, :lock_reason,
+ :continuous_deployment, :created_at, :updated_at, :locked_since, :last_deployed_at, :branch,
+ :merge_queue_enabled, :is_archived, :archived_since, :ignore_ci
def url
api_stack_url(object)
diff --git a/app/serializers/shipit/tail_task_serializer.rb b/app/serializers/shipit/tail_task_serializer.rb
index 0a98a8474..bd4882b14 100644
--- a/app/serializers/shipit/tail_task_serializer.rb
+++ b/app/serializers/shipit/tail_task_serializer.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class TailTaskSerializer < ActiveModel::Serializer
include ChunksHelper
@@ -8,6 +9,7 @@ class TailTaskSerializer < ActiveModel::Serializer
def url
return @url if defined? @url
+
@url = next_chunks_url(task, last_byte: next_offset)
end
@@ -29,7 +31,7 @@ def include_rollback_url?
private
- alias_method :task, :object
+ alias task object
delegate :stack, to: :object
def next_offset
@@ -42,6 +44,7 @@ def last_byte
def rollback
return @rollback if defined? @rollback
+
@rollback = stack.rollbacks.where(parent_id: task.id).last
end
end
diff --git a/app/serializers/shipit/task_serializer.rb b/app/serializers/shipit/task_serializer.rb
index 792936b47..925549ffa 100644
--- a/app/serializers/shipit/task_serializer.rb
+++ b/app/serializers/shipit/task_serializer.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class TaskSerializer < ActiveModel::Serializer
include ConditionalAttributes
diff --git a/app/serializers/shipit/user_serializer.rb b/app/serializers/shipit/user_serializer.rb
index a18112fd8..bc4304e16 100644
--- a/app/serializers/shipit/user_serializer.rb
+++ b/app/serializers/shipit/user_serializer.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class UserSerializer < ActiveModel::Serializer
attributes :id, :name, :email, :login, :avatar_url, :created_at, :updated_at, :github_id, :anonymous
diff --git a/app/validators/ascii_only_validator.rb b/app/validators/ascii_only_validator.rb
index bc0bda063..4de8b3dde 100644
--- a/app/validators/ascii_only_validator.rb
+++ b/app/validators/ascii_only_validator.rb
@@ -1,8 +1,9 @@
# frozen_string_literal: true
+
class AsciiOnlyValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
- if value && !value.ascii_only?
- record.errors.add(attribute, :ascii)
- end
+ return unless value && !value.ascii_only?
+
+ record.errors.add(attribute, :ascii)
end
end
diff --git a/app/validators/subset_validator.rb b/app/validators/subset_validator.rb
index 3eecb397f..d71c9fea3 100644
--- a/app/validators/subset_validator.rb
+++ b/app/validators/subset_validator.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class SubsetValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
superset = options[:of]
diff --git a/app/views/shipit/ccmenu/project.xml.builder b/app/views/shipit/ccmenu/project.xml.builder
index b03ff293d..6a3fdd854 100644
--- a/app/views/shipit/ccmenu/project.xml.builder
+++ b/app/views/shipit/ccmenu/project.xml.builder
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
# Derived from http://timnew.me/blog/2013/04/07/multiple-project-summary-reporting-standard-cctray-xml-feed/
status_map = { 'backlogged' => 'failure', 'locked' => 'failure' }
xml.instruct!
@@ -10,6 +11,6 @@ xml.Projects do
activity: deploy.running? ? 'Building' : 'Sleeping',
lastBuildTime: deploy.ended_at || deploy.started_at || deploy.created_at,
lastBuildLabel: deploy.id,
- webUrl: stack_url(stack),
+ webUrl: stack_url(stack)
)
end
diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb
index 4ea9ee928..5c885d1d2 100644
--- a/config/initializers/inflections.rb
+++ b/config/initializers/inflections.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.acronym('CCMenu')
end
diff --git a/config/routes.rb b/config/routes.rb
index 7d5bce9a1..97a3d6b82 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
Shipit::Engine.routes.draw do
stack_id_format = %r{[^/]+/[^/]+/[^/]+}
repository_id_format = %r{[^/]+/[^/]+}
@@ -15,7 +16,7 @@
# API
namespace :api do
root to: 'base#index'
- resources :stacks, only: %i(index create)
+ resources :stacks, only: %i[index create]
scope '/stacks/*id', id: stack_id_format, as: :stack do
get '/' => 'stacks#show'
delete '/' => 'stacks#destroy'
@@ -25,24 +26,24 @@
scope '/stacks/*stack_id', stack_id: stack_id_format, as: :stack do
get '/ccmenu' => 'ccmenu#show', as: :ccmenu
- resource :lock, only: %i(create update destroy)
- resources :tasks, only: %i(index show) do
+ resource :lock, only: %i[create update destroy]
+ resources :tasks, only: %i[index show] do
resource :output, only: :show
member do
put :abort
end
end
- resources :deploys, only: %i(index create) do
- resources :release_statuses, only: %i(create)
+ resources :deploys, only: %i[index create] do
+ resources :release_statuses, only: %i[create]
end
- resources :rollbacks, only: %i(create)
- resources :commits, only: %i(index)
- resources :merge_requests, only: %i(index show update destroy)
+ resources :rollbacks, only: %i[create]
+ resources :commits, only: %i[index]
+ resources :merge_requests, only: %i[index show update destroy]
post '/task/:task_name' => 'tasks#trigger', as: :trigger_task
- resources :hooks, only: %i(index create show update destroy)
+ resources :hooks, only: %i[index create show update destroy]
end
- resources :hooks, only: %i(index create show update destroy)
+ resources :hooks, only: %i[index create show update destroy]
end
scope '/ccmenu/*stack_id', stack_id: stack_id_format, as: :ccmenu_url do
@@ -57,7 +58,7 @@
# Humans
resources :api_clients
- resources :repositories, only: %i(new index create)
+ resources :repositories, only: %i[new index create]
scope '/repositories/*id', id: repository_id_format, as: :repository do
get '/' => 'repositories#show'
patch '/' => 'repositories#update'
@@ -73,7 +74,7 @@
get :logout
end
- resources :stacks, only: %i(new create index)
+ resources :stacks, only: %i[new create index]
scope '/*id', id: stack_id_format, as: :stack do
get '/' => 'stacks#show'
patch '/' => 'stacks#update'
@@ -85,7 +86,7 @@
get :refresh, controller: :stacks # For easier design, sorry :/
post :clear_git_cache, controller: :stacks
- resource :continuous_delivery_schedule, only: %i(show update)
+ resource :continuous_delivery_schedule, only: %i[show update]
end
scope '/task/:id', controller: :tasks do
@@ -98,9 +99,9 @@
get '/stats' => 'stats#show', as: :stats
- resources :rollbacks, only: %i(create)
- resources :commits, only: %i(update)
- resources :tasks, only: %i(show) do
+ resources :rollbacks, only: %i[create]
+ resources :commits, only: %i[update]
+ resources :tasks, only: %i[show] do
collection do
get '' => 'tasks#index', as: :index
get ':definition_id/new' => 'tasks#new', as: :new
@@ -113,17 +114,17 @@
end
end
- resources :deploys, only: %i(show create) do
+ resources :deploys, only: %i[show create] do
get ':sha', sha: sha_format, on: :new, action: :new, as: ''
member do
get :rollback
get :revert
end
- resources :release_statuses, only: %i(create)
+ resources :release_statuses, only: %i[create]
end
- resources :merge_requests, only: %i(index destroy create)
+ resources :merge_requests, only: %i[index destroy create]
end
get '/stacks/:id' => 'stacks#lookup'
diff --git a/lib/shipit.rb b/lib/shipit.rb
index 5d1e70bfd..1a32d9a4b 100644
--- a/lib/shipit.rb
+++ b/lib/shipit.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'active_support/all'
require 'active_model_serializers'
require 'state_machines-activerecord'
@@ -60,17 +61,17 @@ module Shipit
extend self
GithubOrganizationUnknown = Class.new(StandardError)
- TOP_LEVEL_GH_KEYS = [:app_id, :installation_id, :webhook_secret, :private_key, :oauth, :domain]
+ TOP_LEVEL_GH_KEYS = [:app_id, :installation_id, :webhook_secret, :private_key, :oauth, :domain].freeze
delegate :table_name_prefix, to: :secrets
attr_accessor :disable_api_authentication, :timeout_exit_codes, :deployment_checks, :respect_bare_shipit_file,
- :database_serializer
+ :database_serializer
attr_writer(
:internal_hook_receivers,
:preferred_org_emails,
:task_execution_strategy,
- :task_logger,
+ :task_logger
)
def task_execution_strategy
@@ -80,7 +81,7 @@ def task_execution_strategy
self.timeout_exit_codes = [].freeze
self.respect_bare_shipit_file = true
- alias_method :respect_bare_shipit_file?, :respect_bare_shipit_file
+ alias respect_bare_shipit_file? respect_bare_shipit_file
def authentication_disabled?
ENV['SHIPIT_DISABLE_AUTH'].present?
@@ -104,7 +105,7 @@ def redis
logger: Rails.logger,
reconnect_attempts: 3,
reconnect_delay: 0.5,
- reconnect_delay_max: 1,
+ reconnect_delay_max: 1
)
end
@@ -116,6 +117,7 @@ module SafeJSON
class << self
def load(serial)
return nil if serial.nil?
+
# JSON.load is unsafe, we should use parse instead
JSON.parse(serial)
end
@@ -140,6 +142,7 @@ def load(serial)
def dump(object)
return if object.nil?
+
JSON.dump(object)
end
end
@@ -148,7 +151,7 @@ def dump(object)
self.database_serializer = TransitionalSerializer
def serialized_column(attribute_name, type: nil, coder: nil)
- column = Paquito::SerializedColumn.new(database_serializer, type, attribute_name: attribute_name)
+ column = Paquito::SerializedColumn.new(database_serializer, type, attribute_name:)
if coder
Paquito.chain(coder, column)
else
@@ -171,12 +174,14 @@ def github(organization: github_default_organization)
def github_default_organization
return nil unless secrets&.github
+
org = secrets.github.keys.first
TOP_LEVEL_GH_KEYS.include?(org) ? nil : org
end
def github_organizations
return [nil] unless github_default_organization
+
secrets.github.keys
end
@@ -187,9 +192,9 @@ def github_app_config(organization)
end
def legacy_github_api
- if secrets&.github_api.present?
- @legacy_github_api ||= github.new_client(access_token: secrets.github_api[:access_token])
- end
+ return unless secrets&.github_api.present?
+
+ @legacy_github_api ||= github.new_client(access_token: secrets.github_api[:access_token])
end
def user
@@ -208,7 +213,7 @@ def user_access_tokens_key
if secrets.user_access_tokens_key.present?
secrets.user_access_tokens_key
elsif secrets.secret_key_base
- Digest::SHA256.digest("user_access_tokens_key" + secrets.secret_key_base)
+ Digest::SHA256.digest("user_access_tokens_key#{secrets.secret_key_base}")
end
end
@@ -248,7 +253,7 @@ def all_settings_present?
@all_settings_present ||= [
secrets.github, # TODO: handle GitHub settings
redis_url,
- host,
+ host
].all?(&:present?)
end
@@ -262,10 +267,10 @@ def shell_paths
def revision
@revision ||= if revision_file.exist?
- revision_file.read
- else
- %x(git rev-parse HEAD)
- end.strip
+ revision_file.read
+ else
+ `git rev-parse HEAD`
+ end.strip
end
def default_inactivity_timeout
diff --git a/lib/shipit/cast_value.rb b/lib/shipit/cast_value.rb
index 3ab990084..e204c0617 100644
--- a/lib/shipit/cast_value.rb
+++ b/lib/shipit/cast_value.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
module CastValue
def to_boolean(value)
diff --git a/lib/shipit/command.rb b/lib/shipit/command.rb
index ab6e6a643..6f5eb7455 100644
--- a/lib/shipit/command.rb
+++ b/lib/shipit/command.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'pty'
require 'shellwords'
require 'fileutils'
@@ -27,7 +28,7 @@ def initialize(message, exit_code)
attr_reader :out, :chdir, :env, :args, :pid, :timeout
- def initialize(*args, default_timeout: Shipit.default_inactivity_timeout, env: {}, chdir:)
+ def initialize(*args, chdir:, default_timeout: Shipit.default_inactivity_timeout, env: {})
@args, options = parse_arguments(args)
@timeout = parse_timeout(options['timeout'] || options[:timeout]) || default_timeout
@env = env.transform_values { |v| v&.to_s }
@@ -83,6 +84,7 @@ def interpolated_arguments
def start(&block)
return if @started
+
@control_block = block
@out = @pid = nil
FileUtils.mkdir_p(@chdir)
@@ -106,10 +108,10 @@ def stream(&block)
start
begin
read_stream(@out, &block)
- rescue TimedOut => error
- yield red("No output received in the last #{timeout} seconds.") + "\n"
+ rescue TimedOut => e
+ yield "#{red("No output received in the last #{timeout} seconds.")}\n"
terminate!(&block)
- raise error
+ raise e
rescue Errno::EIO # Somewhat expected on Linux: http://stackoverflow.com/a/10306782
end
@@ -125,6 +127,7 @@ def red(text)
def stream!(&block)
stream(&block)
raise Failed.new(exit_message, code) unless success?
+
self
end
@@ -173,7 +176,7 @@ def terminate!(&block)
ensure
begin
read_stream(@out, &block)
- rescue
+ rescue StandardError
end
end
@@ -187,9 +190,8 @@ def kill_and_wait(sig, wait, &block)
rescue TimedOut
rescue Errno::EIO # EIO is somewhat expected on Linux: http://stackoverflow.com/a/10306782
# If we try to read the stream right after sending a signal, we often get an Errno::EIO.
- if reap_child!(block: false)
- return true
- end
+ return true if reap_child!(block: false)
+
# If we let the child a little bit of time, it solves it.
retry_count -= 1
if retry_count > 0
@@ -252,6 +254,7 @@ def signaled?
def reap_child!(block: true)
return @status if @status
return unless running? # Command was never started e.g. permission denied, not found etc
+
if block
_, @status = Process.waitpid2(@pid)
elsif res = Process.waitpid2(@pid, Process::WNOHANG)
diff --git a/lib/shipit/commands.rb b/lib/shipit/commands.rb
index cbbcff499..ad915fac8 100644
--- a/lib/shipit/commands.rb
+++ b/lib/shipit/commands.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class Commands
class << self
@@ -7,12 +8,13 @@ def for(model)
end
def git_version
- @git_version ||= parse_git_version(%x(git --version))
+ @git_version ||= parse_git_version(`git --version`)
end
def parse_git_version(raw_git_version)
match_info = raw_git_version.match(/(\d+\.\d+\.\d+)/)
raise 'git command not found' unless match_info
+
Gem::Version.new(match_info[1])
end
end
@@ -36,7 +38,7 @@ def base_env
@base_env ||= Shipit.env.merge(
'GITHUB_DOMAIN' => github.domain,
'GITHUB_TOKEN' => github.token,
- 'GIT_ASKPASS' => Shipit::Engine.root.join('lib', 'snippets', 'git-askpass').realpath.to_s,
+ 'GIT_ASKPASS' => Shipit::Engine.root.join('lib', 'snippets', 'git-askpass').realpath.to_s
)
end
diff --git a/lib/shipit/csv_serializer.rb b/lib/shipit/csv_serializer.rb
index 3696fe5ae..f7a3d0d7e 100644
--- a/lib/shipit/csv_serializer.rb
+++ b/lib/shipit/csv_serializer.rb
@@ -1,15 +1,18 @@
# frozen_string_literal: true
+
module Shipit
module CSVSerializer
extend self
def load(payload)
return [] if payload.blank?
+
payload.split(',')
end
def dump(array)
return nil if array.blank?
+
Array.wrap(array).join(',')
end
end
diff --git a/lib/shipit/deploy_commands.rb b/lib/shipit/deploy_commands.rb
index 8bba99c41..aadb09486 100644
--- a/lib/shipit/deploy_commands.rb
+++ b/lib/shipit/deploy_commands.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class DeployCommands < TaskCommands
def steps
@@ -10,7 +11,7 @@ def env
super.merge(
'SHA' => commit.sha,
'REVISION' => commit.sha,
- 'DIFF_LINK' => diff_url,
+ 'DIFF_LINK' => diff_url
)
end
diff --git a/lib/shipit/engine.rb b/lib/shipit/engine.rb
index b1279137f..990a4bc2e 100644
--- a/lib/shipit/engine.rb
+++ b/lib/shipit/engine.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class Engine < ::Rails::Engine
isolate_namespace Shipit
@@ -11,7 +12,7 @@ class Engine < ::Rails::Engine
# But if AR Encryption is already configured, we just use that
app.credentials[:active_record_encryption] = {
primary_key: Shipit.user_access_tokens_key,
- key_derivation_salt: Digest::SHA256.digest("salt:".b + Shipit.user_access_tokens_key),
+ key_derivation_salt: Digest::SHA256.digest("salt:".b + Shipit.user_access_tokens_key)
}
end
end
@@ -24,16 +25,16 @@ class Engine < ::Rails::Engine
Rails.application.credentials.deep_symbolize_keys!
app.config.assets.paths << Emoji.images_path
- app.config.assets.precompile += %w(
+ app.config.assets.precompile += %w[
favicon.ico
task.js
shipit.js
shipit.css
merge_status.js
merge_status.css
- )
+ ]
app.config.assets.precompile << proc do |path|
- path =~ %r{\Aplugins/[\-\w]+\.(js|css)\Z}
+ path =~ %r{\Aplugins/[-\w]+\.(js|css)\Z}
end
app.config.assets.precompile << proc do |path|
path.end_with?('.svg') || (path.start_with?('emoji/') && path.end_with?('.png'))
diff --git a/lib/shipit/environment_variables.rb b/lib/shipit/environment_variables.rb
index fdc2e029f..980a4f266 100644
--- a/lib/shipit/environment_variables.rb
+++ b/lib/shipit/environment_variables.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class EnvironmentVariables
NotPermitted = Class.new(StandardError)
@@ -12,6 +13,7 @@ def with(env)
def permit(variable_definitions)
return {} unless @env
raise "A whitelist is required to sanitize environment variables" unless variable_definitions
+
sanitize_env_vars(variable_definitions)
end
diff --git a/lib/shipit/first_parent_commits_iterator.rb b/lib/shipit/first_parent_commits_iterator.rb
index d8e0c262b..44672ccd6 100644
--- a/lib/shipit/first_parent_commits_iterator.rb
+++ b/lib/shipit/first_parent_commits_iterator.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class FirstParentCommitsIterator < OctokitIterator
def each
@@ -9,9 +10,7 @@ def each
next
end
- if last_ancestor.parents.empty? || last_ancestor.parents.first.sha == commit.sha
- yield last_ancestor = commit
- end
+ yield last_ancestor = commit if last_ancestor.parents.empty? || last_ancestor.parents.first.sha == commit.sha
end
end
end
diff --git a/lib/shipit/flock.rb b/lib/shipit/flock.rb
index 36f1f099b..f558a7d3b 100644
--- a/lib/shipit/flock.rb
+++ b/lib/shipit/flock.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'English'
require 'timeout'
require 'pathname'
@@ -16,19 +17,20 @@ def initialize(path)
def lock(timeout:)
return yield if @acquired
+
path.parent.mkpath
path.open('w') do |file|
- if retrying(timeout: timeout) { file.flock(File::LOCK_EX | File::LOCK_NB) }
- file.write($PROCESS_ID.to_s)
- @acquired = true
- begin
- yield
- ensure
- @acquired = false
- end
- else
+ unless retrying(timeout:) { file.flock(File::LOCK_EX | File::LOCK_NB) }
raise TimeoutError, "Couldn't acquire lock for #{path} in #{timeout} seconds"
end
+
+ file.write($PROCESS_ID.to_s)
+ @acquired = true
+ begin
+ yield
+ ensure
+ @acquired = false
+ end
end
end
diff --git a/lib/shipit/github_app.rb b/lib/shipit/github_app.rb
index ae27297e0..4aebcbc4d 100644
--- a/lib/shipit/github_app.rb
+++ b/lib/shipit/github_app.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class GitHubApp
include Mutex_m
@@ -62,9 +63,7 @@ def login
def api
client = (Thread.current[:github_client] ||= new_client(access_token: token))
- if client.access_token != token
- client.access_token = token
- end
+ client.access_token = token if client.access_token != token
client
end
@@ -99,14 +98,15 @@ def fetch_new_token
Rails.cache.fetch(
"github:integration:#{cache_key}access-token",
expires_in: GITHUB_TOKEN_RAILS_CACHE_LIFETIME,
- race_condition_ttl: 4.minutes,
+ race_condition_ttl: 4.minutes
) do
response = new_client(bearer_token: authentication_payload).create_app_installation_access_token(
- installation_id,
+ installation_id
)
token = Token.from_github(response)
raise AuthenticationFailed if token.blank?
- Rails.logger.info("Created GitHub access token ending #{token.to_s[-5..-1]}, expires at #{token.expires_at}"\
+
+ Rails.logger.info("Created GitHub access token ending #{token.to_s[-5..]}, expires at #{token.expires_at}"\
" and will be refreshed at #{token&.refresh_at}")
token
end
@@ -122,14 +122,14 @@ def oauth_config
options = {
site: api_endpoint,
authorize_url: url('/login/oauth/authorize'),
- token_url: url('/login/oauth/access_token'),
+ token_url: url('/login/oauth/access_token')
}
end
[
oauth_id,
oauth_secret,
- client_options: options,
+ { client_options: options }
]
end
@@ -153,8 +153,8 @@ def enterprise?
def new_client(options = {})
if enterprise?
options = options.reverse_merge(
- api_endpoint: api_endpoint,
- web_endpoint: web_endpoint,
+ api_endpoint:,
+ web_endpoint:
)
end
client = Octokit::Client.new(options)
@@ -173,7 +173,7 @@ def faraday_stack
shared_cache: false,
store: Rails.cache,
logger: Rails.logger,
- serializer: NullSerializer,
+ serializer: NullSerializer
)
builder.use(GitHubHTTPCacheMiddleware)
builder.use(Octokit::Response::RaiseError)
@@ -197,7 +197,7 @@ def authentication_payload
payload = {
iat: Time.now.to_i,
exp: 10.minutes.from_now.to_i,
- iss: app_id,
+ iss: app_id
}
key = OpenSSL::PKey::RSA.new(private_key)
JWT.encode(payload, key, 'RS256')
diff --git a/lib/shipit/github_http_cache_middleware.rb b/lib/shipit/github_http_cache_middleware.rb
index 2accebede..132734c81 100644
--- a/lib/shipit/github_http_cache_middleware.rb
+++ b/lib/shipit/github_http_cache_middleware.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class GitHubHTTPCacheMiddleware < Faraday::Middleware
def call(request_env)
diff --git a/lib/shipit/null_serializer.rb b/lib/shipit/null_serializer.rb
index 085a3997d..432e1529e 100644
--- a/lib/shipit/null_serializer.rb
+++ b/lib/shipit/null_serializer.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
module NullSerializer
extend self
diff --git a/lib/shipit/octokit_check_runs.rb b/lib/shipit/octokit_check_runs.rb
index 4b13172b1..5f8b12a79 100644
--- a/lib/shipit/octokit_check_runs.rb
+++ b/lib/shipit/octokit_check_runs.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module OctokitCheckRuns
def check_runs(repo, sha, options = {})
paginate("#{Octokit::Repository.path(repo)}/commits/#{sha}/check-runs", options)
diff --git a/lib/shipit/octokit_iterator.rb b/lib/shipit/octokit_iterator.rb
index 3a113cb1b..9d594f71e 100644
--- a/lib/shipit/octokit_iterator.rb
+++ b/lib/shipit/octokit_iterator.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class OctokitIterator
include Enumerable
@@ -20,6 +21,7 @@ def each(&block)
response.data.each(&block)
return unless response.rels[:next]
+
response = response.rels[:next].get
end
end
diff --git a/lib/shipit/paginator.rb b/lib/shipit/paginator.rb
index 6016e04f1..d044f3494 100644
--- a/lib/shipit/paginator.rb
+++ b/lib/shipit/paginator.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class Paginator
def initialize(resources, controller, order: { id: :desc }, max_page_size: 100, default_page_size: 30)
diff --git a/lib/shipit/rollback_commands.rb b/lib/shipit/rollback_commands.rb
index a3effab84..e22cc1b53 100644
--- a/lib/shipit/rollback_commands.rb
+++ b/lib/shipit/rollback_commands.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class RollbackCommands < DeployCommands
def steps
@@ -7,7 +8,7 @@ def steps
def env
super.merge(
- 'ROLLBACK' => '1',
+ 'ROLLBACK' => '1'
)
end
end
diff --git a/lib/shipit/same_site_cookie_middleware.rb b/lib/shipit/same_site_cookie_middleware.rb
index 99212ebcc..92a8e1548 100644
--- a/lib/shipit/same_site_cookie_middleware.rb
+++ b/lib/shipit/same_site_cookie_middleware.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class SameSiteCookieMiddleware
COOKIE_SEPARATOR = "\n"
diff --git a/lib/shipit/simple_message_verifier.rb b/lib/shipit/simple_message_verifier.rb
index 15a2079b3..c82a0f63d 100644
--- a/lib/shipit/simple_message_verifier.rb
+++ b/lib/shipit/simple_message_verifier.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
class SimpleMessageVerifier < ActiveSupport::MessageVerifier
def initialize(secret, **options)
diff --git a/lib/shipit/stack_commands.rb b/lib/shipit/stack_commands.rb
index 9f4b63cc3..3097f5391 100644
--- a/lib/shipit/stack_commands.rb
+++ b/lib/shipit/stack_commands.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
-# rubocop:disable Lint/MissingSuper
+
+# rubocop:disable Lint/MissingCopEnableDirective, Lint/MissingSuper
require 'pathname'
require 'fileutils'
@@ -16,26 +17,26 @@ def env
def fetch_commit(commit)
create_directories
if valid_git_repository?(@stack.git_path)
- git('fetch', 'origin', *quiet_git_arg, '--tags', '--force', commit.sha, env: env, chdir: @stack.git_path)
+ git('fetch', 'origin', *quiet_git_arg, '--tags', '--force', commit.sha, env:, chdir: @stack.git_path)
else
@stack.clear_git_cache!
- git_clone(@stack.repo_git_url, @stack.git_path, branch: @stack.branch, env: env, chdir: @stack.deploys_path)
+ git_clone(@stack.repo_git_url, @stack.git_path, branch: @stack.branch, env:, chdir: @stack.deploys_path)
end
end
def fetch
create_directories
if valid_git_repository?(@stack.git_path)
- git('fetch', 'origin', *quiet_git_arg, '--tags', '--force', @stack.branch, env: env, chdir: @stack.git_path)
+ git('fetch', 'origin', *quiet_git_arg, '--tags', '--force', @stack.branch, env:, chdir: @stack.git_path)
else
@stack.clear_git_cache!
- git_clone(@stack.repo_git_url, @stack.git_path, branch: @stack.branch, env: env, chdir: @stack.deploys_path)
+ git_clone(@stack.repo_git_url, @stack.git_path, branch: @stack.branch, env:, chdir: @stack.deploys_path)
end
end
def fetched?(commit)
if valid_git_repository?(@stack.git_path)
- git('rev-parse', *quiet_git_arg, '--verify', "#{commit.sha}^{commit}", env: env, chdir: @stack.git_path)
+ git('rev-parse', *quiet_git_arg, '--verify', "#{commit.sha}^{commit}", env:, chdir: @stack.git_path)
else
# When the stack's git cache is not valid, the commit is
# NOT fetched. To keep the interface of this method
@@ -43,7 +44,7 @@ def fetched?(commit)
# method returns false - has a non-zero exit status. We utilize
# the POSIX 'test' command with no arguments which should
# always have an exit status of 1.
- Command.new('test', env: env, chdir: @stack.deploys_path)
+ Command.new('test', env:, chdir: @stack.deploys_path)
end
end
@@ -51,7 +52,7 @@ def fetch_deployed_revision
with_temporary_working_directory(commit: @stack.commits.reachable.last) do |dir|
spec = DeploySpec::FileSystem.new(dir, @stack)
outputs = spec.fetch_deployed_revision_steps!.map do |command_line|
- Command.new(command_line, env: env, chdir: dir).run
+ Command.new(command_line, env:, chdir: dir).run
end
outputs.find(&:present?).try(:strip)
end
@@ -68,9 +69,7 @@ def with_temporary_working_directory(commit: nil, recursive: true)
if !commit || !fetched?(commit).tap(&:run).success?
@stack.acquire_git_cache_lock do
- unless fetched?(commit).tap(&:run).success?
- fetch.run!
- end
+ fetch.run! unless fetched?(commit).tap(&:run).success?
end
end
@@ -84,14 +83,16 @@ def with_temporary_working_directory(commit: nil, recursive: true)
).run!
git_dir = File.join(dir, @stack.repo_name)
- git(
- '-c',
- 'advice.detachedHead=false',
- 'checkout',
- *quiet_git_arg,
- commit.sha,
- chdir: git_dir
- ).run! if commit
+ if commit
+ git(
+ '-c',
+ 'advice.detachedHead=false',
+ 'checkout',
+ *quiet_git_arg,
+ commit.sha,
+ chdir: git_dir
+ ).run!
+ end
yield Pathname.new(git_dir)
end
end
@@ -114,7 +115,8 @@ def git_clone(url, path, branch: 'main', **kwargs)
def modern_git_args
return [] unless git_version >= Gem::Version.new('1.7.10')
- %w(--single-branch)
+
+ %w[--single-branch]
end
def create_directories
diff --git a/lib/shipit/stat.rb b/lib/shipit/stat.rb
index 03dc16302..c9b8b90fd 100644
--- a/lib/shipit/stat.rb
+++ b/lib/shipit/stat.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
module Stat
extend self
diff --git a/lib/shipit/task_commands.rb b/lib/shipit/task_commands.rb
index 53c61ca87..866480500 100644
--- a/lib/shipit/task_commands.rb
+++ b/lib/shipit/task_commands.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
-# rubocop:disable Lint/MissingSuper
+
+# rubocop:disable Lint/MissingCopEnableDirective, Lint/MissingSuper
module Shipit
class TaskCommands < Commands
delegate :fetch_commit, :fetch, :fetched?, to: :stack_commands
@@ -15,13 +16,13 @@ def deploy_spec
def install_dependencies
deploy_spec.dependencies_steps!.map do |command_line|
- Command.new(command_line, env: env, chdir: steps_directory)
+ Command.new(command_line, env:, chdir: steps_directory)
end
end
def perform
steps.map do |command_line|
- Command.new(command_line, env: env, chdir: steps_directory)
+ Command.new(command_line, env:, chdir: steps_directory)
end
end
@@ -40,7 +41,7 @@ def env
'TASK_ID' => @task.id.to_s,
'IGNORED_SAFETIES' => @task.ignored_safeties? ? '1' : '0',
'GIT_COMMITTER_NAME' => @task.user&.name || Shipit.committer_name,
- 'GIT_COMMITTER_EMAIL' => @task.user&.email || Shipit.committer_email,
+ 'GIT_COMMITTER_EMAIL' => @task.user&.email || Shipit.committer_email
)
.merge(deploy_spec.machine_env)
.merge(@task.env)
@@ -68,7 +69,7 @@ def clone
@task.working_directory,
chdir: @stack.deploys_path
),
- git('remote', 'add', 'origin', @stack.repo_git_url, chdir: @task.working_directory),
+ git('remote', 'add', 'origin', @stack.repo_git_url, chdir: @task.working_directory)
]
end
diff --git a/lib/shipit/version.rb b/lib/shipit/version.rb
index 528579f6b..33ed9f8b5 100644
--- a/lib/shipit/version.rb
+++ b/lib/shipit/version.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module Shipit
VERSION = '0.39.0'
end
diff --git a/lib/tasks/cron.rake b/lib/tasks/cron.rake
index 038fc2647..33306baf2 100644
--- a/lib/tasks/cron.rake
+++ b/lib/tasks/cron.rake
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
namespace :cron do
desc "Updates deployed revisions"
task minutely: :environment do
@@ -10,7 +11,7 @@ namespace :cron do
Shipit::ReviewStackProvisioningQueue.work
end
- task hourly: %i(rollup refresh_users clear_stale_caches delete_old_deployment_directories)
+ task hourly: %i[rollup refresh_users clear_stale_caches delete_old_deployment_directories]
desc "Rolls-up output chunks for completed deploys older than an hour"
task rollup: :environment do
diff --git a/lib/tasks/dev.rake b/lib/tasks/dev.rake
index f02e1a4d3..99d0e232b 100644
--- a/lib/tasks/dev.rake
+++ b/lib/tasks/dev.rake
@@ -1,9 +1,10 @@
# frozen_string_literal: true
+
namespace :dev do
desc "Appends chunks to the last deploy, or specify with DEPLOY=id"
task stream: :environment do
require 'faker'
- logger = Logger.new(STDOUT)
+ logger = Logger.new($stdout)
deploy = Shipit::Deploy.find(ENV['DEPLOY']) if ENV['DEPLOY']
deploy ||= Deploy.last
@@ -25,7 +26,7 @@ namespace :dev do
logger.error(sentence)
- deploy.chunks.create(text: sentence + "\n")
+ deploy.chunks.create(text: "#{sentence}\n")
sleep 1
end
end
diff --git a/lib/tasks/shipit.rake b/lib/tasks/shipit.rake
index 672e3452b..6fe922249 100644
--- a/lib/tasks/shipit.rake
+++ b/lib/tasks/shipit.rake
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
namespace :shipit do
desc "Deploy from a running instance. "
task deploy: :environment do
@@ -12,12 +13,12 @@ namespace :shipit do
class Task
def write(text)
p(text)
- chunks.create!(text: text)
+ chunks.create!(text:)
end
end
end
- Shipit::Stack.run_deploy_in_foreground(stack: stack, revision: revision)
+ Shipit::Stack.run_deploy_in_foreground(stack:, revision:)
rescue ArgumentError
p("Use this command as follows:")
p("bundle exec rake shipit:deploy stack='shopify/shipit/production' revision='$SHA'")
diff --git a/lib/tasks/teams.rake b/lib/tasks/teams.rake
index 885ad0748..b9123fdc5 100644
--- a/lib/tasks/teams.rake
+++ b/lib/tasks/teams.rake
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
namespace :teams do
desc "Import the members of each team configured through the github.oauth.teams config"
task fetch: :environment do
@@ -6,9 +7,9 @@ namespace :teams do
puts "Fetching @#{team.handle} members"
begin
team.refresh_members!
- rescue Octokit::Unauthorized, Octokit::NotFound => error
+ rescue Octokit::Unauthorized, Octokit::NotFound => e
puts "Failed to fetch @#{team.handle} members. Do you have enough permissions?"
- puts "#{error.class}: #{error.message}"
+ puts "#{e.class}: #{e.message}"
end
end
end
diff --git a/shipit-engine.gemspec b/shipit-engine.gemspec
index 9ac89aa91..8a641800e 100644
--- a/shipit-engine.gemspec
+++ b/shipit-engine.gemspec
@@ -1,5 +1,6 @@
# frozen_string_literal: true
-$LOAD_PATH.push(File.expand_path('../lib', __FILE__))
+
+$LOAD_PATH.push(File.expand_path('lib', __dir__))
# Maintain your gem's version:
require 'shipit/version'
@@ -31,21 +32,21 @@ Gem::Specification.new do |s|
s.add_dependency('lodash-rails', '~> 4.17')
s.add_dependency('octokit', '~> 5.6.0')
s.add_dependency('omniauth-github', '~> 1.4')
+ s.add_dependency('paquito')
s.add_dependency('pubsubstub', '~> 0.2.0')
s.add_dependency('rails', '~> 7.2.1')
- s.add_dependency('rails-timeago', '~> 2.13.0')
s.add_dependency('rails_autolink', '~> 1.1.6')
+ s.add_dependency('rails-timeago', '~> 2.13.0')
s.add_dependency('rake')
s.add_dependency('redis-objects', '~> 1.5')
s.add_dependency('responders', '~> 3.0')
s.add_dependency('safe_yaml', '~> 1.0.4')
s.add_dependency('sass-rails', '>= 5.0')
s.add_dependency('securecompare', '~> 1.0.0')
- s.add_dependency('sprockets-rails', '>= 2.3.2')
s.add_dependency('sprockets', '< 4')
+ s.add_dependency('sprockets-rails', '>= 2.3.2')
s.add_dependency('state_machines-activerecord', '~> 0.8.0')
s.add_dependency('validate_url', '~> 1.0.0')
- s.add_dependency('paquito')
s.metadata['allowed_push_host'] = 'https://rubygems.org'
end
diff --git a/test/controllers/api/base_controller_test.rb b/test/controllers/api/base_controller_test.rb
index 348514a46..09099e474 100644
--- a/test/controllers/api/base_controller_test.rb
+++ b/test/controllers/api/base_controller_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/controllers/api/ccmenu_controller_test.rb b/test/controllers/api/ccmenu_controller_test.rb
index ba3dbdf2a..d87a87939 100644
--- a/test/controllers/api/ccmenu_controller_test.rb
+++ b/test/controllers/api/ccmenu_controller_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -32,7 +33,7 @@ class CCMenuControllerTest < ApiControllerTestCase
test "xml contains required attributes" do
get :show, params: { stack_id: @stack.to_param }
project = get_project_from_xml(response.body)
- %w(name activity lastBuildStatus lastBuildLabel lastBuildTime webUrl).each do |attribute|
+ %w[name activity lastBuildStatus lastBuildLabel lastBuildTime webUrl].each do |attribute|
assert_includes project, attribute, "Response missing required attribute: #{attribute}"
end
end
@@ -55,9 +56,9 @@ def get_project_from_xml(xml)
Hash.from_xml(xml)['Projects']['Project']
end
- def assert_payload(k, v)
+ def assert_payload(key, value)
@project ||= get_project_from_xml(response.body)
- assert_equal(v, @project[k])
+ assert_equal(value, @project[key])
end
end
end
diff --git a/test/controllers/api/commits_controller_test.rb b/test/controllers/api/commits_controller_test.rb
index 793216eae..727b8227d 100644
--- a/test/controllers/api/commits_controller_test.rb
+++ b/test/controllers/api/commits_controller_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/controllers/api/deploys_controller_test.rb b/test/controllers/api/deploys_controller_test.rb
index eb17b2abd..cd9971730 100644
--- a/test/controllers/api/deploys_controller_test.rb
+++ b/test/controllers/api/deploys_controller_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/controllers/api/hooks_controller_test.rb b/test/controllers/api/hooks_controller_test.rb
index 1b592d7d0..bcca9c2c8 100644
--- a/test/controllers/api/hooks_controller_test.rb
+++ b/test/controllers/api/hooks_controller_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -49,7 +50,7 @@ class HooksControllerTest < ApiControllerTestCase
test "#create adds a new hook" do
assert_difference -> { Hook.count }, 1 do
- post :create, params: { delivery_url: 'https://example.com/hook', events: %w(deploy rollback) }
+ post :create, params: { delivery_url: 'https://example.com/hook', events: %w[deploy rollback] }
end
hook = Hook.last
assert_json 'delivery_url', 'https://example.com/hook'
@@ -60,14 +61,14 @@ class HooksControllerTest < ApiControllerTestCase
test "#create do not allow to set protected attributes" do
post :create, params: {
delivery_url: 'https://example.com/hook',
- events: %w(deploy rollback),
- created_at: 2.months.ago.to_formatted_s(:db),
+ events: %w[deploy rollback],
+ created_at: 2.months.ago.to_formatted_s(:db)
}
assert_operator Hook.last.created_at, :>, 2.seconds.ago
end
test "#create returns validation errors" do
- post :create, params: { delivery_url: '../etc/passwd', events: %w(deploy) }
+ post :create, params: { delivery_url: '../etc/passwd', events: %w[deploy] }
assert_response :unprocessable_entity
assert_json 'errors', 'delivery_url' => ['is not a valid URL']
end
diff --git a/test/controllers/api/locks_controller_test.rb b/test/controllers/api/locks_controller_test.rb
index faf47aeb1..f5375cdfb 100644
--- a/test/controllers/api/locks_controller_test.rb
+++ b/test/controllers/api/locks_controller_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/controllers/api/merge_requests_controller_test.rb b/test/controllers/api/merge_requests_controller_test.rb
index 7ed252cdd..561b89b82 100644
--- a/test/controllers/api/merge_requests_controller_test.rb
+++ b/test/controllers/api/merge_requests_controller_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/controllers/api/outputs_controller_test.rb b/test/controllers/api/outputs_controller_test.rb
index a2c158e93..4510e989e 100644
--- a/test/controllers/api/outputs_controller_test.rb
+++ b/test/controllers/api/outputs_controller_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/controllers/api/release_statuses_controller_test.rb b/test/controllers/api/release_statuses_controller_test.rb
index 7af530290..8351c6e3e 100644
--- a/test/controllers/api/release_statuses_controller_test.rb
+++ b/test/controllers/api/release_statuses_controller_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -21,7 +22,7 @@ class ReleaseStatusesControllerTest < ApiControllerTestCase
post :create, params: {
stack_id: @stack.to_param,
deploy_id: @deploy.id,
- status: 'foo',
+ status: 'foo'
}
end
@@ -34,7 +35,7 @@ class ReleaseStatusesControllerTest < ApiControllerTestCase
post :create, params: {
stack_id: @stack.to_param,
deploy_id: @deploy.id,
- status: 'success',
+ status: 'success'
}
assert_response :created
end
@@ -51,7 +52,7 @@ class ReleaseStatusesControllerTest < ApiControllerTestCase
post :create, params: {
stack_id: @stack.to_param,
deploy_id: @deploy.id,
- status: 'failure',
+ status: 'failure'
}
assert_response :created
end
diff --git a/test/controllers/api/rollback_controller_test.rb b/test/controllers/api/rollback_controller_test.rb
index e67941a14..13b56635c 100644
--- a/test/controllers/api/rollback_controller_test.rb
+++ b/test/controllers/api/rollback_controller_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/controllers/api/stacks_controller_test.rb b/test/controllers/api/stacks_controller_test.rb
index 0586d221a..58cc0e87e 100644
--- a/test/controllers/api/stacks_controller_test.rb
+++ b/test/controllers/api/stacks_controller_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -41,24 +42,24 @@ class StacksControllerTest < ApiControllerTestCase
test "#create fails to create stack if it already exists" do
repository = shipit_repositories(:rails)
existing_stack = Stack.create!(
- repository: repository,
+ repository:,
environment: 'staging',
- branch: 'staging',
+ branch: 'staging'
)
assert_no_difference -> { Stack.count } do
post :create,
- params: {
- repo_name: existing_stack.repo_name,
- repo_owner: existing_stack.repo_owner,
- environment: existing_stack.environment,
- branch: existing_stack.branch,
- }
+ params: {
+ repo_name: existing_stack.repo_name,
+ repo_owner: existing_stack.repo_owner,
+ environment: existing_stack.environment,
+ branch: existing_stack.branch
+ }
end
assert_response :unprocessable_entity
assert_json 'errors', 'repository' => [
- 'cannot be used more than once with this environment. Check archived stacks.',
+ 'cannot be used more than once with this environment. Check archived stacks.'
]
end
@@ -71,7 +72,7 @@ class StacksControllerTest < ApiControllerTestCase
id: @stack.to_param,
merge_queue_enabled: false,
ignore_ci: true,
- continuous_deployment: true,
+ continuous_deployment: true
}
assert_response :ok
@@ -87,7 +88,7 @@ class StacksControllerTest < ApiControllerTestCase
patch :update, params: {
id: @stack.to_param,
- branch: 'test',
+ branch: 'test'
}
assert_response :ok
@@ -104,7 +105,7 @@ class StacksControllerTest < ApiControllerTestCase
patch :update, params: {
id: @stack.to_param,
- continuous_deployment: false,
+ continuous_deployment: false
}
assert_response :ok
diff --git a/test/controllers/api/tasks_controller_test.rb b/test/controllers/api/tasks_controller_test.rb
index 4649e413d..03b64f59e 100644
--- a/test/controllers/api/tasks_controller_test.rb
+++ b/test/controllers/api/tasks_controller_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -39,42 +40,42 @@ class TasksControllerTest < ApiControllerTestCase
expected_env = {
"FOO" => "1",
- "BAR" => "0",
+ "BAR" => "0"
}
assert_equal expected_env, Shipit::Task.last.env
end
test "#trigger refuses to trigger a task with tasks not whitelisted" do
env = { 'DANGEROUS_VARIABLE' => 'bar' }
- post :trigger, params: { stack_id: @stack.to_param, task_name: 'restart', env: env }
+ post :trigger, params: { stack_id: @stack.to_param, task_name: 'restart', env: }
assert_response :unprocessable_entity
assert_json 'message', 'Variables DANGEROUS_VARIABLE have not been whitelisted'
end
test "#trigger triggers a task with only whitelisted env variables" do
env = { 'FOO' => 'bar' }
- post :trigger, params: { stack_id: @stack.to_param, task_name: 'restart', env: env }
+ post :trigger, params: { stack_id: @stack.to_param, task_name: 'restart', env: }
assert_response :accepted
assert_json 'type', 'task'
assert_json 'status', 'pending'
expected_env = {
"FOO" => "bar",
- "BAR" => "0",
+ "BAR" => "0"
}
assert_equal expected_env, Shipit::Task.last.env
end
test "#trigger triggers a task with explicitly passed and default variables" do
env = { 'WALRUS' => 'overridden value' }
- post :trigger, params: { stack_id: @stack.to_param, task_name: 'restart', env: env }
+ post :trigger, params: { stack_id: @stack.to_param, task_name: 'restart', env: }
assert_response :accepted
# FOO and BAR are variables with a default value
expected_env = {
"FOO" => "1",
"BAR" => "0",
- "WALRUS" => "overridden value",
+ "WALRUS" => "overridden value"
}
assert_equal expected_env, Shipit::Task.last.env
end
diff --git a/test/controllers/api_clients_controller_test.rb b/test/controllers/api_clients_controller_test.rb
index 350cba900..3ad42e43f 100644
--- a/test/controllers/api_clients_controller_test.rb
+++ b/test/controllers/api_clients_controller_test.rb
@@ -23,7 +23,7 @@ class ApiClientsControllerTest < ActionController::TestCase
assert_response :forbidden
assert_equal(
'You must be a member of cyclimse/cooks or shopify/developers to access this application.',
- response.body,
+ response.body
)
end
@@ -44,9 +44,9 @@ class ApiClientsControllerTest < ActionController::TestCase
name: 'walrus_app',
permissions: [
'read:stack',
- 'lock:stack',
- ],
- },
+ 'lock:stack'
+ ]
+ }
}
end
@@ -59,9 +59,9 @@ class ApiClientsControllerTest < ActionController::TestCase
name: 'walrus_app',
permissions: [
'read:stack',
- 'lock:stack',
- ],
- },
+ 'lock:stack'
+ ]
+ }
}
assert_equal shipit_users(:walrus).id, ApiClient.last.creator.id
@@ -84,15 +84,15 @@ class ApiClientsControllerTest < ActionController::TestCase
test "#update updates an existing api_client" do
new_permissions = [
'read:stack',
- 'lock:stack',
+ 'lock:stack'
]
assert_difference "ApiClient.count", 0 do
patch :update, params: {
id: @api_client.id,
api_client: {
- permissions: new_permissions,
- },
+ permissions: new_permissions
+ }
}
end
@api_client.reload
diff --git a/test/controllers/ccmenu_controller_test.rb b/test/controllers/ccmenu_controller_test.rb
index b04df76d5..4bcf8e9bf 100644
--- a/test/controllers/ccmenu_controller_test.rb
+++ b/test/controllers/ccmenu_controller_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'uri'
require 'test_helper'
diff --git a/test/controllers/commit_checks_controller_test.rb b/test/controllers/commit_checks_controller_test.rb
index 41e7ad7ad..4131e01ed 100644
--- a/test/controllers/commit_checks_controller_test.rb
+++ b/test/controllers/commit_checks_controller_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/controllers/commits_controller_test.rb b/test/controllers/commits_controller_test.rb
index 07548d139..122a56c4a 100644
--- a/test/controllers/commits_controller_test.rb
+++ b/test/controllers/commits_controller_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -14,10 +15,10 @@ class CommitsControllerTest < ActionController::TestCase
refute_predicate(@commit, :locked?)
patch(:update, params: {
- stack_id: @stack.to_param,
- id: @commit.id,
- commit: { locked: true },
- })
+ stack_id: @stack.to_param,
+ id: @commit.id,
+ commit: { locked: true }
+ })
assert_response(:ok)
@commit.reload
@@ -29,10 +30,10 @@ class CommitsControllerTest < ActionController::TestCase
@commit.lock(@user)
patch(:update, params: {
- stack_id: @stack.to_param,
- id: @commit.id,
- commit: { locked: false },
- })
+ stack_id: @stack.to_param,
+ id: @commit.id,
+ commit: { locked: false }
+ })
assert_response(:ok)
@commit.reload
diff --git a/test/controllers/continuous_delivery_schedules_controller_test.rb b/test/controllers/continuous_delivery_schedules_controller_test.rb
index af36fe1b6..3cd4398ee 100644
--- a/test/controllers/continuous_delivery_schedules_controller_test.rb
+++ b/test/controllers/continuous_delivery_schedules_controller_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -25,11 +26,11 @@ def valid_params
test "#update" do
patch(:update, params: {
- id: @stack.to_param,
- continuous_delivery_schedule: {
- **valid_params,
- },
- })
+ id: @stack.to_param,
+ continuous_delivery_schedule: {
+ **valid_params
+ }
+ })
assert_redirected_to(stack_continuous_delivery_schedule_path(@stack))
assert_equal("Successfully updated", flash[:success])
@@ -49,12 +50,12 @@ def valid_params
test "#update renders validation errors" do
patch(:update, params: {
- id: @stack.to_param,
- continuous_delivery_schedule: {
+ id: @stack.to_param,
+ continuous_delivery_schedule: {
# Make Sunday end before it starts
- **valid_params.merge(sunday_end: "08:00"),
- },
- })
+ **valid_params.merge(sunday_end: "08:00")
+ }
+ })
assert_response(:unprocessable_entity)
assert_equal("Check form for errors", flash[:warning])
diff --git a/test/controllers/deploys_controller_test.rb b/test/controllers/deploys_controller_test.rb
index ef9d2d944..2a9876531 100644
--- a/test/controllers/deploys_controller_test.rb
+++ b/test/controllers/deploys_controller_test.rb
@@ -1,10 +1,11 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
class DeploysControllerTest < ActionController::TestCase
setup do
- Deploy.where(status: %w(running pending)).update_all(status: 'success')
+ Deploy.where(status: %w[running pending]).update_all(status: 'success')
@stack = shipit_stacks(:shipit)
@deploy = shipit_deploys(:shipit)
@commit = shipit_commits(:second)
@@ -63,7 +64,7 @@ class DeploysControllerTest < ActionController::TestCase
test ":create can receive an :env hash" do
env = { 'SAFETY_DISABLED' => '1' }
- post :create, params: { stack_id: @stack.to_param, deploy: { until_commit_id: @commit.id, env: env } }
+ post :create, params: { stack_id: @stack.to_param, deploy: { until_commit_id: @commit.id, env: } }
new_deploy = Deploy.last
assert_equal env, new_deploy.env
end
diff --git a/test/controllers/github_authentication_controller_test.rb b/test/controllers/github_authentication_controller_test.rb
index ed61f5720..f1e89a638 100644
--- a/test/controllers/github_authentication_controller_test.rb
+++ b/test/controllers/github_authentication_controller_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -6,7 +7,7 @@ class GithubAuthenticationControllerTest < ActionController::TestCase
test ":callback can sign in to github" do
auth = OmniAuth::AuthHash.new(
credentials: OmniAuth::AuthHash.new(
- token: 's3cr3t',
+ token: 's3cr3t'
),
extra: OmniAuth::AuthHash.new(
raw_info: OmniAuth::AuthHash.new(
@@ -15,9 +16,9 @@ class GithubAuthenticationControllerTest < ActionController::TestCase
email: 'shipit-user@example.com',
login: 'shipit-user',
avatar_url: 'https://example.com',
- api_url: 'https://github.com/api/v3/users/shipit-user',
- ),
- ),
+ api_url: 'https://github.com/api/v3/users/shipit-user'
+ )
+ )
)
@request.env['omniauth.auth'] = auth
diff --git a/test/controllers/merge_requests_controller_test.rb b/test/controllers/merge_requests_controller_test.rb
index 27ff3f631..a71872ff0 100644
--- a/test/controllers/merge_requests_controller_test.rb
+++ b/test/controllers/merge_requests_controller_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/controllers/merge_status_controller_test.rb b/test/controllers/merge_status_controller_test.rb
index 77e58ba1e..99224583e 100644
--- a/test/controllers/merge_status_controller_test.rb
+++ b/test/controllers/merge_status_controller_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -38,14 +39,14 @@ class MergeStatusControllerTest < ActionController::TestCase
test "GET show prefers stacks with merge_queue_enabled" do
existing = shipit_stacks(:shipit)
Shipit::Stack.where(
- repository: existing.repository,
+ repository: existing.repository
).update_all(merge_queue_enabled: false)
Shipit::Stack.create(
repository: existing.repository,
environment: 'foo',
branch: existing.branch,
- merge_queue_enabled: true,
+ merge_queue_enabled: true
)
get :show, params: { referrer: 'https://github.com/Shopify/shipit-engine/pull/42', branch: 'master' }
@@ -56,7 +57,7 @@ class MergeStatusControllerTest < ActionController::TestCase
test "GET show prefers locked stacks above all else" do
existing = shipit_stacks(:shipit)
Shipit::Stack.where(
- repository: existing.repository,
+ repository: existing.repository
).update_all(lock_reason: 'testing', merge_queue_enabled: false, locked_since: Time.now.utc)
# Shipit would otherwise prefer this, because it has the merge queue enabled
@@ -64,7 +65,7 @@ class MergeStatusControllerTest < ActionController::TestCase
repository: existing.repository,
environment: 'foo',
branch: existing.branch,
- merge_queue_enabled: true,
+ merge_queue_enabled: true
)
get :show, params: { referrer: 'https://github.com/Shopify/shipit-engine/pull/42', branch: 'master' }
diff --git a/test/controllers/release_statuses_controller_test.rb b/test/controllers/release_statuses_controller_test.rb
index edba4e268..68f49682a 100644
--- a/test/controllers/release_statuses_controller_test.rb
+++ b/test/controllers/release_statuses_controller_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/controllers/repositories_controller_test.rb b/test/controllers/repositories_controller_test.rb
index 2f3b6bd3f..b93dca8ed 100644
--- a/test/controllers/repositories_controller_test.rb
+++ b/test/controllers/repositories_controller_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -22,7 +23,7 @@ class RepositoriesControllerTest < ActionController::TestCase
assert_response :forbidden
assert_equal(
'You must be a member of cyclimse/cooks or shopify/developers to access this application.',
- response.body,
+ response.body
)
end
@@ -36,8 +37,8 @@ class RepositoriesControllerTest < ActionController::TestCase
post :create, params: {
repository: {
name: 'valid',
- owner: 'repository',
- },
+ owner: 'repository'
+ }
}
end
assert_redirected_to repository_path(Repository.last)
@@ -48,8 +49,8 @@ class RepositoriesControllerTest < ActionController::TestCase
post :create, params: {
repository: {
owner: 'some',
- name: 'owner/path',
- },
+ name: 'owner/path'
+ }
}
end
assert_response :success
diff --git a/test/controllers/rollbacks_controller_test.rb b/test/controllers/rollbacks_controller_test.rb
index 5629026f9..a9d719608 100644
--- a/test/controllers/rollbacks_controller_test.rb
+++ b/test/controllers/rollbacks_controller_test.rb
@@ -1,10 +1,11 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
class RollbacksControllerTest < ActionController::TestCase
setup do
- Deploy.where(status: %w(running pending)).update_all(status: 'success')
+ Deploy.where(status: %w[running pending]).update_all(status: 'success')
@stack = shipit_stacks(:shipit)
@deploy = shipit_deploys(:shipit)
session[:user_id] = shipit_users(:walrus).id
@@ -18,7 +19,7 @@ class RollbacksControllerTest < ActionController::TestCase
test ":create can receive an :env hash" do
env = { 'SAFETY_DISABLED' => '1' }
- post :create, params: { stack_id: @stack.to_param, rollback: { parent_id: @deploy.id, env: env } }
+ post :create, params: { stack_id: @stack.to_param, rollback: { parent_id: @deploy.id, env: } }
new_rollback = Rollback.last
assert_equal env, new_rollback.env
end
diff --git a/test/controllers/stacks_controller_test.rb b/test/controllers/stacks_controller_test.rb
index 9ed071348..699144762 100644
--- a/test/controllers/stacks_controller_test.rb
+++ b/test/controllers/stacks_controller_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -54,7 +55,7 @@ class StacksControllerTest < ActionController::TestCase
assert_response :forbidden
assert_equal(
'You must be a member of cyclimse/cooks or shopify/developers to access this application.',
- response.body,
+ response.body
)
end
@@ -115,8 +116,8 @@ class StacksControllerTest < ActionController::TestCase
repo_name: 'rails',
repo_owner: 'rails',
environment: 'staging',
- branch: 'staging',
- },
+ branch: 'staging'
+ }
}
end
@@ -241,8 +242,8 @@ class StacksControllerTest < ActionController::TestCase
repo_owner: 'rails',
environment: 'staging',
branch: 'staging',
- deploy_url: 'Javascript:alert(1);',
- },
+ deploy_url: 'Javascript:alert(1);'
+ }
}
assert_response :success
assert_equal 'Deploy url is invalid', flash[:warning]
diff --git a/test/controllers/status_controller_test.rb b/test/controllers/status_controller_test.rb
index 4af5be052..3e7dfa59d 100644
--- a/test/controllers/status_controller_test.rb
+++ b/test/controllers/status_controller_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/controllers/tasks_controller_test.rb b/test/controllers/tasks_controller_test.rb
index ff5fc08c2..9a404f5fd 100644
--- a/test/controllers/tasks_controller_test.rb
+++ b/test/controllers/tasks_controller_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -54,7 +55,7 @@ class TasksControllerTest < ActionController::TestCase
test "tasks with variables defined in the shipit.yml can be triggered with their variables set" do
env = { "FOO" => "0" }
- post :create, params: { stack_id: @stack, definition_id: @definition.id, task: { env: env }, force: 'true' }
+ post :create, params: { stack_id: @stack, definition_id: @definition.id, task: { env: }, force: 'true' }
assert_redirected_to stack_tasks_path(@stack, Task.last)
end
@@ -113,7 +114,7 @@ class TasksControllerTest < ActionController::TestCase
get :tail, params: { stack_id: @stack.to_param, id: @task.id }, format: :json
assert_response :success
- assert_json_keys %w(url status output)
+ assert_json_keys %w[url status output]
assert_json 'status', @task.status
assert_json 'output', @task.chunk_output
assert_json 'url', "/shopify/shipit-engine/production/tasks/#{@task.id}/tail?last_byte=#{last_chunk}"
@@ -125,7 +126,7 @@ class TasksControllerTest < ActionController::TestCase
get :tail, params: { stack_id: @stack.to_param, id: @task.id, last_byte: "50" }, format: :json
assert_response :success
- assert_json_keys %w(url status output)
+ assert_json_keys %w[url status output]
end
test ":tail doesn't returns the next url if the task is finished" do
@@ -141,7 +142,7 @@ class TasksControllerTest < ActionController::TestCase
get :tail, params: { stack_id: @stack.to_param, id: @task.id }, format: :json
assert_response :success
- assert_json_keys %w(status output rollback_url)
+ assert_json_keys %w[status output rollback_url]
end
test ":lookup returns stack task url if the task is an instance of Task" do
diff --git a/test/controllers/webhooks_controller_test.rb b/test/controllers/webhooks_controller_test.rb
index b0c5eda0a..6d8598152 100644
--- a/test/controllers/webhooks_controller_test.rb
+++ b/test/controllers/webhooks_controller_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -24,7 +25,7 @@ class WebhooksControllerTest < ActionController::TestCase
body = JSON.parse(payload(:push_master)).to_json
assert_enqueued_with(job: GithubSyncJob, args: [stack_id: @stack.id]) do
- post :create, body: body, as: :json
+ post :create, body:, as: :json
end
end
@@ -43,7 +44,7 @@ class WebhooksControllerTest < ActionController::TestCase
body = JSON.parse(payload(:status_master)).merge(repository_params).to_json
assert_difference 'commit.statuses.count', 1 do
- post :create, body: body, as: :json
+ post :create, body:, as: :json
end
status = commit.statuses.last
@@ -74,7 +75,7 @@ class WebhooksControllerTest < ActionController::TestCase
body = JSON.parse(payload(:check_suite_master)).to_json
assert_enqueued_with(job: RefreshCheckRunsJob) do
- post :create, body: body, as: :json
+ post :create, body:, as: :json
assert_response :ok
end
end
@@ -107,11 +108,11 @@ class WebhooksControllerTest < ActionController::TestCase
@request.headers['X-Github-Event'] = 'membership'
assert_difference -> { Team.count }, 1 do
post :create, as: :json, body: membership_params.merge(team: {
- id: 48,
- name: 'Ouiche Cooks',
- slug: 'ouiche-cooks',
- url: 'https://example.com',
- }).to_json
+ id: 48,
+ name: 'Ouiche Cooks',
+ slug: 'ouiche-cooks',
+ url: 'https://example.com'
+ }).to_json
assert_response :ok
end
end
@@ -201,7 +202,7 @@ def george
login: 'george',
email: 'george@cyclim.se',
avatar_url: 'https://avatars.githubusercontent.com/u/42?v=3',
- url: 'https://api.github.com/user/george',
+ url: 'https://api.github.com/user/george'
)
end
end
diff --git a/test/fixtures/shipit/commits.yml b/test/fixtures/shipit/commits.yml
index 4df265192..ef4128121 100644
--- a/test/fixtures/shipit/commits.yml
+++ b/test/fixtures/shipit/commits.yml
@@ -258,7 +258,7 @@ canaries_fifth:
updated_at: <%= 8.days.ago.to_formatted_s(:db) %>
created_at: <%= 1.day.ago.to_formatted_s(:db) %>
-undeployed_1:
+undeployed1:
id: 401
sha: 4d9278037b872fd9a6690523e411ecb3aa181355
message: "lets go"
@@ -271,7 +271,7 @@ undeployed_1:
deletions: 24
updated_at: <%= 8.days.ago.to_formatted_s(:db) %>
-undeployed_2:
+undeployed2:
id: 402
sha: 4890fd8b5f2be05d1fedb763a3605ee461c39074
message: "sheep it!"
@@ -284,7 +284,7 @@ undeployed_2:
deletions: 1
updated_at: <%= 8.days.ago.to_formatted_s(:db) %>
-undeployed_3:
+undeployed3:
id: 403
sha: 467578b362bf2b4df5903e1c7960929361c39074
message: "fix it!"
@@ -297,7 +297,7 @@ undeployed_3:
deletions: 64
updated_at: <%= 8.days.ago.to_formatted_s(:db) %>
-undeployed_4:
+undeployed4:
id: 404
sha: 447578b362bf2b4df5903e1c7960929361c3435a
message: "Merge pull request #7 from shipit-engine/yoloshipit\n\nyoloshipit!"
@@ -310,7 +310,7 @@ undeployed_4:
deletions: 342
updated_at: <%= 8.days.ago.to_formatted_s(:db) %>
-undeployed_5:
+undeployed5:
id: 405
sha: 457578b362bf2b4df5903e1c7960929361c3435a
message: "Merge pull request #7 from shipit-engine/yoloshipit\n\nyoloshipit!"
@@ -323,7 +323,7 @@ undeployed_5:
deletions: 342
updated_at: <%= 8.days.ago.to_formatted_s(:db) %>
-undeployed_6:
+undeployed6:
id: 406
sha: 467578b362bf2b4df5903e1c7960929361c3435a
message: "Merge pull request #7 from shipit-engine/yoloshipit\n\nyoloshipit!"
@@ -336,7 +336,7 @@ undeployed_6:
deletions: 342
updated_at: <%= 8.days.ago.to_formatted_s(:db) %>
-undeployed_7:
+undeployed7:
id: 407
sha: 477578b362bf2b4df5903e1c7960929361c3435a
message: "Merge pull request #7 from shipit-engine/yoloshipit\n\nyoloshipit!"
diff --git a/test/fixtures/shipit/stacks.yml b/test/fixtures/shipit/stacks.yml
index b8a81b11e..0f40ab1bf 100644
--- a/test/fixtures/shipit/stacks.yml
+++ b/test/fixtures/shipit/stacks.yml
@@ -10,8 +10,7 @@ shipit:
cached_deploy_spec: |-
{
"machine": {
- "environment": {
- }
+ "environment": {}
},
"review": {
"checklist": [
@@ -28,9 +27,7 @@ shipit:
]
},
"dependencies": {
- "override": [
-
- ]
+ "override": []
},
"deploy": {
"override": null,
@@ -494,8 +491,7 @@ review_stack:
cached_deploy_spec: |-
{
"machine": {
- "environment": {
- }
+ "environment": {}
},
"review": {
"checklist": [
@@ -512,9 +508,7 @@ review_stack:
]
},
"dependencies": {
- "override": [
-
- ]
+ "override": []
},
"deploy": {
"override": null,
diff --git a/test/fixtures/shipit/tasks.yml b/test/fixtures/shipit/tasks.yml
index 43350eeb3..8a58693be 100644
--- a/test/fixtures/shipit/tasks.yml
+++ b/test/fixtures/shipit/tasks.yml
@@ -223,7 +223,7 @@ shipit_with_title_parsing_issue:
{
"id": "bad-title",
"action": "Task with bad title",
- "title": "Using the %{WRONG_VARIABLE_NAME}",
+ "title": "Using the %",
"description": "This task uses the wrong variable name",
"variables": [
{"name": "VARIABLE_NAME", "title": "Any old variable"}
@@ -238,7 +238,7 @@ shipit_with_title_parsing_issue:
started_at: <%= (60 - 3).minutes.ago.to_formatted_s(:db) %>
ended_at: <%= (60 - 4).minutes.ago.to_formatted_s(:db) %>
-shipit_undeployed_1:
+shipit_undeployed1:
id: 201
user: walrus
since_commit_id: 401
@@ -252,7 +252,7 @@ shipit_undeployed_1:
started_at: <%= (60 - 1).minutes.ago.to_formatted_s(:db) %>
ended_at: <%= (60 - 3).minutes.ago.to_formatted_s(:db) %>
-shipit_undeployed_2:
+shipit_undeployed2:
id: 202
user: walrus
since_commit_id: 402
diff --git a/test/helpers/api_helper.rb b/test/helpers/api_helper.rb
index 45665a007..7ed26715c 100644
--- a/test/helpers/api_helper.rb
+++ b/test/helpers/api_helper.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module ApiHelper
private
@@ -14,9 +15,7 @@ class ApiControllerTestCase < ActionController::TestCase
private
def process(_action, **kwargs)
- if kwargs[:method] != "GET"
- kwargs[:as] ||= :json
- end
+ kwargs[:as] ||= :json if kwargs[:method] != "GET"
super
end
end
diff --git a/test/helpers/fixture_aliases_helper.rb b/test/helpers/fixture_aliases_helper.rb
index a66171f66..83c69a505 100644
--- a/test/helpers/fixture_aliases_helper.rb
+++ b/test/helpers/fixture_aliases_helper.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module FixtureAliasesHelper
def shipit_deploys(*args)
shipit_tasks(*args)
diff --git a/test/helpers/hooks_helper.rb b/test/helpers/hooks_helper.rb
index 50a05f631..5f15d6764 100644
--- a/test/helpers/hooks_helper.rb
+++ b/test/helpers/hooks_helper.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module HooksHelper
def expect_hook(event, stack = nil, payload = nil)
spy_on_hook
diff --git a/test/helpers/json_helper.rb b/test/helpers/json_helper.rb
index 3751e5ea0..db71dcbfc 100644
--- a/test/helpers/json_helper.rb
+++ b/test/helpers/json_helper.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module JSONHelper
UNDEFINED = Object.new.freeze
private_constant :UNDEFINED
@@ -8,7 +9,7 @@ def assert_json(path = nil, expected_value = UNDEFINED, &block)
end
def assert_json_document(document, path, expected_value = UNDEFINED)
- value = follow_path(path.to_s.split('.'), document: document)
+ value = follow_path(path.to_s.split('.'), document:)
if block_given?
yield value
elsif expected_value == UNDEFINED
@@ -26,7 +27,7 @@ def assert_json_keys(path, keys = nil, document: response.body)
path = nil
end
- value = follow_path(path.to_s.split('.'), document: document)
+ value = follow_path(path.to_s.split('.'), document:)
case value
when Hash
assert_equal(keys.sort, value.keys.sort)
@@ -38,7 +39,7 @@ def assert_json_keys(path, keys = nil, document: response.body)
def assert_no_json(path, document: response.body)
segments = path.to_s.split('.')
last_segment = segments.pop
- leaf = follow_path(segments, document: document)
+ leaf = follow_path(segments, document:)
case leaf
when Hash
refute(leaf.key?(last_segment), "Expected #{leaf.inspect} not to include #{last_segment.inspect}")
diff --git a/test/helpers/links_helper.rb b/test/helpers/links_helper.rb
index 387811d2c..ce754e00f 100644
--- a/test/helpers/links_helper.rb
+++ b/test/helpers/links_helper.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: true
+
module LinksHelper
- LINKS_PATTERN = /\<(.*?)\>; rel="(\w+)"/
+ LINKS_PATTERN = /<(.*?)>; rel="(\w+)"/
def assert_link(rel, url)
assert_includes(response_links, rel)
diff --git a/test/helpers/payloads_helper.rb b/test/helpers/payloads_helper.rb
index 3c00231f8..0d5c2dc39 100644
--- a/test/helpers/payloads_helper.rb
+++ b/test/helpers/payloads_helper.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module PayloadsHelper
def payload(name)
Shipit::Engine.root.join('test/fixtures/payloads', "#{name}.json").read
diff --git a/test/helpers/queries_helper.rb b/test/helpers/queries_helper.rb
index 29b1e0633..36e76be5d 100644
--- a/test/helpers/queries_helper.rb
+++ b/test/helpers/queries_helper.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module QueriesHelper
def assert_no_queries(ignored_sql = nil, &block)
assert_queries(0, ignored_sql, &block)
@@ -31,15 +32,14 @@ class SQLCounter
/^BEGIN/,
/^COMMIT/,
/^SHOW FULL FIELDS/,
- /^SHOW TABLES LIKE/,
+ /^SHOW TABLES LIKE/
]
# FIXME: this needs to be refactored so specific database can add their own
# ignored SQL. This ignored SQL is for Oracle.
ignored_sql.concat([/^select .*nextval/i, /^SAVEPOINT/, /^ROLLBACK TO/, /^\s*select .* from all_triggers/im])
- attr_reader :ignore
- attr_reader :log
+ attr_reader :ignore, :log
def initialize(ignore = nil)
@ignore = ignore || self.class.ignored_sql
@@ -52,6 +52,7 @@ def call(_name, _start, _finish, _message_id, values)
# FIXME: this seems bad. we should probably have a better way to indicate
# the query was cached
return if values[:name] == 'CACHE' || ignore.any? { |x| x =~ sql }
+
log << sql
end
end
diff --git a/test/jobs/cache_deploy_spec_job_test.rb b/test/jobs/cache_deploy_spec_job_test.rb
index e16b14968..f9a323fc1 100644
--- a/test/jobs/cache_deploy_spec_job_test.rb
+++ b/test/jobs/cache_deploy_spec_job_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -10,12 +11,12 @@ class CacheDeploySpecJobTest < ActiveSupport::TestCase
end
test "#perform checkout the repository to the last recorded commit and cache the deploy spec" do
- @stack.update!(cached_deploy_spec: DeploySpec.new('review' => { 'checklist' => %w(foo bar) }))
+ @stack.update!(cached_deploy_spec: DeploySpec.new('review' => { 'checklist' => %w[foo bar] }))
dir = Pathname(Dir.tmpdir)
StackCommands.any_instance.expects(:with_temporary_working_directory).with(commit: @last_commit).yields(dir)
- assert_equal %w(foo bar), @stack.checklist
+ assert_equal %w[foo bar], @stack.checklist
@job.perform(@stack)
assert_equal [], @stack.reload.checklist
end
diff --git a/test/jobs/chunk_rollup_job_test.rb b/test/jobs/chunk_rollup_job_test.rb
index 475df86dd..cb09e58db 100644
--- a/test/jobs/chunk_rollup_job_test.rb
+++ b/test/jobs/chunk_rollup_job_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -25,7 +26,7 @@ class ChunkRollupJobTest < ActiveSupport::TestCase
test "#peform ignores non-finished jobs" do
logger = mock
logger.expects(:error).once
- @job.stubs(logger: logger)
+ @job.stubs(logger:)
@task.update_attribute(:status, :pending)
@@ -35,7 +36,7 @@ class ChunkRollupJobTest < ActiveSupport::TestCase
test "#perform ignores tasks already rolled up" do
logger = mock
logger.expects(:error).once
- @job.stubs(logger: logger)
+ @job.stubs(logger:)
@task.rolled_up = true
diff --git a/test/jobs/deliver_hook_job_test.rb b/test/jobs/deliver_hook_job_test.rb
index c896857af..159bd7d89 100644
--- a/test/jobs/deliver_hook_job_test.rb
+++ b/test/jobs/deliver_hook_job_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/jobs/destroy_repository_job_test.rb b/test/jobs/destroy_repository_job_test.rb
index 0f1e185e6..af4f40ac7 100644
--- a/test/jobs/destroy_repository_job_test.rb
+++ b/test/jobs/destroy_repository_job_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/jobs/destroy_stack_job_test.rb b/test/jobs/destroy_stack_job_test.rb
index 8262d9100..bd53febed 100644
--- a/test/jobs/destroy_stack_job_test.rb
+++ b/test/jobs/destroy_stack_job_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/jobs/emit_event_job_test.rb b/test/jobs/emit_event_job_test.rb
index 7d657ff6a..8d97476bb 100644
--- a/test/jobs/emit_event_job_test.rb
+++ b/test/jobs/emit_event_job_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/jobs/fetch_commit_stats_job_test.rb b/test/jobs/fetch_commit_stats_job_test.rb
index 16970d10b..2658bd09f 100644
--- a/test/jobs/fetch_commit_stats_job_test.rb
+++ b/test/jobs/fetch_commit_stats_job_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/jobs/fetch_deployed_revision_job_test.rb b/test/jobs/fetch_deployed_revision_job_test.rb
index b5f59b88b..e521109e3 100644
--- a/test/jobs/fetch_deployed_revision_job_test.rb
+++ b/test/jobs/fetch_deployed_revision_job_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/jobs/github_sync_job_test.rb b/test/jobs/github_sync_job_test.rb
index bac17f3ba..6b6af349c 100644
--- a/test/jobs/github_sync_job_test.rb
+++ b/test/jobs/github_sync_job_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -46,34 +47,34 @@ class GithubSyncJobTest < ActiveSupport::TestCase
["yoloshipit!", false],
["fix it!", false],
["sheep it!", false],
- ["lets go", false],
+ ["lets go", false]
]
- assert_equal initial_queue, @stack.undeployed_commits.map { |c| [c.title, c.locked?] }
+ assert_equal(initial_queue, @stack.undeployed_commits.map { |c| [c.title, c.locked?] })
author = stub(
id: 1234,
login: 'bob',
name: 'Bob the Builder',
email: 'bob@bob.com',
- date: '2011-04-14T16:00:49Z',
+ date: '2011-04-14T16:00:49Z'
)
@job.expects(:fetch_missing_commits).returns([
- [
- stub(
- sha: '36514755579bfb5bc313f403b216f4347a027990',
- author: author,
- committer: author,
- stats: nil,
- commit: stub(
- sha: '36514755579bfb5bc313f403b216f4347a027990',
- message: 'Revert "fix it!"',
- author: author,
- committer: author,
- ),
- ),
- ],
- shipit_commits(:fifth),
- ])
+ [
+ stub(
+ sha: '36514755579bfb5bc313f403b216f4347a027990',
+ author:,
+ committer: author,
+ stats: nil,
+ commit: stub(
+ sha: '36514755579bfb5bc313f403b216f4347a027990',
+ message: 'Revert "fix it!"',
+ author:,
+ committer: author
+ )
+ )
+ ],
+ shipit_commits(:fifth)
+ ])
@job.perform(stack_id: @stack.id)
final_queue = [
@@ -82,9 +83,9 @@ class GithubSyncJobTest < ActiveSupport::TestCase
["yoloshipit!", true],
["fix it!", true],
["sheep it!", false],
- ["lets go", false],
+ ["lets go", false]
]
- assert_equal final_queue, @stack.reload.undeployed_commits.map { |c| [c.title, c.locked?] }
+ assert_equal(final_queue, @stack.reload.undeployed_commits.map { |c| [c.title, c.locked?] })
end
test "#fetch_missing_commits returns the commits in the reverse order if it doesn't know the parent" do
diff --git a/test/jobs/mark_deploy_healthy_job_test.rb b/test/jobs/mark_deploy_healthy_job_test.rb
index a37c7699c..87ead1eaa 100644
--- a/test/jobs/mark_deploy_healthy_job_test.rb
+++ b/test/jobs/mark_deploy_healthy_job_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/jobs/perform_task_job_test.rb b/test/jobs/perform_task_job_test.rb
index 24b289c7a..45f418f07 100644
--- a/test/jobs/perform_task_job_test.rb
+++ b/test/jobs/perform_task_job_test.rb
@@ -1,11 +1,11 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
class PerformTaskJobTest < ActiveSupport::TestCase
class FakeSuccessfulCommand
- def run
- end
+ def run; end
def success?
true
diff --git a/test/jobs/process_merge_requests_job_test.rb b/test/jobs/process_merge_requests_job_test.rb
index 72a81933b..e2731739a 100644
--- a/test/jobs/process_merge_requests_job_test.rb
+++ b/test/jobs/process_merge_requests_job_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -18,15 +19,15 @@ class ProcessMergeRequestsJobTest < ActiveSupport::TestCase
test "#perform rejects unmergeable PRs and merge the others" do
MergeRequest.any_instance.stubs(:refresh!)
- stub_request(:put, "#{@pending_pr.api_url}/merge").to_return(status: %w(200 OK), body: {
+ stub_request(:put, "#{@pending_pr.api_url}/merge").to_return(status: %w[200 OK], body: {
sha: "6dcb09b5b57875f334f61aebed695e2e4193db5e",
merged: true,
- message: "Pull Request successfully merged",
+ message: "Pull Request successfully merged"
}.to_json)
branch_url = "https://api.github.com/repos/shopify/shipit-engine/git/refs/heads/feature-62"
- stub_request(:delete, branch_url).to_return(status: %w(204 No content))
+ stub_request(:delete, branch_url).to_return(status: %w[204 No content])
pulls_url = "https://api.github.com/repos/shopify/shipit-engine/pulls?base=feature-62"
- stub_request(:get, pulls_url).to_return(status: %w(200 OK), body: '[]')
+ stub_request(:get, pulls_url).to_return(status: %w[200 OK], body: '[]')
@job.perform(@stack)
@@ -36,9 +37,9 @@ class ProcessMergeRequestsJobTest < ActiveSupport::TestCase
test "#perform rejects PRs if the merge attempt fails" do
MergeRequest.any_instance.stubs(:refresh!)
- stub_request(:put, "#{@pending_pr.api_url}/merge").to_return(status: %w(405 Method not allowed), body: {
+ stub_request(:put, "#{@pending_pr.api_url}/merge").to_return(status: %w[405 Method not allowed], body: {
message: "Pull Request is not mergeable",
- documentation_url: "https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button",
+ documentation_url: "https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button"
}.to_json)
@job.perform(@stack)
diff --git a/test/jobs/purge_old_deliveries_job_test.rb b/test/jobs/purge_old_deliveries_job_test.rb
index 744676735..31189ceaa 100644
--- a/test/jobs/purge_old_deliveries_job_test.rb
+++ b/test/jobs/purge_old_deliveries_job_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/jobs/reap_dead_tasks_job_test.rb b/test/jobs/reap_dead_tasks_job_test.rb
index 321b2ad27..8e672dd55 100644
--- a/test/jobs/reap_dead_tasks_job_test.rb
+++ b/test/jobs/reap_dead_tasks_job_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/jobs/refresh_github_user_job_test.rb b/test/jobs/refresh_github_user_job_test.rb
index 29003674a..582769240 100644
--- a/test/jobs/refresh_github_user_job_test.rb
+++ b/test/jobs/refresh_github_user_job_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/jobs/refresh_status_job_test.rb b/test/jobs/refresh_status_job_test.rb
index d60e477f8..c289bc66b 100644
--- a/test/jobs/refresh_status_job_test.rb
+++ b/test/jobs/refresh_status_job_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/jobs/shipit/background_job_test.rb b/test/jobs/shipit/background_job_test.rb
index 3c8be33b6..d1e5ddfaa 100644
--- a/test/jobs/shipit/background_job_test.rb
+++ b/test/jobs/shipit/background_job_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -13,7 +14,7 @@ class BackgroundJobTest < ActiveSupport::TestCase
test "#perform retries on Octokit secondary rate limit exceptions" do
freeze_time do
Octokit::Forbidden.any_instance.expects(:response_headers)
- .returns({ "Retry-After" => 45 })
+ .returns({ "Retry-After" => 45 })
Shipit.github.api.expects(:user).with(@user.github_id).raises(Octokit::TooManyRequests)
diff --git a/test/jobs/shipit/continuous_delivery_job_test.rb b/test/jobs/shipit/continuous_delivery_job_test.rb
index 07b7d5331..05af23dcf 100644
--- a/test/jobs/shipit/continuous_delivery_job_test.rb
+++ b/test/jobs/shipit/continuous_delivery_job_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/jobs/unique_job_test.rb b/test/jobs/unique_job_test.rb
index 2d47048a9..9b0083d45 100644
--- a/test/jobs/unique_job_test.rb
+++ b/test/jobs/unique_job_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/jobs/update_github_last_deployed_ref_job_test.rb b/test/jobs/update_github_last_deployed_ref_job_test.rb
index f42306b1e..b576f6fe1 100644
--- a/test/jobs/update_github_last_deployed_ref_job_test.rb
+++ b/test/jobs/update_github_last_deployed_ref_job_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/middleware/same_site_cookie_middleware_test.rb b/test/middleware/same_site_cookie_middleware_test.rb
index 6e9f552f7..80bb64904 100644
--- a/test/middleware/same_site_cookie_middleware_test.rb
+++ b/test/middleware/same_site_cookie_middleware_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -14,8 +15,7 @@ def app
end
def env_for_url(url)
- env = Rack::MockRequest.env_for(url)
- env
+ Rack::MockRequest.env_for(url)
end
def middleware
diff --git a/test/models/api_client_test.rb b/test/models/api_client_test.rb
index 49b2b92e7..db84218a1 100644
--- a/test/models/api_client_test.rb
+++ b/test/models/api_client_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/models/commit_checks_test.rb b/test/models/commit_checks_test.rb
index 35f5b2482..9c786f7d7 100644
--- a/test/models/commit_checks_test.rb
+++ b/test/models/commit_checks_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
require 'tmpdir'
@@ -71,7 +72,7 @@ class CommitChecksTest < ActiveSupport::TestCase
'',
'$ echo review',
'review',
- '',
+ ''
]
assert_equal 'success', @checks.status
assert_equal lines, @checks.output.lines.map(&:strip)
diff --git a/test/models/commit_deployment_status_test.rb b/test/models/commit_deployment_status_test.rb
index 9d75fce59..b7ce1c33b 100644
--- a/test/models/commit_deployment_status_test.rb
+++ b/test/models/commit_deployment_status_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -17,7 +18,7 @@ class CommitDeploymentStatusTest < ActiveSupport::TestCase
'in_progress',
target_url: "http://shipit.com/shopify/shipit-engine/production/deploys/#{@task.id}",
description: "walrus triggered the deploy of shopify/shipit-engine/production to #{@deployment.short_sha}",
- environment_url: "https://shipit.shopify.com",
+ environment_url: "https://shipit.shopify.com"
).returns(response)
@status.create_on_github!
diff --git a/test/models/commit_deployment_test.rb b/test/models/commit_deployment_test.rb
index 8446a038a..429fef25a 100644
--- a/test/models/commit_deployment_test.rb
+++ b/test/models/commit_deployment_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -23,9 +24,9 @@ class CommitDeploymentTest < ActiveSupport::TestCase
shipit: {
task_id: 4,
from_sha: 'f890fd8b5f2be05d1fedb763a3605ee461c39074',
- to_sha: '467578b362bf2b4df5903e1c7960929361c3435a',
- },
- }.to_json,
+ to_sha: '467578b362bf2b4df5903e1c7960929361c3435a'
+ }
+ }.to_json
).returns(deployment_response)
@deployment.create_on_github!
diff --git a/test/models/commits_test.rb b/test/models/commits_test.rb
index 55449bdc5..2c8d8c347 100644
--- a/test/models/commits_test.rb
+++ b/test/models/commits_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -11,9 +12,9 @@ class CommitsTest < ActiveSupport::TestCase
@commit = shipit_commits(:first)
stub_request(:get, "https://api.github.com/user/emails").to_return(
- status: %w(200 OK),
+ status: %w[200 OK],
body: {}.to_json,
- headers: { "Content-Type" => "application/json" },
+ headers: { "Content-Type" => "application/json" }
)
end
@@ -28,16 +29,16 @@ class CommitsTest < ActiveSupport::TestCase
author: {
name: 'George Abitbol',
email: '',
- date: Time.now,
+ date: Time.now
},
committer: {
name: 'George Abitbol',
email: '',
- date: Time.now,
+ date: Time.now
},
- message: "commit to trigger staging build",
- },
- ),
+ message: "commit to trigger staging build"
+ }
+ )
)
end
end
@@ -53,16 +54,16 @@ class CommitsTest < ActiveSupport::TestCase
author: {
name: 'Lando Walrussian',
email: 'walrus@shopify.com',
- date: Time.now,
+ date: Time.now
},
committer: {
name: 'Lando Walrussian',
email: 'walrus@shopify.com',
- date: Time.now,
+ date: Time.now
},
- message: '',
- },
- ),
+ message: ''
+ }
+ )
)
end
commit = Commit.last
@@ -82,16 +83,16 @@ class CommitsTest < ActiveSupport::TestCase
author: {
name: 'Lando Walrussian',
email: 'walrus@shopify.com',
- date: Time.now,
+ date: Time.now
},
committer: {
name: 'Lando Walrussian',
email: 'walrus@shopify.com',
- date: Time.now,
+ date: Time.now
},
- message: message,
- },
- ),
+ message:
+ }
+ )
)
end
@@ -113,16 +114,16 @@ class CommitsTest < ActiveSupport::TestCase
author: {
name: 'Shipit',
email: '',
- date: Time.now,
+ date: Time.now
},
committer: {
name: 'Shipit',
email: '',
- date: Time.now,
+ date: Time.now
},
- message: "commit to trigger staging build\n\nMerge-Requested-By: walrus\n",
- },
- ),
+ message: "commit to trigger staging build\n\nMerge-Requested-By: walrus\n"
+ }
+ )
)
end
@@ -141,20 +142,20 @@ class CommitsTest < ActiveSupport::TestCase
author: {
name: 'Shipit',
email: '',
- date: Time.now,
+ date: Time.now
},
committer: {
name: 'Shipit',
email: '',
- date: Time.now,
+ date: Time.now
},
- message: "Merge pull request #62 from shipit-engine/yoloshipit\n\nyoloshipit!",
+ message: "Merge pull request #62 from shipit-engine/yoloshipit\n\nyoloshipit!"
},
parents: [
{ sha: "1864542e3d2f8a41916a2dec0f2b4d3c1bf4899b", url: '', html_url: '' },
- { sha: "63d7e03e517fd2ae1caeb1b7a9f21767f84d671a", url: '', html_url: '' },
- ],
- ),
+ { sha: "63d7e03e517fd2ae1caeb1b7a9f21767f84d671a", url: '', html_url: '' }
+ ]
+ )
)
end
@@ -270,14 +271,14 @@ class CommitsTest < ActiveSupport::TestCase
author: walrus,
committer: walrus,
authored_at: Time.now,
- committed_at: Time.now,
+ committed_at: Time.now
)
deploy = @stack.deploys.build(
user_id: walrus.id,
since_commit: @stack.commits.first,
until_commit: new_commit,
- status: 'success',
+ status: 'success'
)
deploy.stubs(:pull_request_head_for_commit).returns(nil)
deploy.save!
@@ -321,7 +322,7 @@ class CommitsTest < ActiveSupport::TestCase
sha: "ab12",
authored_at: Time.now,
committed_at: Time.now,
- message: "more fish!",
+ message: "more fish!"
)
end
@@ -331,7 +332,7 @@ class CommitsTest < ActiveSupport::TestCase
description: nil,
context: 'default',
target_url: 'http://example.com',
- created_at: 1.day.ago,
+ created_at: 1.day.ago
)
Shipit.github.api.expects(:statuses).with(@stack.github_repo_name, @commit.sha, per_page: 100).returns([status])
assert_difference '@commit.statuses.count', 1 do
@@ -348,13 +349,13 @@ class CommitsTest < ActiveSupport::TestCase
details_url: 'https://example.com/details',
html_url: 'https://example.com/run',
output: mock(
- title: 'Tests build ran successfully',
+ title: 'Tests build ran successfully'
),
completed_at: Time.now,
- started_at: Time.now - 1.minute,
+ started_at: Time.now - 1.minute
)
response = stub(rels: {}, data: mock(
- check_runs: [check_run],
+ check_runs: [check_run]
))
Shipit.github.api.expects(:check_runs).with(@stack.github_repo_name, @commit.sha, per_page: 100).returns(response.data)
Shipit.github.api.expects(:last_response).returns(response)
@@ -375,7 +376,7 @@ class CommitsTest < ActiveSupport::TestCase
sha: "ab12",
authored_at: Time.now,
committed_at: Time.now,
- message: "more fish!",
+ message: "more fish!"
)
@stack.reload
assert_equal 3, @stack.undeployed_commits_count
@@ -416,7 +417,7 @@ class CommitsTest < ActiveSupport::TestCase
sha: "ab12",
authored_at: Time.now,
committed_at: Time.now,
- message: "more fish!",
+ message: "more fish!"
)
stack.reload
assert_nil stack.last_deployed_at
@@ -456,9 +457,9 @@ class CommitsTest < ActiveSupport::TestCase
assert_equal 'failure', @commit.reload.state
@commit.stack.update!(cached_deploy_spec: DeploySpec.new('ci' => {
- 'hide' => 'metrics/coveralls',
- 'allow_failures' => 'metrics/performance',
- }))
+ 'hide' => 'metrics/coveralls',
+ 'allow_failures' => 'metrics/performance'
+ }))
assert_equal 'pending', @commit.reload.state
end
@@ -474,9 +475,9 @@ class CommitsTest < ActiveSupport::TestCase
assert_predicate commit.status, :group?
assert_equal 3, commit.status.size
commit.stack.update!(cached_deploy_spec: DeploySpec.new('ci' => { 'hide' => [
- 'Travis CI',
- 'metrics/coveralls',
- ] }))
+ 'Travis CI',
+ 'metrics/coveralls'
+ ] }))
commit.reload
refute_predicate commit.status, :group?
end
@@ -503,7 +504,7 @@ class CommitsTest < ActiveSupport::TestCase
test "#deployable? is false if a required status is missing" do
commit = shipit_commits(:cyclimse_first)
- commit.stack.stubs(:required_statuses).returns(%w(ci/very-important))
+ commit.stack.stubs(:required_statuses).returns(%w[ci/very-important])
refute_predicate commit, :deployable?
end
@@ -599,15 +600,15 @@ class CommitsTest < ActiveSupport::TestCase
end
expected_webhook_transitions = { # we expect deployable_status to fire on these transitions, and not on any others
- 'unknown' => %w(pending success failure error),
- 'pending' => %w(success failure error),
- 'success' => %w(failure error),
- 'failure' => %w(success),
- 'error' => %w(success),
+ 'unknown' => %w[pending success failure error],
+ 'pending' => %w[success failure error],
+ 'success' => %w[failure error],
+ 'failure' => %w[success],
+ 'error' => %w[success]
}
expected_webhook_transitions.each do |initial_state, firing_states|
initial_status_attributes = { state: initial_state, description: 'abc', context: 'ci/travis' }
- (expected_webhook_transitions.keys - %w(unknown)).each do |new_state|
+ (expected_webhook_transitions.keys - %w[unknown]).each do |new_state|
should_fire = firing_states.include?(new_state)
action = should_fire ? 'fires' : 'does not fire'
test "#add_status #{action} for status from #{initial_state} to #{new_state}" do
@@ -619,7 +620,7 @@ class CommitsTest < ActiveSupport::TestCase
unless initial_state == 'unknown'
attrs = initial_status_attributes.merge(
stack_id: commit.stack_id,
- created_at: 10.days.ago.to_formatted_s(:db),
+ created_at: 10.days.ago.to_formatted_s(:db)
)
commit.statuses.create!(attrs)
end
@@ -652,7 +653,7 @@ class CommitsTest < ActiveSupport::TestCase
state: 'failure',
description: 'Sad',
context: 'ci/hidden',
- created_at: 1.day.ago.to_formatted_s(:db),
+ created_at: 1.day.ago.to_formatted_s(:db)
)
commit.create_status_from_github!(github_status)
end
@@ -669,7 +670,7 @@ class CommitsTest < ActiveSupport::TestCase
state: 'failure',
description: 'Sad',
context: 'ci/ok_to_fail',
- created_at: 1.day.ago.to_formatted_s(:db),
+ created_at: 1.day.ago.to_formatted_s(:db)
)
commit.create_status_from_github!(github_status)
end
@@ -684,7 +685,7 @@ class CommitsTest < ActiveSupport::TestCase
state: 'failure',
description: 'Sad',
context: 'ci/travis',
- created_at: 1.day.ago.to_formatted_s(:db),
+ created_at: 1.day.ago.to_formatted_s(:db)
)
commit.create_status_from_github!(github_status)
end
@@ -696,7 +697,7 @@ class CommitsTest < ActiveSupport::TestCase
state: 'success',
description: 'Cool',
context: 'metrics/coveralls',
- created_at: 1.day.ago.to_formatted_s(:db),
+ created_at: 1.day.ago.to_formatted_s(:db)
)
assert_equal 'failure', commit.state
@@ -739,7 +740,7 @@ class CommitsTest < ActiveSupport::TestCase
committer: shipit_users(:shipit),
committed_at: Time.now,
sha: '5590fd8b5f2be05d1fedb763a3605ee461c39074',
- message: "Merge pull request #62 from shipit-engine/yoloshipit\n\nyoloshipit!",
+ message: "Merge pull request #62 from shipit-engine/yoloshipit\n\nyoloshipit!"
)
merge_request = shipit_merge_requests(:shipit_pending)
@@ -756,7 +757,7 @@ class CommitsTest < ActiveSupport::TestCase
committer: shipit_users(:shipit),
committed_at: Time.now,
sha: '5590fd8b5f2be05d1fedb763a3605ee461c39074',
- message: "Merge pull request #99 from shipit-engine/yoloshipit\n\nyoloshipit!",
+ message: "Merge pull request #99 from shipit-engine/yoloshipit\n\nyoloshipit!"
)
assert_predicate commit, :pull_request?
@@ -772,7 +773,7 @@ class CommitsTest < ActiveSupport::TestCase
committer: shipit_users(:shipit),
committed_at: Time.now,
sha: '5590fd8b5f2be05d1fedb763a3605ee461c39074',
- message: "Merge pull request #62 from shipit-engine/yoloshipit\n\nyoloshipit!",
+ message: "Merge pull request #62 from shipit-engine/yoloshipit\n\nyoloshipit!"
)
assert_equal shipit_users(:walrus), commit.author
@@ -785,7 +786,7 @@ class CommitsTest < ActiveSupport::TestCase
committer: shipit_users(:shipit),
committed_at: Time.now,
sha: '5590fd8b5f2be05d1fedb763a3605ee461c39074',
- message: "Yoloshipit!",
+ message: "Yoloshipit!"
)
refute_predicate commit, :pull_request?
@@ -801,44 +802,44 @@ class CommitsTest < ActiveSupport::TestCase
test "#revert? returns true for commits reverted by GitHub" do
commit = Commit.new(
- message: "Merge pull request #17 from Shopify/revert-16\n\nRevert \"Create README.md\"",
+ message: "Merge pull request #17 from Shopify/revert-16\n\nRevert \"Create README.md\""
)
assert_predicate commit, :revert?
end
test "#revert? returns true for commits reverted from CLI" do
commit = Commit.new(
- message: "Revert \"Super Feature\"\n\nThis reverts commit 49430d5091abc34f2c576c23ebf369ec7094d8aa.",
+ message: "Revert \"Super Feature\"\n\nThis reverts commit 49430d5091abc34f2c576c23ebf369ec7094d8aa."
)
assert_predicate commit, :revert?
end
test "#revert_of? works with pull requests reverted on GitHub" do
commit = Commit.new(
- message: "Merge pull request #16 from byroot/casperisfine-patch-1\n\nCreate README.md",
+ message: "Merge pull request #16 from byroot/casperisfine-patch-1\n\nCreate README.md"
)
revert = Commit.new(
- message: "Merge pull request #17 from Shopify/revert-16\n\nRevert \"Create README.md\"",
+ message: "Merge pull request #17 from Shopify/revert-16\n\nRevert \"Create README.md\""
)
assert revert.revert_of?(commit)
end
test "#revert_of? works with commits reverted from CLI" do
commit = Commit.new(
- message: "Create README.md",
+ message: "Create README.md"
)
revert = Commit.new(
- message: "Revert \"Create README.md\"\n\nThis reverts commit 49430d5091abc34f2c576c23ebf369ec7094d8aa.",
+ message: "Revert \"Create README.md\"\n\nThis reverts commit 49430d5091abc34f2c576c23ebf369ec7094d8aa."
)
assert revert.revert_of?(commit)
end
test "#revert_of? works with pull requests reverted from CLI" do
commit = Commit.new(
- message: "Merge pull request #19 from byroot/casperisfine-patch-1\n\nUpdate README.md",
+ message: "Merge pull request #19 from byroot/casperisfine-patch-1\n\nUpdate README.md"
)
revert = Commit.new(
- message: "Revert \"Merge pull request #19 from byroot/casperisfine-patch-1\"\n\nThis reverts commit fa3722ef8372b47160f5d96010d3c54743d192f9, reversing\nchanges made to 868b6f65f759d003c04d056f2f928f18d6813c7e.",
+ message: "Revert \"Merge pull request #19 from byroot/casperisfine-patch-1\"\n\nThis reverts commit fa3722ef8372b47160f5d96010d3c54743d192f9, reversing\nchanges made to 868b6f65f759d003c04d056f2f928f18d6813c7e."
)
assert revert.revert_of?(commit)
end
diff --git a/test/models/delivery_test.rb b/test/models/delivery_test.rb
index 14d431511..31b9b9bbf 100644
--- a/test/models/delivery_test.rb
+++ b/test/models/delivery_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -13,7 +14,7 @@ class DeliveryTest < ActiveSupport::TestCase
event: 'deploy',
url: 'http://example.com',
content_type: 'application/json',
- payload: '{}',
+ payload: '{}'
)
assert_equal 'pending', delivery.status
@@ -25,7 +26,7 @@ class DeliveryTest < ActiveSupport::TestCase
test "#send! post the payload and update the status to `sent`" do
headers = { 'content-type' => 'text/plain', 'content-length' => '2' }
- stub_request(:post, @delivery.url).to_return(headers: headers, body: 'OK')
+ stub_request(:post, @delivery.url).to_return(headers:, body: 'OK')
assert_equal 'scheduled', @delivery.status
@delivery.send!
diff --git a/test/models/deploy_spec_test.rb b/test/models/deploy_spec_test.rb
index ecd136b62..fbda048f4 100644
--- a/test/models/deploy_spec_test.rb
+++ b/test/models/deploy_spec_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -34,8 +35,8 @@ class DeploySpecTest < ActiveSupport::TestCase
end
test '#dependencies_steps returns `dependencies.override` if present' do
- @spec.stubs(:load_config).returns('dependencies' => { 'override' => %w(foo bar baz) })
- assert_equal %w(foo bar baz), @spec.dependencies_steps
+ @spec.stubs(:load_config).returns('dependencies' => { 'override' => %w[foo bar baz] })
+ assert_equal %w[foo bar baz], @spec.dependencies_steps
end
test '#dependencies_steps returns `bundle install` if a `Gemfile` is present' do
@@ -77,7 +78,7 @@ class DeploySpecTest < ActiveSupport::TestCase
test '#bundle_install use `dependencies.bundler.without` if present to build the --without argument' do
@spec.stubs(:gemfile_lock_exists?).returns(true)
- @spec.stubs(:load_config).returns('dependencies' => { 'bundler' => { 'without' => %w(some custom groups) } })
+ @spec.stubs(:load_config).returns('dependencies' => { 'bundler' => { 'without' => %w[some custom groups] } })
command = %(
bundle install
--frozen
@@ -90,13 +91,13 @@ class DeploySpecTest < ActiveSupport::TestCase
end
test '#bundle_install has --frozen option if Gemfile.lock is present' do
- @spec.stubs(:load_config).returns('dependencies' => { 'bundler' => { 'without' => %w(some custom groups) } })
+ @spec.stubs(:load_config).returns('dependencies' => { 'bundler' => { 'without' => %w[some custom groups] } })
@spec.stubs(:gemfile_lock_exists?).returns(true)
assert @spec.bundle_install.last.include?('--frozen')
end
test '#bundle_install does not have --frozen option if Gemfile.lock is not present' do
- @spec.stubs(:load_config).returns('dependencies' => { 'bundler' => { 'without' => %w(some custom groups) } })
+ @spec.stubs(:load_config).returns('dependencies' => { 'bundler' => { 'without' => %w[some custom groups] } })
@spec.stubs(:gemfile_lock_exists?).returns(false)
refute @spec.bundle_install.last.include?('--frozen')
end
@@ -114,8 +115,8 @@ class DeploySpecTest < ActiveSupport::TestCase
end
test '#deploy_steps returns `deploy.override` if present' do
- @spec.stubs(:load_config).returns('deploy' => { 'override' => %w(foo bar baz) })
- assert_equal %w(foo bar baz), @spec.deploy_steps
+ @spec.stubs(:load_config).returns('deploy' => { 'override' => %w[foo bar baz] })
+ assert_equal %w[foo bar baz], @spec.deploy_steps
end
test '#deploy_steps returns `cap $ENVIRONMENT deploy` if a `Capfile` is present' do
@@ -128,8 +129,8 @@ class DeploySpecTest < ActiveSupport::TestCase
@spec.stubs(:load_config).returns(
'kubernetes' => {
'namespace' => 'foo',
- 'context' => 'bar',
- },
+ 'context' => 'bar'
+ }
)
assert_equal ["kubernetes-deploy --max-watch-seconds 900 foo bar"], @spec.deploy_steps
end
@@ -139,8 +140,8 @@ class DeploySpecTest < ActiveSupport::TestCase
'kubernetes' => {
'namespace' => 'foo',
'context' => 'bar',
- 'timeout' => false,
- },
+ 'timeout' => false
+ }
)
assert_equal ["kubernetes-deploy foo bar"], @spec.deploy_steps
end
@@ -151,8 +152,8 @@ class DeploySpecTest < ActiveSupport::TestCase
@spec.stubs(:load_config).returns(
'kubernetes' => {
'namespace' => 'foo',
- 'context' => 'bar',
- },
+ 'context' => 'bar'
+ }
)
assert_equal ["kubernetes-deploy --max-watch-seconds 900 foo bar"], @spec.deploy_steps
end
@@ -162,8 +163,8 @@ class DeploySpecTest < ActiveSupport::TestCase
'kubernetes' => {
'namespace' => 'foo',
'context' => 'bar',
- 'template_dir' => 'k8s_templates/',
- },
+ 'template_dir' => 'k8s_templates/'
+ }
)
assert_equal ["kubernetes-deploy --max-watch-seconds 900 --template-dir k8s_templates/ foo bar"], @spec.deploy_steps
end
@@ -193,8 +194,8 @@ class DeploySpecTest < ActiveSupport::TestCase
end
test '#rollback_steps returns `rollback.override` if present' do
- @spec.stubs(:load_config).returns('rollback' => { 'override' => %w(foo bar baz) })
- assert_equal %w(foo bar baz), @spec.rollback_steps
+ @spec.stubs(:load_config).returns('rollback' => { 'override' => %w[foo bar baz] })
+ assert_equal %w[foo bar baz], @spec.rollback_steps
end
test '#retries_on_rollback returns `rollback.retries` if present' do
@@ -224,8 +225,8 @@ class DeploySpecTest < ActiveSupport::TestCase
@spec.stubs(:load_config).returns(
'kubernetes' => {
'namespace' => 'foo',
- 'context' => 'bar',
- },
+ 'context' => 'bar'
+ }
)
assert_equal ["kubernetes-deploy --max-watch-seconds 900 foo bar"], @spec.rollback_steps
end
@@ -236,8 +237,8 @@ class DeploySpecTest < ActiveSupport::TestCase
@spec.stubs(:load_config).returns(
'kubernetes' => {
'namespace' => 'foo',
- 'context' => 'bar',
- },
+ 'context' => 'bar'
+ }
)
assert_equal ["kubernetes-deploy --max-watch-seconds 900 foo bar"], @spec.rollback_steps
end
@@ -246,15 +247,15 @@ class DeploySpecTest < ActiveSupport::TestCase
@spec.stubs(:load_config).returns(
'kubernetes' => {
'namespace' => 'foo',
- 'context' => 'bar',
- },
+ 'context' => 'bar'
+ }
)
tasks = {
'restart' => {
'action' => 'Restart application',
'description' => 'Simulates a rollout of Kubernetes deployments by using kubernetes-restart utility',
- 'steps' => ['kubernetes-restart foo bar --max-watch-seconds 900'],
- },
+ 'steps' => ['kubernetes-restart foo bar --max-watch-seconds 900']
+ }
}
assert_equal tasks, @spec.discover_task_definitions
end
@@ -264,20 +265,20 @@ class DeploySpecTest < ActiveSupport::TestCase
'restart' => {
'action' => 'Restart application',
'description' => 'Simulates a rollout of Kubernetes deployments by using kubernetes-restart utility',
- 'steps' => ['kubernetes-restart something custom'],
+ 'steps' => ['kubernetes-restart something custom']
},
'some-other-tasj' => {
'action' => 'Do something else',
'description' => 'Eat some chips!',
- 'steps' => ['echo chips'],
- },
+ 'steps' => ['echo chips']
+ }
}
@spec.stubs(:load_config).returns(
'kubernetes' => {
'namespace' => 'foo',
- 'context' => 'bar',
+ 'context' => 'bar'
},
- 'tasks' => tasks,
+ 'tasks' => tasks
)
assert_equal tasks, @spec.discover_task_definitions
end
@@ -331,7 +332,7 @@ class DeploySpecTest < ActiveSupport::TestCase
steps = [
'assert-egg-version-tag /tmp/fake_setup.py',
'python setup.py register sdist',
- 'twine upload dist/*',
+ 'twine upload dist/*'
]
assert_equal steps, @spec.deploy_steps
end
@@ -347,43 +348,43 @@ class DeploySpecTest < ActiveSupport::TestCase
'method' => nil,
'max_divergence' => {
'commits' => nil,
- 'age' => nil,
- },
+ 'age' => nil
+ }
},
'ci' => {
'hide' => [],
'allow_failures' => [],
'require' => [],
- 'blocking' => [],
+ 'blocking' => []
},
'machine' => {
'environment' => { 'BUNDLE_PATH' => @spec.bundle_path.to_s },
'directory' => nil,
- 'cleanup' => true,
+ 'cleanup' => true
},
'review' => { 'checklist' => [], 'monitoring' => [], 'checks' => [] },
'status' => {
'context' => nil,
- 'delay' => 0,
+ 'delay' => 0
},
'dependencies' => { 'override' => [] },
'plugins' => {},
'provision' => {
- 'handler_name' => nil,
+ 'handler_name' => nil
},
'deploy' => {
'override' => nil,
'variables' => [],
'max_commits' => 8,
'interval' => 0,
- 'retries' => nil,
+ 'retries' => nil
},
'rollback' => {
'override' => nil,
- 'retries' => nil,
+ 'retries' => nil
},
'fetch' => nil,
- 'tasks' => {},
+ 'tasks' => {}
}
assert_equal config, @spec.cacheable.config
end
@@ -394,10 +395,10 @@ class DeploySpecTest < ActiveSupport::TestCase
test "#deploy_variables returns an array of VariableDefinition instances" do
@spec.stubs(:load_config).returns('deploy' => { 'variables' => [{
- 'name' => 'SAFETY_DISABLED',
- 'title' => 'Set to 1 to do dangerous things',
- 'default' => 0,
- }] })
+ 'name' => 'SAFETY_DISABLED',
+ 'title' => 'Set to 1 to do dangerous things',
+ 'default' => 0
+ }] })
assert_equal 1, @spec.deploy_variables.size
variable_definition = @spec.deploy_variables.first
@@ -405,13 +406,13 @@ class DeploySpecTest < ActiveSupport::TestCase
end
test "task definitions don't prepend bundle exec by default" do
- @spec.expects(:load_config).returns('tasks' => { 'restart' => { 'steps' => %w(foo) } })
+ @spec.expects(:load_config).returns('tasks' => { 'restart' => { 'steps' => %w[foo] } })
definition = @spec.find_task_definition('restart')
assert_equal ['foo'], definition.steps
end
test "task definitions don't bundle exec before serialization" do
- @spec.expects(:discover_task_definitions).returns('restart' => { 'steps' => %w(foo) })
+ @spec.expects(:discover_task_definitions).returns('restart' => { 'steps' => %w[foo] })
@spec.expects(:bundler?).returns(true).at_least_once
cached_spec = DeploySpec.load(DeploySpec.dump(@spec))
@@ -430,7 +431,7 @@ class DeploySpecTest < ActiveSupport::TestCase
module TestTaskDiscovery
def discover_task_definitions
{
- 'config_task' => { 'steps' => %w(bar) },
+ 'config_task' => { 'steps' => %w[bar] }
}.merge!(super)
end
end
@@ -442,12 +443,12 @@ def discover_task_definitions
stack = shipit_stacks(:shipit)
@spec = DuplicateCustomizedDeploySpec.new(@app_dir, stack)
@spec.stubs(:load_config).returns(
- 'tasks' => { 'config_task' => { 'steps' => %w(foo) } },
+ 'tasks' => { 'config_task' => { 'steps' => %w[foo] } }
)
tasks = @spec.task_definitions
# Assert we get only the task from the config, not from the module
- assert_equal %w(config_task), tasks.map(&:id)
+ assert_equal %w[config_task], tasks.map(&:id)
assert_equal ["foo"], tasks.first.steps
end
@@ -461,7 +462,7 @@ def discover_task_definitions
module TestTaskDiscovery
def discover_task_definitions
{
- 'module_task' => { 'steps' => %w(bar) },
+ 'module_task' => { 'steps' => %w[bar] }
}.merge(super)
end
end
@@ -473,18 +474,18 @@ def discover_task_definitions
stack = shipit_stacks(:shipit)
@spec = CustomizedDeploySpec.new(@app_dir, stack)
@spec.stubs(:load_config).returns(
- 'tasks' => { 'config_task' => { 'steps' => %w(foo) } },
+ 'tasks' => { 'config_task' => { 'steps' => %w[foo] } },
'kubernetes' => {
'namespace' => 'foo',
'context' => 'bar',
- 'timeout' => '20m',
- },
+ 'timeout' => '20m'
+ }
)
tasks = @spec.task_definitions
# Assert we get tasks from all three sources: config, shipit-engine defined modules, and
# "third party" modules
- assert_equal %w(config_task module_task restart), tasks.map(&:id).sort
+ assert_equal %w[config_task module_task restart], tasks.map(&:id).sort
module_task = tasks.find { |t| t.id == "config_task" }
assert_equal ["foo"], module_task.steps
@@ -504,15 +505,15 @@ def discover_task_definitions
{
'name' => 'SAFETY_DISABLED',
'title' => 'Set to 1 to do dangerous things',
- 'default' => 0,
+ 'default' => 0
},
{
'name' => 'FOO',
'title' => 'Set to 0 to foo',
- 'default' => 1,
- },
+ 'default' => 1
+ }
],
- 'steps' => %w(foo),
+ 'steps' => %w[foo]
} })
assert_equal 2, @spec.task_definitions.first.variables.size
@@ -525,8 +526,8 @@ def discover_task_definitions
end
test "#review_checklist returns an array" do
- @spec.expects(:load_config).returns('review' => { 'checklist' => %w(foo bar) })
- assert_equal %w(foo bar), @spec.review_checklist
+ @spec.expects(:load_config).returns('review' => { 'checklist' => %w[foo bar] })
+ assert_equal %w[foo bar], @spec.review_checklist
end
test "#review_checklist returns an empty array if the section is missing" do
@@ -535,12 +536,12 @@ def discover_task_definitions
test "#review_monitoring returns an array of hashes" do
@spec.expects(:load_config).returns('review' => { 'monitoring' => [
- { 'image' => 'http://example.com/foo.png', 'width' => 200, 'height' => 400 },
- { 'iframe' => 'http://example.com/', 'width' => 200, 'height' => 400 },
- ] })
+ { 'image' => 'http://example.com/foo.png', 'width' => 200, 'height' => 400 },
+ { 'iframe' => 'http://example.com/', 'width' => 200, 'height' => 400 }
+ ] })
assert_equal [
{ 'image' => 'http://example.com/foo.png', 'width' => 200, 'height' => 400 },
- { 'iframe' => 'http://example.com/', 'width' => 200, 'height' => 400 },
+ { 'iframe' => 'http://example.com/', 'width' => 200, 'height' => 400 }
], @spec.review_monitoring
end
@@ -554,22 +555,22 @@ def discover_task_definitions
test "#hidden_statuses is an array even if the value is a string" do
@spec.expects(:load_config).returns('ci' => { 'hide' => 'ci/circleci' })
- assert_equal %w(ci/circleci), @spec.hidden_statuses
+ assert_equal %w[ci/circleci], @spec.hidden_statuses
end
test "#hidden_statuses is an array even if the value is present" do
- @spec.expects(:load_config).returns('ci' => { 'hide' => %w(ci/circleci ci/jenkins) })
- assert_equal %w(ci/circleci ci/jenkins), @spec.hidden_statuses
+ @spec.expects(:load_config).returns('ci' => { 'hide' => %w[ci/circleci ci/jenkins] })
+ assert_equal %w[ci/circleci ci/jenkins], @spec.hidden_statuses
end
test "#required_statuses automatically includes #blocking_statuses" do
@spec.expects(:load_config).returns(
'ci' => {
- 'require' => %w(ci/circleci),
- 'blocking' => %w(soc/compliance),
- },
+ 'require' => %w[ci/circleci],
+ 'blocking' => %w[soc/compliance]
+ }
)
- assert_equal %w(ci/circleci soc/compliance), @spec.required_statuses
+ assert_equal %w[ci/circleci soc/compliance], @spec.required_statuses
end
test "merge_request_merge_method defaults to `nil`" do
@@ -580,8 +581,8 @@ def discover_task_definitions
test "merge_request_merge_method returns `merge.method`" do
@spec.expects(:load_config).returns(
'merge' => {
- 'method' => 'squash',
- },
+ 'method' => 'squash'
+ }
)
assert_equal 'squash', @spec.merge_request_merge_method
end
@@ -589,8 +590,8 @@ def discover_task_definitions
test "merge_request_merge_method returns `nil` if `merge.method` is invalid" do
@spec.expects(:load_config).returns(
'merge' => {
- 'method' => 'squashing',
- },
+ 'method' => 'squashing'
+ }
)
assert_nil @spec.merge_request_merge_method
end
@@ -598,22 +599,22 @@ def discover_task_definitions
test "merge_request_ignored_statuses defaults to the union of ci.hide and ci.allow_failures" do
@spec.expects(:load_config).returns(
'ci' => {
- 'hide' => %w(ci/circleci ci/jenkins),
- 'allow_failures' => %w(ci/circleci ci/travis),
- },
+ 'hide' => %w[ci/circleci ci/jenkins],
+ 'allow_failures' => %w[ci/circleci ci/travis]
+ }
)
- assert_equal %w(ci/circleci ci/jenkins ci/travis).sort, @spec.merge_request_ignored_statuses.sort
+ assert_equal %w[ci/circleci ci/jenkins ci/travis].sort, @spec.merge_request_ignored_statuses.sort
end
test "merge_request_ignored_statuses defaults to empty if `merge.require` is present" do
@spec.expects(:load_config).returns(
'merge' => {
- 'require' => 'bar',
+ 'require' => 'bar'
},
'ci' => {
- 'hide' => %w(ci/circleci ci/jenkins),
- 'allow_failures' => %w(ci/circleci ci/travis),
- },
+ 'hide' => %w[ci/circleci ci/jenkins],
+ 'allow_failures' => %w[ci/circleci ci/travis]
+ }
)
assert_equal [], @spec.merge_request_ignored_statuses
end
@@ -621,12 +622,12 @@ def discover_task_definitions
test "merge_request_ignored_statuses returns `merge.ignore` if present" do
@spec.expects(:load_config).returns(
'merge' => {
- 'ignore' => 'bar',
+ 'ignore' => 'bar'
},
'ci' => {
- 'hide' => %w(ci/circleci ci/jenkins),
- 'allow_failures' => %w(ci/circleci ci/travis),
- },
+ 'hide' => %w[ci/circleci ci/jenkins],
+ 'allow_failures' => %w[ci/circleci ci/travis]
+ }
)
assert_equal ['bar'], @spec.merge_request_ignored_statuses
end
@@ -634,20 +635,20 @@ def discover_task_definitions
test "merge_request_required_statuses defaults to ci.require" do
@spec.expects(:load_config).returns(
'ci' => {
- 'require' => %w(ci/circleci ci/jenkins),
- },
+ 'require' => %w[ci/circleci ci/jenkins]
+ }
)
- assert_equal %w(ci/circleci ci/jenkins), @spec.merge_request_required_statuses
+ assert_equal %w[ci/circleci ci/jenkins], @spec.merge_request_required_statuses
end
test "merge_request_required_statuses defaults to empty if `merge.ignore` is present" do
@spec.expects(:load_config).returns(
'merge' => {
- 'ignore' => 'bar',
+ 'ignore' => 'bar'
},
'ci' => {
- 'require' => %w(ci/circleci ci/jenkins),
- },
+ 'require' => %w[ci/circleci ci/jenkins]
+ }
)
assert_equal [], @spec.merge_request_required_statuses
end
@@ -655,12 +656,12 @@ def discover_task_definitions
test "merge_request_required_statuses returns `merge.require` if present" do
@spec.expects(:load_config).returns(
'merge' => {
- 'require' => 'bar',
+ 'require' => 'bar'
},
'ci' => {
- 'hide' => %w(ci/circleci ci/jenkins),
- 'allow_failures' => %w(ci/circleci ci/travis),
- },
+ 'hide' => %w[ci/circleci ci/jenkins],
+ 'allow_failures' => %w[ci/circleci ci/travis]
+ }
)
assert_equal ['bar'], @spec.merge_request_required_statuses
end
@@ -673,8 +674,8 @@ def discover_task_definitions
test "revalidate_merge_requests_after defaults to `nil` if `merge.timeout` cannot be parsed" do
@spec.expects(:load_config).returns(
'merge' => {
- 'revalidate_after' => 'ALSKhfjsdkf',
- },
+ 'revalidate_after' => 'ALSKhfjsdkf'
+ }
)
assert_nil @spec.revalidate_merge_requests_after
end
@@ -682,8 +683,8 @@ def discover_task_definitions
test "revalidate_after returns `merge.revalidate_after` if present" do
@spec.expects(:load_config).returns(
'merge' => {
- 'revalidate_after' => '5m30s',
- },
+ 'revalidate_after' => '5m30s'
+ }
)
assert_equal 330, @spec.revalidate_merge_requests_after.to_i
end
@@ -1098,9 +1099,9 @@ def discover_task_definitions
@spec.expects(:load_config).returns(
'merge' => {
'max_divergence' => {
- 'age' => 'badbadbad',
- },
- },
+ 'age' => 'badbadbad'
+ }
+ }
)
assert_nil @spec.max_divergence_age
end
diff --git a/test/models/deploy_stats_test.rb b/test/models/deploy_stats_test.rb
index c91012b14..572a8fddd 100644
--- a/test/models/deploy_stats_test.rb
+++ b/test/models/deploy_stats_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/models/deploys_test.rb b/test/models/deploys_test.rb
index 51e120cf6..7436a3c48 100644
--- a/test/models/deploys_test.rb
+++ b/test/models/deploys_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -66,8 +67,8 @@ def setup
deploy_stack = runnable_deploy.stack
Shipit::Deploy.any_instance.expects(:acquire_git_cache_lock).twice
- .raises(Shipit::Command::TimedOut, 'Deploy timed out')
- .then.raises(Shipit::Command::Error, "Second command error failure")
+ .raises(Shipit::Command::TimedOut, 'Deploy timed out')
+ .then.raises(Shipit::Command::Error, "Second command error failure")
perform_enqueued_jobs(only: Shipit::PerformTaskJob) do
runnable_deploy.enqueue
@@ -90,8 +91,8 @@ def setup
deploy_stack = runnable_deploy.stack
Shipit::Deploy.any_instance.expects(:acquire_git_cache_lock).twice
- .raises(Shipit::Command::Error, 'Deploy failed')
- .then.raises(Shipit::Command::Error, "Second deploy failed")
+ .raises(Shipit::Command::Error, 'Deploy failed')
+ .then.raises(Shipit::Command::Error, "Second deploy failed")
perform_enqueued_jobs(only: Shipit::PerformTaskJob) do
runnable_deploy.enqueue
@@ -114,8 +115,8 @@ def setup
deploy_stack = runnable_deploy.stack
Shipit::Deploy.any_instance.expects(:acquire_git_cache_lock).twice
- .raises(StandardError, 'Deploy failed')
- .then.raises(StandardError, "Second deploy failed")
+ .raises(StandardError, 'Deploy failed')
+ .then.raises(StandardError, "Second deploy failed")
perform_enqueued_jobs(only: Shipit::PerformTaskJob) do
runnable_deploy.enqueue
@@ -138,7 +139,7 @@ def setup
runnable_deploy.update!(retry_attempt: 0, max_retries: 0)
Shipit::Deploy.any_instance.expects(:acquire_git_cache_lock)
- .raises(Shipit::Command::TimedOut, 'Deploy timed out')
+ .raises(Shipit::Command::TimedOut, 'Deploy timed out')
perform_enqueued_jobs(only: Shipit::PerformTaskJob) do
runnable_deploy.enqueue
@@ -157,8 +158,8 @@ def setup
DeploySpec.any_instance.expects(:retries_on_rollback).returns(1)
Shipit::Command.any_instance.expects(:run).twice
- .raises(Shipit::Command::TimedOut, 'Rollback timed out')
- .then.raises(Shipit::Command::Error, "Second command error failure")
+ .raises(Shipit::Command::TimedOut, 'Rollback timed out')
+ .then.raises(Shipit::Command::Error, "Second command error failure")
first_rollback = nil
@@ -185,8 +186,8 @@ def setup
DeploySpec.any_instance.expects(:retries_on_rollback).returns(0)
Shipit::Command.any_instance.expects(:run).once
- .raises(Shipit::Command::TimedOut, 'Rollback timed out')
- .then.raises(Shipit::Command::Error, "Second command error failure")
+ .raises(Shipit::Command::TimedOut, 'Rollback timed out')
+ .then.raises(Shipit::Command::Error, "Second command error failure")
first_rollback = nil
@@ -208,7 +209,7 @@ def setup
deploy = stack.deploys.create!(
since_commit: first,
- until_commit: third,
+ until_commit: third
)
assert_equal 13, deploy.additions
@@ -222,7 +223,7 @@ def setup
deploy = stack.deploys.new(
since_commit: first,
- until_commit: last,
+ until_commit: last
)
commits = deploy.commits
@@ -239,7 +240,7 @@ def setup
deploy = stack.deploys.new(
since_commit: first,
- until_commit: last,
+ until_commit: last
)
assert_equal [4, 3, 2], deploy.commits.pluck(:id)
@@ -260,7 +261,7 @@ def setup
expect_event(deploy)
deploy.status = 'running'
- expect_hook(:deploy, deploy.stack, status: 'success', deploy: deploy, stack: deploy.stack) do
+ expect_hook(:deploy, deploy.stack, status: 'success', deploy:, stack: deploy.stack) do
deploy.complete!
end
end
@@ -280,7 +281,7 @@ def setup
expect_event(deploy)
deploy.status = 'running'
- expect_hook(:deploy, deploy.stack, status: 'failed', deploy: deploy, stack: deploy.stack) do
+ expect_hook(:deploy, deploy.stack, status: 'failed', deploy:, stack: deploy.stack) do
deploy.failure!
end
end
@@ -300,7 +301,7 @@ def setup
expect_event(deploy)
deploy.status = 'running'
- expect_hook(:deploy, deploy.stack, status: 'error', deploy: deploy, stack: deploy.stack) do
+ expect_hook(:deploy, deploy.stack, status: 'error', deploy:, stack: deploy.stack) do
deploy.error!
end
end
@@ -320,7 +321,7 @@ def setup
expect_event(deploy)
deploy.status = 'pending'
- expect_hook(:deploy, deploy.stack, status: 'running', deploy: deploy, stack: deploy.stack) do
+ expect_hook(:deploy, deploy.stack, status: 'running', deploy:, stack: deploy.stack) do
deploy.run!
end
end
@@ -339,7 +340,7 @@ def setup
shipit = shipit_stacks(:shipit)
deploy = shipit.deploys.build(
since_commit: shipit.commits.first,
- until_commit: shipit.commits.last,
+ until_commit: shipit.commits.last
)
deploy.stubs(:merge_request_head_for_commit).returns(nil)
@@ -513,18 +514,18 @@ def setup
def create_test_stack(repository: Shipit::Repository.find_or_create_by!(owner: "shopify-test", name: "shipit-engine-test"))
Shipit::Stack.create(
- repository: repository,
+ repository:,
environment: 'production',
branch: "master",
merge_queue_enabled: true,
created_at: "2019-01-01 00:00:00",
- updated_at: "2019-01-02 10:10:10",
+ updated_at: "2019-01-02 10:10:10"
)
end
def create_test_commit(stack_id:, user_id:)
Shipit::Commit.new(
- stack_id: stack_id,
+ stack_id:,
author_id: user_id,
sha: SecureRandom.hex(20),
additions: 2,
@@ -532,27 +533,27 @@ def create_test_commit(stack_id:, user_id:)
committer_id: user_id,
message: "Some commit message.",
authored_at: "2019-01-02 10:11:10",
- committed_at: "2019-01-02 10:11:10",
+ committed_at: "2019-01-02 10:11:10"
)
end
def create_test_status(commit_id:, stack_id:, state: "success")
Shipit::Status.new(
description: "Description for commit #{commit_id}",
- stack_id: stack_id,
- commit_id: commit_id,
- state: state,
+ stack_id:,
+ commit_id:,
+ state:
)
end
def create_test_deploy(stack_id:, user_id:, since_commit_id:, until_commit_id: since_commit_id)
Shipit::Deploy.new(
- stack_id: stack_id,
- user_id: user_id,
- since_commit_id: since_commit_id,
- until_commit_id: until_commit_id,
+ stack_id:,
+ user_id:,
+ since_commit_id:,
+ until_commit_id:,
status: "success",
- type: "Shipit::Deploy",
+ type: "Shipit::Deploy"
)
end
@@ -567,13 +568,13 @@ def assert_generated_record_ids_are_sequential(record_id_series)
def generate_commits(amount:, stack_id:, user_id:, validate:)
commit_ids = []
amount.times do
- commit = create_test_commit(stack_id: stack_id, user_id: user_id)
+ commit = create_test_commit(stack_id:, user_id:)
commit.save
commit.reload
commit_ids << commit.id
end
- if validate then assert_generated_record_ids_are_sequential(commit_ids) end
+ assert_generated_record_ids_are_sequential(commit_ids) if validate
commit_ids
end
@@ -585,11 +586,11 @@ def generate_commits(amount:, stack_id:, user_id:, validate:)
stack_id = test_stack.id
# Create valid commit history for the stack. We need several commits to deploy and roll back through.
- commit_ids = generate_commits(amount: 4, stack_id: stack_id, user_id: user_id, validate: true)
- commit_ids.each { |commit_id| create_test_status(commit_id: commit_id, stack_id: stack_id, state: "success").save }
+ commit_ids = generate_commits(amount: 4, stack_id:, user_id:, validate: true)
+ commit_ids.each { |commit_id| create_test_status(commit_id:, stack_id:, state: "success").save }
# Three deploys of commits 1-2, 2-3 and 3-4 respectively. Reverting last should result in Deploy 3 (commit 3) being latest.
- 3.times { |index| create_test_deploy(stack_id: stack_id, user_id: user_id, since_commit_id: commit_ids[index], until_commit_id: commit_ids[index + 1]).save }
+ 3.times { |index| create_test_deploy(stack_id:, user_id:, since_commit_id: commit_ids[index], until_commit_id: commit_ids[index + 1]).save }
# Get the reference with Rails-mutated field values.
commit3 = Shipit::Commit.second_to_last
@@ -621,7 +622,7 @@ def generate_commits(amount:, stack_id:, user_id:, validate:)
running_deploy = shipit_deploys(:shipit_running)
rollback_to = shipit_deploys(:shipit_pending)
- final_rollback = running_deploy.trigger_revert(rollback_to: rollback_to)
+ final_rollback = running_deploy.trigger_revert(rollback_to:)
assert_equal "Shipit::Rollback", final_rollback.type
assert_equal 4, final_rollback.until_commit_id
@@ -635,8 +636,8 @@ def generate_commits(amount:, stack_id:, user_id:, validate:)
stack_id = test_stack.id
# Create valid commit history for the stack. We need several commits to deploy and roll back through.
- commit_ids = generate_commits(amount: 4, stack_id: stack_id, user_id: user_id, validate: true)
- commit_ids.each { |commit_id| create_test_status(commit_id: commit_id, stack_id: stack_id, state: "success").save }
+ commit_ids = generate_commits(amount: 4, stack_id:, user_id:, validate: true)
+ commit_ids.each { |commit_id| create_test_status(commit_id:, stack_id:, state: "success").save }
# We want the following order of Deploys:
# 1. Success (commits 1-2)
@@ -645,10 +646,10 @@ def generate_commits(amount:, stack_id:, user_id:, validate:)
# 4. Running (commits 3-4)
# 5. Reversion of the running deploy to the last successful deploy. (-> commits 1-2, i.e. the successful deploy.)
- deploy1 = create_test_deploy(stack_id: stack_id, user_id: user_id, since_commit_id: commit_ids[0], until_commit_id: commit_ids[1])
+ deploy1 = create_test_deploy(stack_id:, user_id:, since_commit_id: commit_ids[0], until_commit_id: commit_ids[1])
deploy1.save
- deploy2 = create_test_deploy(stack_id: stack_id, user_id: user_id, since_commit_id: commit_ids[1], until_commit_id: commit_ids[2])
+ deploy2 = create_test_deploy(stack_id:, user_id:, since_commit_id: commit_ids[1], until_commit_id: commit_ids[2])
deploy2.status = "faulty"
deploy2.save
@@ -658,7 +659,7 @@ def generate_commits(amount:, stack_id:, user_id:, validate:)
assert_equal commit_ids[1], test_stack.last_deployed_commit.id
- deploy3 = create_test_deploy(stack_id: stack_id, user_id: user_id, since_commit_id: commit_ids[2], until_commit_id: commit_ids[3])
+ deploy3 = create_test_deploy(stack_id:, user_id:, since_commit_id: commit_ids[2], until_commit_id: commit_ids[3])
deploy3.status = "running"
deploy3.rollback_once_aborted = false
deploy3.save
@@ -693,8 +694,8 @@ def generate_commits(amount:, stack_id:, user_id:, validate:)
stack_id = test_stack.id
# Create valid commit history for the stack. We need several commits to deploy and roll back through.
- commit_ids = generate_commits(amount: 4, stack_id: stack_id, user_id: user_id, validate: true)
- commit_ids.each { |commit_id| create_test_status(commit_id: commit_id, stack_id: stack_id, state: "success").save }
+ commit_ids = generate_commits(amount: 4, stack_id:, user_id:, validate: true)
+ commit_ids.each { |commit_id| create_test_status(commit_id:, stack_id:, state: "success").save }
# We want the following order of Deploys:
# 1. Success (commits 1-2)
@@ -703,14 +704,14 @@ def generate_commits(amount:, stack_id:, user_id:, validate:)
# 4. Reversion of the running deploy to the last successful deploy. (-> commits 1-2, i.e. the successful deploy.)
# If the revert functionality doesn't restrict to deploys and rollbacks, then commit 3 will be latest deployed when the reversion is done.
- deploy1 = create_test_deploy(stack_id: stack_id, user_id: user_id, since_commit_id: commit_ids[0], until_commit_id: commit_ids[1])
+ deploy1 = create_test_deploy(stack_id:, user_id:, since_commit_id: commit_ids[0], until_commit_id: commit_ids[1])
deploy1.save
- deploy2 = create_test_deploy(stack_id: stack_id, user_id: user_id, since_commit_id: commit_ids[1], until_commit_id: commit_ids[2])
+ deploy2 = create_test_deploy(stack_id:, user_id:, since_commit_id: commit_ids[1], until_commit_id: commit_ids[2])
deploy2.type = "Shipit::Fake"
deploy2.save
- deploy3 = create_test_deploy(stack_id: stack_id, user_id: user_id, since_commit_id: commit_ids[2], until_commit_id: commit_ids[3])
+ deploy3 = create_test_deploy(stack_id:, user_id:, since_commit_id: commit_ids[2], until_commit_id: commit_ids[3])
deploy3.status = "running"
deploy3.rollback_once_aborted = false
deploy3.save
@@ -744,8 +745,8 @@ def generate_commits(amount:, stack_id:, user_id:, validate:)
stack_id = test_stack.id
# Create valid commit history for the stack. We need several commits to deploy and roll back through.
- commit_ids = generate_commits(amount: 4, stack_id: stack_id, user_id: user_id, validate: true)
- commit_ids.each { |commit_id| create_test_status(commit_id: commit_id, stack_id: stack_id, state: "success").save }
+ commit_ids = generate_commits(amount: 4, stack_id:, user_id:, validate: true)
+ commit_ids.each { |commit_id| create_test_status(commit_id:, stack_id:, state: "success").save }
# We want the following order of Deploys:
# 1. Success (commits 1-2)
@@ -754,13 +755,13 @@ def generate_commits(amount:, stack_id:, user_id:, validate:)
# 4. Reversion of the running deploy to the last successful deploy of the same stack. (-> commits 1-2, i.e. the successful deploy.)
# If the revert functionality doesn't restrict to the correct stack, then commit 3 will be latest deployed when the reversion is done.
- deploy1 = create_test_deploy(stack_id: stack_id, user_id: user_id, since_commit_id: commit_ids[0], until_commit_id: commit_ids[1])
+ deploy1 = create_test_deploy(stack_id:, user_id:, since_commit_id: commit_ids[0], until_commit_id: commit_ids[1])
deploy1.save
- deploy2 = create_test_deploy(stack_id: other_stack.id, user_id: user_id, since_commit_id: commit_ids[1], until_commit_id: commit_ids[2])
+ deploy2 = create_test_deploy(stack_id: other_stack.id, user_id:, since_commit_id: commit_ids[1], until_commit_id: commit_ids[2])
deploy2.save
- deploy3 = create_test_deploy(stack_id: stack_id, user_id: user_id, since_commit_id: commit_ids[2], until_commit_id: commit_ids[3])
+ deploy3 = create_test_deploy(stack_id:, user_id:, since_commit_id: commit_ids[2], until_commit_id: commit_ids[3])
deploy3.status = "running"
deploy3.rollback_once_aborted = false
deploy3.save
@@ -788,9 +789,9 @@ def generate_commits(amount:, stack_id:, user_id:, validate:)
test_stack.reload
stack_id = test_stack.id
- commit_ids = generate_commits(amount: 2, stack_id: stack_id, user_id: user_id, validate: true)
- commit_ids.each { |commit_id| create_test_status(commit_id: commit_id, stack_id: stack_id, state: "success").save }
- deploy1 = create_test_deploy(stack_id: stack_id, user_id: user_id, since_commit_id: commit_ids[0], until_commit_id: commit_ids[1])
+ commit_ids = generate_commits(amount: 2, stack_id:, user_id:, validate: true)
+ commit_ids.each { |commit_id| create_test_status(commit_id:, stack_id:, state: "success").save }
+ deploy1 = create_test_deploy(stack_id:, user_id:, since_commit_id: commit_ids[0], until_commit_id: commit_ids[1])
deploy1.save
rollback = deploy1.trigger_revert
@@ -1093,7 +1094,7 @@ def generate_commits(amount:, stack_id:, user_id:, validate:)
template_task = shipit_tasks(:shipit_pending)
deploy = template_task.stack.deploys.build(
since_commit: template_task.since_commit,
- until_commit: template_task.until_commit,
+ until_commit: template_task.until_commit
)
expected_delta = deploy.commits.select(&:pull_request?).size + 1
diff --git a/test/models/duration_test.rb b/test/models/duration_test.rb
index 0b00ba915..089c4184b 100644
--- a/test/models/duration_test.rb
+++ b/test/models/duration_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -7,7 +8,6 @@ class DurationTest < ActiveSupport::TestCase
assert_equal Duration.new(1), Duration.new(1)
assert Duration.new(2) > Duration.new(1)
assert Duration.new(2) > 1
- assert 1 < Duration.new(2)
end
test "can be added to a Time instance" do
diff --git a/test/models/github_hook_test.rb b/test/models/github_hook_test.rb
index 458369d61..ece7d7db1 100644
--- a/test/models/github_hook_test.rb
+++ b/test/models/github_hook_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/models/hook_test.rb b/test/models/hook_test.rb
index f8a92f861..eade2a8af 100644
--- a/test/models/hook_test.rb
+++ b/test/models/hook_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -21,11 +22,11 @@ class HookTest < ActiveSupport::TestCase
end
test "#events is accessible as an array" do
- assert_equal %w(deploy rollback), @hook.events
+ assert_equal %w[deploy rollback], @hook.events
end
test "#events can only contain a defined set of values" do
- @hook.events = %w(foo)
+ @hook.events = %w[foo]
refute @hook.valid?
assert_equal ["Events is not a strict subset of #{Hook::EVENTS.inspect}"], @hook.errors.full_messages
end
diff --git a/test/models/membership_test.rb b/test/models/membership_test.rb
index 13f2fbb76..4970b6ab4 100644
--- a/test/models/membership_test.rb
+++ b/test/models/membership_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/models/merge_request_test.rb b/test/models/merge_request_test.rb
index a0140d4a6..401a0297f 100644
--- a/test/models/merge_request_test.rb
+++ b/test/models/merge_request_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -82,38 +83,38 @@ class MergeRequestTest < ActiveSupport::TestCase
merged_at: nil,
head: stub(
ref: 'super-branch',
- sha: head_sha,
+ sha: head_sha
),
base: stub(
- ref: 'default-branch',
- sha: base_sha,
- ),
- ),
+ ref: 'default-branch',
+ sha: base_sha
+ )
+ )
)
author = stub(
id: 1234,
login: 'bob',
name: 'Bob the Builder',
- email: 'bob@bob.com',
+ email: 'bob@bob.com'
)
[head_sha, base_sha].each do |sha|
Shipit.github.api.expects(:commit).with(@stack.github_repo_name, sha).returns(
stub(
- sha: sha,
- author: author,
+ sha:,
+ author:,
committer: author,
commit: stub(
message: 'Great feature',
author: stub(date: 1.day.ago),
- committer: stub(date: 1.day.ago),
+ committer: stub(date: 1.day.ago)
),
stats: stub(
additions: 24,
- deletions: 5,
- ),
- ),
+ deletions: 5
+ )
+ )
)
end
@@ -122,21 +123,21 @@ class MergeRequestTest < ActiveSupport::TestCase
description: nil,
context: 'default',
target_url: 'http://example.com',
- created_at: 1.day.ago,
+ created_at: 1.day.ago
)])
response = stub(rels: {}, data: stub(
check_runs: [stub(
- id: 123456,
+ id: 123_456,
name: 'check run',
conclusion: 'success',
output: stub(
- title: 'a test checkrun',
+ title: 'a test checkrun'
),
details_url: 'http://example.com',
html_url: 'http://example.com',
completed_at: Time.now,
- started_at: 1.minute.ago,
+ started_at: 1.minute.ago
)]
))
@@ -245,7 +246,7 @@ class MergeRequestTest < ActiveSupport::TestCase
end
test "status transitions emit hooks" do
- expected_args = ->(job_args) do
+ expected_args = lambda do |job_args|
job_args.first[:event] == 'merge'
end
job = assert_enqueued_with(job: EmitEventJob, args: expected_args) do
@@ -289,8 +290,8 @@ class MergeRequestTest < ActiveSupport::TestCase
@pr.base_ref = 'default-branch'
Shipit.github.api.expects(:compare).with(@stack.github_repo_name, @pr.base_ref, @pr.head.sha).returns(
stub(
- behind_by: 10,
- ),
+ behind_by: 10
+ )
)
spec = { 'merge' => { 'max_divergence' => { 'commits' => 1 } } }
@pr.stack.cached_deploy_spec = DeploySpec.new(spec)
diff --git a/test/models/release_statuses_test.rb b/test/models/release_statuses_test.rb
index 5687564ba..d47584a1a 100644
--- a/test/models/release_statuses_test.rb
+++ b/test/models/release_statuses_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -10,7 +11,7 @@ class ReleaseStatusesTest < ActiveSupport::TestCase
'pending',
context: 'shipit/canaries',
target_url: 'https://example.com/deploys/42',
- description: 'Deploy started',
+ description: 'Deploy started'
).returns(resource(id: 42))
@status = shipit_release_statuses(:to_be_created)
diff --git a/test/models/rollbacks_test.rb b/test/models/rollbacks_test.rb
index 9c5431d6b..c20e16213 100644
--- a/test/models/rollbacks_test.rb
+++ b/test/models/rollbacks_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -36,13 +37,13 @@ class RollbackTest < ActiveSupport::TestCase
author: reverted_commit.author,
committer: reverted_commit.committer,
authored_at: Time.zone.now,
- committed_at: Time.zone.now,
+ committed_at: Time.zone.now
)
expected = [
['Revert "Merge pull request #7 from shipit-engine/yoloshipit"', false, nil],
["whoami", false, nil],
- ['fix all the things', false, nil],
+ ['fix all the things', false, nil]
]
assert_equal(expected, @stack.undeployed_commits.map { |c| [c.title, c.locked?, c.lock_author_id] })
@@ -55,7 +56,7 @@ class RollbackTest < ActiveSupport::TestCase
['Revert "Merge pull request #7 from shipit-engine/yoloshipit"', false, nil],
["whoami", true, user_id],
['fix all the things', true, user_id],
- ['yoloshipit!', true, user_id],
+ ['yoloshipit!', true, user_id]
]
assert_equal(expected, @stack.undeployed_commits.map { |c| [c.title, c.locked?, c.lock_author_id] })
diff --git a/test/models/shipit/check_run_test.rb b/test/models/shipit/check_run_test.rb
index 7aa55a8f1..138c3c182 100644
--- a/test/models/shipit/check_run_test.rb
+++ b/test/models/shipit/check_run_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -33,14 +34,14 @@ class CheckRunTest < ActiveSupport::TestCase
assert_difference -> { @commit.check_runs.count }, +1 do
@commit.check_runs.create_or_update_from_github!(
@stack.id,
- github_check_run(conclusion: 'success', completed_at: completed_at)
+ github_check_run(conclusion: 'success', completed_at:)
)
end
assert_enqueued_with(job: RefreshCheckRunsJob) do
@commit.check_runs.create_or_update_from_github!(
@stack.id,
- github_check_run(conclusion: nil, completed_at: completed_at)
+ github_check_run(conclusion: nil, completed_at:)
)
end
@@ -50,9 +51,9 @@ class CheckRunTest < ActiveSupport::TestCase
@stack.id,
github_check_run(
conclusion: 'action_required',
- completed_at: completed_at,
- started_at: completed_at + 1.minute,
- ),
+ completed_at:,
+ started_at: completed_at + 1.minute
+ )
)
end
@@ -62,12 +63,12 @@ class CheckRunTest < ActiveSupport::TestCase
test ".create_or_update_from_github! is idempotent" do
completed_at = Time.now
assert_difference -> { @commit.check_runs.count }, +1 do
- @commit.check_runs.create_or_update_from_github!(@stack.id, github_check_run(completed_at: completed_at))
+ @commit.check_runs.create_or_update_from_github!(@stack.id, github_check_run(completed_at:))
end
assert_no_difference -> { @commit.check_runs.count } do
assert_no_enqueued_jobs(only: RefreshCheckRunsJob) do
- @commit.check_runs.create_or_update_from_github!(@stack.id, github_check_run(completed_at: completed_at))
+ @commit.check_runs.create_or_update_from_github!(@stack.id, github_check_run(completed_at:))
end
end
end
@@ -77,7 +78,7 @@ class CheckRunTest < ActiveSupport::TestCase
assert_difference -> { @commit.check_runs.count }, +1 do
@commit.check_runs.create_or_update_from_github!(
@stack.id,
- github_check_run(conclusion: 'success', completed_at: completed_at)
+ github_check_run(conclusion: 'success', completed_at:)
)
end
@@ -109,7 +110,7 @@ class CheckRunTest < ActiveSupport::TestCase
assert_difference -> { @commit.check_runs.count }, +1 do
@commit.check_runs.create_or_update_from_github!(
@stack.id,
- github_check_run(conclusion: 'success', completed_at: completed_at)
+ github_check_run(conclusion: 'success', completed_at:)
)
end
@@ -143,10 +144,10 @@ class CheckRunTest < ActiveSupport::TestCase
'neutral' => 'success',
'cancelled' => 'failure',
'timed_out' => 'error',
- 'action_required' => 'pending',
+ 'action_required' => 'pending'
}.each do |conclusion, expected_status|
test "#state is #{expected_status.inspect} when conclusion is #{conclusion.inspect}" do
- @check_run.update!(conclusion: conclusion)
+ @check_run.update!(conclusion:)
assert_equal expected_status, @check_run.state
end
end
@@ -156,15 +157,15 @@ class CheckRunTest < ActiveSupport::TestCase
def github_check_run(conclusion: 'success', completed_at: Time.now, started_at: Time.now - 1.minute)
OpenStruct.new(
id: 424_242,
- conclusion: conclusion,
+ conclusion:,
output: OpenStruct.new(
- description: 'This is a description',
+ description: 'This is a description'
),
name: 'Test Suite',
html_url: 'http://example.com/run',
details_url: 'http://example.com/details',
- completed_at: completed_at,
- started_at: started_at,
+ completed_at:,
+ started_at:
)
end
end
diff --git a/test/models/shipit/continuous_delivery_schedule_test.rb b/test/models/shipit/continuous_delivery_schedule_test.rb
index 2c41bcee4..1e311f33a 100644
--- a/test/models/shipit/continuous_delivery_schedule_test.rb
+++ b/test/models/shipit/continuous_delivery_schedule_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require "test_helper"
module Shipit
@@ -9,7 +10,7 @@ class ContinuousDeliveryScheduleTest < ActiveSupport::TestCase
assert(schedule.valid?)
- Shipit::ContinuousDeliverySchedule::DAYS.each_with_index do |day|
+ Shipit::ContinuousDeliverySchedule::DAYS.each do |day|
assert(schedule.read_attribute("#{day}_enabled"))
day_start = schedule.read_attribute("#{day}_start")
@@ -24,7 +25,7 @@ class ContinuousDeliveryScheduleTest < ActiveSupport::TestCase
schedule = Shipit::ContinuousDeliverySchedule.new(
monday_enabled: false,
monday_start: "09:15",
- monday_end: "17:30",
+ monday_end: "17:30"
)
monday = Date.current.monday
@@ -50,7 +51,7 @@ class ContinuousDeliveryScheduleTest < ActiveSupport::TestCase
schedule = Shipit::ContinuousDeliverySchedule.new(
tuesday_enabled: false,
tuesday_start: "00:00",
- tuesday_end: "23:59",
+ tuesday_end: "23:59"
)
tuesday = Date.current.monday.advance(days: 1).beginning_of_day
@@ -62,7 +63,7 @@ class ContinuousDeliveryScheduleTest < ActiveSupport::TestCase
schedule = Shipit::ContinuousDeliverySchedule.new(
wednesday_enabled: true,
wednesday_start: "09:15",
- wednesday_end: "17:30",
+ wednesday_end: "17:30"
)
wednesday = Date.current.monday.advance(days: 2).beginning_of_day
@@ -87,7 +88,7 @@ class ContinuousDeliveryScheduleTest < ActiveSupport::TestCase
test "validates `*_enabled` fields" do
schedule = Shipit::ContinuousDeliverySchedule.new(
- friday_enabled: nil,
+ friday_enabled: nil
)
schedule.validate
@@ -97,7 +98,7 @@ class ContinuousDeliveryScheduleTest < ActiveSupport::TestCase
test "requires `_start` and `_end` fields" do
schedule = Shipit::ContinuousDeliverySchedule.new(
saturday_start: nil,
- saturday_end: nil,
+ saturday_end: nil
)
schedule.validate
diff --git a/test/models/shipit/deploy_spec/file_system_test.rb b/test/models/shipit/deploy_spec/file_system_test.rb
index ece77e67b..329408452 100644
--- a/test/models/shipit/deploy_spec/file_system_test.rb
+++ b/test/models/shipit/deploy_spec/file_system_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
require 'tmpdir'
@@ -9,7 +10,7 @@ class FileSystemTest < ActiveSupport::TestCase
Shipit.expects(:respect_bare_shipit_file?).returns(false).at_least_once
stack = shipit_stacks(:shipit)
deploy_spec = Shipit::DeploySpec::FileSystem.new(Dir.tmpdir, stack)
- deploy_spec.expects(:config_file_path).returns(Pathname.new(Dir.tmpdir) + '/shipit.yml').at_least_once
+ deploy_spec.expects(:config_file_path).returns("#{Pathname.new(Dir.tmpdir)}/shipit.yml").at_least_once
deploy_spec.expects(:read_config).never
pre_commands = deploy_spec.send(:config, 'deploy', 'pre')
assert pre_commands.include?('exit 1')
@@ -21,7 +22,7 @@ class FileSystemTest < ActiveSupport::TestCase
Shipit.expects(:respect_bare_shipit_file?).returns(true).at_least_once
stack = shipit_stacks(:shipit)
deploy_spec = Shipit::DeploySpec::FileSystem.new(Dir.tmpdir, stack)
- deploy_spec.expects(:config_file_path).returns(Pathname.new(Dir.tmpdir) + '/shipit.yml').at_least_once
+ deploy_spec.expects(:config_file_path).returns("#{Pathname.new(Dir.tmpdir)}/shipit.yml").at_least_once
deploy_spec.expects(:read_config).returns(SafeYAML.load(deploy_spec_yaml))
pre_commands = deploy_spec.send(:config, 'deploy', 'pre')
refute pre_commands.include?('exit 1')
@@ -33,7 +34,7 @@ class FileSystemTest < ActiveSupport::TestCase
Shipit.expects(:respect_bare_shipit_file?).returns(obey_val).at_least_once
stack = shipit_stacks(:shipit)
deploy_spec = Shipit::DeploySpec::FileSystem.new(Dir.tmpdir, stack)
- deploy_spec.expects(:config_file_path).returns(Pathname.new(Dir.tmpdir) + '/shipit.env.yml').at_least_once
+ deploy_spec.expects(:config_file_path).returns("#{Pathname.new(Dir.tmpdir)}/shipit.env.yml").at_least_once
deploy_spec.expects(:read_config).returns(SafeYAML.load(deploy_spec_yaml))
pre_commands = deploy_spec.send(:config, 'deploy', 'pre')
refute pre_commands.include?('exit 1')
@@ -45,7 +46,7 @@ class FileSystemTest < ActiveSupport::TestCase
Shipit.expects(:respect_bare_shipit_file?).returns(true).at_least_once
stack = shipit_stacks(:shipit)
deploy_spec = Shipit::DeploySpec::FileSystem.new(Dir.tmpdir, stack)
- deploy_spec.expects(:config_file_path).returns(Pathname.new(Dir.tmpdir) + '/shipit.env.yml').at_least_once
+ deploy_spec.expects(:config_file_path).returns("#{Pathname.new(Dir.tmpdir)}/shipit.env.yml").at_least_once
deploy_spec.expects(:read_config).at_least_once.returns(false)
loaded_config = deploy_spec.send(:cacheable_config)
refute loaded_config == false
@@ -55,7 +56,7 @@ class FileSystemTest < ActiveSupport::TestCase
Shipit.expects(:respect_bare_shipit_file?).returns(false).at_least_once
stack = shipit_stacks(:shipit)
deploy_spec = Shipit::DeploySpec::FileSystem.new(Dir.tmpdir, stack)
- deploy_spec.expects(:config_file_path).returns(Pathname.new(Dir.tmpdir) + '/shipit.yml').at_least_once
+ deploy_spec.expects(:config_file_path).returns("#{Pathname.new(Dir.tmpdir)}/shipit.yml").at_least_once
deploy_spec.expects(:read_config).never
loaded_config = deploy_spec.send(:load_config)
assert loaded_config.key?("deploy")
diff --git a/test/models/shipit/pull_request_test.rb b/test/models/shipit/pull_request_test.rb
index 344d50bcf..7b4f5a484 100644
--- a/test/models/shipit/pull_request_test.rb
+++ b/test/models/shipit/pull_request_test.rb
@@ -8,28 +8,28 @@ class PullRequestTest < ActiveSupport::TestCase
github_pull_request = resource(
{
url: "https://api.github.com/repos/Codertocat/Hello-World/pulls/2",
- id: 279147437,
+ id: 279_147_437,
number: 2,
state: "open",
additions: 100,
deletions: 101,
title: "Update the README with new information.",
head: {
- sha: "ec26c3e57ca3a959ca5aad62de7213c562f8c821",
+ sha: "ec26c3e57ca3a959ca5aad62de7213c562f8c821"
},
user: {
- login: "Codertocat",
+ login: "Codertocat"
},
assignees: [
{
- login: "bob",
- },
+ login: "bob"
+ }
],
labels: [
{
- name: "deploy",
- },
- ],
+ name: "deploy"
+ }
+ ]
}
)
stack = shipit_stacks(:review_stack)
@@ -37,7 +37,7 @@ class PullRequestTest < ActiveSupport::TestCase
stack.pull_request.github_pull_request = github_pull_request
- assert_equal 279147437, pull_request.github_id
+ assert_equal 279_147_437, pull_request.github_id
assert_equal 2, pull_request.number
assert_equal "https://api.github.com/repos/Codertocat/Hello-World/pulls/2", pull_request.api_url
assert_equal "Update the README with new information.", pull_request.title
diff --git a/test/models/shipit/repository_test.rb b/test/models/shipit/repository_test.rb
index b71f21384..8a6adee47 100644
--- a/test/models/shipit/repository_test.rb
+++ b/test/models/shipit/repository_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -23,7 +24,7 @@ class RepositoryTest < ActiveSupport::TestCase
error = assert_raises(ActiveRecord::RecordInvalid) do
Repository.create!(
owner: @repository.owner.upcase,
- name: @repository.name.upcase,
+ name: @repository.name.upcase
)
end
assert_equal 'Validation failed: Name cannot be used more than once', error.message
@@ -71,7 +72,7 @@ class RepositoryTest < ActiveSupport::TestCase
owner = "repository-owner"
name = "repository-name"
github_repo_name = [owner, name].join("/")
- expected_repository = Repository.create(owner: owner, name: name)
+ expected_repository = Repository.create(owner:, name:)
found_repository = Repository.from_github_repo_name(github_repo_name)
diff --git a/test/models/shipit/review_stack_provisioning_queue_test.rb b/test/models/shipit/review_stack_provisioning_queue_test.rb
index cfaa858cd..85be20444 100644
--- a/test/models/shipit/review_stack_provisioning_queue_test.rb
+++ b/test/models/shipit/review_stack_provisioning_queue_test.rb
@@ -39,7 +39,7 @@ class ReviewStackProvisioningQueueTest < ActiveSupport::TestCase
def setup_provisioning_handler(for_stack:, provision:)
provisioning_handler_instance = mock("ProvisioningHandler instance")
provisioning_handler_instance.expects(:provision?).returns(provision)
- provisioning_handler_instance.expects(:up).returns(true) if !!provision
+ provisioning_handler_instance.expects(:up).returns(true) if provision
provisioning_handler_class = mock("ProvisioningHandler class")
provisioning_handler_class.expects(:new).at_least_once.with(for_stack).returns(provisioning_handler_instance)
Shipit::ProvisioningHandler.expects(:fetch).at_least_once.returns(provisioning_handler_class)
@@ -50,7 +50,7 @@ def setup_provisioning_handler(for_stack:, provision:)
def provisionable_review_stack
review_stack = shipit_stacks(:review_stack)
review_stack.update(
- provision_status: :deprovisioned,
+ provision_status: :deprovisioned
)
review_stack
diff --git a/test/models/shipit/stack_test.rb b/test/models/shipit/stack_test.rb
index a65e82efe..693720676 100644
--- a/test/models/shipit/stack_test.rb
+++ b/test/models/shipit/stack_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
require 'securerandom'
@@ -82,10 +83,10 @@ def self.deliver(event, stack, payload)
last_commit = shipit_commits(:third)
deploy = @stack.trigger_deploy(last_commit, AnonymousUser.new)
assert_includes(FakeReceiver.hooks, [
- :deploy,
- @stack,
- { deploy: deploy, status: "pending", stack: @stack },
- ])
+ :deploy,
+ @stack,
+ { deploy:, status: "pending", stack: @stack }
+ ])
ensure
Shipit.internal_hook_receivers = original_receivers
end
@@ -262,7 +263,7 @@ def self.deliver(event, stack, payload)
stack = Stack.create!(
repository: Repository.new(owner: "foo", name: "bar"),
environment: 'production',
- branch: 'main',
+ branch: 'main'
)
commit = shipit_commits(:first)
stack.commits << commit
@@ -815,7 +816,7 @@ def self.deliver(event, stack, payload)
assert !commits.empty?
commits.each { |c| refute_predicate c, :deployable? }
- assert_nil @stack.next_expected_commit_to_deploy(commits: commits)
+ assert_nil @stack.next_expected_commit_to_deploy(commits:)
end
test "#next_expected_commit_to_deploy returns nil if all deployable commits are active" do
@@ -825,7 +826,7 @@ def self.deliver(event, stack, payload)
assert !commits.empty?
commits.each { |c| assert_predicate c, :active? }
- assert_nil @stack.next_expected_commit_to_deploy(commits: commits)
+ assert_nil @stack.next_expected_commit_to_deploy(commits:)
end
test "#next_expected_commit_to_deploy returns nil if there are no commits" do
@@ -838,7 +839,7 @@ def self.deliver(event, stack, payload)
assert !commits.empty?
- most_recent_limited = @stack.next_expected_commit_to_deploy(commits: commits)
+ most_recent_limited = @stack.next_expected_commit_to_deploy(commits:)
most_recent = commits.find { |c| !c.active? && c.deployable? }
assert most_recent.id > most_recent_limited.id
@@ -857,16 +858,16 @@ def self.deliver(event, stack, payload)
test "#lock_reverted_commits! locks all commits between the original and reverted commits" do
reverted_commit = @stack.undeployed_commits.first
revert_author = shipit_users(:bob)
- generate_revert_commit(stack: @stack, reverted_commit: reverted_commit, author: revert_author)
+ generate_revert_commit(stack: @stack, reverted_commit:, author: revert_author)
@stack.reload
assert_equal(
[
['Revert "whoami"', false, nil],
["whoami", false, nil],
- ["fix all the things", false, nil],
+ ["fix all the things", false, nil]
],
- @stack.undeployed_commits.map { |c| [c.message, c.locked, c.lock_author_id] },
+ @stack.undeployed_commits.map { |c| [c.message, c.locked, c.lock_author_id] }
)
@stack.lock_reverted_commits!
@@ -876,27 +877,27 @@ def self.deliver(event, stack, payload)
[
['Revert "whoami"', false, nil],
["whoami", true, revert_author.id],
- ["fix all the things", false, nil],
+ ["fix all the things", false, nil]
],
- @stack.undeployed_commits.map { |c| [c.message, c.locked, c.lock_author_id] },
+ @stack.undeployed_commits.map { |c| [c.message, c.locked, c.lock_author_id] }
)
end
test "#lock_reverted_commits! is a no-op if the reverted commit has already shipped" do
reverted_commit = shipit_commits(:first)
revert_author = shipit_users(:bob)
- generate_revert_commit(stack: @stack, reverted_commit: reverted_commit, author: revert_author)
+ generate_revert_commit(stack: @stack, reverted_commit:, author: revert_author)
@stack.reload
initial_state = [
['Revert "lets go"', false, nil],
["whoami", false, nil],
- ["fix all the things", false, nil],
+ ["fix all the things", false, nil]
]
assert_equal(
initial_state,
- @stack.undeployed_commits.map { |c| [c.message, c.locked, c.lock_author_id] },
+ @stack.undeployed_commits.map { |c| [c.message, c.locked, c.lock_author_id] }
)
@stack.lock_reverted_commits!
@@ -904,7 +905,7 @@ def self.deliver(event, stack, payload)
assert_equal(
initial_state,
- @stack.undeployed_commits.map { |c| [c.message, c.locked, c.lock_author_id] },
+ @stack.undeployed_commits.map { |c| [c.message, c.locked, c.lock_author_id] }
)
end
@@ -922,9 +923,9 @@ def self.deliver(event, stack, payload)
['Revert "whoami"', false, nil],
['Revert "fix all the things"', false, nil],
["whoami", false, nil],
- ["fix all the things", false, nil],
+ ["fix all the things", false, nil]
],
- @stack.undeployed_commits.map { |c| [c.message, c.locked, c.lock_author_id] },
+ @stack.undeployed_commits.map { |c| [c.message, c.locked, c.lock_author_id] }
)
@stack.lock_reverted_commits!
@@ -935,9 +936,9 @@ def self.deliver(event, stack, payload)
['Revert "whoami"', false, nil],
['Revert "fix all the things"', true, second_revert_author.id],
["whoami", true, first_revert_author.id],
- ["fix all the things", true, first_revert_author.id],
+ ["fix all the things", true, first_revert_author.id]
],
- @stack.undeployed_commits.map { |c| [c.message, c.locked, c.lock_author_id] },
+ @stack.undeployed_commits.map { |c| [c.message, c.locked, c.lock_author_id] }
)
end
@@ -962,16 +963,16 @@ def self.deliver(event, stack, payload)
@stack.cached_deploy_spec = create_deploy_spec(
"links" => {
"logs" => "http://logs.$GITHUB_REPO_NAME.$ENVIRONMENT.domain.com",
- "monitoring" => "https://graphs.$GITHUB_REPO_NAME.$ENVIRONMENT.domain.com",
- },
+ "monitoring" => "https://graphs.$GITHUB_REPO_NAME.$ENVIRONMENT.domain.com"
+ }
)
assert_equal(
{
"logs" => "http://logs.expected-repository-name.expected-environment.domain.com",
- "monitoring" => "https://graphs.expected-repository-name.expected-environment.domain.com",
+ "monitoring" => "https://graphs.expected-repository-name.expected-environment.domain.com"
},
- @stack.links,
+ @stack.links
)
end
@@ -982,12 +983,12 @@ def self.deliver(event, stack, payload)
'GITHUB_REPO_OWNER' => @stack.repository.owner,
'GITHUB_REPO_NAME' => @stack.repository.name,
'DEPLOY_URL' => @stack.deploy_url,
- 'BRANCH' => @stack.branch,
+ 'BRANCH' => @stack.branch
}
assert_equal(
@stack.env,
- expected_environment,
+ expected_environment
)
end
@@ -1013,10 +1014,10 @@ def generate_revert_commit(stack:, reverted_commit:, author: reverted_commit.aut
stack.commits.create(
sha: SecureRandom.hex(20),
message: "Revert \"#{reverted_commit.message_header}\"",
- author: author,
+ author:,
committer: author,
authored_at: Time.zone.now,
- committed_at: Time.zone.now,
+ committed_at: Time.zone.now
)
end
diff --git a/test/models/shipit/webhooks/handlers/pull_request/closed_handler_test.rb b/test/models/shipit/webhooks/handlers/pull_request/closed_handler_test.rb
index e38207da7..82f8abe82 100644
--- a/test/models/shipit/webhooks/handlers/pull_request/closed_handler_test.rb
+++ b/test/models/shipit/webhooks/handlers/pull_request/closed_handler_test.rb
@@ -42,7 +42,7 @@ class ClosedHandlerTest < ActiveSupport::TestCase
stack = create_stack
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :allow_all
)
@@ -55,7 +55,7 @@ class ClosedHandlerTest < ActiveSupport::TestCase
stack = create_stack
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :allow_with_label,
label: "pull-requests-label"
)
@@ -71,7 +71,7 @@ class ClosedHandlerTest < ActiveSupport::TestCase
stack = create_stack
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :allow_with_label,
label: "pull-requests-label"
)
@@ -87,7 +87,7 @@ class ClosedHandlerTest < ActiveSupport::TestCase
stack = create_stack
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :prevent_with_label,
label: "pull-requests-label"
)
@@ -103,7 +103,7 @@ class ClosedHandlerTest < ActiveSupport::TestCase
stack = create_stack
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :prevent_with_label,
label: "pull-requests-label"
)
@@ -150,8 +150,8 @@ def create_stack
def complete_active_tasks(stack)
active_tasks = stack
- .tasks
- .active
+ .tasks
+ .active
active_tasks.map(&:run)
active_tasks.reload
@@ -160,32 +160,32 @@ def complete_active_tasks(stack)
setup do
Shipit.github.api.stubs(:commit)
- .with("shopify/shipit-engine", "ec26c3e57ca3a959ca5aad62de7213c562f8c821")
- .returns(
- resource(
- {
- sha: "ec26c3e57ca3a959ca5aad62de7213c562f8c821",
- commit: {
- author: {
- name: "Codertocat",
- email: "21031067+Codertocat@users.noreply.github.com",
- date: "2019-05-15 15:20:30",
- },
- committer: {
- name: "Codertocat",
- email: "21031067+Codertocat@users.noreply.github.com",
- date: "2019-05-15 15:20:30",
- },
- message: "Update README.md",
- },
- stats: {
- total: 2,
- additions: 1,
- deletions: 1,
- },
- }
- )
- )
+ .with("shopify/shipit-engine", "ec26c3e57ca3a959ca5aad62de7213c562f8c821")
+ .returns(
+ resource(
+ {
+ sha: "ec26c3e57ca3a959ca5aad62de7213c562f8c821",
+ commit: {
+ author: {
+ name: "Codertocat",
+ email: "21031067+Codertocat@users.noreply.github.com",
+ date: "2019-05-15 15:20:30"
+ },
+ committer: {
+ name: "Codertocat",
+ email: "21031067+Codertocat@users.noreply.github.com",
+ date: "2019-05-15 15:20:30"
+ },
+ message: "Update README.md"
+ },
+ stats: {
+ total: 2,
+ additions: 1,
+ deletions: 1
+ }
+ }
+ )
+ )
end
end
end
diff --git a/test/models/shipit/webhooks/handlers/pull_request/label_capturing_handler_test.rb b/test/models/shipit/webhooks/handlers/pull_request/label_capturing_handler_test.rb
index 77b91d459..7b1a6c734 100644
--- a/test/models/shipit/webhooks/handlers/pull_request/label_capturing_handler_test.rb
+++ b/test/models/shipit/webhooks/handlers/pull_request/label_capturing_handler_test.rb
@@ -153,8 +153,8 @@ def create_stack
def complete_active_tasks(stack)
active_tasks = stack
- .tasks
- .active
+ .tasks
+ .active
active_tasks.map(&:run)
active_tasks.reload
@@ -175,32 +175,32 @@ def environment_for(payload)
setup do
Shipit.github.api.stubs(:commit)
- .with("shopify/shipit-engine", "ec26c3e57ca3a959ca5aad62de7213c562f8c821")
- .returns(
- resource(
- {
- sha: "ec26c3e57ca3a959ca5aad62de7213c562f8c821",
- commit: {
- author: {
- name: "Codertocat",
- email: "21031067+Codertocat@users.noreply.github.com",
- date: "2019-05-15 15:20:30",
- },
- committer: {
- name: "Codertocat",
- email: "21031067+Codertocat@users.noreply.github.com",
- date: "2019-05-15 15:20:30",
- },
- message: "Update README.md",
- },
- stats: {
- total: 2,
- additions: 1,
- deletions: 1,
- },
- }
- )
- )
+ .with("shopify/shipit-engine", "ec26c3e57ca3a959ca5aad62de7213c562f8c821")
+ .returns(
+ resource(
+ {
+ sha: "ec26c3e57ca3a959ca5aad62de7213c562f8c821",
+ commit: {
+ author: {
+ name: "Codertocat",
+ email: "21031067+Codertocat@users.noreply.github.com",
+ date: "2019-05-15 15:20:30"
+ },
+ committer: {
+ name: "Codertocat",
+ email: "21031067+Codertocat@users.noreply.github.com",
+ date: "2019-05-15 15:20:30"
+ },
+ message: "Update README.md"
+ },
+ stats: {
+ total: 2,
+ additions: 1,
+ deletions: 1
+ }
+ }
+ )
+ )
end
end
end
diff --git a/test/models/shipit/webhooks/handlers/pull_request/labeled_handler_test.rb b/test/models/shipit/webhooks/handlers/pull_request/labeled_handler_test.rb
index b8cc48641..03b72eb4a 100644
--- a/test/models/shipit/webhooks/handlers/pull_request/labeled_handler_test.rb
+++ b/test/models/shipit/webhooks/handlers/pull_request/labeled_handler_test.rb
@@ -26,7 +26,7 @@ class LabeledHandlerTest < ActiveSupport::TestCase
test "ignores Github PullRequest webhooks when the Repository has disabled the Review Stacks feature" do
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
provisioning_enabled: false,
behavior: :allow_with_label,
label: "pull-requests-label"
@@ -40,7 +40,7 @@ class LabeledHandlerTest < ActiveSupport::TestCase
test "ignores Github PullRequest webhooks when the repository allows_all PullRequests to create ReviewStacks" do
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :allow_all
)
@@ -53,7 +53,7 @@ class LabeledHandlerTest < ActiveSupport::TestCase
stack = create_archived_stack
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :allow_with_label,
label: "pull-requests-label"
)
@@ -69,7 +69,7 @@ class LabeledHandlerTest < ActiveSupport::TestCase
test "creates and provisions a new review stack when the repository creates ReviewStacks with allow_with_label and the label is present" do
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :allow_with_label,
label: "pull-requests-label"
)
@@ -91,7 +91,7 @@ class LabeledHandlerTest < ActiveSupport::TestCase
stack = create_stack
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :allow_with_label,
label: "pull-requests-label"
)
@@ -107,7 +107,7 @@ class LabeledHandlerTest < ActiveSupport::TestCase
stack = create_stack
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :allow_with_label,
label: "pull-requests-label"
)
@@ -122,7 +122,7 @@ class LabeledHandlerTest < ActiveSupport::TestCase
test "ignores Github PullRequest webhooks when the repository allow_with_label to create ReviewStacks and the label is absent" do
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :allow_with_label,
label: "pull-requests-label"
)
@@ -138,7 +138,7 @@ class LabeledHandlerTest < ActiveSupport::TestCase
stack = create_stack
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :prevent_with_label,
label: "pull-requests-label"
)
@@ -152,7 +152,7 @@ class LabeledHandlerTest < ActiveSupport::TestCase
stack = create_stack
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :prevent_with_label,
label: "pull-requests-label"
)
@@ -165,7 +165,7 @@ class LabeledHandlerTest < ActiveSupport::TestCase
test "ignores Github PullRequest webhooks when the repository prevent_with_label to create ReviewStacks and the label is present" do
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :prevent_with_label,
label: "pull-requests-label"
)
@@ -179,7 +179,7 @@ class LabeledHandlerTest < ActiveSupport::TestCase
stack = create_archived_stack
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :prevent_with_label,
label: "pull-requests-label"
)
@@ -195,7 +195,7 @@ class LabeledHandlerTest < ActiveSupport::TestCase
test "creates and provisions a new review stack when the repository creates ReviewStacks with prevent_with_label and the label is absent" do
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :prevent_with_label,
label: "pull-requests-label"
)
@@ -216,7 +216,7 @@ class LabeledHandlerTest < ActiveSupport::TestCase
test "assigns the PullRequest to newly created stacks" do
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :prevent_with_label,
label: "pull-requests-label"
)
@@ -232,7 +232,7 @@ class LabeledHandlerTest < ActiveSupport::TestCase
create_archived_stack
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :allow_with_label,
label: "pull-requests-label"
)
@@ -281,8 +281,8 @@ def create_stack
def complete_active_tasks(stack)
active_tasks = stack
- .tasks
- .active
+ .tasks
+ .active
active_tasks.map(&:run)
active_tasks.reload
@@ -298,32 +298,32 @@ def assert_pending_provision(stack)
setup do
Shipit.github.api.stubs(:commit)
- .with("shopify/shipit-engine", "ec26c3e57ca3a959ca5aad62de7213c562f8c821")
- .returns(
- resource(
- {
- sha: "ec26c3e57ca3a959ca5aad62de7213c562f8c821",
- commit: {
- author: {
- name: "Codertocat",
- email: "21031067+Codertocat@users.noreply.github.com",
- date: "2019-05-15 15:20:30",
- },
- committer: {
- name: "Codertocat",
- email: "21031067+Codertocat@users.noreply.github.com",
- date: "2019-05-15 15:20:30",
- },
- message: "Update README.md",
- },
- stats: {
- total: 2,
- additions: 1,
- deletions: 1,
- },
- }
- )
- )
+ .with("shopify/shipit-engine", "ec26c3e57ca3a959ca5aad62de7213c562f8c821")
+ .returns(
+ resource(
+ {
+ sha: "ec26c3e57ca3a959ca5aad62de7213c562f8c821",
+ commit: {
+ author: {
+ name: "Codertocat",
+ email: "21031067+Codertocat@users.noreply.github.com",
+ date: "2019-05-15 15:20:30"
+ },
+ committer: {
+ name: "Codertocat",
+ email: "21031067+Codertocat@users.noreply.github.com",
+ date: "2019-05-15 15:20:30"
+ },
+ message: "Update README.md"
+ },
+ stats: {
+ total: 2,
+ additions: 1,
+ deletions: 1
+ }
+ }
+ )
+ )
end
end
end
diff --git a/test/models/shipit/webhooks/handlers/pull_request/opened_handler_test.rb b/test/models/shipit/webhooks/handlers/pull_request/opened_handler_test.rb
index 2bcd3a75e..d5474c7ab 100644
--- a/test/models/shipit/webhooks/handlers/pull_request/opened_handler_test.rb
+++ b/test/models/shipit/webhooks/handlers/pull_request/opened_handler_test.rb
@@ -51,7 +51,7 @@ class OpenedHandlerTest < ActiveSupport::TestCase
url: "https://api.github.com/user/some-new-user-login"
)
Shipit.github.api.expects(:user).with("some-new-user-login")
- .returns(github_user)
+ .returns(github_user)
payload = payload_parsed(:pull_request_opened)
payload["pull_request"]["user"]["login"] = github_user.login
@@ -96,7 +96,7 @@ class OpenedHandlerTest < ActiveSupport::TestCase
test "only provision stacks for repos with auto-provisioning enabled" do
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
provisioning_enabled: false,
behavior: :allow_all
)
@@ -116,7 +116,7 @@ class OpenedHandlerTest < ActiveSupport::TestCase
test "creates stacks for repos that allow_all" do
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :allow_all,
label: "pull-requests-label"
)
@@ -129,7 +129,7 @@ class OpenedHandlerTest < ActiveSupport::TestCase
test "creates stacks for repos that allow_with_label when label is present" do
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :allow_with_label,
label: "pull-requests-label"
)
@@ -144,7 +144,7 @@ class OpenedHandlerTest < ActiveSupport::TestCase
test "does not create stacks for repos that allow_with_label when label is absent" do
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :allow_with_label,
label: "pull-requests-label"
)
@@ -159,7 +159,7 @@ class OpenedHandlerTest < ActiveSupport::TestCase
test "create stacks for repos what prevent_with_label when label is absent" do
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :prevent_with_label,
label: "pull-requests-label"
)
@@ -174,7 +174,7 @@ class OpenedHandlerTest < ActiveSupport::TestCase
test "does not create stacks for repos what prevent_with_label when label is present" do
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :prevent_with_label,
label: "pull-requests-label"
)
@@ -204,32 +204,32 @@ def assert_pending_provision(stack)
setup do
Shipit.github.api.stubs(:commit)
- .with("shopify/shipit-engine", "ec26c3e57ca3a959ca5aad62de7213c562f8c821")
- .returns(
- resource(
- {
- sha: "ec26c3e57ca3a959ca5aad62de7213c562f8c821",
- commit: {
- author: {
- name: "Codertocat",
- email: "21031067+Codertocat@users.noreply.github.com",
- date: "2019-05-15 15:20:30",
- },
- committer: {
- name: "Codertocat",
- email: "21031067+Codertocat@users.noreply.github.com",
- date: "2019-05-15 15:20:30",
- },
- message: "Update README.md",
- },
- stats: {
- total: 2,
- additions: 1,
- deletions: 1,
- },
- }
- )
- )
+ .with("shopify/shipit-engine", "ec26c3e57ca3a959ca5aad62de7213c562f8c821")
+ .returns(
+ resource(
+ {
+ sha: "ec26c3e57ca3a959ca5aad62de7213c562f8c821",
+ commit: {
+ author: {
+ name: "Codertocat",
+ email: "21031067+Codertocat@users.noreply.github.com",
+ date: "2019-05-15 15:20:30"
+ },
+ committer: {
+ name: "Codertocat",
+ email: "21031067+Codertocat@users.noreply.github.com",
+ date: "2019-05-15 15:20:30"
+ },
+ message: "Update README.md"
+ },
+ stats: {
+ total: 2,
+ additions: 1,
+ deletions: 1
+ }
+ }
+ )
+ )
end
end
end
diff --git a/test/models/shipit/webhooks/handlers/pull_request/reopened_handler_test.rb b/test/models/shipit/webhooks/handlers/pull_request/reopened_handler_test.rb
index 886e263dc..b47165fb9 100644
--- a/test/models/shipit/webhooks/handlers/pull_request/reopened_handler_test.rb
+++ b/test/models/shipit/webhooks/handlers/pull_request/reopened_handler_test.rb
@@ -47,7 +47,7 @@ class ReopenedHandlerTest < ActiveSupport::TestCase
stack = create_archived_stack
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :allow_all
)
@@ -60,7 +60,7 @@ class ReopenedHandlerTest < ActiveSupport::TestCase
test "provisions missing stacks for repos that allow_all" do
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :allow_all
)
payload = payload_parsed(:pull_request_reopened)
@@ -79,7 +79,7 @@ class ReopenedHandlerTest < ActiveSupport::TestCase
test "auto-created stack should have pull request assigned" do
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :allow_all
)
payload = payload_parsed(:pull_request_reopened)
@@ -93,7 +93,7 @@ class ReopenedHandlerTest < ActiveSupport::TestCase
stack = create_archived_stack
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :allow_with_label,
label: "pull-requests-label"
)
@@ -109,7 +109,7 @@ class ReopenedHandlerTest < ActiveSupport::TestCase
test "provisions missing stacks for repos that allow_with_label when label is present" do
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :allow_with_label,
label: "pull-requests-label"
)
@@ -131,7 +131,7 @@ class ReopenedHandlerTest < ActiveSupport::TestCase
stack = create_archived_stack
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :allow_with_label,
label: "pull-requests-label"
)
@@ -147,7 +147,7 @@ class ReopenedHandlerTest < ActiveSupport::TestCase
stack = create_archived_stack
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :prevent_with_label,
label: "pull-requests-label"
)
@@ -163,7 +163,7 @@ class ReopenedHandlerTest < ActiveSupport::TestCase
test "provisions missing stacks for repos that prevent_with_label when label is absent" do
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :prevent_with_label,
label: "pull-requests-label"
)
@@ -185,7 +185,7 @@ class ReopenedHandlerTest < ActiveSupport::TestCase
stack = create_archived_stack
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :prevent_with_label,
label: "pull-requests-label"
)
@@ -231,8 +231,8 @@ def create_stack
def complete_active_tasks(stack)
active_tasks = stack
- .tasks
- .active
+ .tasks
+ .active
active_tasks.map(&:run)
active_tasks.reload
@@ -248,32 +248,32 @@ def assert_pending_provision(stack)
setup do
Shipit.github.api.stubs(:commit)
- .with("shopify/shipit-engine", "ec26c3e57ca3a959ca5aad62de7213c562f8c821")
- .returns(
- resource(
- {
- sha: "ec26c3e57ca3a959ca5aad62de7213c562f8c821",
- commit: {
- author: {
- name: "Codertocat",
- email: "21031067+Codertocat@users.noreply.github.com",
- date: "2019-05-15 15:20:30",
- },
- committer: {
- name: "Codertocat",
- email: "21031067+Codertocat@users.noreply.github.com",
- date: "2019-05-15 15:20:30",
- },
- message: "Update README.md",
- },
- stats: {
- total: 2,
- additions: 1,
- deletions: 1,
- },
- }
- )
- )
+ .with("shopify/shipit-engine", "ec26c3e57ca3a959ca5aad62de7213c562f8c821")
+ .returns(
+ resource(
+ {
+ sha: "ec26c3e57ca3a959ca5aad62de7213c562f8c821",
+ commit: {
+ author: {
+ name: "Codertocat",
+ email: "21031067+Codertocat@users.noreply.github.com",
+ date: "2019-05-15 15:20:30"
+ },
+ committer: {
+ name: "Codertocat",
+ email: "21031067+Codertocat@users.noreply.github.com",
+ date: "2019-05-15 15:20:30"
+ },
+ message: "Update README.md"
+ },
+ stats: {
+ total: 2,
+ additions: 1,
+ deletions: 1
+ }
+ }
+ )
+ )
end
end
end
diff --git a/test/models/shipit/webhooks/handlers/pull_request/review_stack_adapter_test.rb b/test/models/shipit/webhooks/handlers/pull_request/review_stack_adapter_test.rb
index 41a58d823..63217449d 100644
--- a/test/models/shipit/webhooks/handlers/pull_request/review_stack_adapter_test.rb
+++ b/test/models/shipit/webhooks/handlers/pull_request/review_stack_adapter_test.rb
@@ -71,7 +71,7 @@ def params_for(stack)
OpenStruct.new(
number: pr_number,
repository: {
- "full_name" => stack.github_repo_name,
+ "full_name" => stack.github_repo_name
},
sender: { login: shipit_users(:walrus).login }
)
diff --git a/test/models/shipit/webhooks/handlers/pull_request/unlabeled_handler_test.rb b/test/models/shipit/webhooks/handlers/pull_request/unlabeled_handler_test.rb
index 07d3f87d2..19fe3a607 100644
--- a/test/models/shipit/webhooks/handlers/pull_request/unlabeled_handler_test.rb
+++ b/test/models/shipit/webhooks/handlers/pull_request/unlabeled_handler_test.rb
@@ -26,7 +26,7 @@ class UnlabeledHandlerTest < ActiveSupport::TestCase
test "ignores Github PullRequest webhooks when the Repository has disabled the Review Stacks feature" do
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
provisioning_enabled: false,
behavior: :allow_with_label,
label: "pull-requests-label"
@@ -47,7 +47,7 @@ class UnlabeledHandlerTest < ActiveSupport::TestCase
stack = create_stack
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :allow_with_label,
label: "pull-requests-label"
)
@@ -61,7 +61,7 @@ class UnlabeledHandlerTest < ActiveSupport::TestCase
stack = create_stack
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :allow_with_label,
label: "pull-requests-label"
)
@@ -74,7 +74,7 @@ class UnlabeledHandlerTest < ActiveSupport::TestCase
test "ignores Github PullRequest webhooks when the repository allow_with_label to create ReviewStacks and the label is absent" do
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :allow_with_label,
label: "pull-requests-label"
)
@@ -88,7 +88,7 @@ class UnlabeledHandlerTest < ActiveSupport::TestCase
stack = create_archived_stack
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :allow_with_label,
label: "pull-requests-label"
)
@@ -104,7 +104,7 @@ class UnlabeledHandlerTest < ActiveSupport::TestCase
test "creates and provisions a new review stack when the repository creates ReviewStacks with allow_with_label and the label is present" do
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :allow_with_label,
label: "pull-requests-label"
)
@@ -126,7 +126,7 @@ class UnlabeledHandlerTest < ActiveSupport::TestCase
stack = create_stack
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :prevent_with_label,
label: "pull-requests-label"
)
@@ -142,7 +142,7 @@ class UnlabeledHandlerTest < ActiveSupport::TestCase
stack = create_stack
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :prevent_with_label,
label: "pull-requests-label"
)
@@ -157,7 +157,7 @@ class UnlabeledHandlerTest < ActiveSupport::TestCase
test "ignores Github PullRequest webhooks when the repository prevent_with_label to create ReviewStacks and the label is present" do
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :prevent_with_label,
label: "pull-requests-label"
)
@@ -173,7 +173,7 @@ class UnlabeledHandlerTest < ActiveSupport::TestCase
stack = create_archived_stack
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :prevent_with_label,
label: "pull-requests-label"
)
@@ -189,7 +189,7 @@ class UnlabeledHandlerTest < ActiveSupport::TestCase
test "creates and provisions a new review stack when the repository creates ReviewStacks with prevent_with_label and the label is absent" do
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :prevent_with_label,
label: "pull-requests-label"
)
@@ -210,7 +210,7 @@ class UnlabeledHandlerTest < ActiveSupport::TestCase
test "assigns the PullRequest to newly created stacks" do
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :prevent_with_label,
label: "pull-requests-label"
)
@@ -226,7 +226,7 @@ class UnlabeledHandlerTest < ActiveSupport::TestCase
create_archived_stack
repository = shipit_repositories(:shipit)
configure_provisioning_behavior(
- repository: repository,
+ repository:,
behavior: :allow_with_label,
label: "pull-requests-label"
)
@@ -275,8 +275,8 @@ def create_stack
def complete_active_tasks(stack)
active_tasks = stack
- .tasks
- .active
+ .tasks
+ .active
active_tasks.map(&:run)
active_tasks.reload
@@ -292,32 +292,32 @@ def assert_pending_provision(stack)
setup do
Shipit.github.api.stubs(:commit)
- .with("shopify/shipit-engine", "ec26c3e57ca3a959ca5aad62de7213c562f8c821")
- .returns(
- resource(
- {
- sha: "ec26c3e57ca3a959ca5aad62de7213c562f8c821",
- commit: {
- author: {
- name: "Codertocat",
- email: "21031067+Codertocat@users.noreply.github.com",
- date: "2019-05-15 15:20:30",
- },
- committer: {
- name: "Codertocat",
- email: "21031067+Codertocat@users.noreply.github.com",
- date: "2019-05-15 15:20:30",
- },
- message: "Update README.md",
- },
- stats: {
- total: 2,
- additions: 1,
- deletions: 1,
- },
- }
- )
- )
+ .with("shopify/shipit-engine", "ec26c3e57ca3a959ca5aad62de7213c562f8c821")
+ .returns(
+ resource(
+ {
+ sha: "ec26c3e57ca3a959ca5aad62de7213c562f8c821",
+ commit: {
+ author: {
+ name: "Codertocat",
+ email: "21031067+Codertocat@users.noreply.github.com",
+ date: "2019-05-15 15:20:30"
+ },
+ committer: {
+ name: "Codertocat",
+ email: "21031067+Codertocat@users.noreply.github.com",
+ date: "2019-05-15 15:20:30"
+ },
+ message: "Update README.md"
+ },
+ stats: {
+ total: 2,
+ additions: 1,
+ deletions: 1
+ }
+ }
+ )
+ )
end
end
end
diff --git a/test/models/shipit/webhooks/handlers_test.rb b/test/models/shipit/webhooks/handlers_test.rb
index a95f8b0ca..e278347b4 100644
--- a/test/models/shipit/webhooks/handlers_test.rb
+++ b/test/models/shipit/webhooks/handlers_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/models/status/group_test.rb b/test/models/status/group_test.rb
index ea14c0afa..949916a12 100644
--- a/test/models/status/group_test.rb
+++ b/test/models/status/group_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -21,7 +22,7 @@ class StatusGroupTest < ActiveSupport::TestCase
end
test "#state is significant's status state" do
- assert_equal %w(success success failure), @group.statuses.map(&:state)
+ assert_equal %w[success success failure], @group.statuses.map(&:state)
assert_equal 'failure', @group.state
end
@@ -42,7 +43,7 @@ class StatusGroupTest < ActiveSupport::TestCase
end
test "missing required status will have MissingRequiredStatus as placeholder" do
- @commit.stubs(:required_statuses).returns(%w(ci/very-important))
+ @commit.stubs(:required_statuses).returns(%w[ci/very-important])
status = Status::Group.compact(@commit, [])
assert_instance_of Status::Missing, status
assert_predicate status, :pending?
diff --git a/test/models/status/missing_test.rb b/test/models/status/missing_test.rb
index 0213feb25..6de6b1c69 100644
--- a/test/models/status/missing_test.rb
+++ b/test/models/status/missing_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/models/status_test.rb b/test/models/status_test.rb
index 14417124b..0b5fcd9c8 100644
--- a/test/models/status_test.rb
+++ b/test/models/status_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -50,7 +51,7 @@ def github_status
description: 'This is a description',
context: 'default',
target_url: 'http://example.com',
- created_at: 1.day.ago.to_time,
+ created_at: 1.day.ago.to_time
)
end
diff --git a/test/models/task_definitions_test.rb b/test/models/task_definitions_test.rb
index 6582e3430..b11d85415 100644
--- a/test/models/task_definitions_test.rb
+++ b/test/models/task_definitions_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -7,7 +8,7 @@ class TaskDefinitionsTest < ActiveSupport::TestCase
@definition = TaskDefinition.new(
'restart',
'action' => 'Restart application',
- 'title' => 'Restart application %{FOO}',
+ 'title' => 'Restart application %s',
'description' => 'Restart app and job servers',
'steps' => ['touch tmp/restart'],
'allow_concurrency' => true,
@@ -15,8 +16,8 @@ class TaskDefinitionsTest < ActiveSupport::TestCase
{ 'name' => 'FOO', 'title' => 'Set to 0 to foo', 'default' => '1' },
{ 'name' => 'BAR', 'title' => 'Set to 1 to bar', 'default' => '0' },
{ 'name' => 'WALRUS', 'title' => 'Use with caution', 'default' => ' ' },
- { 'name' => 'NODEFAULT', 'title' => 'Variable without default' },
- ],
+ { 'name' => 'NODEFAULT', 'title' => 'Variable without default' }
+ ]
)
end
@@ -38,7 +39,7 @@ class TaskDefinitionsTest < ActiveSupport::TestCase
as_json = {
id: 'restart',
action: 'Restart application',
- title: "Restart application %{FOO}",
+ title: "Restart application %s",
description: 'Restart app and job servers',
steps: ['touch tmp/restart'],
checklist: [],
@@ -47,8 +48,8 @@ class TaskDefinitionsTest < ActiveSupport::TestCase
{ 'name' => 'FOO', 'title' => 'Set to 0 to foo', 'default' => '1', 'select' => nil },
{ 'name' => 'BAR', 'title' => 'Set to 1 to bar', 'default' => '0', 'select' => nil },
{ 'name' => 'WALRUS', 'title' => 'Use with caution', 'default' => ' ', 'select' => nil },
- { 'name' => 'NODEFAULT', 'title' => 'Variable without default', 'default' => '', 'select' => nil },
- ],
+ { 'name' => 'NODEFAULT', 'title' => 'Variable without default', 'default' => '', 'select' => nil }
+ ]
}
assert_equal as_json, TaskDefinition.load(TaskDefinition.dump(@definition)).as_json
end
diff --git a/test/models/tasks_test.rb b/test/models/tasks_test.rb
index 011c20c55..6f006931b 100644
--- a/test/models/tasks_test.rb
+++ b/test/models/tasks_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -16,7 +17,7 @@ class TasksTest < ActiveSupport::TestCase
test '#title returns an error message when the title raises an error' do
task = shipit_tasks(:shipit_with_title_parsing_issue)
- assert_equal 'This task (title: Using the %{WRONG_VARIABLE_NAME}) cannot be shown due to an incorrect variable name. Check your shipit.yml file', task.title
+ assert_equal 'This task (title: Using the %) cannot be shown due to an incorrect variable name. Check your shipit.yml file', task.title
end
test "#write sends line-buffered output to task logger" do
@@ -44,7 +45,7 @@ class TasksTest < ActiveSupport::TestCase
# We don't use assert_includes because it will print the whole message
assert(
output.include?(Task::OUTPUT_TRUNCATED_MESSAGE),
- "'#{Task::OUTPUT_TRUNCATED_MESSAGE.chomp}' was not present in the output",
+ "'#{Task::OUTPUT_TRUNCATED_MESSAGE.chomp}' was not present in the output"
)
end
@@ -94,7 +95,7 @@ class TasksTest < ActiveSupport::TestCase
task.update(
rolled_up: false,
created_at: (60 + 1).minutes.ago.to_formatted_s(:db),
- status: "success",
+ status: "success"
)
assert_includes Shipit::Task.due_for_rollup, task
@@ -105,7 +106,7 @@ class TasksTest < ActiveSupport::TestCase
task.update(
rolled_up: false,
created_at: (60 + 1).minutes.ago.to_formatted_s(:db),
- status: "error",
+ status: "error"
)
assert_includes Shipit::Task.due_for_rollup, task
diff --git a/test/models/team_test.rb b/test/models/team_test.rb
index 584b96232..ea2adf02f 100644
--- a/test/models/team_test.rb
+++ b/test/models/team_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -34,7 +35,7 @@ class TeamTest < ActiveSupport::TestCase
skip unless limit
slug = 'a' * 255
- team = new_team(slug: slug)
+ team = new_team(slug:)
response = stub(rels: {}, data: [team])
Shipit.github.api.expects(:org_teams).with('shopify', per_page: 100).returns(response.data)
@@ -61,7 +62,7 @@ def george
login: 'george',
email: 'george@cyclim.se',
avatar_url: 'https://avatars.githubusercontent.com/u/42?v=3',
- url: 'https://api.github.com/user/george',
+ url: 'https://api.github.com/user/george'
)
end
@@ -69,10 +70,10 @@ def new_team(slug: 'new-team')
stub(
id: 24,
name: 'New Team',
- slug: slug,
+ slug:,
url: 'https://example.com',
description: 'The Best one',
- organization: 'shopify',
+ organization: 'shopify'
)
end
end
diff --git a/test/models/undeployed_commits_test.rb b/test/models/undeployed_commits_test.rb
index 9b87148e7..15e70eec0 100644
--- a/test/models/undeployed_commits_test.rb
+++ b/test/models/undeployed_commits_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -41,9 +42,9 @@ class UndeployedCommitsTest < ActiveSupport::TestCase
end
test "#expected_to_be_deployed? returns true if the stack has continuous deployment enabled, next expected commit to deploy id is greater or equals to the commit id and commit is not active" do
- commit = shipit_commits(:undeployed_4)
+ commit = shipit_commits(:undeployed4)
next_expected_commit_to_deploy = commit.stack.next_expected_commit_to_deploy
- undeployed_commit = UndeployedCommit.new(commit, index: 1, next_expected_commit_to_deploy: next_expected_commit_to_deploy)
+ undeployed_commit = UndeployedCommit.new(commit, index: 1, next_expected_commit_to_deploy:)
refute_predicate next_expected_commit_to_deploy, :nil?
assert_predicate undeployed_commit.stack, :continuous_deployment
@@ -56,7 +57,7 @@ class UndeployedCommitsTest < ActiveSupport::TestCase
test "#expected_to_be_deployed? returns true if the active task has no commit range" do
commit = shipit_commits(:task_no_commits)
next_expected_commit_to_deploy = commit.stack.next_expected_commit_to_deploy
- undeployed_commit = UndeployedCommit.new(commit, index: 1, next_expected_commit_to_deploy: next_expected_commit_to_deploy)
+ undeployed_commit = UndeployedCommit.new(commit, index: 1, next_expected_commit_to_deploy:)
refute_predicate next_expected_commit_to_deploy, :nil?
assert_predicate undeployed_commit.stack, :continuous_deployment
@@ -69,7 +70,7 @@ class UndeployedCommitsTest < ActiveSupport::TestCase
test "#expected_to_be_deployed? returns false if the stack has continuous deployment disabled" do
commit = shipit_commits(:cyclimse_first)
next_expected_commit_to_deploy = commit.stack.next_expected_commit_to_deploy
- undeployed_commit = UndeployedCommit.new(commit, index: 1, next_expected_commit_to_deploy: next_expected_commit_to_deploy)
+ undeployed_commit = UndeployedCommit.new(commit, index: 1, next_expected_commit_to_deploy:)
refute_predicate next_expected_commit_to_deploy, :nil?
refute_predicate undeployed_commit.stack, :continuous_deployment
@@ -80,9 +81,9 @@ class UndeployedCommitsTest < ActiveSupport::TestCase
end
test "#expected_to_be_deployed? returns false if the commit is part of the active task" do
- commit = shipit_commits(:undeployed_3)
+ commit = shipit_commits(:undeployed3)
next_expected_commit_to_deploy = commit.stack.next_expected_commit_to_deploy
- undeployed_commit = UndeployedCommit.new(commit, index: 1, next_expected_commit_to_deploy: next_expected_commit_to_deploy)
+ undeployed_commit = UndeployedCommit.new(commit, index: 1, next_expected_commit_to_deploy:)
refute_predicate next_expected_commit_to_deploy, :nil?
assert_predicate undeployed_commit.stack, :continuous_deployment
@@ -93,16 +94,16 @@ class UndeployedCommitsTest < ActiveSupport::TestCase
end
test "#expected_to_be_deployed? returns false if there is no commit to deploy" do
- commit = shipit_commits(:undeployed_3)
+ commit = shipit_commits(:undeployed3)
undeployed_commit = UndeployedCommit.new(commit, index: 1, next_expected_commit_to_deploy: nil)
refute_predicate undeployed_commit, :expected_to_be_deployed?
end
test "#expected_to_be_deployed? returns false if the commit has an id greater than next commit to deploy" do
- commit = shipit_commits(:undeployed_7)
+ commit = shipit_commits(:undeployed7)
next_expected_commit_to_deploy = commit.stack.next_expected_commit_to_deploy
- undeployed_commit = UndeployedCommit.new(commit, index: 1, next_expected_commit_to_deploy: next_expected_commit_to_deploy)
+ undeployed_commit = UndeployedCommit.new(commit, index: 1, next_expected_commit_to_deploy:)
refute_predicate next_expected_commit_to_deploy, :nil?
assert_predicate undeployed_commit.stack, :continuous_deployment
diff --git a/test/models/users_test.rb b/test/models/users_test.rb
index b62083c05..4d2b81756 100644
--- a/test/models/users_test.rb
+++ b/test/models/users_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -12,7 +13,7 @@ class UsersTest < ActiveSupport::TestCase
login: 'george',
email: 'george@cyclim.se',
avatar_url: 'https://avatars.githubusercontent.com/u/42?v=3',
- url: 'https://api.github.com/user/george',
+ url: 'https://api.github.com/user/george'
)
@org_domain = "shopify.com"
@emails_url = "https://api.github.com/user/emails"
@@ -23,7 +24,7 @@ class UsersTest < ActiveSupport::TestCase
email: nil,
avatar_url: 'https://avatars.githubusercontent.com/u/43?v=3',
url: 'https://api.github.com/user/peter',
- rels: nil,
+ rels: nil
)
end
@@ -78,7 +79,7 @@ class UsersTest < ActiveSupport::TestCase
login: 'jim',
email: "jim@#{@org_domain}",
avatar_url: 'https://avatars.githubusercontent.com/u/42?v=3',
- url: 'https://api.github.com/user/jim',
+ url: 'https://api.github.com/user/jim'
)
Shipit.preferred_org_emails = [].freeze
@@ -91,9 +92,9 @@ class UsersTest < ActiveSupport::TestCase
expected_email = "myuser@#{@org_domain}"
stub_request(:get, @emails_url).to_return(
- status: %w(200 OK),
+ status: %w[200 OK],
body: [{ email: expected_email }].to_json,
- headers: { "Content-Type" => "application/json" },
+ headers: { "Content-Type" => "application/json" }
)
user = User.find_or_create_from_github(@github_user)
@@ -106,21 +107,21 @@ class UsersTest < ActiveSupport::TestCase
result_email_records = [
{
email: "notmyuser1@#{@org_domain}",
- primary: false,
+ primary: false
},
{
- email: "notmyuser2@#{@org_domain}",
+ email: "notmyuser2@#{@org_domain}"
},
{
email: expected_email,
- primary: true,
- },
+ primary: true
+ }
]
stub_request(:get, @emails_url).to_return(
- status: %w(200 OK),
+ status: %w[200 OK],
body: result_email_records.to_json,
- headers: { "Content-Type" => "application/json" },
+ headers: { "Content-Type" => "application/json" }
)
user = User.find_or_create_from_github(@github_user)
@@ -132,17 +133,17 @@ class UsersTest < ActiveSupport::TestCase
result_email_records = [
{
email: "notmyuser1@not#{@org_domain}",
- primary: false,
+ primary: false
},
{
- email: "notmyuser2@not#{@org_domain}",
- },
+ email: "notmyuser2@not#{@org_domain}"
+ }
]
stub_request(:get, @emails_url).to_return(
- status: %w(200 OK),
+ status: %w[200 OK],
body: result_email_records.to_json,
- headers: { "Content-Type" => "application/json" },
+ headers: { "Content-Type" => "application/json" }
)
user = User.find_or_create_from_github(@github_user)
@@ -273,15 +274,15 @@ class UsersTest < ActiveSupport::TestCase
id: user.github_id,
name: user.name,
email: user.email,
- date: Time.now.utc,
+ date: Time.now.utc
},
committer: {
name: user.name,
email: user.email,
- date: Time.now.utc,
+ date: Time.now.utc
},
- message: "commit to trigger staging build\n\nMerge-Requested-By: missinguser\n",
- },
+ message: "commit to trigger staging build\n\nMerge-Requested-By: missinguser\n"
+ }
)
found_user = Shipit::User.find_or_create_author_from_github_commit(github_commit)
assert_equal user, found_user
diff --git a/test/test_command_integration.rb b/test/test_command_integration.rb
index 65dcb90a4..e878a95a7 100755
--- a/test/test_command_integration.rb
+++ b/test/test_command_integration.rb
@@ -16,7 +16,7 @@
"Sleeping for 10 seconds\r\n",
"\e[1;31mNo output received in the last 2 seconds.\e[0m\n",
"\e[1;31mSending SIGINT to PID #{command.pid}\n\e[0m",
- "Recieved SIGINT, aborting.\r\n",
+ "Recieved SIGINT, aborting.\r\n"
]
unless buffer.join == expected_output.join
diff --git a/test/test_helper.rb b/test/test_helper.rb
index c80a0690a..efc3f1ff5 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -1,9 +1,8 @@
# frozen_string_literal: true
+
ENV["RAILS_ENV"] ||= "test"
-if Warning.respond_to?(:[]=)
- Warning[:deprecated] = true
-end
+Warning[:deprecated] = true if Warning.respond_to?(:[]=)
require 'simplecov'
SimpleCov.start('rails') do
@@ -12,10 +11,10 @@
require 'webmock/minitest'
-require File.expand_path('../../test/dummy/config/environment.rb', __FILE__)
+require File.expand_path('../test/dummy/config/environment.rb', __dir__)
ActiveRecord::Migrator.migrations_paths = [
- File.expand_path('../../test/dummy/db/migrate', __FILE__),
- File.expand_path('../../db/migrate', __FILE__),
+ File.expand_path('../test/dummy/db/migrate', __dir__),
+ File.expand_path('../db/migrate', __dir__)
]
require 'rails/test_help'
require 'mocha/minitest'
@@ -23,11 +22,11 @@
# Load fixtures from the engine
if ActiveSupport::TestCase.respond_to?(:fixture_path=)
- ActiveSupport::TestCase.fixture_paths << File.expand_path("../fixtures", __FILE__)
+ ActiveSupport::TestCase.fixture_paths << File.expand_path('fixtures', __dir__)
ActiveSupport::TestCase.fixtures(:all)
end
-Dir[File.expand_path('../helpers/**/*.rb', __FILE__)].each do |helper|
+Dir[File.expand_path('helpers/**/*.rb', __dir__)].each do |helper|
require helper
end
@@ -66,14 +65,15 @@ class TestCase
teardown do
Shipit.redis.flushdb
Shipit.instance_variable_names.each do |name|
- next if %w(@mocha @redis).include?(name)
+ next if %w[@mocha @redis].include?(name)
+
Shipit.remove_instance_variable(name)
end
end
ActiveRecord::Migration.check_all_pending!
- fixture_paths << File.expand_path("../fixtures", __FILE__)
+ fixture_paths << File.expand_path('fixtures', __dir__)
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
#
diff --git a/test/unit/anonymous_user_serializer_test.rb b/test/unit/anonymous_user_serializer_test.rb
index 54dde2e49..855e1c62a 100644
--- a/test/unit/anonymous_user_serializer_test.rb
+++ b/test/unit/anonymous_user_serializer_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/unit/command_test.rb b/test/unit/command_test.rb
index c1c7283aa..6597e0c32 100644
--- a/test/unit/command_test.rb
+++ b/test/unit/command_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -67,7 +68,7 @@ class CommandTest < ActiveSupport::TestCase
assert system(
Engine.root.join('test/dummy/bin/rails').to_s,
'runner',
- Engine.root.join('test/test_command_integration.rb').to_s,
+ Engine.root.join('test/test_command_integration.rb').to_s
)
end
diff --git a/test/unit/commands_test.rb b/test/unit/commands_test.rb
index b102b108e..212784d8e 100644
--- a/test/unit/commands_test.rb
+++ b/test/unit/commands_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/unit/commit_serializer_test.rb b/test/unit/commit_serializer_test.rb
index 5010c9ed6..171c8e958 100644
--- a/test/unit/commit_serializer_test.rb
+++ b/test/unit/commit_serializer_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/unit/csv_serializer_test.rb b/test/unit/csv_serializer_test.rb
index ba36ef9a2..7af7dde9b 100644
--- a/test/unit/csv_serializer_test.rb
+++ b/test/unit/csv_serializer_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -17,11 +18,11 @@ class CSVSerializerTest < ActiveSupport::TestCase
end
test "load split the words by comma" do
- assert_loaded %w(foo bar), 'foo,bar'
+ assert_loaded %w[foo bar], 'foo,bar'
end
test "dump join the words with a comma" do
- assert_dumped 'foo,bar', %w(foo bar)
+ assert_dumped 'foo,bar', %w[foo bar]
end
private
diff --git a/test/unit/deploy_commands_test.rb b/test/unit/deploy_commands_test.rb
index 41dccea85..5fe8406c3 100644
--- a/test/unit/deploy_commands_test.rb
+++ b/test/unit/deploy_commands_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -14,7 +15,7 @@ def setup
rollback_steps!: ['bundle exec cap $ENVIRONMENT deploy:rollback'],
machine_env: { 'GLOBAL' => '1' },
directory: nil,
- clear_working_directory?: true,
+ clear_working_directory?: true
)
@commands.stubs(:deploy_spec).returns(@deploy_spec)
@@ -27,7 +28,7 @@ def setup
command = @commands.fetch_commit(@deploy.until_commit)
- assert_equal %W(git fetch origin --quiet --tags --force #{@deploy.until_commit.sha}), command.args
+ assert_equal %W[git fetch origin --quiet --tags --force #{@deploy.until_commit.sha}], command.args
end
test "#fetch_commit calls git fetch in git_path directory if repository cache already exist" do
@@ -44,7 +45,7 @@ def setup
command = @commands.fetch_commit(@deploy.until_commit)
- expected = %W(git clone --quiet --single-branch --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path})
+ expected = %W[git clone --quiet --single-branch --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path}]
assert_equal expected, command.args.map(&:to_s)
end
@@ -54,7 +55,7 @@ def setup
command = @commands.fetch_commit(@deploy.until_commit)
- expected = %W(git clone --quiet --single-branch --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path})
+ expected = %W[git clone --quiet --single-branch --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path}]
assert_equal expected, command.args
end
@@ -62,12 +63,12 @@ def setup
@stack.git_path.stubs(:exist?).returns(true)
@stack.git_path.stubs(:empty?).returns(false)
StackCommands.any_instance.expects(:git_cmd_succeeds?)
- .with(@stack.git_path)
- .returns(false)
+ .with(@stack.git_path)
+ .returns(false)
command = @commands.fetch_commit(@deploy.until_commit)
- expected = %W(git clone --quiet --single-branch --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path})
+ expected = %W[git clone --quiet --single-branch --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path}]
assert_equal expected, command.args
end
@@ -76,12 +77,12 @@ def setup
@stack.git_path.stubs(:exist?).returns(true)
@stack.git_path.stubs(:empty?).returns(false)
StackCommands.any_instance.expects(:git_cmd_succeeds?)
- .with(@stack.git_path)
- .returns(false)
+ .with(@stack.git_path)
+ .returns(false)
command = @commands.fetch_commit(@deploy.until_commit)
- expected = %W(git clone --quiet --single-branch --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path})
+ expected = %W[git clone --quiet --single-branch --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path}]
assert_equal expected, command.args
end
@@ -91,7 +92,7 @@ def setup
command = @commands.fetch_commit(@deploy.until_commit)
- expected = %W(git clone --quiet --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path})
+ expected = %W[git clone --quiet --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path}]
assert_equal expected, command.args.map(&:to_s)
end
@@ -121,7 +122,7 @@ def setup
command = @commands.fetch
- assert_equal %w(git fetch origin --quiet --tags --force master), command.args
+ assert_equal %w[git fetch origin --quiet --tags --force master], command.args
end
test "#fetch calls git fetch in git_path directory if repository cache already exist" do
@@ -138,7 +139,7 @@ def setup
command = @commands.fetch
- expected = %W(git clone --quiet --single-branch --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path})
+ expected = %W[git clone --quiet --single-branch --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path}]
assert_equal expected, command.args.map(&:to_s)
end
@@ -148,7 +149,7 @@ def setup
command = @commands.fetch
- expected = %W(git clone --quiet --single-branch --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path})
+ expected = %W[git clone --quiet --single-branch --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path}]
assert_equal expected, command.args
end
@@ -156,12 +157,12 @@ def setup
@stack.git_path.stubs(:exist?).returns(true)
@stack.git_path.stubs(:empty?).returns(false)
StackCommands.any_instance.expects(:git_cmd_succeeds?)
- .with(@stack.git_path)
- .returns(false)
+ .with(@stack.git_path)
+ .returns(false)
command = @commands.fetch
- expected = %W(git clone --quiet --single-branch --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path})
+ expected = %W[git clone --quiet --single-branch --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path}]
assert_equal expected, command.args
end
@@ -170,12 +171,12 @@ def setup
@stack.git_path.stubs(:exist?).returns(true)
@stack.git_path.stubs(:empty?).returns(false)
StackCommands.any_instance.expects(:git_cmd_succeeds?)
- .with(@stack.git_path)
- .returns(false)
+ .with(@stack.git_path)
+ .returns(false)
command = @commands.fetch
- expected = %W(git clone --quiet --single-branch --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path})
+ expected = %W[git clone --quiet --single-branch --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path}]
assert_equal expected, command.args
end
@@ -185,7 +186,7 @@ def setup
command = @commands.fetch
- expected = %W(git clone --quiet --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path})
+ expected = %W[git clone --quiet --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path}]
assert_equal expected, command.args.map(&:to_s)
end
@@ -194,7 +195,7 @@ def setup
command = @commands.fetch
- expected = %W(git clone --single-branch --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path})
+ expected = %W[git clone --single-branch --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path}]
assert_equal expected, command.args.map(&:to_s)
end
@@ -218,7 +219,7 @@ def setup
clone_args = [
'git', 'clone', '--quiet',
'--local', '--origin', 'cache',
- @stack.git_path.to_s, @deploy.working_directory,
+ @stack.git_path.to_s, @deploy.working_directory
]
assert_equal clone_args, commands.first.args
assert_equal ['git', 'remote', 'add', 'origin', @stack.repo_git_url.to_s], commands.second.args
@@ -233,7 +234,7 @@ def setup
command = @commands.checkout(@deploy.until_commit)
checkout_args = [
'git', '-c', 'advice.detachedHead=false', 'checkout', '--quiet',
- @deploy.until_commit.sha,
+ @deploy.until_commit.sha
]
assert_equal checkout_args, command.args
end
diff --git a/test/unit/deploy_serializer_test.rb b/test/unit/deploy_serializer_test.rb
index 470e4e0d9..810024a84 100644
--- a/test/unit/deploy_serializer_test.rb
+++ b/test/unit/deploy_serializer_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/unit/environment_variables_test.rb b/test/unit/environment_variables_test.rb
index 3d028e55d..f24f3f40c 100644
--- a/test/unit/environment_variables_test.rb
+++ b/test/unit/environment_variables_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -6,7 +7,7 @@ class EnvironmentVariablesTest < ActiveSupport::TestCase
def setup
variable_defs = [
{ "name" => "FOO", "title" => "Set to 0 to foo", "default" => 1 },
- { "name" => "BAR", "title" => "Set to 1 to bar", "default" => 0 },
+ { "name" => "BAR", "title" => "Set to 1 to bar", "default" => 0 }
]
@variable_definitions = variable_defs.map(&VariableDefinition.method(:new))
end
diff --git a/test/unit/github_app_test.rb b/test/unit/github_app_test.rb
index 4e2aab2eb..3b1e29ef0 100644
--- a/test/unit/github_app_test.rb
+++ b/test/unit/github_app_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -45,7 +46,7 @@ class GitHubAppTest < ActiveSupport::TestCase
}
]
}
- ),
+ )
)
assert_equal "operational", app.api_status[:status]
end
@@ -78,15 +79,15 @@ class GitHubAppTest < ActiveSupport::TestCase
config = {
app_id: "test_id",
installation_id: "test_installation_id",
- private_key: "test_private_key",
+ private_key: "test_private_key"
}
initial_token = OpenStruct.new(
token: "some_initial_github_token",
- expires_at: Time.now.utc + 60.minutes,
+ expires_at: Time.now.utc + 60.minutes
)
second_token = OpenStruct.new(
token: "some_new_github_token",
- expires_at: initial_token.expires_at + 60.minutes,
+ expires_at: initial_token.expires_at + 60.minutes
)
auth_payload = "test_auth_payload"
@@ -116,15 +117,15 @@ class GitHubAppTest < ActiveSupport::TestCase
config = {
app_id: "test_id",
installation_id: "test_installation_id",
- private_key: "test_private_key",
+ private_key: "test_private_key"
}
initial_token = OpenStruct.new(
token: "some_initial_github_token",
- expires_at: Time.now.utc + 60.minutes,
+ expires_at: Time.now.utc + 60.minutes
)
second_token = OpenStruct.new(
token: "some_new_github_token",
- expires_at: initial_token.expires_at + 60.minutes,
+ expires_at: initial_token.expires_at + 60.minutes
)
auth_payload = "test_auth_payload"
@@ -161,14 +162,14 @@ class GitHubAppTest < ActiveSupport::TestCase
config = {
app_id: "test_id",
installation_id: "test_installation_id",
- private_key: "test_private_key",
+ private_key: "test_private_key"
}
initial_cached_token = Shipit::GitHubApp::Token.new("some_initial_github_token", Time.now.utc - 1.minute)
initial_cached_token.instance_variable_set(:@refresh_at, nil)
second_token = OpenStruct.new(
token: "some_new_github_token",
- expires_at: initial_cached_token.expires_at + 60.minutes,
+ expires_at: initial_cached_token.expires_at + 60.minutes
)
auth_payload = "test_auth_payload"
diff --git a/test/unit/github_apps_test.rb b/test/unit/github_apps_test.rb
index 4e5465337..f6a3ce0e5 100644
--- a/test/unit/github_apps_test.rb
+++ b/test/unit/github_apps_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -69,7 +70,7 @@ class GitHubAppsTestOrgOne < ActiveSupport::TestCase
}
]
}
- ),
+ )
)
assert_equal "operational", app(@organization).api_status[:status]
end
@@ -79,15 +80,15 @@ class GitHubAppsTestOrgOne < ActiveSupport::TestCase
config = {
app_id: "test_id",
installation_id: "test_installation_id",
- private_key: "test_private_key",
+ private_key: "test_private_key"
}
initial_token = OpenStruct.new(
token: "some_initial_github_token",
- expires_at: Time.now.utc + 60.minutes,
+ expires_at: Time.now.utc + 60.minutes
)
second_token = OpenStruct.new(
token: "some_new_github_token",
- expires_at: initial_token.expires_at + 60.minutes,
+ expires_at: initial_token.expires_at + 60.minutes
)
auth_payload = "test_auth_payload"
@@ -117,15 +118,15 @@ class GitHubAppsTestOrgOne < ActiveSupport::TestCase
config = {
app_id: "test_id",
installation_id: "test_installation_id",
- private_key: "test_private_key",
+ private_key: "test_private_key"
}
initial_token = OpenStruct.new(
token: "some_initial_github_token",
- expires_at: Time.now.utc + 60.minutes,
+ expires_at: Time.now.utc + 60.minutes
)
second_token = OpenStruct.new(
token: "some_new_github_token",
- expires_at: initial_token.expires_at + 60.minutes,
+ expires_at: initial_token.expires_at + 60.minutes
)
auth_payload = "test_auth_payload"
@@ -162,14 +163,14 @@ class GitHubAppsTestOrgOne < ActiveSupport::TestCase
config = {
app_id: "test_id",
installation_id: "test_installation_id",
- private_key: "test_private_key",
+ private_key: "test_private_key"
}
initial_cached_token = Shipit::GitHubApp::Token.new("some_initial_github_token", Time.now.utc - 1.minute)
initial_cached_token.instance_variable_set(:@refresh_at, nil)
second_token = OpenStruct.new(
token: "some_new_github_token",
- expires_at: initial_cached_token.expires_at + 60.minutes,
+ expires_at: initial_cached_token.expires_at + 60.minutes
)
auth_payload = "test_auth_payload"
@@ -275,7 +276,7 @@ class GitHubAppsTestOrgTwo < ActiveSupport::TestCase
}
]
}
- ),
+ )
)
assert_equal "operational", app(@organization).api_status[:status]
end
@@ -285,15 +286,15 @@ class GitHubAppsTestOrgTwo < ActiveSupport::TestCase
config = {
app_id: "test_id",
installation_id: "test_installation_id",
- private_key: "test_private_key",
+ private_key: "test_private_key"
}
initial_token = OpenStruct.new(
token: "some_initial_github_token",
- expires_at: Time.now.utc + 60.minutes,
+ expires_at: Time.now.utc + 60.minutes
)
second_token = OpenStruct.new(
token: "some_new_github_token",
- expires_at: initial_token.expires_at + 60.minutes,
+ expires_at: initial_token.expires_at + 60.minutes
)
auth_payload = "test_auth_payload"
@@ -323,15 +324,15 @@ class GitHubAppsTestOrgTwo < ActiveSupport::TestCase
config = {
app_id: "test_id",
installation_id: "test_installation_id",
- private_key: "test_private_key",
+ private_key: "test_private_key"
}
initial_token = OpenStruct.new(
token: "some_initial_github_token",
- expires_at: Time.now.utc + 60.minutes,
+ expires_at: Time.now.utc + 60.minutes
)
second_token = OpenStruct.new(
token: "some_new_github_token",
- expires_at: initial_token.expires_at + 60.minutes,
+ expires_at: initial_token.expires_at + 60.minutes
)
auth_payload = "test_auth_payload"
@@ -368,14 +369,14 @@ class GitHubAppsTestOrgTwo < ActiveSupport::TestCase
config = {
app_id: "test_id",
installation_id: "test_installation_id",
- private_key: "test_private_key",
+ private_key: "test_private_key"
}
initial_cached_token = Shipit::GitHubApp::Token.new("some_initial_github_token", Time.now.utc - 1.minute)
initial_cached_token.instance_variable_set(:@refresh_at, nil)
second_token = OpenStruct.new(
token: "some_new_github_token",
- expires_at: initial_cached_token.expires_at + 60.minutes,
+ expires_at: initial_cached_token.expires_at + 60.minutes
)
auth_payload = "test_auth_payload"
diff --git a/test/unit/github_url_helper_test.rb b/test/unit/github_url_helper_test.rb
index 0b5cd18e7..c60ec099c 100644
--- a/test/unit/github_url_helper_test.rb
+++ b/test/unit/github_url_helper_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/unit/line_buffer_test.rb b/test/unit/line_buffer_test.rb
index 9da775152..0179de97c 100644
--- a/test/unit/line_buffer_test.rb
+++ b/test/unit/line_buffer_test.rb
@@ -13,7 +13,7 @@ class LineBufferTest < ActiveSupport::TestCase
end
test "splits up multiple lines" do
- assert_equal(%w(a b), @buffer.buffer("a\nb\n").to_a)
+ assert_equal(%w[a b], @buffer.buffer("a\nb\n").to_a)
assert_predicate(@buffer, :empty?)
end
end
diff --git a/test/unit/rollback_commands_test.rb b/test/unit/rollback_commands_test.rb
index bf503171f..3092e5425 100644
--- a/test/unit/rollback_commands_test.rb
+++ b/test/unit/rollback_commands_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -13,7 +14,7 @@ def setup
rollback_steps!: ['bundle exec cap $ENVIRONMENT deploy:rollback'],
machine_env: { 'GLOBAL' => '1' },
directory: nil,
- clear_working_directory?: true,
+ clear_working_directory?: true
)
@commands.stubs(:deploy_spec).returns(@deploy_spec)
diff --git a/test/unit/shipit_helper_test.rb b/test/unit/shipit_helper_test.rb
index 46668d1fb..a24ced0f6 100644
--- a/test/unit/shipit_helper_test.rb
+++ b/test/unit/shipit_helper_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/unit/shipit_test.rb b/test/unit/shipit_test.rb
index 8ae98f2a6..92946ebc3 100644
--- a/test/unit/shipit_test.rb
+++ b/test/unit/shipit_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/unit/user_serializer_test.rb b/test/unit/user_serializer_test.rb
index 85ae23614..2136aedc8 100644
--- a/test/unit/user_serializer_test.rb
+++ b/test/unit/user_serializer_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
diff --git a/test/unit/variable_definition_test.rb b/test/unit/variable_definition_test.rb
index 29fec6916..53810071a 100644
--- a/test/unit/variable_definition_test.rb
+++ b/test/unit/variable_definition_test.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'test_helper'
module Shipit
@@ -7,9 +8,9 @@ class VariableDefinitionTest < ActiveSupport::TestCase
@attributes = {
"name" => "Variable name",
"title" => "Variable title",
- "default" => "Variable default",
+ "default" => "Variable default"
}
- @select = %w(var1 var2 var3)
+ @select = %w[var1 var2 var3]
end
test "#initialize sets up the expected values" do
@@ -53,7 +54,7 @@ class VariableDefinitionTest < ActiveSupport::TestCase
test "#default_provided?" do
attributes = {
"name" => "Variable name",
- "title" => "Variable title",
+ "title" => "Variable title"
}
subject = Shipit::VariableDefinition.new(attributes)
refute subject.default_provided?