Class: Labels::PromoteService

Inherits:
BaseService show all
Defined in:
app/services/labels/promote_service.rb

Constant Summary collapse

BATCH_SIZE =
1000

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#convert_color_name_to_hex

Methods inherited from BaseService

#initialize

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#execute(label) ⇒ Object

rubocop: disable CodeReuse/ActiveRecord



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/services/labels/promote_service.rb', line 8

def execute(label)
  return unless project.group &&
      label.is_a?(ProjectLabel)

  ProjectLabel.transaction do
    # use the existing group label if it exists
    group_label = find_or_create_group_label(label)

    label_ids_for_merge(group_label).find_in_batches(batch_size: BATCH_SIZE) do |batched_ids|
      update_old_label_relations(group_label, batched_ids)
      destroy_project_labels(batched_ids)
    end

    group_label
  end
end