Commit 1cfbfb77 authored by Douwe Maan's avatar Douwe Maan

Prefer leading style for Style/DotPosition

parent e0e39806
......@@ -138,7 +138,7 @@ Style/Documentation:
Style/DotPosition:
Enabled: true
EnforcedStyle: trailing
EnforcedStyle: leading
# Align elses and elsifs correctly.
Style/ElseAlignment:
......
......@@ -5,9 +5,9 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
end
def update
successful = ApplicationSettings::UpdateService.
new(@application_setting, current_user, application_setting_params).
execute
successful = ApplicationSettings::UpdateService
.new(@application_setting, current_user, application_setting_params)
.execute
if successful
redirect_to admin_application_settings_path,
......
......@@ -83,8 +83,8 @@ module CreatesCommit
def merge_request_exists?
return @merge_request if defined?(@merge_request)
@merge_request = MergeRequestsFinder.new(current_user, project_id: @mr_target_project.id).execute.opened.
find_by(source_branch: @mr_source_branch, target_branch: @mr_target_branch, source_project_id: @mr_source_project)
@merge_request = MergeRequestsFinder.new(current_user, project_id: @mr_target_project.id).execute.opened
.find_by(source_branch: @mr_source_branch, target_branch: @mr_target_branch, source_project_id: @mr_source_project)
end
def different_project?
......
......@@ -5,9 +5,9 @@ module IssuesAction
def issues
@label = issues_finder.labels.first
@issues = issues_collection.
non_archived.
page(params[:page])
@issues = issues_collection
.non_archived
.page(params[:page])
@collection_type = "Issue"
@issuable_meta_data = issuable_meta_data(@issues)
......
......@@ -17,8 +17,8 @@ module MembershipActions
end
def leave
member = Members::DestroyService.new(membershipable, current_user, user_id: current_user.id).
execute(:all)
member = Members::DestroyService.new(membershipable, current_user, user_id: current_user.id)
.execute(:all)
source_type = membershipable.class.to_s.humanize(capitalize: false)
notice =
......
......@@ -5,8 +5,8 @@ module MergeRequestsAction
def merge_requests
@label = merge_requests_finder.labels.first
@merge_requests = merge_requests_collection.
page(params[:page])
@merge_requests = merge_requests_collection
.page(params[:page])
@collection_type = "MergeRequest"
@issuable_meta_data = issuable_meta_data(@merge_requests)
......
......@@ -29,9 +29,9 @@ class Import::BitbucketController < Import::BaseController
end
def jobs
render json: current_user.created_projects.
where(import_type: 'bitbucket').
to_json(only: [:id, :import_status])
render json: current_user.created_projects
.where(import_type: 'bitbucket')
.to_json(only: [:id, :import_status])
end
def create
......
......@@ -11,8 +11,8 @@ class JwtController < ApplicationController
service = SERVICES[params[:service]]
return head :not_found unless service
result = service.new(@authentication_result.project, @authentication_result.actor, auth_params).
execute(authentication_abilities: @authentication_result.authentication_abilities)
result = service.new(@authentication_result.project, @authentication_result.actor, auth_params)
.execute(authentication_abilities: @authentication_result.authentication_abilities)
render json: result, status: result[:http_status]
end
......
......@@ -155,7 +155,7 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
end
def log_audit_event(user, options = {})
AuditEventService.new(user, user, options).
for_authentication.security_event
AuditEventService.new(user, user, options)
.for_authentication.security_event
end
end
......@@ -41,9 +41,9 @@ class ProfilesController < Profiles::ApplicationController
end
def audit_log
@events = AuditEvent.where(entity_type: "User", entity_id: current_user.id).
order("created_at DESC").
page(params[:page])
@events = AuditEvent.where(entity_type: "User", entity_id: current_user.id)
.order("created_at DESC")
.page(params[:page])
end
def update_username
......
......@@ -4,15 +4,15 @@ class Projects::BadgesController < Projects::ApplicationController
before_action :no_cache_headers, except: [:index]
def build
build_status = Gitlab::Badge::Build::Status.
new(project, params[:ref])
build_status = Gitlab::Badge::Build::Status
.new(project, params[:ref])
render_badge build_status
end
def coverage
coverage_report = Gitlab::Badge::Coverage::Report.
new(project, params[:ref], params[:job])
coverage_report = Gitlab::Badge::Coverage::Report
.new(project, params[:ref], params[:job])
render_badge coverage_report
end
......
......@@ -164,7 +164,7 @@ class Projects::BlobController < Projects::ApplicationController
end
def set_last_commit_sha
@last_commit_sha = Gitlab::Git::Commit.
last_for_path(@repository, @ref, @path).sha
@last_commit_sha = Gitlab::Git::Commit
.last_for_path(@repository, @ref, @path).sha
end
end
......@@ -40,10 +40,10 @@ module Projects
def issue
@issue ||=
IssuesFinder.new(current_user, project_id: project.id).
execute.
where(iid: params[:id]).
first!
IssuesFinder.new(current_user, project_id: project.id)
.execute
.where(iid: params[:id])
.first!
end
def authorize_read_issue!
......
......@@ -32,8 +32,8 @@ class Projects::BranchesController < Projects::ApplicationController
branch_name = sanitize(strip_tags(params[:branch_name]))
branch_name = Addressable::URI.unescape(branch_name)
result = CreateBranchService.new(project, current_user).
execute(branch_name, ref)
result = CreateBranchService.new(project, current_user)
.execute(branch_name, ref)
if params[:issue_iid]
issue = IssuesFinder.new(current_user, project_id: @project.id).find_by(iid: params[:issue_iid])
......
......@@ -48,8 +48,8 @@ class Projects::BuildsController < Projects::ApplicationController
respond_to do |format|
format.json do
state = params[:state].presence
render json: @build.trace_with_state(state: state).
merge!(id: @build.id, status: @build.status)
render json: @build.trace_with_state(state: state)
.merge!(id: @build.id, status: @build.status)
end
end
end
......
......@@ -35,9 +35,9 @@ class Projects::CommitController < Projects::ApplicationController
respond_to do |format|
format.html
format.json do
render json: PipelineSerializer.
new(project: @project, user: @current_user).
represent(@pipelines)
render json: PipelineSerializer
.new(project: @project, user: @current_user)
.represent(@pipelines)
end
end
end
......
......@@ -18,11 +18,11 @@ class Projects::CommitsController < Projects::ApplicationController
@repository.commits(@ref, path: @path, limit: @limit, offset: @offset)
end
@note_counts = project.notes.where(commit_id: @commits.map(&:id)).
group(:commit_id).count
@note_counts = project.notes.where(commit_id: @commits.map(&:id))
.group(:commit_id).count
@merge_request = MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened.
find_by(source_project: @project, source_branch: @ref, target_branch: @repository.root_ref)
@merge_request = MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened
.find_by(source_project: @project, source_branch: @ref, target_branch: @repository.root_ref)
respond_to do |format|
format.html
......
......@@ -46,8 +46,8 @@ class Projects::CompareController < Projects::ApplicationController
end
def define_diff_vars
@compare = CompareService.new(@project, @head_ref).
execute(@project, @start_ref)
@compare = CompareService.new(@project, @head_ref)
.execute(@project, @start_ref)
if @compare
@commits = @compare.commits
......@@ -66,7 +66,7 @@ class Projects::CompareController < Projects::ApplicationController
end
def merge_request
@merge_request ||= MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened.
find_by(source_project: @project, source_branch: @head_ref, target_branch: @start_ref)
@merge_request ||= MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened
.find_by(source_project: @project, source_branch: @head_ref, target_branch: @start_ref)
end
end
......@@ -9,18 +9,18 @@ class Projects::EnvironmentsController < Projects::ApplicationController
before_action :verify_api_request!, only: :terminal_websocket_authorize
def index
@environments = project.environments.
with_state(params[:scope] || :available)
@environments = project.environments
.with_state(params[:scope] || :available)
respond_to do |format|
format.html
format.json do
render json: {
environments: EnvironmentSerializer.
new(project: @project, user: @current_user).
with_pagination(request, response).
within_folders.
represent(@environments),
environments: EnvironmentSerializer
.new(project: @project, user: @current_user)
.with_pagination(request, response)
.within_folders
.represent(@environments),
available_count: project.environments.available.count,
stopped_count: project.environments.stopped.count
}
......@@ -36,10 +36,10 @@ class Projects::EnvironmentsController < Projects::ApplicationController
format.html
format.json do
render json: {
environments: EnvironmentSerializer.
new(project: @project, user: @current_user).
with_pagination(request, response).
represent(@environments),
environments: EnvironmentSerializer
.new(project: @project, user: @current_user)
.with_pagination(request, response)
.represent(@environments),
available_count: folder_environments.available.count,
stopped_count: folder_environments.stopped.count
}
......
......@@ -82,8 +82,8 @@ class Projects::IssuesController < Projects::ApplicationController
def show
raw_notes = @issue.notes.inc_relations_for_view.fresh
@notes = Banzai::NoteRenderer.
render(raw_notes, @project, current_user, @path, @project_wiki, @ref)
@notes = Banzai::NoteRenderer
.render(raw_notes, @project, current_user, @path, @project_wiki, @ref)
@note = @project.notes.new(noteable: @issue)
@noteable = @issue
......@@ -210,9 +210,9 @@ class Projects::IssuesController < Projects::ApplicationController
def merge_request_for_resolving_discussions
return unless merge_request_iid = params[:merge_request_for_resolving_discussions]
@merge_request_for_resolving_discussions ||= MergeRequestsFinder.new(current_user, project_id: project.id).
execute.
find_by(iid: merge_request_iid)
@merge_request_for_resolving_discussions ||= MergeRequestsFinder.new(current_user, project_id: project.id)
.execute
.find_by(iid: merge_request_iid)
end
def authorize_read_issue!
......
......@@ -165,8 +165,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController
# Get commits from repository
# or from cache if already merged
@commits = @merge_request.commits
@note_counts = Note.where(commit_id: @commits.map(&:id)).
group(:commit_id).count
@note_counts = Note.where(commit_id: @commits.map(&:id))
.group(:commit_id).count
render json: { html: view_to_html_string('projects/merge_requests/show/_commits') }
end
......@@ -235,9 +235,9 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end
format.json do
render json: PipelineSerializer.
new(project: @project, user: @current_user).
represent(@pipelines)
render json: PipelineSerializer
.new(project: @project, user: @current_user)
.represent(@pipelines)
end
end
end
......@@ -248,9 +248,9 @@ class Projects::MergeRequestsController < Projects::ApplicationController
format.json do
define_pipelines_vars
render json: PipelineSerializer.
new(project: @project, user: @current_user).
represent(@pipelines)
render json: PipelineSerializer
.new(project: @project, user: @current_user)
.represent(@pipelines)
end
end
end
......@@ -343,9 +343,9 @@ class Projects::MergeRequestsController < Projects::ApplicationController
return access_denied!
end
MergeRequests::MergeWhenPipelineSucceedsService.
new(@project, current_user).
cancel(@merge_request)
MergeRequests::MergeWhenPipelineSucceedsService
.new(@project, current_user)
.cancel(@merge_request)
end
def merge
......@@ -380,9 +380,9 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end
if @merge_request.head_pipeline.active?
MergeRequests::MergeWhenPipelineSucceedsService.
new(@project, current_user, merge_params).
execute(@merge_request)
MergeRequests::MergeWhenPipelineSucceedsService
.new(@project, current_user, merge_params)
.execute(@merge_request)
@status = :merge_when_build_succeeds
elsif @merge_request.head_pipeline.success?
......@@ -685,8 +685,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@commit = @merge_request.diff_head_commit
@base_commit = @merge_request.diff_base_commit
@note_counts = Note.where(commit_id: @commits.map(&:id)).
group(:commit_id).count
@note_counts = Note.where(commit_id: @commits.map(&:id))
.group(:commit_id).count
@labels = LabelsFinder.new(current_user, project_id: @project.id).execute
......@@ -709,8 +709,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end
def merge_request_params
params.require(:merge_request).
permit(merge_request_params_ce << merge_request_params_ee)
params.require(:merge_request)
.permit(merge_request_params_ce << merge_request_params_ee)
end
def merge_request_params_ce
......
......@@ -7,26 +7,26 @@ class Projects::PipelinesController < Projects::ApplicationController
def index
@scope = params[:scope]
@pipelines = PipelinesFinder.
new(project).
execute(scope: @scope).
page(params[:page]).
per(30)
@pipelines = PipelinesFinder
.new(project)
.execute(scope: @scope)
.page(params[:page])
.per(30)
@running_or_pending_count = PipelinesFinder.
new(project).execute(scope: 'running').count
@running_or_pending_count = PipelinesFinder
.new(project).execute(scope: 'running').count
@pipelines_count = PipelinesFinder.
new(project).execute.count
@pipelines_count = PipelinesFinder
.new(project).execute.count
respond_to do |format|
format.html
format.json do
render json: {
pipelines: PipelineSerializer.
new(project: @project, user: @current_user).
with_pagination(request, response).
represent(@pipelines),
pipelines: PipelineSerializer
.new(project: @project, user: @current_user)
.with_pagination(request, response)
.represent(@pipelines),
count: {
all: @pipelines_count,
running_or_pending: @running_or_pending_count
......@@ -41,9 +41,9 @@ class Projects::PipelinesController < Projects::ApplicationController
end
def create
@pipeline = Ci::CreatePipelineService.
new(project, current_user, create_params).
execute(ignore_skip_ci: true, save_on_errors: false)
@pipeline = Ci::CreatePipelineService
.new(project, current_user, create_params)
.execute(ignore_skip_ci: true, save_on_errors: false)
unless @pipeline.persisted?
render 'new'
return
......
......@@ -41,8 +41,8 @@ class Projects::ProjectMembersController < Projects::ApplicationController
end
def destroy
member = Members::DestroyService.new(@project, current_user, params).
execute(:all)
member = Members::DestroyService.new(@project, current_user, params)
.execute(:all)
log_audit_event(member, action: :destroy)
......
......@@ -14,8 +14,8 @@ module Projects
def define_runners_variables
@project_runners = @project.runners.ordered
@assignable_runners = current_user.ci_authorized_runners.
assignable_for(project).ordered.page(params[:page]).per(20)
@assignable_runners = current_user.ci_authorized_runners
.assignable_for(project).ordered.page(params[:page]).per(20)
@shared_runners = Ci::Runner.shared.active
@shared_runners_count = @shared_runners.count(:all)
end
......
......@@ -41,10 +41,10 @@ module Projects
wheres = ["members.id IN (#{@project_members.select(:id).to_sql})"]
wheres << "members.id IN (#{group_members.select(:id).to_sql})" if group_members
@project_members = Member.
where(wheres.join(' OR ')).
sort(@sort).
page(params[:page])
@project_members = Member
.where(wheres.join(' OR '))
.sort(@sort)
.page(params[:page])
@requesters = AccessRequestsFinder.new(@project).execute(current_user)
......
......@@ -27,8 +27,8 @@ class Projects::TagsController < Projects::ApplicationController
end
def create
result = Tags::CreateService.new(@project, current_user).
execute(params[:tag_name], params[:ref], params[:message], params[:release_description])
result = Tags::CreateService.new(@project, current_user)
.execute(params[:tag_name], params[:ref], params[:message], params[:release_description])
if result[:status] == :success
@tag = result[:tag]
......
......@@ -5,8 +5,8 @@ class Projects::UploadsController < Projects::ApplicationController
before_action :authorize_upload_file!, only: [:create]
def create
link_to_file = ::Projects::UploadService.new(project, params[:file]).
execute
link_to_file = ::Projects::UploadService.new(project, params[:file])
.execute
respond_to do |format|
if link_to_file
......
......@@ -294,8 +294,8 @@ class ProjectsController < Projects::ApplicationController
end
def project_params
params.require(:project).
permit(project_params_ce << project_params_ee)
params.require(:project)
.permit(project_params_ce << project_params_ee)
end
def project_params_ce
......
......@@ -143,8 +143,8 @@ class SessionsController < Devise::SessionsController
end
def log_audit_event(user, options = {})
AuditEventService.new(user, user, options).
for_authentication.security_event
AuditEventService.new(user, user, options)
.for_authentication.security_event
end
def log_user_activity(user)
......
......@@ -4,8 +4,8 @@ module Sherlock
def find_transaction
if params[:transaction_id]
@transaction = Gitlab::Sherlock.collection.
find_transaction(params[:transaction_id])
@transaction = Gitlab::Sherlock.collection
.find_transaction(params[:transaction_id])
end
end
end
......
......@@ -28,8 +28,8 @@ class SnippetsController < ApplicationController
@snippets = SnippetsFinder.new.execute(current_user, {
filter: :by_user,
user: @user,
scope: params[:scope] }).
page(params[:page])
scope: params[:scope] })
.page(params[:page])
render 'index'
else
......@@ -79,8 +79,8 @@ class SnippetsController < ApplicationController
@snippet ||= if current_user
PersonalSnippet.where("author_id = ? OR visibility_level IN (?)",
current_user.id,
[Snippet::PUBLIC, Snippet::INTERNAL]).
find(params[:id])
[Snippet::PUBLIC, Snippet::INTERNAL])
.find(params[:id])
else
PersonalSnippet.find(params[:id])
end
......
......@@ -109,17 +109,17 @@ class UsersController < ApplicationController
def load_events
# Get user activity feed for projects common for both users
@events = user.recent_events.
merge(projects_for_current_user).
references(:project).
with_associations.
limit_recent(20, params[:offset])
@events = user.recent_events
.merge(projects_for_current_user)
.references(:project)
.with_associations
.limit_recent(20, params[:offset])
end
def load_projects
@projects =
PersonalProjectsFinder.new(user).execute(current_user).
page(params[:page])
PersonalProjectsFinder.new(user).execute(current_user)
.page(params[:page])
end
def load_contributed_projects
......
......@@ -17,12 +17,12 @@ class EnvironmentsFinder
deployments.none
end
environment_ids = deployments.
group(:environment_id).
select(:environment_id)
environment_ids = deployments
.group(:environment_id)
.select(:environment_id)
environments = project.environments.available.
where(id: environment_ids).order_by_last_deployed_at.to_a
environments = project.environments.available
.where(id: environment_ids).order_by_last_deployed_at.to_a
environments.select! do |environment|
Ability.allowed?(current_user, :read_environment, environment)
......
......@@ -8,9 +8,9 @@ class GroupMembersFinder < Projects::ApplicationController
return group_members unless @group.parent
parents_members = GroupMember.non_request.
where(source_id: @group.ancestors.select(:id)).
where.not(user_id: @group.users.select(:id))
parents_members = GroupMember.non_request
.where(source_id: @group.ancestors.select(:id))
.where.not(user_id: @group.users.select(:id))
wheres = ["members.id IN (#{group_members.select(:id).to_sql})"]
wheres << "members.id IN (#{parents_members.select(:id).to_sql})"
......
......@@ -8,10 +8,10 @@ module FormHelper
content_tag(:div, class: 'alert alert-danger', id: 'error_explanation') do
content_tag(:h4, headline) <<
content_tag(:ul) do
model.errors.full_messages.
map { |msg| content_tag(:li, msg) }.
join.
html_safe
model.errors.full_messages
.map { |msg| content_tag(:li, msg) }
.join
.html_safe
end
end
end
......
......@@ -105,8 +105,8 @@ module SearchHelper
# Autocomplete results for the current user's projects
def projects_autocomplete(term, limit = 5)
current_user.authorized_projects.search_by_title(term).
sorted_by_stars.non_archived.limit(limit).map do |p|
current_user.authorized_projects.search_by_title(term)
.sorted_by_stars.non_archived.limit(limit).map do |p|
{
category: "Projects",
id: p.id,
......
......@@ -6,8 +6,8 @@ module WikiHelper
# Returns a String composed of the capitalized name of each directory and the
# capitalized name of the page itself.
def breadcrumb(page_slug)
page_slug.split('/').
map { |dir_or_page| WikiPage.unhyphenize(dir_or_page).capitalize }.
join(' / ')
page_slug.split('/')
.map { |dir_or_page| WikiPage.unhyphenize(dir_or_page).capitalize }
.join(' / ')
end
end
......@@ -18,9 +18,9 @@ class AwardEmoji < ActiveRecord::Base
class << self
def votes_for_collection(ids, type)
select('name', 'awardable_id', 'COUNT(*) as count').
where('name IN (?) AND awardable_type = ? AND awardable_id IN (?)', [DOWNVOTE_NAME, UPVOTE_NAME], type, ids).
group('name', 'awardable_id')
select('name', 'awardable_id', 'COUNT(*) as count')
.where('name IN (?) AND awardable_type = ? AND awardable_id IN (?)', [DOWNVOTE_NAME, UPVOTE_NAME], type, ids)
.group('name', 'awardable_id')
end
end
......
......@@ -64,9 +64,9 @@ module Ci
end
def retry(build, current_user)
Ci::RetryBuildService.
new(build.project, current_user).
execute(build)
Ci::RetryBuildService
.new(build.project, current_user)
.execute(build)
end
end
......@@ -97,9 +97,9 @@ module Ci
end
def detailed_status(current_user)
Gitlab::Ci::Status::Build::Factory.
new(self, current_user).
fabricate!
Gitlab::Ci::Status::Build::Factory
.new(self, current_user)
.fabricate!
end
def manual?
......@@ -221,9 +221,9 @@ module Ci
end
def merge_request
merge_requests = MergeRequest.includes(:merge_request_diff).
where(source_branch: ref, source_project_id: pipeline.gl_project_id).
reorder(iid: :asc)
merge_requests = MergeRequest.includes(:merge_request_diff)
.where(source_branch: ref, source_project_id: pipeline.gl_project_id)
.reorder(iid: :asc)
merge_requests.find do |merge_request|
merge_request.commits_sha.include?(pipeline.sha)
......@@ -279,8 +279,8 @@ module Ci
def raw_trace(last_lines: nil)
if File.exist?(trace_file_path)
Gitlab::Ci::TraceReader.new(trace_file_path).
read(last_lines: last_lines)
Gitlab::Ci::TraceReader.new(trace_file_path)
.read(last_lines: last_lines)
else
# backward compatibility
read_attribute :trace
......
......@@ -89,9 +89,9 @@ module Ci
# ref can't be HEAD or SHA, can only be branch/tag name
scope :latest, ->(ref = nil) do
max_id = unscope(:select).
select("max(#{quoted_table_name}.id)").
group(:ref, :sha)
max_id = unscope(:select)
.select("max(#{quoted_table_name}.id)")
.group(:ref, :sha)
relation = ref ? where(ref: ref) : self
relation.where(id: max_id)
......@@ -123,23 +123,23 @@ module Ci
end
def stages_name
statuses.order(:stage_idx).distinct.
pluck(:stage, :stage_idx).map(&:first)
statuses.order(:stage_idx).distinct
.pluck(:stage, :stage_idx).map(&:first)
end
def stages
# TODO, this needs refactoring, see gitlab-ce#26481.
stages_query = statuses.
group('stage').select(:stage).order('max(stage_idx)')
stages_query = statuses
.group('stage').select(:stage).order('max(stage_idx)')
status_sql = statuses.latest.where('stage=sg.stage').status_sql
warnings_sql = statuses.latest.select('COUNT(*) > 0').
where('stage=sg.stage').failed_but_allowed.to_sql
warnings_sql = statuses.latest.select('COUNT(*) > 0')
.where('stage=sg.stage').failed_but_allowed.to_sql
stages_with_statuses = CommitStatus.from(stages_query, :sg).
pluck('sg.stage', status_sql, "(#{warnings_sql})")
stages_with_statuses = CommitStatus.from(stages_query, :sg)
.pluck('sg.stage', status_sql, "(#{warnings_sql})")
stages_with_statuses.map do |stage|
Ci::Stage.new(self, Hash[%i[name status warnings].zip(stage)])
......@@ -219,8 +219,8 @@ module Ci
end
def retry_failed(current_user)
Ci::RetryPipelineService.new(project, current_user).
execute(self)
Ci::RetryPipelineService.new(project, current_user)
.execute(self)
end
def mark_as_processable_after_stage(stage_idx)
......@@ -252,9 +252,9 @@ module Ci
def config_builds_attributes
return [] unless config_processor
config_processor.
builds_for_ref(ref, tag?, trigger_requests.first).
sort_by { |build| build[:stage_idx] }
config_processor
.builds_for_ref(ref, tag?, trigger_requests.first)
.sort_by { |build| build[:stage_idx] }
end
def has_warnings?
......@@ -352,15 +352,15 @@ module Ci
# Merge requests for which the current pipeline is running against
# the merge request's latest commit.
def merge_requests
@merge_requests ||= project.merge_requests.
where(source_branch: self.ref).
select { |merge_request| merge_request.head_pipeline.try(:id) == self.id }
@merge_requests ||= project.merge_requests
.where(source_branch: self.ref)
.select { |merge_request| merge_request.head_pipeline.try(:id) == self.id }
end
def detailed_status(current_user)
Gitlab::Ci::Status::Pipeline::Factory.
new(self, current_user).
fabricate!
Gitlab::Ci::Status::Pipeline::Factory
.new(self, current_user)
.fabricate!
end
private
......
......@@ -23,15 +23,15 @@ module Ci
scope :ordered, ->() { order(id: :desc) }
scope :owned_or_shared, ->(project_id) do
joins('LEFT JOIN ci_runner_projects ON ci_runner_projects.runner_id = ci_runners.id').
where("ci_runner_projects.gl_project_id = :project_id OR ci_runners.is_shared = true", project_id: project_id)
joins('LEFT JOIN ci_runner_projects ON ci_runner_projects.runner_id = ci_runners.id')
.where("ci_runner_projects.gl_project_id = :project_id OR ci_runners.is_shared = true", project_id: project_id)
end
scope :assignable_for, ->(project) do
# FIXME: That `to_sql` is needed to workaround a weird Rails bug.
# Without that, placeholders would miss one and couldn't match.
where(locked: false).
where.not("id IN (#{project.runners.select(:id).to_sql})").specific
where(locked: false)
.where.not("id IN (#{project.runners.select(:id).to_sql})").specific
end
validate :tag_constraints
......
......@@ -28,9 +28,9 @@ module Ci
end
def detailed_status(current_user)
Gitlab::Ci::Status::Stage::Factory.
new(self, current_user).
fabricate!
Gitlab::Ci::Status::Stage::Factory
.new(self, current_user)
.fabricate!
end
def statuses
......
......@@ -96,8 +96,8 @@ class CommitStatus < ActiveRecord::Base
after_transition any => :failed do |commit_status|
commit_status.run_after_commit do
MergeRequests::AddTodoWhenBuildFailsService.
new(pipeline.project, nil).execute(self)
MergeRequests::AddTodoWhenBuildFailsService
.new(pipeline.project, nil).execute(self)
end
end
end
......@@ -133,9 +133,9 @@ class CommitStatus < ActiveRecord::Base
end
def detailed_status(current_user)
Gitlab::Ci::Status::Factory.
new(self, current_user).
fabricate!
Gitlab::Ci::Status::Factory
.new(self, current_user)
.fabricate!
end
def sortable_name
......
......@@ -165,9 +165,9 @@ module Issuable
highest_priority = highest_label_priority(params).to_sql
select("#{table_name}.*, (#{highest_priority}) AS highest_priority").
group(arel_table[:id]).
reorder(Gitlab::Database.nulls_last_order('highest_priority', 'ASC'))
select("#{table_name}.*, (#{highest_priority}) AS highest_priority")
.group(arel_table[:id])
.reorder(Gitlab::Database.nulls_last_order('highest_priority', 'ASC'))
end
def with_label(title, sort = nil)
......
......@@ -48,8 +48,8 @@ module Mentionable
if extractor
@extractor = extractor
else
@extractor ||= Gitlab::ReferenceExtractor.
new(project, current_user)
@extractor ||= Gitlab::ReferenceExtractor
.new(project, current_user)
@extractor.reset_memoized_values
end
......
......@@ -39,8 +39,8 @@ module Milestoneish
def issues_visible_to_user(user)
memoize_per_user(user, :issues_visible_to_user) do
IssuesFinder.new(user, issues_finder_params).
execute.where(milestone_id: milestoneish_ids)
IssuesFinder.new(user, issues_finder_params)
.execute.where(milestone_id: milestoneish_ids)
end
end
......
module Presentable
def present(**attributes)
Gitlab::View::Presenter::Factory.
new(self, attributes).
fabricate!
Gitlab::View::Presenter::Factory
.new(self, attributes)
.fabricate!
end
end
......@@ -75,11 +75,11 @@ module Routable
#
# Returns an ActiveRecord::Relation.
def member_descendants(user_id)
joins(:route).
joins("INNER JOIN routes r2 ON routes.path LIKE CONCAT(r2.path, '/%')
joins(:route)
.joins("INNER JOIN routes r2 ON routes.path LIKE CONCAT(r2.path, '/%')
INNER JOIN members ON members.source_id = r2.source_id
AND members.source_type = r2.source_type").
where('members.user_id = ?', user_id)
AND members.source_type = r2.source_type")
.where('members.user_id = ?', user_id)
end
end
......
......@@ -39,12 +39,12 @@ module Sortable
private
def highest_label_priority(target_type_column: nil, target_type: nil, target_column:, project_column:, excluded_labels: [])
query = Label.select(LabelPriority.arel_table[:priority].minimum).
left_join_priorities.
joins(:label_links).
where("label_priorities.project_id = #{project_column}").
where("label_links.target_id = #{target_column}").
reorder(nil)
query = Label.select(LabelPriority.arel_table[:priority].minimum)
.left_join_priorities
.joins(:label_links)
.where("label_priorities.project_id = #{project_column}")
.where("label_links.target_id = #{target_column}")
.reorder(nil)
query =
if target_type_column
......
......@@ -27,30 +27,30 @@ module Subscribable
end
def subscribers(project)
subscriptions_available(project).
where(subscribed: true).
map(&:user)
subscriptions_available(project)
.where(subscribed: true)
.map(&:user)
end
def toggle_subscription(user, project = nil)
unsubscribe_from_other_levels(user, project)
find_or_initialize_subscription(user, project).
update(subscribed: !subscribed?(user, project))
find_or_initialize_subscription(user, project)
.update(subscribed: !subscribed?(user, project))
end
def subscribe(user, project = nil)
unsubscribe_from_other_levels(user, project)
find_or_initialize_subscription(user, project).
update(subscribed: true)
find_or_initialize_subscription(user, project)
.update(subscribed: true)
end
def unsubscribe(user, project = nil)
unsubscribe_from_other_levels(user, project)
find_or_initialize_subscription(user, project).
update(subscribed: false)
find_or_initialize_subscription(user, project)
.update(subscribed: false)
end
private
......@@ -69,14 +69,14 @@ module Subscribable
end
def find_or_initialize_subscription(user, project)
subscriptions.
find_or_initialize_by(user_id: user.id, project_id: project.try(:id))
subscriptions
.find_or_initialize_by(user_id: user.id, project_id: project.try(:id))
end
def subscriptions_available(project)
t = Subscription.arel_table
subscriptions.
where(t[:project_id].eq(nil).or(t[:project_id].eq(project.try(:id))))
subscriptions
.where(t[:project_id].eq(nil).or(t[:project_id].eq(project.try(:id))))
end
end
......@@ -53,10 +53,10 @@ class Deployment < ActiveRecord::Base
def update_merge_request_metrics!
return unless environment.update_merge_request_metrics?
merge_requests = project.merge_requests.
joins(:metrics).
where(target_branch: self.ref, merge_request_metrics: { first_deployed_to_production_at: nil }).
where("merge_request_metrics.merged_at <= ?", self.created_at)
merge_requests = project.merge_requests
.joins(:metrics)
.where(target_branch: self.ref, merge_request_metrics: { first_deployed_to_production_at: nil })
.where("merge_request_metrics.merged_at <= ?", self.created_at)
if previous_deployment
merge_requests = merge_requests.where("merge_request_metrics.merged_at >= ?", previous_deployment.created_at)
......@@ -71,17 +71,17 @@ class Deployment < ActiveRecord::Base
merge_requests.map(&:id)
end
MergeRequest::Metrics.
where(merge_request_id: merge_request_ids, first_deployed_to_production_at: nil).
update_all(first_deployed_to_production_at: self.created_at)
MergeRequest::Metrics
.where(merge_request_id: merge_request_ids, first_deployed_to_production_at: nil)
.update_all(first_deployed_to_production_at: self.created_at)
end
def previous_deployment
@previous_deployment ||=
project.deployments.joins(:environment).
where(environments: { name: self.environment.name }, ref: self.ref).
where.not(id: self.id).
take
project.deployments.joins(:environment)
.where(environments: { name: self.environment.name }, ref: self.ref)
.where.not(id: self.id)
.take
end
def stop_action
......
......@@ -40,9 +40,9 @@ class Environment < ActiveRecord::Base
scope :stopped, -> { with_state(:stopped) }
scope :order_by_last_deployed_at, -> do
max_deployment_id_sql =
Deployment.select(Deployment.arel_table[:id].maximum).
where(Deployment.arel_table[:environment_id].eq(arel_table[:id])).
to_sql
Deployment.select(Deployment.arel_table[:id].maximum)
.where(Deployment.arel_table[:environment_id].eq(arel_table[:id]))
.to_sql
order(Gitlab::Database.nulls_first_order("(#{max_deployment_id_sql})", 'ASC'))
end
......
......@@ -348,9 +348,9 @@ class Event < ActiveRecord::Base
# At this point it's possible for multiple threads/processes to try to
# update the project. Only one query should actually perform the update,
# hence we add the extra WHERE clause for last_activity_at.
Project.unscoped.where(id: project_id).
where('last_activity_at <= ?', RESET_PROJECT_ACTIVITY_INTERVAL.ago).
update_all(last_activity_at: created_at)
Project.unscoped.where(id: project_id)
.where('last_activity_at <= ?', RESET_PROJECT_ACTIVITY_INTERVAL.ago)
.update_all(last_activity_at: created_at)
end
def authored_by?(user)
......
......@@ -18,8 +18,8 @@ class GenericCommitStatus < CommitStatus
end
def detailed_status(current_user)
Gitlab::Ci::Status::External::Factory.
new(self, current_user).
fabricate!
Gitlab::Ci::Status::External::Factory
.new(self, current_user)
.fabricate!
end
end
......@@ -76,8 +76,8 @@ class GlobalMilestone
end
def labels
@labels ||= GlobalLabel.build_collection(milestones.includes(:labels).map(&:labels).flatten).
sort_by!(&:title)
@labels ||= GlobalLabel.build_collection(milestones.includes(:labels).map(&:labels).flatten)
.sort_by!(&:title)
end
def due_date
......
......@@ -87,9 +87,9 @@ class Group < Namespace
def select_for_project_authorization
if current_scope.joins_values.include?(:shared_projects)
joins('INNER JOIN namespaces project_namespace ON project_namespace.id = projects.namespace_id').
where('project_namespace.share_with_group_lock = ?', false).
select("members.user_id, projects.id AS project_id, LEAST(project_group_links.group_access, members.access_level) AS access_level")
joins('INNER JOIN namespaces project_namespace ON project_namespace.id = projects.namespace_id')
.where('project_namespace.share_with_group_lock = ?', false)
.select("members.user_id, projects.id AS project_id, LEAST(project_group_links.group_access, members.access_level) AS access_level")
else
super
end
......@@ -241,8 +241,8 @@ class Group < Namespace
end
def refresh_members_authorized_projects
UserProjectAccessChangedService.new(user_ids_for_project_authorizations).
execute
UserProjectAccessChangedService.new(user_ids_for_project_authorizations)
.execute
end
def user_ids_for_project_authorizations
......
......@@ -17,9 +17,9 @@ class IssueCollection
# Given all the issue projects we get a list of projects that the current
# user has at least reporter access to.
projects_with_reporter_access = user.
projects_with_reporter_access_limited_to(project_ids).
pluck(:id)
projects_with_reporter_access = user
.projects_with_reporter_access_limited_to(project_ids)
.pluck(:id)
collection.select do |issue|
if projects_with_reporter_access.include?(issue.project_id)
......
......@@ -34,18 +34,18 @@ class Label < ActiveRecord::Base
scope :with_title, ->(title) { where(title: title) }
def self.prioritized(project)
joins(:priorities).
where(label_priorities: { project_id: project }).
reorder('label_priorities.priority ASC, labels.title ASC')
joins(:priorities)
.where(label_priorities: { project_id: project })
.reorder('label_priorities.priority ASC, labels.title ASC')
end
def self.unprioritized(project)
labels = Label.arel_table
priorities = LabelPriority.arel_table
label_priorities = labels.join(priorities, Arel::Nodes::OuterJoin).
on(labels[:id].eq(priorities[:label_id]).and(priorities[:project_id].eq(project.id))).
join_sources
label_priorities = labels.join(priorities, Arel::Nodes::OuterJoin)
.on(labels[:id].eq(priorities[:label_id]).and(priorities[:project_id].eq(project.id)))
.join_sources
joins(label_priorities).where(priorities[:priority].eq(nil))
end
......@@ -54,9 +54,9 @@ class Label < ActiveRecord::Base
labels = Label.arel_table
priorities = LabelPriority.arel_table
label_priorities = labels.join(priorities, Arel::Nodes::OuterJoin).
on(labels[:id].eq(priorities[:label_id])).
join_sources
label_priorities = labels.join(priorities, Arel::Nodes::OuterJoin)
.on(labels[:id].eq(priorities[:label_id]))
.join_sources
joins(label_priorities)
end
......
......@@ -19,8 +19,8 @@ class LfsObject < ActiveRecord::Base
end
def self.destroy_unreferenced
joins("LEFT JOIN lfs_objects_projects ON lfs_objects_projects.lfs_object_id = #{table_name}.id").
where(lfs_objects_projects: { id: nil }).
destroy_all
joins("LEFT JOIN lfs_objects_projects ON lfs_objects_projects.lfs_object_id = #{table_name}.id")
.where(lfs_objects_projects: { id: nil })
.destroy_all
end
end
......@@ -40,9 +40,9 @@ class Member < ActiveRecord::Base
is_external_invite = arel_table[:user_id].eq(nil).and(arel_table[:invite_token].not_eq(nil))
user_is_active = User.arel_table[:state].eq(:active)
includes(:user).references(:users).
where(is_external_invite.or(user_is_active)).
where(requested_at: nil)
includes(:user).references(:users)
.where(is_external_invite.or(user_is_active))
.where(requested_at: nil)
end
scope :invite, -> { where.not(invite_token: nil) }
......@@ -100,9 +100,9 @@ class Member < ActiveRecord::Base
users = User.arel_table
members = Member.arel_table
member_users = members.join(users, Arel::Nodes::OuterJoin).
on(members[:user_id].eq(users[:id])).
join_sources
member_users = members.join(users, Arel::Nodes::OuterJoin)
.on(members[:user_id].eq(users[:id]))
.join_sources
joins(member_users)
end
......
......@@ -498,10 +498,10 @@ class MergeRequest < ActiveRecord::Base
end
def discussions
@discussions ||= self.related_notes.
inc_relations_for_view.
fresh.
discussions
@discussions ||= self.related_notes
.inc_relations_for_view
.fresh
.discussions
end
def diff_discussions
......@@ -587,8 +587,8 @@ class MergeRequest < ActiveRecord::Base
messages = [title, description]
messages.concat(commits.map(&:safe_message)) if merge_request_diff
Gitlab::ClosingIssueExtractor.new(project, current_user).
closed_by_message(messages.join("\n"))
Gitlab::ClosingIssueExtractor.new(project, current_user)
.closed_by_message(messages.join("\n"))
else
[]
end
......@@ -880,9 +880,9 @@ class MergeRequest < ActiveRecord::Base
def all_pipelines
return Ci::Pipeline.none unless source_project
@all_pipelines ||= source_project.pipelines.
where(sha: all_commits_sha, ref: source_branch).
order(id: :desc)
@all_pipelines ||= source_project.pipelines
.where(sha: all_commits_sha, ref: source_branch)
.order(id: :desc)
end
# Note that this could also return SHA from now dangling commits
......
......@@ -169,8 +169,8 @@ class MergeRequestDiff < ActiveRecord::Base
# When compare merge request versions we want diff A..B instead of A...B
# so we handle cases when user does squash and rebase of the commits between versions.
# For this reason we set straight to true by default.
CompareService.new(project, head_commit_sha).
execute(project, sha, straight: straight)
CompareService.new(project, head_commit_sha)
.execute(project, sha, straight: straight)
end
def commits_count
......
......@@ -99,11 +99,11 @@ class Milestone < ActiveRecord::Base
if Gitlab::Database.postgresql?
rel.order(:project_id, :due_date).select('DISTINCT ON (project_id) id')
else
rel.
group(:project_id).
having('due_date = MIN(due_date)').
pluck(:id, :project_id, :due_date).
map(&:first)
rel
.group(:project_id)
.having('due_date = MIN(due_date)')
.pluck(:id, :project_id, :due_date)
.map(&:first)
end
end
......@@ -178,8 +178,8 @@ class Milestone < ActiveRecord::Base
conditions = 'WHEN id = ? THEN ? ' * ids.length
issues.where(id: ids).
update_all(["position = CASE #{conditions} ELSE position END", *pairs])
issues.where(id: ids)
.update_all(["position = CASE #{conditions} ELSE position END", *pairs])
end
private
......
......@@ -49,9 +49,9 @@ class Namespace < ActiveRecord::Base
scope :root, -> { where('type IS NULL') }
scope :with_statistics, -> do
joins('LEFT JOIN project_statistics ps ON ps.namespace_id = namespaces.id').
group('namespaces.id').
select(
joins('LEFT JOIN project_statistics ps ON ps.namespace_id = namespaces.id')
.group('namespaces.id')
.select(
'namespaces.*',
'COALESCE(SUM(ps.storage_size), 0) AS storage_size',
'COALESCE(SUM(ps.repository_size), 0) AS repository_size',
......@@ -256,10 +256,10 @@ class Namespace < ActiveRecord::Base
end
def refresh_access_of_projects_invited_groups
Group.
joins(project_group_links: :project).
where(projects: { namespace_id: id }).
find_each(&:refresh_members_authorized_projects)
Group
.joins(project_group_links: :project)
.where(projects: { namespace_id: id })
.find_each(&:refresh_members_authorized_projects)
end
def remove_exports!
......
......@@ -28,8 +28,8 @@ module Network
if map.include?(p.id)
map[p.id]
end
end.
compact
end
.compact
end
end
end
......@@ -23,12 +23,12 @@ module Network
def collect_notes
h = Hash.new(0)
@project.
notes.
where('noteable_type = ?', 'Commit').
group('notes.commit_id').
select('notes.commit_id, count(notes.id) as note_count').
each do |item|
@project
.notes
.where('noteable_type = ?', 'Commit')
.group('notes.commit_id')
.select('notes.commit_id, count(notes.id) as note_count')
.each do |item|
h[item.commit_id] = item.note_count.to_i
end
......
......@@ -107,14 +107,14 @@ class Note < ActiveRecord::Base
def grouped_diff_discussions
active_notes = diff_notes.fresh.select(&:active?)
Discussion.for_diff_notes(active_notes).
map { |d| [d.line_code, d] }.to_h
Discussion.for_diff_notes(active_notes)
.map { |d| [d.line_code, d] }.to_h
end
def count_for_collection(ids, type)
user.select('noteable_id', 'COUNT(*) as count').
group(:noteable_id).
where(noteable_type: type, noteable_id: ids)
user.select('noteable_id', 'COUNT(*) as count')
.group(:noteable_id)
.where(noteable_type: type, noteable_id: ids)
end
end
......
......@@ -255,8 +255,8 @@ class Project < ActiveRecord::Base
scope :inside_path, ->(path) do
# We need routes alias rs for JOIN so it does not conflict with
# includes(:route) which we use in ProjectsFinder.
joins("INNER JOIN routes rs ON rs.source_id = projects.id AND rs.source_type = 'Project'").
where('rs.path LIKE ?', "#{path}/%")
joins("INNER JOIN routes rs ON rs.source_id = projects.id AND rs.source_type = 'Project'")
.where('rs.path LIKE ?', "#{path}/%")
end
# "enabled" here means "not disabled". It includes private features!
......@@ -350,9 +350,9 @@ class Project < ActiveRecord::Base
pattern = "%#{query}%"
projects = select(:id).where(
ptable[:path].matches(pattern).
or(ptable[:name].matches(pattern)).
or(ptable[:description].matches(pattern))
ptable[:path].matches(pattern)
.or(ptable[:name].matches(pattern))
.or(ptable[:description].matches(pattern))
)
# We explicitly remove any eager loading clauses as they're:
......@@ -361,10 +361,10 @@ class Project < ActiveRecord::Base
# 2. Combined with .joins(:namespace) lead to all columns from the
# projects & namespaces tables being selected, leading to a SQL error
# due to the columns of all UNION'd queries no longer being the same.
namespaces = select(:id).
except(:includes).
joins(:namespace).
where(ntable[:name].matches(pattern))
namespaces = select(:id)
.except(:includes)
.joins(:namespace)
.where(ntable[:name].matches(pattern))
union = Gitlab::SQL::Union.new([projects, namespaces])
......@@ -406,8 +406,8 @@ class Project < ActiveRecord::Base
end
def trending
joins('INNER JOIN trending_projects ON projects.id = trending_projects.project_id').
reorder('trending_projects.id ASC')
joins('INNER JOIN trending_projects ON projects.id = trending_projects.project_id')
.reorder('trending_projects.id ASC')
end
def cached_count
......
......@@ -109,9 +109,9 @@ class KubernetesService < DeploymentService
def terminals(environment)
with_reactive_cache do |data|
pods = data.fetch(:pods, nil)
filter_pods(pods, app: environment.slug).
flat_map { |pod| terminals_for_pod(api_url, namespace, pod) }.
each { |terminal| add_terminal_auth(terminal, terminal_auth) }
filter_pods(pods, app: environment.slug)
.flat_map { |pod| terminals_for_pod(api_url, namespace, pod) }
.each { |terminal| add_terminal_auth(terminal, terminal_auth) }
end
end
......
......@@ -20,8 +20,8 @@ class MattermostSlashCommandsService < ChatSlashCommandsService
end
def configure(user, params)
token = Mattermost::Command.new(user).
create(command(params))
token = Mattermost::Command.new(user)
.create(command(params))
update(active: true, token: token) if token
rescue Mattermost::Error => e
......
......@@ -171,10 +171,10 @@ class ProjectTeam
# Lookup only the IDs we need
user_ids = user_ids - access.keys
users_access = project.project_authorizations.
where(user: user_ids).
group(:user_id).
maximum(:access_level)
users_access = project.project_authorizations
.where(user: user_ids)
.group(:user_id)
.maximum(:access_level)
access.merge!(users_access)
access
......
......@@ -256,11 +256,11 @@ class Repository
cache.fetch(:"diverging_commit_counts_#{branch.name}") do
# Rugged seems to throw a `ReferenceError` when given branch_names rather
# than SHA-1 hashes
number_commits_behind = raw_repository.
count_commits_between(branch.dereferenced_target.sha, root_ref_hash)
number_commits_behind = raw_repository
.count_commits_between(branch.dereferenced_target.sha, root_ref_hash)
number_commits_ahead = raw_repository.
count_commits_between(root_ref_hash, branch.dereferenced_target.sha)
number_commits_ahead = raw_repository
.count_commits_between(root_ref_hash, branch.dereferenced_target.sha)
{ behind: number_commits_behind, ahead: number_commits_ahead }
end
......@@ -775,8 +775,8 @@ class Repository
check_tree_entry_for_dir(branch_name, path)
if start_branch_name
start_project.repository.
check_tree_entry_for_dir(start_branch_name, path)
start_project.repository
.check_tree_entry_for_dir(start_branch_name, path)
end
commit_file(
......
......@@ -64,9 +64,9 @@ class Todo < ActiveRecord::Base
highest_priority = highest_label_priority(params).to_sql
select("#{table_name}.*, (#{highest_priority}) AS highest_priority").
order(Gitlab::Database.nulls_last_order('highest_priority', 'ASC')).
order('todos.created_at')
select("#{table_name}.*, (#{highest_priority}) AS highest_priority")
.order(Gitlab::Database.nulls_last_order('highest_priority', 'ASC'))
.order('todos.created_at')
end
end
......
......@@ -213,13 +213,13 @@ class User < ActiveRecord::Base
scope :order_oldest_sign_in, -> { reorder(Gitlab::Database.nulls_last_order('last_sign_in_at', 'ASC')) }
def self.with_two_factor
joins("LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id = users.id").
where("u2f.id IS NOT NULL OR otp_required_for_login = ?", true).distinct(arel_table[:id])
joins("LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id = users.id")
.where("u2f.id IS NOT NULL OR otp_required_for_login = ?", true).distinct(arel_table[:id])
end
def self.without_two_factor
joins("LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id = users.id").
where("u2f.id IS NULL AND otp_required_for_login = ?", false)
joins("LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id = users.id")
.where("u2f.id IS NULL AND otp_required_for_login = ?", false)
end
#
......@@ -294,9 +294,9 @@ class User < ActiveRecord::Base
pattern = "%#{query}%"
where(
table[:name].matches(pattern).
or(table[:email].matches(pattern)).
or(table[:username].matches(pattern))
table[:name].matches(pattern)
.or(table[:email].matches(pattern))
.or(table[:username].matches(pattern))
)
end
......@@ -311,10 +311,10 @@ class User < ActiveRecord::Base
matched_by_emails_user_ids = email_table.project(email_table[:user_id]).where(email_table[:email].matches(pattern))
where(
table[:name].matches(pattern).
or(table[:email].matches(pattern)).
or(table[:username].matches(pattern)).
or(table[:id].in(matched_by_emails_user_ids))
table[:name].matches(pattern)
.or(table[:email].matches(pattern))
.or(table[:username].matches(pattern))
.or(table[:id].in(matched_by_emails_user_ids))
)
end
......@@ -472,8 +472,8 @@ class User < ActiveRecord::Base
# Returns the groups a user has access to
def authorized_groups
union = Gitlab::SQL::Union.
new([groups.select(:id), authorized_projects.select(:namespace_id)])
union = Gitlab::SQL::Union
.new([groups.select(:id), authorized_projects.select(:namespace_id)])
Group.where("namespaces.id IN (#{union.to_sql})")
end
......@@ -483,8 +483,8 @@ class User < ActiveRecord::Base
end
def nested_projects
Project.joins(:namespace).where('namespaces.parent_id IS NOT NULL').
member_descendants(id)
Project.joins(:namespace).where('namespaces.parent_id IS NOT NULL')
.member_descendants(id)
end
def refresh_authorized_projects
......@@ -604,8 +604,8 @@ class User < ActiveRecord::Base
next unless project
if project.repository.branch_exists?(event.branch_name)
merge_requests = MergeRequest.where("created_at >= ?", event.created_at).
where(source_project_id: project.id,
merge_requests = MergeRequest.where("created_at >= ?", event.created_at)
.where(source_project_id: project.id,
source_branch: event.branch_name)
merge_requests.empty?
end
......@@ -822,8 +822,8 @@ class User < ActiveRecord::Base
def toggle_star(project)
UsersStarProject.transaction do
user_star_project = users_star_projects.
where(project: project, user: self).lock(true).first
user_star_project = users_star_projects
.where(project: project, user: self).lock(true).first
if user_star_project
user_star_project.destroy
......@@ -859,11 +859,11 @@ class User < ActiveRecord::Base
# ms on a database with a similar size to GitLab.com's database. On the other
# hand, using a subquery means we can get the exact same data in about 40 ms.
def contributed_projects
events = Event.select(:project_id).
contributions.where(author_id: self).
where("created_at > ?", Time.now - 1.year).
uniq.
reorder(nil)
events = Event.select(:project_id)
.contributions.where(author_id: self)
.where("created_at > ?", Time.now - 1.year)
.uniq
.reorder(nil)
Project.where(id: events)
end
......@@ -874,9 +874,9 @@ class User < ActiveRecord::Base
def ci_authorized_runners
@ci_authorized_runners ||= begin
runner_ids = Ci::RunnerProject.
where("ci_runner_projects.gl_project_id IN (#{ci_projects_union.to_sql})").
select(:runner_id)
runner_ids = Ci::RunnerProject
.where("ci_runner_projects.gl_project_id IN (#{ci_projects_union.to_sql})")
.select(:runner_id)
Ci::Runner.specific.where(id: runner_ids)
end
end
......
......@@ -22,16 +22,16 @@ class WikiPage
def self.group_by_directory(pages)
return [] if pages.blank?
pages.sort_by { |page| [page.directory, page.slug] }.
group_by(&:directory).
map do |dir, pages|
pages.sort_by { |page| [page.directory, page.slug] }
.group_by(&:directory)
.map do |dir, pages|
if dir.present?
WikiDirectory.new(dir, pages)
else
pages
end
end.
flatten
end
.flatten
end
def self.unhyphenize(name)
......
......@@ -4,9 +4,9 @@ class BaseSerializer
end
def represent(resource, opts = {})
self.class.entity_class.
represent(resource, opts.merge(request: @request)).
as_json
self.class.entity_class
.represent(resource, opts.merge(request: @request))
.as_json
end
def self.entity(entity_class)
......
......@@ -36,9 +36,9 @@ class EnvironmentSerializer < BaseSerializer
private
def itemize(resource)
items = resource.order('folder_name ASC').
group('COALESCE(environment_type, name)').
select('COALESCE(environment_type, name) AS folder_name',
items = resource.order('folder_name ASC')
.group('COALESCE(environment_type, name)')
.select('COALESCE(environment_type, name) AS folder_name',
'COUNT(*) AS size', 'MAX(id) AS last_id')
# It makes a difference when you call `paginate` method, because
......
......@@ -14,8 +14,8 @@ class AfterBranchDeleteService < BaseService
private
def stop_environments
Ci::StopEnvironmentsService.
new(project, current_user).
execute(branch_name)
Ci::StopEnvironmentsService
.new(project, current_user)
.execute(branch_name)
end
end
......@@ -57,15 +57,15 @@ module Boards
return issues unless board_label_ids.any?
issues.where.not(
LabelLink.where("label_links.target_type = 'Issue' AND label_links.target_id = issues.id").
where(label_id: board_label_ids).limit(1).arel.exists
LabelLink.where("label_links.target_type = 'Issue' AND label_links.target_id = issues.id")
.where(label_id: board_label_ids).limit(1).arel.exists
)
end
def with_list_label(issues)
issues.where(
LabelLink.where("label_links.target_type = 'Issue' AND label_links.target_id = issues.id").
where("label_links.label_id = ?", list.label_id).limit(1).arel.exists
LabelLink.where("label_links.target_type = 'Issue' AND label_links.target_id = issues.id")
.where("label_links.label_id = ?", list.label_id).limit(1).arel.exists
)
end
end
......
......@@ -17,8 +17,8 @@ module Boards
attr_reader :board
def decrement_higher_lists(list)
board.lists.movable.where('position > ?', list.position).
update_all('position = position - 1')
board.lists.movable.where('position > ?', list.position)
.update_all('position = position - 1')
end
def remove_list(list)
......
......@@ -33,15 +33,15 @@ module Boards
end
def decrement_intermediate_lists
board.lists.movable.where('position > ?', old_position).
where('position <= ?', new_position).
update_all('position = position - 1')
board.lists.movable.where('position > ?', old_position)
.where('position <= ?', new_position)
.update_all('position = position - 1')
end
def increment_intermediate_lists
board.lists.movable.where('position >= ?', new_position).
where('position < ?', old_position).
update_all('position = position + 1')
board.lists.movable.where('position >= ?', new_position)
.where('position < ?', old_position)
.update_all('position = position + 1')
end
def update_list_position(list)
......
......@@ -36,8 +36,8 @@ module Ci
end
def new_builds
@new_builds ||= pipeline.config_builds_attributes.
reject { |build| existing_build_names.include?(build[:name]) }
@new_builds ||= pipeline.config_builds_attributes
.reject { |build| existing_build_names.include?(build[:name]) }
end
def existing_build_names
......
......@@ -52,9 +52,9 @@ module Ci
Ci::Pipeline.transaction do
pipeline.save
Ci::CreatePipelineBuildsService.
new(project, current_user).
execute(pipeline)
Ci::CreatePipelineBuildsService
.new(project, current_user)
.execute(pipeline)
end
pipeline.tap(&:process!)
......
......@@ -3,8 +3,8 @@ module Ci
def execute(project, trigger, ref, variables = nil)
trigger_request = trigger.trigger_requests.create(variables: variables)
pipeline = Ci::CreatePipelineService.new(project, nil, ref: ref).
execute(ignore_skip_ci: true, trigger_request: trigger_request)
pipeline = Ci::CreatePipelineService.new(project, nil, ref: ref)
.execute(ignore_skip_ci: true, trigger_request: trigger_request)
if pipeline.persisted?
trigger_request
end
......
......@@ -78,9 +78,9 @@ module Ci
def ensure_created_builds!
return if created_builds.any?
Ci::CreatePipelineBuildsService.
new(project, current_user).
execute(pipeline)
Ci::CreatePipelineBuildsService
.new(project, current_user)
.execute(pipeline)
end
end
end
......@@ -43,15 +43,15 @@ module Ci
def builds_for_shared_runner
new_builds.
# don't run projects which have not enabled shared runners and builds
joins(:project).where(projects: { shared_runners_enabled: true }).
joins('LEFT JOIN project_features ON ci_builds.gl_project_id = project_features.project_id').
where('project_features.builds_access_level IS NULL or project_features.builds_access_level > 0').
joins(:project).where(projects: { shared_runners_enabled: true })
.joins('LEFT JOIN project_features ON ci_builds.gl_project_id = project_features.project_id')
.where('project_features.builds_access_level IS NULL or project_features.builds_access_level > 0').
# Implement fair scheduling
# this returns builds that are ordered by number of running builds
# we prefer projects that don't use shared runners at all
joins("LEFT JOIN (#{running_builds_for_shared_runners.to_sql}) AS project_builds ON ci_builds.gl_project_id=project_builds.gl_project_id").
order('COALESCE(project_builds.running_builds, 0) ASC', 'ci_builds.id ASC')
joins("LEFT JOIN (#{running_builds_for_shared_runners.to_sql}) AS project_builds ON ci_builds.gl_project_id=project_builds.gl_project_id")
.order('COALESCE(project_builds.running_builds, 0) ASC', 'ci_builds.id ASC')
end
def builds_for_specific_runner
......@@ -59,8 +59,8 @@ module Ci
end
def running_builds_for_shared_runners
Ci::Build.running.where(runner: Ci::Runner.shared).
group(:gl_project_id).select(:gl_project_id, 'count(*) AS running_builds')
Ci::Build.running.where(runner: Ci::Runner.shared)
.group(:gl_project_id).select(:gl_project_id, 'count(*) AS running_builds')
end
def new_builds
......
......@@ -2,8 +2,8 @@ module Ci
class RetryBuildService < ::BaseService
CLONE_ATTRIBUTES = %i[pipeline ref tag options commands tag_list name
allow_failure stage stage_idx trigger_request
yaml_variables when environment coverage_regex].
freeze
yaml_variables when environment coverage_regex]
.freeze
REJECT_ATTRIBUTES = %i[id status user token coverage trace runner
artifacts_file artifacts_metadata artifacts_size
......@@ -19,9 +19,9 @@ module Ci
new_build.enqueue!
MergeRequests::AddTodoWhenBuildFailsService.
new(project, current_user).
close(new_build)
MergeRequests::AddTodoWhenBuildFailsService
.new(project, current_user)
.close(new_build)
end
end
......
......@@ -8,13 +8,13 @@ module Ci
pipeline.builds.failed_or_canceled.find_each do |build|
next unless build.retryable?
Ci::RetryBuildService.new(project, current_user).
reprocess(build)
Ci::RetryBuildService.new(project, current_user)
.reprocess(build)
end
MergeRequests::AddTodoWhenBuildFailsService.
new(project, current_user).
close_all(pipeline)
MergeRequests::AddTodoWhenBuildFailsService
.new(project, current_user)
.close_all(pipeline)
pipeline.process!
end
......
......@@ -70,8 +70,8 @@ module Commits
# Temporary branch exists and contains the change commit
return if repository.find_branch(new_branch)
result = ValidateNewBranchService.new(@project, current_user).
execute(new_branch)
result = ValidateNewBranchService.new(@project, current_user)
.execute(new_branch)
if result[:status] == :error
raise ChangeError, "There was an error creating the source branch: #{result[:message]}"
......
class CreateBranchService < BaseService
def execute(branch_name, ref)
result = ValidateNewBranchService.new(project, current_user).
execute(branch_name)
result = ValidateNewBranchService.new(project, current_user)
.execute(branch_name)
return result if result[:status] == :error
......
......@@ -76,8 +76,8 @@ module Files
end
def validate_target_branch
result = ValidateNewBranchService.new(project, current_user).
execute(@target_branch)
result = ValidateNewBranchService.new(project, current_user)
.execute(@target_branch)
if result[:status] == :error
raise_error("Something went wrong when we tried to create #{@target_branch} for you: #{result[:message]}")
......
......@@ -24,8 +24,8 @@ module Files
end
def last_commit
@last_commit ||= Gitlab::Git::Commit.
last_for_path(@start_project.repository, @start_branch, @file_path)
@last_commit ||= Gitlab::Git::Commit
.last_for_path(@start_project.repository, @start_branch, @file_path)
end
end
end
......@@ -89,8 +89,8 @@ class GitPushService < BaseService
default = is_default_branch?
push_commits.last(PROCESS_COMMIT_LIMIT).each do |commit|
ProcessCommitWorker.
perform_async(project.id, current_user.id, commit.to_hash, default)
ProcessCommitWorker
.perform_async(project.id, current_user.id, commit.to_hash, default)
end
end
......@@ -100,8 +100,8 @@ class GitPushService < BaseService
# Update merge requests that may be affected by this push. A new branch
# could cause the last commit of a merge request to change.
#
UpdateMergeRequestsWorker.
perform_async(@project.id, current_user.id, params[:oldrev], params[:newrev], params[:ref])
UpdateMergeRequestsWorker
.perform_async(@project.id, current_user.id, params[:oldrev], params[:newrev], params[:ref])
mirror_update = @project.mirror? && @project.repository.up_to_date_with_upstream?(branch_name)
......@@ -111,9 +111,9 @@ class GitPushService < BaseService
Ci::CreatePipelineService.new(@project, current_user, build_push_data).execute(mirror_update: mirror_update)
if push_remove_branch?
AfterBranchDeleteService.
new(project, current_user).
execute(branch_name)
AfterBranchDeleteService
.new(project, current_user)
.execute(branch_name)
end
end
......
......@@ -144,8 +144,8 @@ class IssuableBaseService < BaseService
def merge_slash_commands_into_params!(issuable)
description, command_params =
SlashCommands::InterpretService.new(project, current_user).
execute(params[:description], issuable)
SlashCommands::InterpretService.new(project, current_user)
.execute(params[:description], issuable)
# Avoid a description already set on an issuable to be overwritten by a nil
params[:description] = description if params.has_key?(:description)
......
......@@ -36,8 +36,8 @@ module Issues
def resolve_discussions_in_merge_request(issue)
Discussions::ResolveService.new(project, current_user,
merge_request: merge_request_for_resolving_discussions,
follow_up_issue: issue).
execute(merge_request_for_resolving_discussions.resolvable_discussions)
follow_up_issue: issue)
.execute(merge_request_for_resolving_discussions.resolvable_discussions)
end
private
......
......@@ -61,8 +61,8 @@ module Issues
end
def cloneable_milestone_id
@new_project.milestones.
find_by(title: @old_issue.milestone.try(:title)).try(:id)
@new_project.milestones
.find_by(title: @old_issue.milestone.try(:title)).try(:id)
end
def rewrite_notes
......
......@@ -26,29 +26,29 @@ module Labels
private
def label_ids_for_merge(new_label)
LabelsFinder.
new(current_user, title: new_label.title, group_id: project.group.id).
execute(skip_authorization: true).
where.not(id: new_label).
select(:id) # Can't use pluck() to avoid object-creation because of the batching
LabelsFinder
.new(current_user, title: new_label.title, group_id: project.group.id)
.execute(skip_authorization: true)
.where.not(id: new_label)
.select(:id) # Can't use pluck() to avoid object-creation because of the batching
end
def update_issuables(new_label, label_ids)
LabelLink.
where(label: label_ids).
update_all(label_id: new_label)
LabelLink
.where(label: label_ids)
.update_all(label_id: new_label)
end
def update_issue_board_lists(new_label, label_ids)
List.
where(label: label_ids).
update_all(label_id: new_label)
List
.where(label: label_ids)
.update_all(label_id: new_label)
end
def update_priorities(new_label, label_ids)
LabelPriority.
where(label: label_ids).
update_all(label_id: new_label)
LabelPriority
.where(label: label_ids)
.update_all(label_id: new_label)
end
def update_project_labels(label_ids)
......
......@@ -41,16 +41,16 @@ module Labels
end
def group_labels_applied_to_issues
Label.joins(:issues).
where(
Label.joins(:issues)
.where(
issues: { project_id: project.id },
labels: { type: 'GroupLabel', group_id: old_group.id }
)
end
def group_labels_applied_to_merge_requests
Label.joins(:merge_requests).
where(
Label.joins(:merge_requests)
.where(
merge_requests: { target_project_id: project.id },
labels: { type: 'GroupLabel', group_id: old_group.id }
)
......@@ -64,15 +64,15 @@ module Labels
end
def update_label_links(labels, old_label_id:, new_label_id:)
LabelLink.joins(:label).
merge(labels).
where(label_id: old_label_id).
update_all(label_id: new_label_id)
LabelLink.joins(:label)
.merge(labels)
.where(label_id: old_label_id)
.update_all(label_id: new_label_id)
end
def update_label_priorities(old_label_id:, new_label_id:)
LabelPriority.where(project_id: project.id, label_id: old_label_id).
update_all(label_id: new_label_id)
LabelPriority.where(project_id: project.id, label_id: old_label_id)
.update_all(label_id: new_label_id)
end
end
end
......@@ -40,11 +40,11 @@ module MergeRequests
# Returns all origin and fork merge requests from `@project` satisfying passed arguments.
def merge_requests_for(source_branch, mr_states: [:opened])
MergeRequest.
with_state(mr_states).
where(source_branch: source_branch, source_project_id: @project.id).
preload(:source_project). # we don't need a #includes since we're just preloading for the #select
select(&:source_project)
MergeRequest
.with_state(mr_states)
.where(source_branch: source_branch, source_project_id: @project.id)
.preload(:source_project) # we don't need a #includes since we're just preloading for the #select
.select(&:source_project)
end
def pipeline_merge_requests(pipeline)
......
......@@ -95,8 +95,8 @@ module MergeRequests
MergeRequests::PostMergeService.new(project, current_user).execute(merge_request)
if params[:should_remove_source_branch].present? || @merge_request.force_remove_source_branch?
DeleteBranchService.new(@merge_request.source_project, branch_deletion_user).
execute(merge_request.source_branch)
DeleteBranchService.new(@merge_request.source_project, branch_deletion_user)
.execute(merge_request.source_branch)
end
end
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment