Reuse LabelsFinder on Issueable#add_labels_by_names
This commit is contained in:
parent
3db2261005
commit
7e11ca86fd
5 changed files with 11 additions and 16 deletions
|
@ -234,19 +234,13 @@ module Issuable
|
|||
labels.delete_all
|
||||
end
|
||||
|
||||
def add_labels_by_names(label_names)
|
||||
label_ids = []
|
||||
label_ids << project.group.labels.select(:id) if project.group.present?
|
||||
label_ids << project.labels.select(:id)
|
||||
|
||||
union = Gitlab::SQL::Union.new(label_ids)
|
||||
|
||||
available_labels = Label.where("labels.id IN (#{union.to_sql})")
|
||||
def add_labels_by_names(label_names, current_user)
|
||||
available_labels = LabelsFinder.new(current_user, project_id: project.id).execute
|
||||
|
||||
label_names.each do |label_name|
|
||||
title = label_name.strip
|
||||
label = available_labels.find_by(title: title)
|
||||
label = project.labels.build(title: title, color: Label::DEFAULT_COLOR) if label.nil?
|
||||
label ||= project.labels.build(title: title, color: Label::DEFAULT_COLOR)
|
||||
|
||||
self.labels << label
|
||||
end
|
||||
|
|
|
@ -91,7 +91,7 @@ module API
|
|||
if merge_request.valid?
|
||||
# Find or create labels and attach to issue
|
||||
if params[:labels].present?
|
||||
merge_request.add_labels_by_names(params[:labels].split(","))
|
||||
merge_request.add_labels_by_names(params[:labels].split(","), current_user)
|
||||
end
|
||||
|
||||
present merge_request, with: Entities::MergeRequest, current_user: current_user
|
||||
|
@ -201,7 +201,7 @@ module API
|
|||
# Find or create labels and attach to issue
|
||||
unless params[:labels].nil?
|
||||
merge_request.remove_labels
|
||||
merge_request.add_labels_by_names(params[:labels].split(","))
|
||||
merge_request.add_labels_by_names(params[:labels].split(","), current_user)
|
||||
end
|
||||
|
||||
present merge_request, with: Entities::MergeRequest, current_user: current_user
|
||||
|
|
|
@ -129,7 +129,7 @@ module Gitlab
|
|||
assignee_id: assignee_id,
|
||||
state: bug['fOpen'] == 'true' ? 'opened' : 'closed'
|
||||
)
|
||||
issue.add_labels_by_names(labels)
|
||||
issue.add_labels_by_names(labels, project.creator)
|
||||
|
||||
if issue.iid != bug['ixBug']
|
||||
issue.update_attribute(:iid, bug['ixBug'])
|
||||
|
|
|
@ -100,7 +100,7 @@ module Gitlab
|
|||
state: raw_issue["state"] == "closed" ? "closed" : "opened"
|
||||
)
|
||||
|
||||
issue.add_labels_by_names(labels)
|
||||
issue.add_labels_by_names(labels, project.creator)
|
||||
|
||||
if issue.iid != raw_issue["id"]
|
||||
issue.update_attribute(:iid, raw_issue["id"])
|
||||
|
|
|
@ -15,6 +15,7 @@ describe Gitlab::GoogleCodeImport::Importer, lib: true do
|
|||
subject { described_class.new(project) }
|
||||
|
||||
before do
|
||||
project.team << [project.creator, :master]
|
||||
project.create_import_data(data: import_data)
|
||||
end
|
||||
|
||||
|
@ -31,9 +32,9 @@ describe Gitlab::GoogleCodeImport::Importer, lib: true do
|
|||
subject.execute
|
||||
|
||||
%w(
|
||||
Type-Defect Type-Enhancement Type-Task Type-Review Type-Other Milestone-0.12 Priority-Critical
|
||||
Priority-High Priority-Medium Priority-Low OpSys-All OpSys-Windows OpSys-Linux OpSys-OSX Security
|
||||
Performance Usability Maintainability Component-Panel Component-Taskbar Component-Battery
|
||||
Type-Defect Type-Enhancement Type-Task Type-Review Type-Other Milestone-0.12 Priority-Critical
|
||||
Priority-High Priority-Medium Priority-Low OpSys-All OpSys-Windows OpSys-Linux OpSys-OSX Security
|
||||
Performance Usability Maintainability Component-Panel Component-Taskbar Component-Battery
|
||||
Component-Systray Component-Clock Component-Launcher Component-Tint2conf Component-Docs Component-New
|
||||
).each do |label|
|
||||
label.sub!("-", ": ")
|
||||
|
|
Loading…
Reference in a new issue