Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
38 changes: 35 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ AllCops:
- lib/shipit-engine.rb
- template.rb

inherit_gem:
rubocop-shopify: rubocop.yml

Layout/LineLength:
Exclude:
- config/routes.rb
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 17 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -423,8 +425,7 @@ DEPENDENCIES
mysql2
pg
pry
rubocop (= 1.18.3)
rubocop-shopify
rubocop (~> 1.48.0)
shipit-engine!
simplecov
spy
Expand Down
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module Shipit
module ActiveModelSerializersPatch
private
Expand Down
1 change: 1 addition & 0 deletions app/controllers/concerns/shipit/api/cacheable.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module Shipit
module Api
module Cacheable
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/concerns/shipit/api/paginable.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module Shipit
module Api
module Paginable
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions app/controllers/concerns/shipit/api/rendering.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module Shipit
module Api
module Rendering
Expand Down
1 change: 1 addition & 0 deletions app/controllers/concerns/shipit/authentication.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module Shipit
module Authentication
extend ActiveSupport::Concern
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/concerns/shipit/pagination.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module Shipit
module Pagination
extend ActiveSupport::Concern
Expand All @@ -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
Expand Down
18 changes: 10 additions & 8 deletions app/controllers/shipit/api/base_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module Shipit
module Api
class BaseController < ActionController::Base
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/shipit/api/ccmenu_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module Shipit
module Api
class CCMenuController < BaseController
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions app/controllers/shipit/api/commits_controller.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# frozen_string_literal: true

module Shipit
module Api
class CommitsController < BaseController
require_permission :read, :stack

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
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/shipit/api/deploys_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module Shipit
module Api
class DeploysController < BaseController
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions app/controllers/shipit/api/hooks_controller.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -43,7 +44,7 @@ def hook
end

def hooks
Hook.where(stack_id: stack_id)
Hook.where(stack_id:)
end

def stack_id
Expand Down
1 change: 1 addition & 0 deletions app/controllers/shipit/api/locks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module Shipit
module Api
class LocksController < BaseController
Expand Down
11 changes: 6 additions & 5 deletions app/controllers/shipit/api/merge_requests_controller.rb
Original file line number Diff line number Diff line change
@@ -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))
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/controllers/shipit/api/outputs_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module Shipit
module Api
class OutputsController < BaseController
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/shipit/api/release_statuses_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# frozen_string_literal: true

module Shipit
module Api
class ReleaseStatusesController < BaseController
require_permission :deploy, :stack

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])
Expand Down
Loading