Enable Style/DotPosition Rubocop 👮
This commit is contained in:
parent
78ee24ba53
commit
0430b76441
|
|
@ -164,6 +164,11 @@ Style/DefWithParentheses:
|
|||
Style/Documentation:
|
||||
Enabled: false
|
||||
|
||||
# Multi-line method chaining should be done with leading dots.
|
||||
Style/DotPosition:
|
||||
Enabled: true
|
||||
EnforcedStyle: leading
|
||||
|
||||
# This cop checks for uses of double negation (!!) to convert something
|
||||
# to a boolean value. As this is both cryptic and usually redundant, it
|
||||
# should be avoided.
|
||||
|
|
|
|||
|
|
@ -88,13 +88,6 @@ Security/YAMLLoad:
|
|||
Style/BarePercentLiterals:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 1403
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||
# SupportedStyles: leading, trailing
|
||||
Style/DotPosition:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 5
|
||||
# Cop supports --auto-correct.
|
||||
Style/EachWithObject:
|
||||
|
|
|
|||
|
|
@ -97,8 +97,8 @@ module CreatesCommit
|
|||
def merge_request_exists?
|
||||
return @merge_request if defined?(@merge_request)
|
||||
|
||||
@merge_request = MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened.
|
||||
find_by(source_project_id: @project_to_commit_into, source_branch: @branch_name, target_branch: @start_branch)
|
||||
@merge_request = MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened
|
||||
.find_by(source_project_id: @project_to_commit_into, source_branch: @branch_name, target_branch: @start_branch)
|
||||
end
|
||||
|
||||
def different_project?
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ module MembershipActions
|
|||
end
|
||||
|
||||
def destroy
|
||||
Members::DestroyService.new(membershipable, current_user, params).
|
||||
execute(:all)
|
||||
Members::DestroyService.new(membershipable, current_user, params)
|
||||
.execute(:all)
|
||||
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
|
|
@ -42,8 +42,8 @@ module MembershipActions
|
|||
end
|
||||
|
||||
def leave
|
||||
member = Members::DestroyService.new(membershipable, current_user, user_id: current_user.id).
|
||||
execute(:all)
|
||||
member = Members::DestroyService.new(membershipable, current_user, user_id: current_user.id)
|
||||
.execute(:all)
|
||||
|
||||
notice =
|
||||
if member.request?
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
|
|||
end
|
||||
|
||||
def starred
|
||||
@projects = load_projects(params.merge(starred: true)).
|
||||
includes(:forked_from_project, :tags).page(params[:page])
|
||||
@projects = load_projects(params.merge(starred: true))
|
||||
.includes(:forked_from_project, :tags).page(params[:page])
|
||||
|
||||
@groups = []
|
||||
|
||||
|
|
@ -45,8 +45,8 @@ class Dashboard::ProjectsController < Dashboard::ApplicationController
|
|||
end
|
||||
|
||||
def load_projects(finder_params)
|
||||
ProjectsFinder.new(params: finder_params, current_user: current_user).
|
||||
execute.includes(:route, namespace: :route)
|
||||
ProjectsFinder.new(params: finder_params, current_user: current_user)
|
||||
.execute.includes(:route, namespace: :route)
|
||||
end
|
||||
|
||||
def load_events
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class Explore::ProjectsController < Explore::ApplicationController
|
|||
private
|
||||
|
||||
def load_projects
|
||||
ProjectsFinder.new(current_user: current_user, params: params).
|
||||
execute.includes(:route, namespace: :route)
|
||||
ProjectsFinder.new(current_user: current_user, params: params)
|
||||
.execute.includes(:route, namespace: :route)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ class JwtController < ApplicationController
|
|||
service = SERVICES[params[:service]]
|
||||
return head :not_found unless service
|
||||
|
||||
result = service.new(@authentication_result.project, @authentication_result.actor, auth_params).
|
||||
execute(authentication_abilities: @authentication_result.authentication_abilities)
|
||||
result = service.new(@authentication_result.project, @authentication_result.actor, auth_params)
|
||||
.execute(authentication_abilities: @authentication_result.authentication_abilities)
|
||||
|
||||
render json: result, status: result[:http_status]
|
||||
end
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
|||
end
|
||||
|
||||
def log_audit_event(user, options = {})
|
||||
AuditEventService.new(user, user, options).
|
||||
for_authentication.security_event
|
||||
AuditEventService.new(user, user, options)
|
||||
.for_authentication.security_event
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -49,9 +49,9 @@ class ProfilesController < Profiles::ApplicationController
|
|||
end
|
||||
|
||||
def audit_log
|
||||
@events = AuditEvent.where(entity_type: "User", entity_id: current_user.id).
|
||||
order("created_at DESC").
|
||||
page(params[:page])
|
||||
@events = AuditEvent.where(entity_type: "User", entity_id: current_user.id)
|
||||
.order("created_at DESC")
|
||||
.page(params[:page])
|
||||
end
|
||||
|
||||
def update_username
|
||||
|
|
|
|||
|
|
@ -187,7 +187,7 @@ class Projects::BlobController < Projects::ApplicationController
|
|||
end
|
||||
|
||||
def set_last_commit_sha
|
||||
@last_commit_sha = Gitlab::Git::Commit.
|
||||
last_for_path(@repository, @ref, @path).sha
|
||||
@last_commit_sha = Gitlab::Git::Commit
|
||||
.last_for_path(@repository, @ref, @path).sha
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@ class Projects::BranchesController < Projects::ApplicationController
|
|||
|
||||
redirect_to_autodeploy = project.empty_repo? && project.deployment_services.present?
|
||||
|
||||
result = CreateBranchService.new(project, current_user).
|
||||
execute(branch_name, ref)
|
||||
result = CreateBranchService.new(project, current_user)
|
||||
.execute(branch_name, ref)
|
||||
|
||||
if params[:issue_iid]
|
||||
issue = IssuesFinder.new(current_user, project_id: @project.id).find_by(iid: params[:issue_iid])
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@ class Projects::CommitsController < Projects::ApplicationController
|
|||
@repository.commits(@ref, path: @path, limit: @limit, offset: @offset)
|
||||
end
|
||||
|
||||
@note_counts = project.notes.where(commit_id: @commits.map(&:id)).
|
||||
group(:commit_id).count
|
||||
@note_counts = project.notes.where(commit_id: @commits.map(&:id))
|
||||
.group(:commit_id).count
|
||||
|
||||
@merge_request = MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened.
|
||||
find_by(source_project: @project, source_branch: @ref, target_branch: @repository.root_ref)
|
||||
@merge_request = MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened
|
||||
.find_by(source_project: @project, source_branch: @ref, target_branch: @repository.root_ref)
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ class Projects::CompareController < Projects::ApplicationController
|
|||
end
|
||||
|
||||
def merge_request
|
||||
@merge_request ||= MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened.
|
||||
find_by(source_project: @project, source_branch: @head_ref, target_branch: @start_ref)
|
||||
@merge_request ||= MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened
|
||||
.find_by(source_project: @project, source_branch: @head_ref, target_branch: @start_ref)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -143,8 +143,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController
|
|||
# Get commits from repository
|
||||
# or from cache if already merged
|
||||
@commits = @merge_request.commits
|
||||
@note_counts = Note.where(commit_id: @commits.map(&:id)).
|
||||
group(:commit_id).count
|
||||
@note_counts = Note.where(commit_id: @commits.map(&:id))
|
||||
.group(:commit_id).count
|
||||
|
||||
render json: { html: view_to_html_string('projects/merge_requests/show/_commits') }
|
||||
end
|
||||
|
|
@ -192,9 +192,9 @@ class Projects::MergeRequestsController < Projects::ApplicationController
|
|||
end
|
||||
|
||||
begin
|
||||
MergeRequests::Conflicts::ResolveService.
|
||||
new(merge_request).
|
||||
execute(current_user, params)
|
||||
MergeRequests::Conflicts::ResolveService
|
||||
.new(merge_request)
|
||||
.execute(current_user, params)
|
||||
|
||||
flash[:notice] = 'All merge conflicts were resolved. The merge request can now be merged.'
|
||||
|
||||
|
|
@ -562,8 +562,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController
|
|||
@commits = @merge_request.compare_commits.reverse
|
||||
@commit = @merge_request.diff_head_commit
|
||||
|
||||
@note_counts = Note.where(commit_id: @commits.map(&:id)).
|
||||
group(:commit_id).count
|
||||
@note_counts = Note.where(commit_id: @commits.map(&:id))
|
||||
.group(:commit_id).count
|
||||
|
||||
@labels = LabelsFinder.new(current_user, project_id: @project.id).execute
|
||||
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ module Projects
|
|||
|
||||
def define_runners_variables
|
||||
@project_runners = @project.runners.ordered
|
||||
@assignable_runners = current_user.ci_authorized_runners.
|
||||
assignable_for(project).ordered.page(params[:page]).per(20)
|
||||
@assignable_runners = current_user.ci_authorized_runners
|
||||
.assignable_for(project).ordered.page(params[:page]).per(20)
|
||||
@shared_runners = Ci::Runner.shared.active
|
||||
@shared_runners_count = @shared_runners.count(:all)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -29,8 +29,8 @@ class Projects::TagsController < Projects::ApplicationController
|
|||
end
|
||||
|
||||
def create
|
||||
result = Tags::CreateService.new(@project, current_user).
|
||||
execute(params[:tag_name], params[:ref], params[:message], params[:release_description])
|
||||
result = Tags::CreateService.new(@project, current_user)
|
||||
.execute(params[:tag_name], params[:ref], params[:message], params[:release_description])
|
||||
|
||||
if result[:status] == :success
|
||||
@tag = result[:tag]
|
||||
|
|
|
|||
|
|
@ -128,8 +128,8 @@ class SessionsController < Devise::SessionsController
|
|||
end
|
||||
|
||||
def log_audit_event(user, options = {})
|
||||
AuditEventService.new(user, user, options).
|
||||
for_authentication.security_event
|
||||
AuditEventService.new(user, user, options)
|
||||
.for_authentication.security_event
|
||||
end
|
||||
|
||||
def log_user_activity(user)
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ module Sherlock
|
|||
|
||||
def find_transaction
|
||||
if params[:transaction_id]
|
||||
@transaction = Gitlab::Sherlock.collection.
|
||||
find_transaction(params[:transaction_id])
|
||||
@transaction = Gitlab::Sherlock.collection
|
||||
.find_transaction(params[:transaction_id])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -106,11 +106,11 @@ class UsersController < ApplicationController
|
|||
|
||||
def load_events
|
||||
# Get user activity feed for projects common for both users
|
||||
@events = user.recent_events.
|
||||
merge(projects_for_current_user).
|
||||
references(:project).
|
||||
with_associations.
|
||||
limit_recent(20, params[:offset])
|
||||
@events = user.recent_events
|
||||
.merge(projects_for_current_user)
|
||||
.references(:project)
|
||||
.with_associations
|
||||
.limit_recent(20, params[:offset])
|
||||
end
|
||||
|
||||
def load_projects
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ class EventsFinder
|
|||
private
|
||||
|
||||
def by_current_user_access(events)
|
||||
events.merge(ProjectsFinder.new(current_user: current_user).execute).
|
||||
joins(:project)
|
||||
events.merge(ProjectsFinder.new(current_user: current_user).execute)
|
||||
.joins(:project)
|
||||
end
|
||||
|
||||
def by_action(events)
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ class GroupMembersFinder
|
|||
|
||||
return group_members unless @group.parent
|
||||
|
||||
parents_members = GroupMember.non_request.
|
||||
where(source_id: @group.ancestors.select(:id)).
|
||||
where.not(user_id: @group.users.select(:id))
|
||||
parents_members = GroupMember.non_request
|
||||
.where(source_id: @group.ancestors.select(:id))
|
||||
.where.not(user_id: @group.users.select(:id))
|
||||
|
||||
wheres = ["members.id IN (#{group_members.select(:id).to_sql})"]
|
||||
wheres << "members.id IN (#{parents_members.select(:id).to_sql})"
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@ module FormHelper
|
|||
content_tag(:div, class: 'alert alert-danger', id: 'error_explanation') do
|
||||
content_tag(:h4, headline) <<
|
||||
content_tag(:ul) do
|
||||
model.errors.full_messages.
|
||||
map { |msg| content_tag(:li, msg) }.
|
||||
join.
|
||||
html_safe
|
||||
model.errors.full_messages
|
||||
.map { |msg| content_tag(:li, msg) }
|
||||
.join
|
||||
.html_safe
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -194,8 +194,8 @@ module ProjectsHelper
|
|||
end
|
||||
|
||||
def load_pipeline_status(projects)
|
||||
Gitlab::Cache::Ci::ProjectPipelineStatus.
|
||||
load_in_batch_for_projects(projects)
|
||||
Gitlab::Cache::Ci::ProjectPipelineStatus
|
||||
.load_in_batch_for_projects(projects)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -97,8 +97,8 @@ module SearchHelper
|
|||
|
||||
# Autocomplete results for the current user's projects
|
||||
def projects_autocomplete(term, limit = 5)
|
||||
current_user.authorized_projects.search_by_title(term).
|
||||
sorted_by_stars.non_archived.limit(limit).map do |p|
|
||||
current_user.authorized_projects.search_by_title(term)
|
||||
.sorted_by_stars.non_archived.limit(limit).map do |p|
|
||||
{
|
||||
category: "Projects",
|
||||
id: p.id,
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ module WikiHelper
|
|||
# Returns a String composed of the capitalized name of each directory and the
|
||||
# capitalized name of the page itself.
|
||||
def breadcrumb(page_slug)
|
||||
page_slug.split('/').
|
||||
map { |dir_or_page| WikiPage.unhyphenize(dir_or_page).capitalize }.
|
||||
join(' / ')
|
||||
page_slug.split('/')
|
||||
.map { |dir_or_page| WikiPage.unhyphenize(dir_or_page).capitalize }
|
||||
.join(' / ')
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ class AwardEmoji < ActiveRecord::Base
|
|||
|
||||
class << self
|
||||
def votes_for_collection(ids, type)
|
||||
select('name', 'awardable_id', 'COUNT(*) as count').
|
||||
where('name IN (?) AND awardable_type = ? AND awardable_id IN (?)', [DOWNVOTE_NAME, UPVOTE_NAME], type, ids).
|
||||
group('name', 'awardable_id')
|
||||
select('name', 'awardable_id', 'COUNT(*) as count')
|
||||
.where('name IN (?) AND awardable_type = ? AND awardable_id IN (?)', [DOWNVOTE_NAME, UPVOTE_NAME], type, ids)
|
||||
.group('name', 'awardable_id')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -168,8 +168,8 @@ module Ci
|
|||
end
|
||||
|
||||
def stages_names
|
||||
statuses.order(:stage_idx).distinct.
|
||||
pluck(:stage, :stage_idx).map(&:first)
|
||||
statuses.order(:stage_idx).distinct
|
||||
.pluck(:stage, :stage_idx).map(&:first)
|
||||
end
|
||||
|
||||
def legacy_stage(name)
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ module Ci
|
|||
scope :assignable_for, ->(project) do
|
||||
# FIXME: That `to_sql` is needed to workaround a weird Rails bug.
|
||||
# Without that, placeholders would miss one and couldn't match.
|
||||
where(locked: false).
|
||||
where.not("id IN (#{project.runners.select(:id).to_sql})").specific
|
||||
where(locked: false)
|
||||
.where.not("id IN (#{project.runners.select(:id).to_sql})").specific
|
||||
end
|
||||
|
||||
validate :tag_constraints
|
||||
|
|
|
|||
|
|
@ -161,9 +161,9 @@ module Issuable
|
|||
#
|
||||
milestones_due_date = 'MIN(milestones.due_date)'
|
||||
|
||||
order_milestone_due_asc.
|
||||
order_labels_priority(excluded_labels: excluded_labels, extra_select_columns: [milestones_due_date]).
|
||||
reorder(Gitlab::Database.nulls_last_order(milestones_due_date, 'ASC'),
|
||||
order_milestone_due_asc
|
||||
.order_labels_priority(excluded_labels: excluded_labels, extra_select_columns: [milestones_due_date])
|
||||
.reorder(Gitlab::Database.nulls_last_order(milestones_due_date, 'ASC'),
|
||||
Gitlab::Database.nulls_last_order('highest_priority', 'ASC'))
|
||||
end
|
||||
|
||||
|
|
@ -182,9 +182,9 @@ module Issuable
|
|||
"(#{highest_priority}) AS highest_priority"
|
||||
] + extra_select_columns
|
||||
|
||||
select(select_columns.join(', ')).
|
||||
group(arel_table[:id]).
|
||||
reorder(Gitlab::Database.nulls_last_order('highest_priority', 'ASC'))
|
||||
select(select_columns.join(', '))
|
||||
.group(arel_table[:id])
|
||||
.reorder(Gitlab::Database.nulls_last_order('highest_priority', 'ASC'))
|
||||
end
|
||||
|
||||
def with_label(title, sort = nil)
|
||||
|
|
|
|||
|
|
@ -18,10 +18,10 @@ module RelativePositioning
|
|||
prev_pos = nil
|
||||
|
||||
if self.relative_position
|
||||
prev_pos = self.class.
|
||||
in_projects(project.id).
|
||||
where('relative_position < ?', self.relative_position).
|
||||
maximum(:relative_position)
|
||||
prev_pos = self.class
|
||||
.in_projects(project.id)
|
||||
.where('relative_position < ?', self.relative_position)
|
||||
.maximum(:relative_position)
|
||||
end
|
||||
|
||||
prev_pos
|
||||
|
|
@ -31,10 +31,10 @@ module RelativePositioning
|
|||
next_pos = nil
|
||||
|
||||
if self.relative_position
|
||||
next_pos = self.class.
|
||||
in_projects(project.id).
|
||||
where('relative_position > ?', self.relative_position).
|
||||
minimum(:relative_position)
|
||||
next_pos = self.class
|
||||
.in_projects(project.id)
|
||||
.where('relative_position > ?', self.relative_position)
|
||||
.minimum(:relative_position)
|
||||
end
|
||||
|
||||
next_pos
|
||||
|
|
|
|||
|
|
@ -39,12 +39,12 @@ module Sortable
|
|||
private
|
||||
|
||||
def highest_label_priority(target_type_column: nil, target_type: nil, target_column:, project_column:, excluded_labels: [])
|
||||
query = Label.select(LabelPriority.arel_table[:priority].minimum).
|
||||
left_join_priorities.
|
||||
joins(:label_links).
|
||||
where("label_priorities.project_id = #{project_column}").
|
||||
where("label_links.target_id = #{target_column}").
|
||||
reorder(nil)
|
||||
query = Label.select(LabelPriority.arel_table[:priority].minimum)
|
||||
.left_join_priorities
|
||||
.joins(:label_links)
|
||||
.where("label_priorities.project_id = #{project_column}")
|
||||
.where("label_links.target_id = #{target_column}")
|
||||
.reorder(nil)
|
||||
|
||||
query =
|
||||
if target_type_column
|
||||
|
|
|
|||
|
|
@ -27,16 +27,16 @@ module Subscribable
|
|||
end
|
||||
|
||||
def subscribers(project)
|
||||
subscriptions_available(project).
|
||||
where(subscribed: true).
|
||||
map(&:user)
|
||||
subscriptions_available(project)
|
||||
.where(subscribed: true)
|
||||
.map(&:user)
|
||||
end
|
||||
|
||||
def toggle_subscription(user, project = nil)
|
||||
unsubscribe_from_other_levels(user, project)
|
||||
|
||||
find_or_initialize_subscription(user, project).
|
||||
update(subscribed: !subscribed?(user, project))
|
||||
find_or_initialize_subscription(user, project)
|
||||
.update(subscribed: !subscribed?(user, project))
|
||||
end
|
||||
|
||||
def subscribe(user, project = nil)
|
||||
|
|
@ -69,14 +69,14 @@ module Subscribable
|
|||
end
|
||||
|
||||
def find_or_initialize_subscription(user, project)
|
||||
subscriptions.
|
||||
find_or_initialize_by(user_id: user.id, project_id: project.try(:id))
|
||||
subscriptions
|
||||
.find_or_initialize_by(user_id: user.id, project_id: project.try(:id))
|
||||
end
|
||||
|
||||
def subscriptions_available(project)
|
||||
t = Subscription.arel_table
|
||||
|
||||
subscriptions.
|
||||
where(t[:project_id].eq(nil).or(t[:project_id].eq(project.try(:id))))
|
||||
subscriptions
|
||||
.where(t[:project_id].eq(nil).or(t[:project_id].eq(project.try(:id))))
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -58,10 +58,10 @@ class Deployment < ActiveRecord::Base
|
|||
def update_merge_request_metrics!
|
||||
return unless environment.update_merge_request_metrics?
|
||||
|
||||
merge_requests = project.merge_requests.
|
||||
joins(:metrics).
|
||||
where(target_branch: self.ref, merge_request_metrics: { first_deployed_to_production_at: nil }).
|
||||
where("merge_request_metrics.merged_at <= ?", self.created_at)
|
||||
merge_requests = project.merge_requests
|
||||
.joins(:metrics)
|
||||
.where(target_branch: self.ref, merge_request_metrics: { first_deployed_to_production_at: nil })
|
||||
.where("merge_request_metrics.merged_at <= ?", self.created_at)
|
||||
|
||||
if previous_deployment
|
||||
merge_requests = merge_requests.where("merge_request_metrics.merged_at >= ?", previous_deployment.created_at)
|
||||
|
|
@ -76,17 +76,17 @@ class Deployment < ActiveRecord::Base
|
|||
merge_requests.map(&:id)
|
||||
end
|
||||
|
||||
MergeRequest::Metrics.
|
||||
where(merge_request_id: merge_request_ids, first_deployed_to_production_at: nil).
|
||||
update_all(first_deployed_to_production_at: self.created_at)
|
||||
MergeRequest::Metrics
|
||||
.where(merge_request_id: merge_request_ids, first_deployed_to_production_at: nil)
|
||||
.update_all(first_deployed_to_production_at: self.created_at)
|
||||
end
|
||||
|
||||
def previous_deployment
|
||||
@previous_deployment ||=
|
||||
project.deployments.joins(:environment).
|
||||
where(environments: { name: self.environment.name }, ref: self.ref).
|
||||
where.not(id: self.id).
|
||||
take
|
||||
project.deployments.joins(:environment)
|
||||
.where(environments: { name: self.environment.name }, ref: self.ref)
|
||||
.where.not(id: self.id)
|
||||
.take
|
||||
end
|
||||
|
||||
def stop_action
|
||||
|
|
|
|||
|
|
@ -40,9 +40,9 @@ class Environment < ActiveRecord::Base
|
|||
scope :stopped, -> { with_state(:stopped) }
|
||||
scope :order_by_last_deployed_at, -> do
|
||||
max_deployment_id_sql =
|
||||
Deployment.select(Deployment.arel_table[:id].maximum).
|
||||
where(Deployment.arel_table[:environment_id].eq(arel_table[:id])).
|
||||
to_sql
|
||||
Deployment.select(Deployment.arel_table[:id].maximum)
|
||||
.where(Deployment.arel_table[:environment_id].eq(arel_table[:id]))
|
||||
.to_sql
|
||||
order(Gitlab::Database.nulls_first_order("(#{max_deployment_id_sql})", 'ASC'))
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -376,9 +376,9 @@ class Event < ActiveRecord::Base
|
|||
# At this point it's possible for multiple threads/processes to try to
|
||||
# update the project. Only one query should actually perform the update,
|
||||
# hence we add the extra WHERE clause for last_activity_at.
|
||||
Project.unscoped.where(id: project_id).
|
||||
where('last_activity_at <= ?', RESET_PROJECT_ACTIVITY_INTERVAL.ago).
|
||||
update_all(last_activity_at: created_at)
|
||||
Project.unscoped.where(id: project_id)
|
||||
.where('last_activity_at <= ?', RESET_PROJECT_ACTIVITY_INTERVAL.ago)
|
||||
.update_all(last_activity_at: created_at)
|
||||
end
|
||||
|
||||
def authored_by?(user)
|
||||
|
|
@ -392,7 +392,7 @@ class Event < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def set_last_repository_updated_at
|
||||
Project.unscoped.where(id: project_id).
|
||||
update_all(last_repository_updated_at: created_at)
|
||||
Project.unscoped.where(id: project_id)
|
||||
.update_all(last_repository_updated_at: created_at)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -206,8 +206,8 @@ class Group < Namespace
|
|||
end
|
||||
|
||||
def refresh_members_authorized_projects
|
||||
UserProjectAccessChangedService.new(user_ids_for_project_authorizations).
|
||||
execute
|
||||
UserProjectAccessChangedService.new(user_ids_for_project_authorizations)
|
||||
.execute
|
||||
end
|
||||
|
||||
def user_ids_for_project_authorizations
|
||||
|
|
@ -225,10 +225,10 @@ class Group < Namespace
|
|||
def max_member_access_for_user(user)
|
||||
return GroupMember::OWNER if user.admin?
|
||||
|
||||
members_with_parents.
|
||||
where(user_id: user).
|
||||
reorder(access_level: :desc).
|
||||
first&.
|
||||
members_with_parents
|
||||
.where(user_id: user)
|
||||
.reorder(access_level: :desc)
|
||||
.first&.
|
||||
access_level || GroupMember::NO_ACCESS
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -124,8 +124,8 @@ class Issue < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.order_by_position_and_priority
|
||||
order_labels_priority.
|
||||
reorder(Gitlab::Database.nulls_last_order('relative_position', 'ASC'),
|
||||
order_labels_priority
|
||||
.reorder(Gitlab::Database.nulls_last_order('relative_position', 'ASC'),
|
||||
Gitlab::Database.nulls_last_order('highest_priority', 'ASC'),
|
||||
"id DESC")
|
||||
end
|
||||
|
|
|
|||
|
|
@ -17,9 +17,9 @@ class IssueCollection
|
|||
|
||||
# Given all the issue projects we get a list of projects that the current
|
||||
# user has at least reporter access to.
|
||||
projects_with_reporter_access = user.
|
||||
projects_with_reporter_access_limited_to(project_ids).
|
||||
pluck(:id)
|
||||
projects_with_reporter_access = user
|
||||
.projects_with_reporter_access_limited_to(project_ids)
|
||||
.pluck(:id)
|
||||
|
||||
collection.select do |issue|
|
||||
if projects_with_reporter_access.include?(issue.project_id)
|
||||
|
|
|
|||
|
|
@ -46,9 +46,9 @@ class Label < ActiveRecord::Base
|
|||
labels = Label.arel_table
|
||||
priorities = LabelPriority.arel_table
|
||||
|
||||
label_priorities = labels.join(priorities, Arel::Nodes::OuterJoin).
|
||||
on(labels[:id].eq(priorities[:label_id]).and(priorities[:project_id].eq(project.id))).
|
||||
join_sources
|
||||
label_priorities = labels.join(priorities, Arel::Nodes::OuterJoin)
|
||||
.on(labels[:id].eq(priorities[:label_id]).and(priorities[:project_id].eq(project.id)))
|
||||
.join_sources
|
||||
|
||||
joins(label_priorities).where(priorities[:priority].eq(nil))
|
||||
end
|
||||
|
|
@ -57,9 +57,9 @@ class Label < ActiveRecord::Base
|
|||
labels = Label.arel_table
|
||||
priorities = LabelPriority.arel_table
|
||||
|
||||
label_priorities = labels.join(priorities, Arel::Nodes::OuterJoin).
|
||||
on(labels[:id].eq(priorities[:label_id])).
|
||||
join_sources
|
||||
label_priorities = labels.join(priorities, Arel::Nodes::OuterJoin)
|
||||
.on(labels[:id].eq(priorities[:label_id]))
|
||||
.join_sources
|
||||
|
||||
joins(label_priorities)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -99,9 +99,9 @@ class Member < ActiveRecord::Base
|
|||
users = User.arel_table
|
||||
members = Member.arel_table
|
||||
|
||||
member_users = members.join(users, Arel::Nodes::OuterJoin).
|
||||
on(members[:user_id].eq(users[:id])).
|
||||
join_sources
|
||||
member_users = members.join(users, Arel::Nodes::OuterJoin)
|
||||
.on(members[:user_id].eq(users[:id]))
|
||||
.join_sources
|
||||
|
||||
joins(member_users)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -577,8 +577,8 @@ class MergeRequest < ActiveRecord::Base
|
|||
messages = [title, description]
|
||||
messages.concat(commits.map(&:safe_message)) if merge_request_diff
|
||||
|
||||
Gitlab::ClosingIssueExtractor.new(project, current_user).
|
||||
closed_by_message(messages.join("\n"))
|
||||
Gitlab::ClosingIssueExtractor.new(project, current_user)
|
||||
.closed_by_message(messages.join("\n"))
|
||||
else
|
||||
[]
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ class MergeRequestsClosingIssues < ActiveRecord::Base
|
|||
|
||||
class << self
|
||||
def count_for_collection(ids)
|
||||
group(:issue_id).
|
||||
where(issue_id: ids).
|
||||
pluck('issue_id', 'COUNT(*) as count')
|
||||
group(:issue_id)
|
||||
.where(issue_id: ids)
|
||||
.pluck('issue_id', 'COUNT(*) as count')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -98,11 +98,11 @@ class Milestone < ActiveRecord::Base
|
|||
if Gitlab::Database.postgresql?
|
||||
rel.order(:project_id, :due_date).select('DISTINCT ON (project_id) id')
|
||||
else
|
||||
rel.
|
||||
group(:project_id).
|
||||
having('due_date = MIN(due_date)').
|
||||
pluck(:id, :project_id, :due_date).
|
||||
map(&:first)
|
||||
rel
|
||||
.group(:project_id)
|
||||
.having('due_date = MIN(due_date)')
|
||||
.pluck(:id, :project_id, :due_date)
|
||||
.map(&:first)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -181,16 +181,16 @@ class Namespace < ActiveRecord::Base
|
|||
def ancestors
|
||||
return self.class.none unless parent_id
|
||||
|
||||
Gitlab::GroupHierarchy.
|
||||
new(self.class.where(id: parent_id)).
|
||||
base_and_ancestors
|
||||
Gitlab::GroupHierarchy
|
||||
.new(self.class.where(id: parent_id))
|
||||
.base_and_ancestors
|
||||
end
|
||||
|
||||
# Returns all the descendants of the current namespace.
|
||||
def descendants
|
||||
Gitlab::GroupHierarchy.
|
||||
new(self.class.where(parent_id: id)).
|
||||
base_and_descendants
|
||||
Gitlab::GroupHierarchy
|
||||
.new(self.class.where(parent_id: id))
|
||||
.base_and_descendants
|
||||
end
|
||||
|
||||
def user_ids_for_project_authorizations
|
||||
|
|
@ -253,10 +253,10 @@ class Namespace < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def refresh_access_of_projects_invited_groups
|
||||
Group.
|
||||
joins(project_group_links: :project).
|
||||
where(projects: { namespace_id: id }).
|
||||
find_each(&:refresh_members_authorized_projects)
|
||||
Group
|
||||
.joins(project_group_links: :project)
|
||||
.where(projects: { namespace_id: id })
|
||||
.find_each(&:refresh_members_authorized_projects)
|
||||
end
|
||||
|
||||
def remove_exports!
|
||||
|
|
|
|||
|
|
@ -137,9 +137,9 @@ class Note < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def count_for_collection(ids, type)
|
||||
user.select('noteable_id', 'COUNT(*) as count').
|
||||
group(:noteable_id).
|
||||
where(noteable_type: type, noteable_id: ids)
|
||||
user.select('noteable_id', 'COUNT(*) as count')
|
||||
.group(:noteable_id)
|
||||
.where(noteable_type: type, noteable_id: ids)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -244,8 +244,8 @@ class Project < ActiveRecord::Base
|
|||
scope :inside_path, ->(path) do
|
||||
# We need routes alias rs for JOIN so it does not conflict with
|
||||
# includes(:route) which we use in ProjectsFinder.
|
||||
joins("INNER JOIN routes rs ON rs.source_id = projects.id AND rs.source_type = 'Project'").
|
||||
where('rs.path LIKE ?', "#{sanitize_sql_like(path)}/%")
|
||||
joins("INNER JOIN routes rs ON rs.source_id = projects.id AND rs.source_type = 'Project'")
|
||||
.where('rs.path LIKE ?', "#{sanitize_sql_like(path)}/%")
|
||||
end
|
||||
|
||||
# "enabled" here means "not disabled". It includes private features!
|
||||
|
|
@ -270,10 +270,10 @@ class Project < ActiveRecord::Base
|
|||
# logged in user.
|
||||
def self.public_or_visible_to_user(user = nil)
|
||||
if user
|
||||
authorized = user.
|
||||
project_authorizations.
|
||||
select(1).
|
||||
where('project_authorizations.project_id = projects.id')
|
||||
authorized = user
|
||||
.project_authorizations
|
||||
.select(1)
|
||||
.where('project_authorizations.project_id = projects.id')
|
||||
|
||||
levels = Gitlab::VisibilityLevel.levels_for_user(user)
|
||||
|
||||
|
|
@ -298,11 +298,11 @@ class Project < ActiveRecord::Base
|
|||
elsif user
|
||||
column = ProjectFeature.quoted_access_level_column(feature)
|
||||
|
||||
authorized = user.project_authorizations.select(1).
|
||||
where('project_authorizations.project_id = projects.id')
|
||||
authorized = user.project_authorizations.select(1)
|
||||
.where('project_authorizations.project_id = projects.id')
|
||||
|
||||
with_project_feature.
|
||||
where("#{column} IN (?) OR (#{column} = ? AND EXISTS (?))",
|
||||
with_project_feature
|
||||
.where("#{column} IN (?) OR (#{column} = ? AND EXISTS (?))",
|
||||
visible,
|
||||
ProjectFeature::PRIVATE,
|
||||
authorized)
|
||||
|
|
@ -369,14 +369,14 @@ class Project < ActiveRecord::Base
|
|||
# unscoping unnecessary conditions that'll be applied
|
||||
# when executing `where("projects.id IN (#{union.to_sql})")`
|
||||
projects = unscoped.select(:id).where(
|
||||
ptable[:path].matches(pattern).
|
||||
or(ptable[:name].matches(pattern)).
|
||||
or(ptable[:description].matches(pattern))
|
||||
ptable[:path].matches(pattern)
|
||||
.or(ptable[:name].matches(pattern))
|
||||
.or(ptable[:description].matches(pattern))
|
||||
)
|
||||
|
||||
namespaces = unscoped.select(:id).
|
||||
joins(:namespace).
|
||||
where(ntable[:name].matches(pattern))
|
||||
namespaces = unscoped.select(:id)
|
||||
.joins(:namespace)
|
||||
.where(ntable[:name].matches(pattern))
|
||||
|
||||
union = Gitlab::SQL::Union.new([projects, namespaces])
|
||||
|
||||
|
|
@ -417,8 +417,8 @@ class Project < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def trending
|
||||
joins('INNER JOIN trending_projects ON projects.id = trending_projects.project_id').
|
||||
reorder('trending_projects.id ASC')
|
||||
joins('INNER JOIN trending_projects ON projects.id = trending_projects.project_id')
|
||||
.reorder('trending_projects.id ASC')
|
||||
end
|
||||
|
||||
def cached_count
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ class ProjectAuthorization < ActiveRecord::Base
|
|||
validates :user, uniqueness: { scope: [:project, :access_level] }, presence: true
|
||||
|
||||
def self.select_from_union(union)
|
||||
select(['project_id', 'MAX(access_level) AS access_level']).
|
||||
from("(#{union.to_sql}) #{ProjectAuthorization.table_name}").
|
||||
group(:project_id)
|
||||
select(['project_id', 'MAX(access_level) AS access_level'])
|
||||
.from("(#{union.to_sql}) #{ProjectAuthorization.table_name}")
|
||||
.group(:project_id)
|
||||
end
|
||||
|
||||
def self.insert_authorizations(rows, per_batch = 1000)
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ class MattermostSlashCommandsService < SlashCommandsService
|
|||
end
|
||||
|
||||
def configure(user, params)
|
||||
token = Mattermost::Command.new(user).
|
||||
create(command(params))
|
||||
token = Mattermost::Command.new(user)
|
||||
.create(command(params))
|
||||
|
||||
update(active: true, token: token) if token
|
||||
rescue Mattermost::Error => e
|
||||
|
|
|
|||
|
|
@ -172,10 +172,10 @@ class ProjectTeam
|
|||
|
||||
return access if user_ids.empty?
|
||||
|
||||
users_access = project.project_authorizations.
|
||||
where(user: user_ids).
|
||||
group(:user_id).
|
||||
maximum(:access_level)
|
||||
users_access = project.project_authorizations
|
||||
.where(user: user_ids)
|
||||
.group(:user_id)
|
||||
.maximum(:access_level)
|
||||
|
||||
access.merge!(users_access)
|
||||
|
||||
|
|
|
|||
|
|
@ -241,11 +241,11 @@ class Repository
|
|||
cache.fetch(:"diverging_commit_counts_#{branch.name}") do
|
||||
# Rugged seems to throw a `ReferenceError` when given branch_names rather
|
||||
# than SHA-1 hashes
|
||||
number_commits_behind = raw_repository.
|
||||
count_commits_between(branch.dereferenced_target.sha, root_ref_hash)
|
||||
number_commits_behind = raw_repository
|
||||
.count_commits_between(branch.dereferenced_target.sha, root_ref_hash)
|
||||
|
||||
number_commits_ahead = raw_repository.
|
||||
count_commits_between(root_ref_hash, branch.dereferenced_target.sha)
|
||||
number_commits_ahead = raw_repository
|
||||
.count_commits_between(root_ref_hash, branch.dereferenced_target.sha)
|
||||
|
||||
{ behind: number_commits_behind, ahead: number_commits_ahead }
|
||||
end
|
||||
|
|
|
|||
|
|
@ -70,9 +70,9 @@ class Todo < ActiveRecord::Base
|
|||
|
||||
highest_priority = highest_label_priority(params).to_sql
|
||||
|
||||
select("#{table_name}.*, (#{highest_priority}) AS highest_priority").
|
||||
order(Gitlab::Database.nulls_last_order('highest_priority', 'ASC')).
|
||||
order('todos.created_at')
|
||||
select("#{table_name}.*, (#{highest_priority}) AS highest_priority")
|
||||
.order(Gitlab::Database.nulls_last_order('highest_priority', 'ASC'))
|
||||
.order('todos.created_at')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -223,13 +223,13 @@ class User < ActiveRecord::Base
|
|||
scope :order_oldest_sign_in, -> { reorder(Gitlab::Database.nulls_last_order('last_sign_in_at', 'ASC')) }
|
||||
|
||||
def self.with_two_factor
|
||||
joins("LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id = users.id").
|
||||
where("u2f.id IS NOT NULL OR otp_required_for_login = ?", true).distinct(arel_table[:id])
|
||||
joins("LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id = users.id")
|
||||
.where("u2f.id IS NOT NULL OR otp_required_for_login = ?", true).distinct(arel_table[:id])
|
||||
end
|
||||
|
||||
def self.without_two_factor
|
||||
joins("LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id = users.id").
|
||||
where("u2f.id IS NULL AND otp_required_for_login = ?", false)
|
||||
joins("LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id = users.id")
|
||||
.where("u2f.id IS NULL AND otp_required_for_login = ?", false)
|
||||
end
|
||||
|
||||
#
|
||||
|
|
@ -300,9 +300,9 @@ class User < ActiveRecord::Base
|
|||
pattern = "%#{query}%"
|
||||
|
||||
where(
|
||||
table[:name].matches(pattern).
|
||||
or(table[:email].matches(pattern)).
|
||||
or(table[:username].matches(pattern))
|
||||
table[:name].matches(pattern)
|
||||
.or(table[:email].matches(pattern))
|
||||
.or(table[:username].matches(pattern))
|
||||
)
|
||||
end
|
||||
|
||||
|
|
@ -317,10 +317,10 @@ class User < ActiveRecord::Base
|
|||
matched_by_emails_user_ids = email_table.project(email_table[:user_id]).where(email_table[:email].matches(pattern))
|
||||
|
||||
where(
|
||||
table[:name].matches(pattern).
|
||||
or(table[:email].matches(pattern)).
|
||||
or(table[:username].matches(pattern)).
|
||||
or(table[:id].in(matched_by_emails_user_ids))
|
||||
table[:name].matches(pattern)
|
||||
.or(table[:email].matches(pattern))
|
||||
.or(table[:username].matches(pattern))
|
||||
.or(table[:id].in(matched_by_emails_user_ids))
|
||||
)
|
||||
end
|
||||
|
||||
|
|
@ -503,8 +503,8 @@ class User < ActiveRecord::Base
|
|||
|
||||
# Returns the groups a user has access to
|
||||
def authorized_groups
|
||||
union = Gitlab::SQL::Union.
|
||||
new([groups.select(:id), authorized_projects.select(:namespace_id)])
|
||||
union = Gitlab::SQL::Union
|
||||
.new([groups.select(:id), authorized_projects.select(:namespace_id)])
|
||||
|
||||
Group.where("namespaces.id IN (#{union.to_sql})")
|
||||
end
|
||||
|
|
@ -533,8 +533,8 @@ class User < ActiveRecord::Base
|
|||
projects = super()
|
||||
|
||||
if min_access_level
|
||||
projects = projects.
|
||||
where('project_authorizations.access_level >= ?', min_access_level)
|
||||
projects = projects
|
||||
.where('project_authorizations.access_level >= ?', min_access_level)
|
||||
end
|
||||
|
||||
projects
|
||||
|
|
@ -619,9 +619,9 @@ class User < ActiveRecord::Base
|
|||
next unless project
|
||||
|
||||
if project.repository.branch_exists?(event.branch_name)
|
||||
merge_requests = MergeRequest.where("created_at >= ?", event.created_at).
|
||||
where(source_project_id: project.id,
|
||||
source_branch: event.branch_name)
|
||||
merge_requests = MergeRequest.where("created_at >= ?", event.created_at)
|
||||
.where(source_project_id: project.id,
|
||||
source_branch: event.branch_name)
|
||||
merge_requests.empty?
|
||||
end
|
||||
end
|
||||
|
|
@ -832,8 +832,8 @@ class User < ActiveRecord::Base
|
|||
|
||||
def toggle_star(project)
|
||||
UsersStarProject.transaction do
|
||||
user_star_project = users_star_projects.
|
||||
where(project: project, user: self).lock(true).first
|
||||
user_star_project = users_star_projects
|
||||
.where(project: project, user: self).lock(true).first
|
||||
|
||||
if user_star_project
|
||||
user_star_project.destroy
|
||||
|
|
@ -869,11 +869,11 @@ class User < ActiveRecord::Base
|
|||
# ms on a database with a similar size to GitLab.com's database. On the other
|
||||
# hand, using a subquery means we can get the exact same data in about 40 ms.
|
||||
def contributed_projects
|
||||
events = Event.select(:project_id).
|
||||
contributions.where(author_id: self).
|
||||
where("created_at > ?", Time.now - 1.year).
|
||||
uniq.
|
||||
reorder(nil)
|
||||
events = Event.select(:project_id)
|
||||
.contributions.where(author_id: self)
|
||||
.where("created_at > ?", Time.now - 1.year)
|
||||
.uniq
|
||||
.reorder(nil)
|
||||
|
||||
Project.where(id: events)
|
||||
end
|
||||
|
|
@ -884,9 +884,9 @@ class User < ActiveRecord::Base
|
|||
|
||||
def ci_authorized_runners
|
||||
@ci_authorized_runners ||= begin
|
||||
runner_ids = Ci::RunnerProject.
|
||||
where("ci_runner_projects.project_id IN (#{ci_projects_union.to_sql})").
|
||||
select(:runner_id)
|
||||
runner_ids = Ci::RunnerProject
|
||||
.where("ci_runner_projects.project_id IN (#{ci_projects_union.to_sql})")
|
||||
.select(:runner_id)
|
||||
Ci::Runner.specific.where(id: runner_ids)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -22,16 +22,16 @@ class WikiPage
|
|||
def self.group_by_directory(pages)
|
||||
return [] if pages.blank?
|
||||
|
||||
pages.sort_by { |page| [page.directory, page.slug] }.
|
||||
group_by(&:directory).
|
||||
map do |dir, pages|
|
||||
pages.sort_by { |page| [page.directory, page.slug] }
|
||||
.group_by(&:directory)
|
||||
.map do |dir, pages|
|
||||
if dir.present?
|
||||
WikiDirectory.new(dir, pages)
|
||||
else
|
||||
pages
|
||||
end
|
||||
end.
|
||||
flatten
|
||||
end
|
||||
.flatten
|
||||
end
|
||||
|
||||
def self.unhyphenize(name)
|
||||
|
|
|
|||
|
|
@ -67,8 +67,8 @@ module Ci
|
|||
def update_merge_requests_head_pipeline
|
||||
return unless pipeline.latest?
|
||||
|
||||
MergeRequest.where(source_project: @pipeline.project, source_branch: @pipeline.ref).
|
||||
update_all(head_pipeline_id: @pipeline.id)
|
||||
MergeRequest.where(source_project: @pipeline.project, source_branch: @pipeline.ref)
|
||||
.update_all(head_pipeline_id: @pipeline.id)
|
||||
end
|
||||
|
||||
def skip_ci?
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ module Ci
|
|||
def execute(project, trigger, ref, variables = nil)
|
||||
trigger_request = trigger.trigger_requests.create(variables: variables)
|
||||
|
||||
pipeline = Ci::CreatePipelineService.new(project, trigger.owner, ref: ref).
|
||||
execute(:trigger, ignore_skip_ci: true, trigger_request: trigger_request)
|
||||
pipeline = Ci::CreatePipelineService.new(project, trigger.owner, ref: ref)
|
||||
.execute(:trigger, ignore_skip_ci: true, trigger_request: trigger_request)
|
||||
|
||||
trigger_request if pipeline.persisted?
|
||||
end
|
||||
|
|
|
|||
|
|
@ -54,15 +54,15 @@ module Ci
|
|||
def builds_for_shared_runner
|
||||
new_builds.
|
||||
# don't run projects which have not enabled shared runners and builds
|
||||
joins(:project).where(projects: { shared_runners_enabled: true }).
|
||||
joins('LEFT JOIN project_features ON ci_builds.project_id = project_features.project_id').
|
||||
where('project_features.builds_access_level IS NULL or project_features.builds_access_level > 0').
|
||||
joins(:project).where(projects: { shared_runners_enabled: true })
|
||||
.joins('LEFT JOIN project_features ON ci_builds.project_id = project_features.project_id')
|
||||
.where('project_features.builds_access_level IS NULL or project_features.builds_access_level > 0').
|
||||
|
||||
# Implement fair scheduling
|
||||
# this returns builds that are ordered by number of running builds
|
||||
# we prefer projects that don't use shared runners at all
|
||||
joins("LEFT JOIN (#{running_builds_for_shared_runners.to_sql}) AS project_builds ON ci_builds.project_id=project_builds.project_id").
|
||||
order('COALESCE(project_builds.running_builds, 0) ASC', 'ci_builds.id ASC')
|
||||
joins("LEFT JOIN (#{running_builds_for_shared_runners.to_sql}) AS project_builds ON ci_builds.project_id=project_builds.project_id")
|
||||
.order('COALESCE(project_builds.running_builds, 0) ASC', 'ci_builds.id ASC')
|
||||
end
|
||||
|
||||
def builds_for_specific_runner
|
||||
|
|
@ -70,8 +70,8 @@ module Ci
|
|||
end
|
||||
|
||||
def running_builds_for_shared_runners
|
||||
Ci::Build.running.where(runner: Ci::Runner.shared).
|
||||
group(:project_id).select(:project_id, 'count(*) AS running_builds')
|
||||
Ci::Build.running.where(runner: Ci::Runner.shared)
|
||||
.group(:project_id).select(:project_id, 'count(*) AS running_builds')
|
||||
end
|
||||
|
||||
def new_builds
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@ module Issues
|
|||
def merge_request_to_resolve_discussions_of
|
||||
return @merge_request_to_resolve_discussions_of if defined?(@merge_request_to_resolve_discussions_of)
|
||||
|
||||
@merge_request_to_resolve_discussions_of = MergeRequestsFinder.new(current_user, project_id: project.id).
|
||||
execute.
|
||||
find_by(iid: merge_request_to_resolve_discussions_of_iid)
|
||||
@merge_request_to_resolve_discussions_of = MergeRequestsFinder.new(current_user, project_id: project.id)
|
||||
.execute
|
||||
.find_by(iid: merge_request_to_resolve_discussions_of_iid)
|
||||
end
|
||||
|
||||
def discussions_to_resolve
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ module Files
|
|||
end
|
||||
|
||||
def last_commit
|
||||
@last_commit ||= Gitlab::Git::Commit.
|
||||
last_for_path(@start_project.repository, @start_branch, @file_path)
|
||||
@last_commit ||= Gitlab::Git::Commit
|
||||
.last_for_path(@start_project.repository, @start_branch, @file_path)
|
||||
end
|
||||
|
||||
def validate!
|
||||
|
|
|
|||
|
|
@ -86,8 +86,8 @@ class GitPushService < BaseService
|
|||
|
||||
push_commits.last(PROCESS_COMMIT_LIMIT).each do |commit|
|
||||
if commit.matches_cross_reference_regex?
|
||||
ProcessCommitWorker.
|
||||
perform_async(project.id, current_user.id, commit.to_hash, default)
|
||||
ProcessCommitWorker
|
||||
.perform_async(project.id, current_user.id, commit.to_hash, default)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -144,8 +144,8 @@ class IssuableBaseService < BaseService
|
|||
|
||||
def merge_quick_actions_into_params!(issuable)
|
||||
description, command_params =
|
||||
QuickActions::InterpretService.new(project, current_user).
|
||||
execute(params[:description], issuable)
|
||||
QuickActions::InterpretService.new(project, current_user)
|
||||
.execute(params[:description], issuable)
|
||||
|
||||
# Avoid a description already set on an issuable to be overwritten by a nil
|
||||
params[:description] = description if params.key?(:description)
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ module Issues
|
|||
|
||||
Discussions::ResolveService.new(project, current_user,
|
||||
merge_request: merge_request_to_resolve_discussions_of,
|
||||
follow_up_issue: issue).
|
||||
execute(discussions_to_resolve)
|
||||
follow_up_issue: issue)
|
||||
.execute(discussions_to_resolve)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -26,29 +26,29 @@ module Labels
|
|||
private
|
||||
|
||||
def label_ids_for_merge(new_label)
|
||||
LabelsFinder.
|
||||
new(current_user, title: new_label.title, group_id: project.group.id).
|
||||
execute(skip_authorization: true).
|
||||
where.not(id: new_label).
|
||||
select(:id) # Can't use pluck() to avoid object-creation because of the batching
|
||||
LabelsFinder
|
||||
.new(current_user, title: new_label.title, group_id: project.group.id)
|
||||
.execute(skip_authorization: true)
|
||||
.where.not(id: new_label)
|
||||
.select(:id) # Can't use pluck() to avoid object-creation because of the batching
|
||||
end
|
||||
|
||||
def update_issuables(new_label, label_ids)
|
||||
LabelLink.
|
||||
where(label: label_ids).
|
||||
update_all(label_id: new_label)
|
||||
LabelLink
|
||||
.where(label: label_ids)
|
||||
.update_all(label_id: new_label)
|
||||
end
|
||||
|
||||
def update_issue_board_lists(new_label, label_ids)
|
||||
List.
|
||||
where(label: label_ids).
|
||||
update_all(label_id: new_label)
|
||||
List
|
||||
.where(label: label_ids)
|
||||
.update_all(label_id: new_label)
|
||||
end
|
||||
|
||||
def update_priorities(new_label, label_ids)
|
||||
LabelPriority.
|
||||
where(label: label_ids).
|
||||
update_all(label_id: new_label)
|
||||
LabelPriority
|
||||
.where(label: label_ids)
|
||||
.update_all(label_id: new_label)
|
||||
end
|
||||
|
||||
def update_project_labels(label_ids)
|
||||
|
|
|
|||
|
|
@ -41,16 +41,16 @@ module Labels
|
|||
end
|
||||
|
||||
def group_labels_applied_to_issues
|
||||
Label.joins(:issues).
|
||||
where(
|
||||
Label.joins(:issues)
|
||||
.where(
|
||||
issues: { project_id: project.id },
|
||||
labels: { type: 'GroupLabel', group_id: old_group.id }
|
||||
)
|
||||
end
|
||||
|
||||
def group_labels_applied_to_merge_requests
|
||||
Label.joins(:merge_requests).
|
||||
where(
|
||||
Label.joins(:merge_requests)
|
||||
.where(
|
||||
merge_requests: { target_project_id: project.id },
|
||||
labels: { type: 'GroupLabel', group_id: old_group.id }
|
||||
)
|
||||
|
|
@ -64,15 +64,15 @@ module Labels
|
|||
end
|
||||
|
||||
def update_label_links(labels, old_label_id:, new_label_id:)
|
||||
LabelLink.joins(:label).
|
||||
merge(labels).
|
||||
where(label_id: old_label_id).
|
||||
update_all(label_id: new_label_id)
|
||||
LabelLink.joins(:label)
|
||||
.merge(labels)
|
||||
.where(label_id: old_label_id)
|
||||
.update_all(label_id: new_label_id)
|
||||
end
|
||||
|
||||
def update_label_priorities(old_label_id:, new_label_id:)
|
||||
LabelPriority.where(project_id: project.id, label_id: old_label_id).
|
||||
update_all(label_id: new_label_id)
|
||||
LabelPriority.where(project_id: project.id, label_id: old_label_id)
|
||||
.update_all(label_id: new_label_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -26,30 +26,30 @@ module Members
|
|||
|
||||
def unassign_issues_and_merge_requests(member)
|
||||
if member.is_a?(GroupMember)
|
||||
issues = Issue.unscoped.select(1).
|
||||
joins(:project).
|
||||
where('issues.id = issue_assignees.issue_id AND projects.namespace_id = ?', member.source_id)
|
||||
issues = Issue.unscoped.select(1)
|
||||
.joins(:project)
|
||||
.where('issues.id = issue_assignees.issue_id AND projects.namespace_id = ?', member.source_id)
|
||||
|
||||
# DELETE FROM issue_assignees WHERE user_id = X AND EXISTS (...)
|
||||
IssueAssignee.unscoped.
|
||||
where('user_id = :user_id AND EXISTS (:sub)', user_id: member.user_id, sub: issues).
|
||||
delete_all
|
||||
IssueAssignee.unscoped
|
||||
.where('user_id = :user_id AND EXISTS (:sub)', user_id: member.user_id, sub: issues)
|
||||
.delete_all
|
||||
|
||||
MergeRequestsFinder.new(user, group_id: member.source_id, assignee_id: member.user_id).
|
||||
execute.
|
||||
update_all(assignee_id: nil)
|
||||
MergeRequestsFinder.new(user, group_id: member.source_id, assignee_id: member.user_id)
|
||||
.execute
|
||||
.update_all(assignee_id: nil)
|
||||
else
|
||||
project = member.source
|
||||
|
||||
# SELECT 1 FROM issues WHERE issues.id = issue_assignees.issue_id AND issues.project_id = X
|
||||
issues = Issue.unscoped.select(1).
|
||||
where('issues.id = issue_assignees.issue_id').
|
||||
where(project_id: project.id)
|
||||
issues = Issue.unscoped.select(1)
|
||||
.where('issues.id = issue_assignees.issue_id')
|
||||
.where(project_id: project.id)
|
||||
|
||||
# DELETE FROM issue_assignees WHERE user_id = X AND EXISTS (...)
|
||||
IssueAssignee.unscoped.
|
||||
where('user_id = :user_id AND EXISTS (:sub)', user_id: member.user_id, sub: issues).
|
||||
delete_all
|
||||
IssueAssignee.unscoped
|
||||
.where('user_id = :user_id AND EXISTS (:sub)', user_id: member.user_id, sub: issues)
|
||||
.delete_all
|
||||
|
||||
project.merge_requests.opened.assigned_to(member.user).update_all(assignee_id: nil)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -27,10 +27,10 @@ module MergeRequests
|
|||
tree: merge_index.write_tree(rugged)
|
||||
}
|
||||
|
||||
conflicts_for_resolution.
|
||||
project.
|
||||
repository.
|
||||
resolve_conflicts(current_user, merge_request.source_branch, commit_params)
|
||||
conflicts_for_resolution
|
||||
.project
|
||||
.repository
|
||||
.resolve_conflicts(current_user, merge_request.source_branch, commit_params)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -61,8 +61,8 @@ module MergeRequests
|
|||
MergeRequests::PostMergeService.new(project, current_user).execute(merge_request)
|
||||
|
||||
if params[:should_remove_source_branch].present? || @merge_request.force_remove_source_branch?
|
||||
DeleteBranchService.new(@merge_request.source_project, branch_deletion_user).
|
||||
execute(merge_request.source_branch)
|
||||
DeleteBranchService.new(@merge_request.source_project, branch_deletion_user)
|
||||
.execute(merge_request.source_branch)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -43,9 +43,9 @@ module MergeRequests
|
|||
end
|
||||
|
||||
filter_merge_requests(merge_requests).each do |merge_request|
|
||||
MergeRequests::PostMergeService.
|
||||
new(merge_request.target_project, @current_user).
|
||||
execute(merge_request)
|
||||
MergeRequests::PostMergeService
|
||||
.new(merge_request.target_project, @current_user)
|
||||
.execute(merge_request)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -56,8 +56,8 @@ module MergeRequests
|
|||
# Refresh merge request diff if we push to source or target branch of merge request
|
||||
# Note: we should update merge requests from forks too
|
||||
def reload_merge_requests
|
||||
merge_requests = @project.merge_requests.opened.
|
||||
by_source_or_target_branch(@branch_name).to_a
|
||||
merge_requests = @project.merge_requests.opened
|
||||
.by_source_or_target_branch(@branch_name).to_a
|
||||
|
||||
# Fork merge requests
|
||||
merge_requests += MergeRequest.opened
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ module Notes
|
|||
def extract_commands(note, options = {})
|
||||
return [note.note, {}] unless supported?(note)
|
||||
|
||||
QuickActions::InterpretService.new(project, current_user, options).
|
||||
execute(note.note, note.noteable)
|
||||
QuickActions::InterpretService.new(project, current_user, options)
|
||||
.execute(note.note, note.noteable)
|
||||
end
|
||||
|
||||
def execute(command_params, note)
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ module Tags
|
|||
|
||||
if new_tag
|
||||
if release_description
|
||||
CreateReleaseService.new(@project, @current_user).
|
||||
execute(tag_name, release_description)
|
||||
CreateReleaseService.new(@project, @current_user)
|
||||
.execute(tag_name, release_description)
|
||||
end
|
||||
|
||||
success.merge(tag: new_tag)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ class MergeWorker
|
|||
current_user = User.find(current_user_id)
|
||||
merge_request = MergeRequest.find(merge_request_id)
|
||||
|
||||
MergeRequests::MergeService.new(merge_request.target_project, current_user, params).
|
||||
execute(merge_request)
|
||||
MergeRequests::MergeService.new(merge_request.target_project, current_user, params)
|
||||
.execute(merge_request)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -47,8 +47,8 @@ class ProcessCommitWorker
|
|||
# therefor we use IssueCollection here and skip the authorization check in
|
||||
# Issues::CloseService#execute.
|
||||
IssueCollection.new(issues).updatable_by_user(user).each do |issue|
|
||||
Issues::CloseService.new(project, author).
|
||||
close_issue(issue, commit: commit)
|
||||
Issues::CloseService.new(project, author)
|
||||
.close_issue(issue, commit: commit)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -57,8 +57,8 @@ class ProcessCommitWorker
|
|||
|
||||
return if mentioned_issues.empty?
|
||||
|
||||
Issue::Metrics.where(issue_id: mentioned_issues.map(&:id), first_mentioned_in_commit_at: nil).
|
||||
update_all(first_mentioned_in_commit_at: commit.committed_date)
|
||||
Issue::Metrics.where(issue_id: mentioned_issues.map(&:id), first_mentioned_in_commit_at: nil)
|
||||
.update_all(first_mentioned_in_commit_at: commit.committed_date)
|
||||
end
|
||||
|
||||
def build_commit(project, hash)
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ class ProjectCacheWorker
|
|||
private
|
||||
|
||||
def try_obtain_lease_for(project_id, section)
|
||||
Gitlab::ExclusiveLease.
|
||||
new("project_cache_worker:#{project_id}:#{section}", timeout: LEASE_TIMEOUT).
|
||||
try_obtain
|
||||
Gitlab::ExclusiveLease
|
||||
.new("project_cache_worker:#{project_id}:#{section}", timeout: LEASE_TIMEOUT)
|
||||
.try_obtain
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ class PropagateServiceTemplateWorker
|
|||
private
|
||||
|
||||
def try_obtain_lease_for(template_id)
|
||||
Gitlab::ExclusiveLease.
|
||||
new("propagate_service_template_worker:#{template_id}", timeout: LEASE_TIMEOUT).
|
||||
try_obtain
|
||||
Gitlab::ExclusiveLease
|
||||
.new("propagate_service_template_worker:#{template_id}", timeout: LEASE_TIMEOUT)
|
||||
.try_obtain
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@ class PruneOldEventsWorker
|
|||
'(id IN (SELECT id FROM (?) ids_to_remove))',
|
||||
Event.unscoped.where(
|
||||
'created_at < ?',
|
||||
(12.months + 1.day).ago).
|
||||
select(:id).
|
||||
limit(10_000)).
|
||||
delete_all
|
||||
(12.months + 1.day).ago)
|
||||
.select(:id)
|
||||
.limit(10_000))
|
||||
.delete_all
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -32,10 +32,10 @@ module RepositoryCheck
|
|||
# has to sit and wait for this query to finish.
|
||||
def project_ids
|
||||
limit = 10_000
|
||||
never_checked_projects = Project.where('last_repository_check_at IS NULL AND created_at < ?', 24.hours.ago).
|
||||
limit(limit).pluck(:id)
|
||||
old_check_projects = Project.where('last_repository_check_at < ?', 1.month.ago).
|
||||
reorder('last_repository_check_at ASC').limit(limit).pluck(:id)
|
||||
never_checked_projects = Project.where('last_repository_check_at IS NULL AND created_at < ?', 24.hours.ago)
|
||||
.limit(limit).pluck(:id)
|
||||
old_check_projects = Project.where('last_repository_check_at < ?', 1.month.ago)
|
||||
.reorder('last_repository_check_at ASC').limit(limit).pluck(:id)
|
||||
never_checked_projects + old_check_projects
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ class UpdateUserActivityWorker
|
|||
ids = pairs.keys
|
||||
conditions = 'WHEN id = ? THEN ? ' * ids.length
|
||||
|
||||
User.where(id: ids).
|
||||
update_all([
|
||||
User.where(id: ids)
|
||||
.update_all([
|
||||
"last_activity_on = CASE #{conditions} ELSE last_activity_on END",
|
||||
*pairs.to_a.flatten
|
||||
])
|
||||
|
|
|
|||
|
|
@ -154,8 +154,8 @@ if Gitlab::Metrics.enabled?
|
|||
ActiveRecord::Querying.public_instance_methods(false).map(&:to_s)
|
||||
)
|
||||
|
||||
Gitlab::Metrics::Instrumentation.
|
||||
instrument_class_hierarchy(ActiveRecord::Base) do |klass, method|
|
||||
Gitlab::Metrics::Instrumentation
|
||||
.instrument_class_hierarchy(ActiveRecord::Base) do |klass, method|
|
||||
# Instrumenting the ApplicationSetting class can lead to an infinite
|
||||
# loop. Since the data is cached any way we don't really need to
|
||||
# instrument it.
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ class MigrateProcessCommitWorkerJobs < ActiveRecord::Migration
|
|||
|
||||
class Project < ActiveRecord::Base
|
||||
def self.find_including_path(id)
|
||||
select("projects.*, CONCAT(namespaces.path, '/', projects.path) AS path_with_namespace").
|
||||
joins('INNER JOIN namespaces ON namespaces.id = projects.namespace_id').
|
||||
find_by(id: id)
|
||||
select("projects.*, CONCAT(namespaces.path, '/', projects.path) AS path_with_namespace")
|
||||
.joins('INNER JOIN namespaces ON namespaces.id = projects.namespace_id')
|
||||
.find_by(id: id)
|
||||
end
|
||||
|
||||
def repository_storage_path
|
||||
|
|
|
|||
|
|
@ -8,11 +8,11 @@ class FixupEnvironmentNameUniqueness < ActiveRecord::Migration
|
|||
environments = Arel::Table.new(:environments)
|
||||
|
||||
# Get all [project_id, name] pairs that occur more than once
|
||||
finder_sql = environments.
|
||||
group(environments[:project_id], environments[:name]).
|
||||
having(Arel.sql("COUNT(1)").gt(1)).
|
||||
project(environments[:project_id], environments[:name]).
|
||||
to_sql
|
||||
finder_sql = environments
|
||||
.group(environments[:project_id], environments[:name])
|
||||
.having(Arel.sql("COUNT(1)").gt(1))
|
||||
.project(environments[:project_id], environments[:name])
|
||||
.to_sql
|
||||
|
||||
conflicting = connection.exec_query(finder_sql)
|
||||
|
||||
|
|
@ -28,12 +28,12 @@ class FixupEnvironmentNameUniqueness < ActiveRecord::Migration
|
|||
# Rename conflicting environments by appending "-#{id}" to all but the first
|
||||
def fix_duplicates(project_id, name)
|
||||
environments = Arel::Table.new(:environments)
|
||||
finder_sql = environments.
|
||||
where(environments[:project_id].eq(project_id)).
|
||||
where(environments[:name].eq(name)).
|
||||
order(environments[:id].asc).
|
||||
project(environments[:id], environments[:name]).
|
||||
to_sql
|
||||
finder_sql = environments
|
||||
.where(environments[:project_id].eq(project_id))
|
||||
.where(environments[:name].eq(name))
|
||||
.order(environments[:id].asc)
|
||||
.project(environments[:id], environments[:name])
|
||||
.to_sql
|
||||
|
||||
# Now we have the data for all the conflicting rows
|
||||
conflicts = connection.exec_query(finder_sql).rows
|
||||
|
|
@ -41,11 +41,11 @@ class FixupEnvironmentNameUniqueness < ActiveRecord::Migration
|
|||
|
||||
conflicts.each do |id, name|
|
||||
update_sql =
|
||||
Arel::UpdateManager.new(ActiveRecord::Base).
|
||||
table(environments).
|
||||
set(environments[:name] => name + "-" + id.to_s).
|
||||
where(environments[:id].eq(id)).
|
||||
to_sql
|
||||
Arel::UpdateManager.new(ActiveRecord::Base)
|
||||
.table(environments)
|
||||
.set(environments[:name] => name + "-" + id.to_s)
|
||||
.where(environments[:id].eq(id))
|
||||
.to_sql
|
||||
|
||||
connection.exec_update(update_sql, self.class.name, [])
|
||||
end
|
||||
|
|
|
|||
|
|
@ -19,10 +19,10 @@ class AddEnvironmentSlug < ActiveRecord::Migration
|
|||
finder = environments.project(:id, :name)
|
||||
|
||||
connection.exec_query(finder.to_sql).rows.each do |id, name|
|
||||
updater = Arel::UpdateManager.new(ActiveRecord::Base).
|
||||
table(environments).
|
||||
set(environments[:slug] => generate_slug(name)).
|
||||
where(environments[:id].eq(id))
|
||||
updater = Arel::UpdateManager.new(ActiveRecord::Base)
|
||||
.table(environments)
|
||||
.set(environments[:slug] => generate_slug(name))
|
||||
.where(environments[:id].eq(id))
|
||||
|
||||
connection.exec_update(updater.to_sql, self.class.name, [])
|
||||
end
|
||||
|
|
|
|||
|
|
@ -159,9 +159,9 @@ class RenameSystemNamespaces < ActiveRecord::Migration
|
|||
end
|
||||
|
||||
def system_namespace
|
||||
@system_namespace ||= Namespace.where(parent_id: nil).
|
||||
where(arel_table[:path].matches(system_namespace_path)).
|
||||
first
|
||||
@system_namespace ||= Namespace.where(parent_id: nil)
|
||||
.where(arel_table[:path].matches(system_namespace_path))
|
||||
.first
|
||||
end
|
||||
|
||||
def system_namespace_path
|
||||
|
|
@ -209,8 +209,8 @@ class RenameSystemNamespaces < ActiveRecord::Migration
|
|||
end
|
||||
|
||||
def repo_paths_for_namespace(namespace)
|
||||
projects_for_namespace(namespace).distinct.
|
||||
select(:repository_storage).map(&:repository_storage_path)
|
||||
projects_for_namespace(namespace).distinct
|
||||
.select(:repository_storage).map(&:repository_storage_path)
|
||||
end
|
||||
|
||||
def uploads_dir
|
||||
|
|
|
|||
|
|
@ -87,8 +87,8 @@ class TurnNestedGroupsIntoRegularGroupsForMysql < ActiveRecord::Migration
|
|||
while current&.parent_id
|
||||
# We're using find_by(id: ...) here to deal with cases where the
|
||||
# parent_id may point to a missing row.
|
||||
current = Namespace.unscoped.select([:id, :parent_id]).
|
||||
find_by(id: current.parent_id)
|
||||
current = Namespace.unscoped.select([:id, :parent_id])
|
||||
.find_by(id: current.parent_id)
|
||||
|
||||
ancestors << current.id if current
|
||||
end
|
||||
|
|
@ -99,11 +99,11 @@ class TurnNestedGroupsIntoRegularGroupsForMysql < ActiveRecord::Migration
|
|||
# Returns a relation containing all the members that have access to any of
|
||||
# the current namespace's parent namespaces.
|
||||
def all_members_for(namespace)
|
||||
Member.
|
||||
unscoped.
|
||||
select(['user_id', 'MAX(access_level) AS access_level']).
|
||||
where(source_type: 'Namespace', source_id: ancestors_for(namespace)).
|
||||
group(:user_id)
|
||||
Member
|
||||
.unscoped
|
||||
.select(['user_id', 'MAX(access_level) AS access_level'])
|
||||
.where(source_type: 'Namespace', source_id: ancestors_for(namespace))
|
||||
.group(:user_id)
|
||||
end
|
||||
|
||||
def bulk_insert_members(rows)
|
||||
|
|
|
|||
|
|
@ -13,13 +13,13 @@ class FixProjectRecordsWithInvalidVisibility < ActiveRecord::Migration
|
|||
namespaces = Arel::Table.new(:namespaces)
|
||||
|
||||
finder_sql =
|
||||
projects.
|
||||
join(namespaces, Arel::Nodes::InnerJoin).
|
||||
on(projects[:namespace_id].eq(namespaces[:id])).
|
||||
where(projects[:visibility_level].gt(namespaces[:visibility_level])).
|
||||
project(projects[:id], namespaces[:visibility_level]).
|
||||
take(BATCH_SIZE).
|
||||
to_sql
|
||||
projects
|
||||
.join(namespaces, Arel::Nodes::InnerJoin)
|
||||
.on(projects[:namespace_id].eq(namespaces[:id]))
|
||||
.where(projects[:visibility_level].gt(namespaces[:visibility_level]))
|
||||
.project(projects[:id], namespaces[:visibility_level])
|
||||
.take(BATCH_SIZE)
|
||||
.to_sql
|
||||
|
||||
# Update matching rows in batches. Each batch can cause up to 3 UPDATE
|
||||
# statements, in addition to the SELECT: one per visibility_level
|
||||
|
|
@ -33,10 +33,10 @@ class FixProjectRecordsWithInvalidVisibility < ActiveRecord::Migration
|
|||
end
|
||||
|
||||
updates.each do |visibility_level, project_ids|
|
||||
updater = Arel::UpdateManager.new(ActiveRecord::Base).
|
||||
table(projects).
|
||||
set(projects[:visibility_level] => visibility_level).
|
||||
where(projects[:id].in(project_ids))
|
||||
updater = Arel::UpdateManager.new(ActiveRecord::Base)
|
||||
.table(projects)
|
||||
.set(projects[:visibility_level] => visibility_level)
|
||||
.where(projects[:id].in(project_ids))
|
||||
|
||||
ActiveRecord::Base.connection.exec_update(updater.to_sql, self.class.name, [])
|
||||
end
|
||||
|
|
|
|||
|
|
@ -79,17 +79,17 @@ class RenameReservedProjectNames < ActiveRecord::Migration
|
|||
private
|
||||
|
||||
def reserved_projects
|
||||
Project.unscoped.
|
||||
includes(:namespace).
|
||||
where('EXISTS (SELECT 1 FROM namespaces WHERE projects.namespace_id = namespaces.id)').
|
||||
where('projects.path' => KNOWN_PATHS)
|
||||
Project.unscoped
|
||||
.includes(:namespace)
|
||||
.where('EXISTS (SELECT 1 FROM namespaces WHERE projects.namespace_id = namespaces.id)')
|
||||
.where('projects.path' => KNOWN_PATHS)
|
||||
end
|
||||
|
||||
def route_exists?(full_path)
|
||||
quoted_path = ActiveRecord::Base.connection.quote_string(full_path)
|
||||
|
||||
ActiveRecord::Base.connection.
|
||||
select_all("SELECT id, path FROM routes WHERE path = '#{quoted_path}'").present?
|
||||
ActiveRecord::Base.connection
|
||||
.select_all("SELECT id, path FROM routes WHERE path = '#{quoted_path}'").present?
|
||||
end
|
||||
|
||||
# Adds number to the end of the path that is not taken by other route
|
||||
|
|
|
|||
|
|
@ -39,11 +39,11 @@ class RequeuePendingDeleteProjects < ActiveRecord::Migration
|
|||
|
||||
def find_batch
|
||||
projects = Arel::Table.new(:projects)
|
||||
projects.project(projects[:id]).
|
||||
where(projects[:pending_delete].eq(true)).
|
||||
where(projects[:namespace_id].not_eq(nil)).
|
||||
skip(@offset * BATCH_SIZE).
|
||||
take(BATCH_SIZE).
|
||||
to_sql
|
||||
projects.project(projects[:id])
|
||||
.where(projects[:pending_delete].eq(true))
|
||||
.where(projects[:namespace_id].not_eq(nil))
|
||||
.skip(@offset * BATCH_SIZE)
|
||||
.take(BATCH_SIZE)
|
||||
.to_sql
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ class FillAuthorizedProjects < ActiveRecord::Migration
|
|||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
relation = User.select(:id).
|
||||
where('authorized_projects_populated IS NOT TRUE')
|
||||
relation = User.select(:id)
|
||||
.where('authorized_projects_populated IS NOT TRUE')
|
||||
|
||||
relation.find_in_batches(batch_size: 1_000) do |rows|
|
||||
args = rows.map { |row| [row.id] }
|
||||
|
|
|
|||
|
|
@ -21,17 +21,17 @@ class RenameMoreReservedProjectNames < ActiveRecord::Migration
|
|||
private
|
||||
|
||||
def reserved_projects
|
||||
Project.unscoped.
|
||||
includes(:namespace).
|
||||
where('EXISTS (SELECT 1 FROM namespaces WHERE projects.namespace_id = namespaces.id)').
|
||||
where('projects.path' => KNOWN_PATHS)
|
||||
Project.unscoped
|
||||
.includes(:namespace)
|
||||
.where('EXISTS (SELECT 1 FROM namespaces WHERE projects.namespace_id = namespaces.id)')
|
||||
.where('projects.path' => KNOWN_PATHS)
|
||||
end
|
||||
|
||||
def route_exists?(full_path)
|
||||
quoted_path = ActiveRecord::Base.connection.quote_string(full_path)
|
||||
|
||||
ActiveRecord::Base.connection.
|
||||
select_all("SELECT id, path FROM routes WHERE path = '#{quoted_path}'").present?
|
||||
ActiveRecord::Base.connection
|
||||
.select_all("SELECT id, path FROM routes WHERE path = '#{quoted_path}'").present?
|
||||
end
|
||||
|
||||
# Adds number to the end of the path that is not taken by other route
|
||||
|
|
|
|||
|
|
@ -38,11 +38,11 @@ class MigrateUserActivitiesToUsersLastActivityOn < ActiveRecord::Migration
|
|||
activities = activities(day.at_beginning_of_day, day.at_end_of_day, page: page)
|
||||
|
||||
update_sql =
|
||||
Arel::UpdateManager.new(ActiveRecord::Base).
|
||||
table(users_table).
|
||||
set(users_table[:last_activity_on] => day.to_date).
|
||||
where(users_table[:username].in(activities.map(&:first))).
|
||||
to_sql
|
||||
Arel::UpdateManager.new(ActiveRecord::Base)
|
||||
.table(users_table)
|
||||
.set(users_table[:last_activity_on] => day.to_date)
|
||||
.where(users_table[:username].in(activities.map(&:first)))
|
||||
.to_sql
|
||||
|
||||
connection.exec_update(update_sql, self.class.name, [])
|
||||
|
||||
|
|
|
|||
|
|
@ -37,11 +37,11 @@ class CleanupNamespacelessPendingDeleteProjects < ActiveRecord::Migration
|
|||
|
||||
def find_batch
|
||||
projects = Arel::Table.new(:projects)
|
||||
projects.project(projects[:id]).
|
||||
where(projects[:pending_delete].eq(true)).
|
||||
where(projects[:namespace_id].eq(nil)).
|
||||
skip(@offset * BATCH_SIZE).
|
||||
take(BATCH_SIZE).
|
||||
to_sql
|
||||
projects.project(projects[:id])
|
||||
.where(projects[:pending_delete].eq(true))
|
||||
.where(projects[:namespace_id].eq(nil))
|
||||
.skip(@offset * BATCH_SIZE)
|
||||
.take(BATCH_SIZE)
|
||||
.to_sql
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@ class AddHeadPipelineForEachMergeRequest < ActiveRecord::Migration
|
|||
pipelines = Arel::Table.new(:ci_pipelines)
|
||||
merge_requests = Arel::Table.new(:merge_requests)
|
||||
|
||||
head_id = pipelines.
|
||||
project(Arel::Nodes::NamedFunction.new('max', [pipelines[:id]])).
|
||||
from(pipelines).
|
||||
where(pipelines[:ref].eq(merge_requests[:source_branch])).
|
||||
where(pipelines[:project_id].eq(merge_requests[:source_project_id]))
|
||||
head_id = pipelines
|
||||
.project(Arel::Nodes::NamedFunction.new('max', [pipelines[:id]]))
|
||||
.from(pipelines)
|
||||
.where(pipelines[:ref].eq(merge_requests[:source_branch]))
|
||||
.where(pipelines[:project_id].eq(merge_requests[:source_project_id]))
|
||||
|
||||
sub_query = Arel::Nodes::SqlLiteral.new(Arel::Nodes::Grouping.new(head_id).to_sql)
|
||||
|
||||
|
|
|
|||
|
|
@ -68,8 +68,8 @@ module API
|
|||
delete ":id/access_requests/:user_id" do
|
||||
source = find_source(source_type, params[:id])
|
||||
|
||||
::Members::DestroyService.new(source, current_user, params).
|
||||
execute(:requesters)
|
||||
::Members::DestroyService.new(source, current_user, params)
|
||||
.execute(:requesters)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -102,8 +102,8 @@ module API
|
|||
post ":id/repository/branches" do
|
||||
authorize_push_project
|
||||
|
||||
result = CreateBranchService.new(user_project, current_user).
|
||||
execute(params[:branch], params[:ref])
|
||||
result = CreateBranchService.new(user_project, current_user)
|
||||
.execute(params[:branch], params[:ref])
|
||||
|
||||
if result[:status] == :success
|
||||
present result[:branch],
|
||||
|
|
@ -121,8 +121,8 @@ module API
|
|||
delete ":id/repository/branches/:branch", requirements: { branch: /.+/ } do
|
||||
authorize_push_project
|
||||
|
||||
result = DeleteBranchService.new(user_project, current_user).
|
||||
execute(params[:branch])
|
||||
result = DeleteBranchService.new(user_project, current_user)
|
||||
.execute(params[:branch])
|
||||
|
||||
if result[:status] != :success
|
||||
render_api_error!(result[:message], result[:return_code])
|
||||
|
|
|
|||
|
|
@ -484,9 +484,9 @@ module API
|
|||
expose :job_events
|
||||
# Expose serialized properties
|
||||
expose :properties do |service, options|
|
||||
field_names = service.fields.
|
||||
select { |field| options[:include_passwords] || field[:type] != 'password' }.
|
||||
map { |field| field[:name] }
|
||||
field_names = service.fields
|
||||
.select { |field| options[:include_passwords] || field[:type] != 'password' }
|
||||
.map { |field| field[:name] }
|
||||
service.properties.slice(*field_names)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ module API
|
|||
# paginate() only works with a relation. This could lead to a
|
||||
# mismatch between the pagination headers info and the actual notes
|
||||
# array returned, but this is really a edge-case.
|
||||
paginate(noteable.notes).
|
||||
reject { |n| n.cross_reference_not_visible_for?(current_user) }
|
||||
paginate(noteable.notes)
|
||||
.reject { |n| n.cross_reference_not_visible_for?(current_user) }
|
||||
present notes, with: Entities::Note
|
||||
else
|
||||
not_found!("Notes")
|
||||
|
|
|
|||
|
|
@ -44,8 +44,8 @@ module API
|
|||
post ':id/repository/tags' do
|
||||
authorize_push_project
|
||||
|
||||
result = ::Tags::CreateService.new(user_project, current_user).
|
||||
execute(params[:tag_name], params[:ref], params[:message], params[:release_description])
|
||||
result = ::Tags::CreateService.new(user_project, current_user)
|
||||
.execute(params[:tag_name], params[:ref], params[:message], params[:release_description])
|
||||
|
||||
if result[:status] == :success
|
||||
present result[:tag],
|
||||
|
|
@ -63,8 +63,8 @@ module API
|
|||
delete ":id/repository/tags/:tag_name", requirements: { tag_name: /.+/ } do
|
||||
authorize_push_project
|
||||
|
||||
result = ::Tags::DestroyService.new(user_project, current_user).
|
||||
execute(params[:tag_name])
|
||||
result = ::Tags::DestroyService.new(user_project, current_user)
|
||||
.execute(params[:tag_name])
|
||||
|
||||
if result[:status] != :success
|
||||
render_api_error!(result[:message], result[:return_code])
|
||||
|
|
@ -81,8 +81,8 @@ module API
|
|||
post ':id/repository/tags/:tag_name/release', requirements: { tag_name: /.+/ } do
|
||||
authorize_push_project
|
||||
|
||||
result = CreateReleaseService.new(user_project, current_user).
|
||||
execute(params[:tag_name], params[:description])
|
||||
result = CreateReleaseService.new(user_project, current_user)
|
||||
.execute(params[:tag_name], params[:description])
|
||||
|
||||
if result[:status] == :success
|
||||
present result[:release], with: Entities::Release
|
||||
|
|
@ -101,8 +101,8 @@ module API
|
|||
put ':id/repository/tags/:tag_name/release', requirements: { tag_name: /.+/ } do
|
||||
authorize_push_project
|
||||
|
||||
result = UpdateReleaseService.new(user_project, current_user).
|
||||
execute(params[:tag_name], params[:description])
|
||||
result = UpdateReleaseService.new(user_project, current_user)
|
||||
.execute(params[:tag_name], params[:description])
|
||||
|
||||
if result[:status] == :success
|
||||
present result[:release], with: Entities::Release
|
||||
|
|
|
|||
|
|
@ -103,13 +103,13 @@ module API
|
|||
if user.persisted?
|
||||
present user, with: Entities::UserPublic
|
||||
else
|
||||
conflict!('Email has already been taken') if User.
|
||||
where(email: user.email).
|
||||
count > 0
|
||||
conflict!('Email has already been taken') if User
|
||||
.where(email: user.email)
|
||||
.count > 0
|
||||
|
||||
conflict!('Username has already been taken') if User.
|
||||
where(username: user.username).
|
||||
count > 0
|
||||
conflict!('Username has already been taken') if User
|
||||
.where(username: user.username)
|
||||
.count > 0
|
||||
|
||||
render_validation_error!(user)
|
||||
end
|
||||
|
|
@ -133,12 +133,12 @@ module API
|
|||
not_found!('User') unless user
|
||||
|
||||
conflict!('Email has already been taken') if params[:email] &&
|
||||
User.where(email: params[:email]).
|
||||
where.not(id: user.id).count > 0
|
||||
User.where(email: params[:email])
|
||||
.where.not(id: user.id).count > 0
|
||||
|
||||
conflict!('Username has already been taken') if params[:username] &&
|
||||
User.where(username: params[:username]).
|
||||
where.not(id: user.id).count > 0
|
||||
User.where(username: params[:username])
|
||||
.where.not(id: user.id).count > 0
|
||||
|
||||
user_params = declared_params(include_missing: false)
|
||||
identity_attrs = user_params.slice(:provider, :extern_uid)
|
||||
|
|
@ -517,9 +517,9 @@ module API
|
|||
get "activities" do
|
||||
authenticated_as_admin!
|
||||
|
||||
activities = User.
|
||||
where(User.arel_table[:last_activity_on].gteq(params[:from])).
|
||||
reorder(last_activity_on: :asc)
|
||||
activities = User
|
||||
.where(User.arel_table[:last_activity_on].gteq(params[:from]))
|
||||
.reorder(last_activity_on: :asc)
|
||||
|
||||
present paginate(activities), with: Entities::UserActivity
|
||||
end
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ module API
|
|||
delete ":id/repository/branches/:branch", requirements: { branch: /.+/ } do
|
||||
authorize_push_project
|
||||
|
||||
result = DeleteBranchService.new(user_project, current_user).
|
||||
execute(params[:branch])
|
||||
result = DeleteBranchService.new(user_project, current_user)
|
||||
.execute(params[:branch])
|
||||
|
||||
if result[:status] == :success
|
||||
status(200)
|
||||
|
|
@ -55,8 +55,8 @@ module API
|
|||
end
|
||||
post ":id/repository/branches" do
|
||||
authorize_push_project
|
||||
result = CreateBranchService.new(user_project, current_user).
|
||||
execute(params[:branch_name], params[:ref])
|
||||
result = CreateBranchService.new(user_project, current_user)
|
||||
.execute(params[:branch_name], params[:ref])
|
||||
|
||||
if result[:status] == :success
|
||||
present result[:branch],
|
||||
|
|
|
|||
|
|
@ -245,9 +245,9 @@ module API
|
|||
expose :job_events, as: :build_events
|
||||
# Expose serialized properties
|
||||
expose :properties do |service, options|
|
||||
field_names = service.fields.
|
||||
select { |field| options[:include_passwords] || field[:type] != 'password' }.
|
||||
map { |field| field[:name] }
|
||||
field_names = service.fields
|
||||
.select { |field| options[:include_passwords] || field[:type] != 'password' }
|
||||
.map { |field| field[:name] }
|
||||
service.properties.slice(*field_names)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@ module API
|
|||
# paginate() only works with a relation. This could lead to a
|
||||
# mismatch between the pagination headers info and the actual notes
|
||||
# array returned, but this is really a edge-case.
|
||||
paginate(noteable.notes).
|
||||
reject { |n| n.cross_reference_not_visible_for?(current_user) }
|
||||
paginate(noteable.notes)
|
||||
.reject { |n| n.cross_reference_not_visible_for?(current_user) }
|
||||
present notes, with: ::API::V3::Entities::Note
|
||||
else
|
||||
not_found!("Notes")
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ module API
|
|||
delete ":id/repository/tags/:tag_name", requirements: { tag_name: /.+/ } do
|
||||
authorize_push_project
|
||||
|
||||
result = ::Tags::DestroyService.new(user_project, current_user).
|
||||
execute(params[:tag_name])
|
||||
result = ::Tags::DestroyService.new(user_project, current_user)
|
||||
.execute(params[:tag_name])
|
||||
|
||||
if result[:status] == :success
|
||||
status(200)
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue