This instance was upgraded to Heptapod 0.27.2 on 2021-12-08 at 22:00 UTC+1

Commit d009d38e authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre
Browse files

User Labes::CreateService to create labels

parent 9f7d02646595
......@@ -733,7 +733,8 @@ def build_missing_services
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 @@ def create_list(board, params)
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 @@ def find_or_create_label_ids
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 @@ def label_links
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 @@ def nice_label_color(name)
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 @@ def klass
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 @@ def escape_for_markdown(s)
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 @@ def generate(project)
{ 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