Class: Labels::CreateService
- Inherits:
-
BaseService
- Object
- BaseService
- BaseService
- Labels::CreateService
- Defined in:
- app/services/labels/create_service.rb
Instance Attribute Summary
Attributes inherited from BaseService
#current_user, #params, #project
Instance Method Summary collapse
-
#execute(target_params) ⇒ Object
returns the created label.
-
#initialize(params = {}) ⇒ CreateService
constructor
A new instance of CreateService.
Methods inherited from BaseService
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
Constructor Details
#initialize(params = {}) ⇒ CreateService
Returns a new instance of CreateService.
5 6 7 |
# File 'app/services/labels/create_service.rb', line 5 def initialize(params = {}) @params = params.to_h.dup.with_indifferent_access end |
Instance Method Details
#execute(target_params) ⇒ Object
returns the created label
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/services/labels/create_service.rb', line 10 def execute(target_params) params[:color] = convert_color_name_to_hex if params[:color].present? project_or_group = target_params[:project] || target_params[:group] if project_or_group.present? params.delete(:lock_on_merge) unless project_or_group.supports_lock_on_merge? project_or_group.labels.create(params) elsif target_params[:template] label = Label.new(params) label.template = true label.save label else Gitlab::AppLogger.warn("target_params should contain :project or :group or :template, actual value: #{target_params}") end end |