User Labes::CreateService to create labels

parent 6c189dcc
......@@ -733,7 +733,8 @@ class Project < ActiveRecord::Base
def create_labels
Label.templates.each do |label|
self.labels.create!(label.attributes.symbolize_keys.except(:id, :template))
params = label.attributes.except('id', 'template', 'created_at', 'updated_at')
Labels::CreateService.new(owner, self, params).execute
end
end
......
......@@ -19,8 +19,7 @@ module Boards
end
def find_or_create_label(params)
project.labels.create_with(color: params[:color])
.find_or_create_by(name: params[:name])
::Labels::CreateService.new(current_user, project, params).execute
end
def label_params
......
......@@ -88,8 +88,8 @@ class IssuableBaseService < BaseService
return unless labels
params[:label_ids] = labels.split(',').map do |label_name|
label = available_labels.find_by(title: label_name)
label ||= project.labels.create(title: label_name.strip, color: Label::DEFAULT_COLOR)
service = Labels::CreateService.new(current_user, project, title: label_name.strip)
label = service.execute
label.id
end
......
......@@ -41,13 +41,9 @@ module Labels
LabelLink.where("label_links.id IN (#{union.to_sql})")
end
def labels
@labels ||= LabelsFinder.new(current_user, project_id: project.id).execute
end
def find_or_create_label!(label)
new_label = labels.find_by(title: label.title)
new_label ||= project.labels.create!(label.attributes.slice("title", "description", "color"))
params = label.attributes.slice('title', 'description', 'color')
new_label = CreateService.new(current_user, project, params).execute
new_label.id
end
......
......@@ -74,8 +74,8 @@ module Gitlab
end
def create_label(name)
color = nice_label_color(name)
Label.create!(project_id: project.id, title: name, color: color)
params = { title: name, color: nice_label_color(name) }
::Labels::CreateService.new(project.owner, project, params).execute
end
def user_info(person_id)
......
......@@ -14,9 +14,10 @@ module Gitlab
end
def create!
project.labels.find_or_create_by!(title: title) do |label|
label.color = color
end
params = attributes.except(:project)
service = ::Labels::CreateService.new(project.owner, project, params)
service.execute
end
private
......
......@@ -233,8 +233,8 @@ module Gitlab
end
def create_label(name)
color = nice_label_color(name)
project.labels.create!(name: name, color: color)
params = { name: name, color: nice_label_color(name) }
::Labels::CreateService.new(project.owner, project, params).execute
end
def format_content(raw_content)
......
......@@ -18,8 +18,8 @@ module Gitlab
{ title: "enhancement", color: green }
]
labels.each do |label|
project.labels.create(label)
labels.each do |params|
::Labels::CreateService.new(project.owner, project).execute(params)
end
end
end
......
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