summaryrefslogtreecommitdiff
path: root/app/services/labels
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2018-08-27 17:31:01 +0200
committerYorick Peterse <yorickpeterse@gmail.com>2018-09-11 17:32:00 +0200
commit2039c8280db1646845c33d6c5a74e5f23ca6f4de (patch)
treee2b3cd3012d9711cda7c6afb962ae4228d59521a /app/services/labels
parent91c40973dc620430b173ea2df968587d2a708dff (diff)
downloadgitlab-ce-2039c8280db1646845c33d6c5a74e5f23ca6f4de.tar.gz
Disable existing offenses for the CodeReuse cops
This whitelists all existing offenses for the various CodeReuse cops, of which most are triggered by the CodeReuse/ActiveRecord cop.
Diffstat (limited to 'app/services/labels')
-rw-r--r--app/services/labels/find_or_create_service.rb2
-rw-r--r--app/services/labels/promote_service.rb16
-rw-r--r--app/services/labels/transfer_service.rb10
3 files changed, 28 insertions, 0 deletions
diff --git a/app/services/labels/find_or_create_service.rb b/app/services/labels/find_or_create_service.rb
index e4486764a4d..628873519d7 100644
--- a/app/services/labels/find_or_create_service.rb
+++ b/app/services/labels/find_or_create_service.rb
@@ -29,6 +29,7 @@ module Labels
# Only creates the label if current_user can do so, if the label does not exist
# and the user can not create the label, nil is returned
+ # rubocop: disable CodeReuse/ActiveRecord
def find_or_create_label
new_label = available_labels.find_by(title: title)
@@ -39,6 +40,7 @@ module Labels
new_label
end
+ # rubocop: enable CodeReuse/ActiveRecord
def title
params[:title] || params[:name]
diff --git a/app/services/labels/promote_service.rb b/app/services/labels/promote_service.rb
index fcdcea2d0ea..f30ad706c63 100644
--- a/app/services/labels/promote_service.rb
+++ b/app/services/labels/promote_service.rb
@@ -4,6 +4,7 @@ module Labels
class PromoteService < BaseService
BATCH_SIZE = 1000
+ # rubocop: disable CodeReuse/ActiveRecord
def execute(label)
return unless project.group &&
label.is_a?(ProjectLabel)
@@ -27,9 +28,11 @@ module Labels
new_label
end
end
+ # rubocop: enable CodeReuse/ActiveRecord
private
+ # rubocop: disable CodeReuse/ActiveRecord
def subscribe_users(new_label, label_ids)
# users can be subscribed to multiple labels that will be merged into the group one
# we want to keep only one subscription / user
@@ -38,7 +41,9 @@ module Labels
.pluck('MAX(id)')
Subscription.where(id: ids_to_update).update_all(subscribable_id: new_label.id)
end
+ # rubocop: enable CodeReuse/ActiveRecord
+ # rubocop: disable CodeReuse/ActiveRecord
def label_ids_for_merge(new_label)
LabelsFinder
.new(current_user, title: new_label.title, group_id: project.group.id)
@@ -46,34 +51,45 @@ module Labels
.where.not(id: new_label)
.select(:id) # Can't use pluck() to avoid object-creation because of the batching
end
+ # rubocop: enable CodeReuse/ActiveRecord
+ # rubocop: disable CodeReuse/ActiveRecord
def update_issuables(new_label, label_ids)
LabelLink
.where(label: label_ids)
.update_all(label_id: new_label)
end
+ # rubocop: enable CodeReuse/ActiveRecord
+ # rubocop: disable CodeReuse/ActiveRecord
def update_resource_label_events(new_label, label_ids)
ResourceLabelEvent
.where(label: label_ids)
.update_all(label_id: new_label)
end
+ # rubocop: enable CodeReuse/ActiveRecord
+ # rubocop: disable CodeReuse/ActiveRecord
def update_issue_board_lists(new_label, label_ids)
List
.where(label: label_ids)
.update_all(label_id: new_label)
end
+ # rubocop: enable CodeReuse/ActiveRecord
+ # rubocop: disable CodeReuse/ActiveRecord
def update_priorities(new_label, label_ids)
LabelPriority
.where(label: label_ids)
.update_all(label_id: new_label)
end
+ # rubocop: enable CodeReuse/ActiveRecord
+ # rubocop: disable CodeReuse/ActiveRecord
def update_project_labels(label_ids)
Label.where(id: label_ids).destroy_all # rubocop: disable DestroyAll
end
+ # rubocop: enable CodeReuse/ActiveRecord
def clone_label_to_group_label(label)
params = label.attributes.slice('title', 'description', 'color')
diff --git a/app/services/labels/transfer_service.rb b/app/services/labels/transfer_service.rb
index 1bd8d9fc325..aec0282b31b 100644
--- a/app/services/labels/transfer_service.rb
+++ b/app/services/labels/transfer_service.rb
@@ -32,6 +32,7 @@ module Labels
attr_reader :current_user, :old_group, :project
+ # rubocop: disable CodeReuse/ActiveRecord
def labels_to_transfer
label_ids = []
label_ids << group_labels_applied_to_issues.select(:id)
@@ -41,7 +42,9 @@ module Labels
Label.where("labels.id IN (#{union.to_sql})").reorder(nil).uniq # rubocop:disable GitlabSecurity/SqlInjection
end
+ # rubocop: enable CodeReuse/ActiveRecord
+ # rubocop: disable CodeReuse/ActiveRecord
def group_labels_applied_to_issues
Label.joins(:issues)
.where(
@@ -49,7 +52,9 @@ module Labels
labels: { type: 'GroupLabel', group_id: old_group.id }
)
end
+ # rubocop: enable CodeReuse/ActiveRecord
+ # rubocop: disable CodeReuse/ActiveRecord
def group_labels_applied_to_merge_requests
Label.joins(:merge_requests)
.where(
@@ -57,6 +62,7 @@ module Labels
labels: { type: 'GroupLabel', group_id: old_group.id }
)
end
+ # rubocop: enable CodeReuse/ActiveRecord
def find_or_create_label!(label)
params = label.attributes.slice('title', 'description', 'color')
@@ -65,6 +71,7 @@ module Labels
new_label.id
end
+ # rubocop: disable CodeReuse/ActiveRecord
def update_label_links(labels, old_label_id:, new_label_id:)
# use 'labels' relation to get label_link ids only of issues/MRs
# in the project being transferred.
@@ -76,10 +83,13 @@ module Labels
LabelLink.where(id: link_ids, label_id: old_label_id)
.update_all(label_id: new_label_id)
end
+ # rubocop: enable CodeReuse/ActiveRecord
+ # rubocop: disable CodeReuse/ActiveRecord
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)
end
+ # rubocop: enable CodeReuse/ActiveRecord
end
end