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

Revert "Prefer leading style for Style/DotPosition"

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