User Labes::CreateService to create labels

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