Commit db377437 authored by Sean McGivern's avatar Sean McGivern

Make /copy_metadata only handle the first issuable passed

parent 78aebc49
...@@ -269,21 +269,21 @@ module QuickActions ...@@ -269,21 +269,21 @@ module QuickActions
end end
desc 'Copy labels and milestone from other issue or merge request' desc 'Copy labels and milestone from other issue or merge request'
explanation do |issuable_id| explanation do |source_issuable|
"Copy labels and milestone from issue or merge_request #{issuable_id}." "Copy labels and milestone from #{source_issuable.to_reference}."
end end
params '#issue | !merge_request' params '#issue | !merge_request'
condition do condition do
issuable.persisted? && issuable.persisted? &&
current_user.can?(:"update_#{issuable.to_ability_name}", issuable) current_user.can?(:"update_#{issuable.to_ability_name}", issuable)
end end
command :copy_metadata do |issuable_id| parse_params do |issuable_param|
source_issuable = extract_references(issuable_id, :issue).first extract_references(issuable_param, :issue).first ||
source_issuable ||= extract_references(issuable_id, :merge_request).first extract_references(issuable_param, :merge_request).first
end
command :copy_metadata do |source_issuable|
if source_issuable.present? && source_issuable.project.id == issuable.project.id if source_issuable.present? && source_issuable.project.id == issuable.project.id
@updates[:add_label_ids] = source_issuable.labels.map(&:id) @updates[:add_label_ids] = source_issuable.labels.map(&:id)
@updates[:milestone_id] = source_issuable.milestone.id if source_issuable.milestone @updates[:milestone_id] = source_issuable.milestone.id if source_issuable.milestone
end end
end end
......
...@@ -41,4 +41,4 @@ do. ...@@ -41,4 +41,4 @@ do.
| `/move path/to/project` | Moves issue to another project | | `/move path/to/project` | Moves issue to another project |
| `/tableflip` | Append the comment with `(╯°□°)╯︵ ┻━┻` | | `/tableflip` | Append the comment with `(╯°□°)╯︵ ┻━┻` |
| `/shrug` | Append the comment with `¯\_(ツ)_/¯` | | `/shrug` | Append the comment with `¯\_(ツ)_/¯` |
| <code>/copy_metadata #issue &#124; !merge_request </code> | Copy labels and milestone from other issue or merge request | | <code>/copy_metadata #issue &#124; !merge_request</code> | Copy labels and milestone from other issue or merge request |
...@@ -775,8 +775,8 @@ describe QuickActions::InterpretService do ...@@ -775,8 +775,8 @@ describe QuickActions::InterpretService do
end end
context '/copy_metadata command' do context '/copy_metadata command' do
let!(:todo_label) { create(:label, project: project, title: 'To Do') } let(:todo_label) { create(:label, project: project, title: 'To Do') }
let!(:inreview_label) { create(:label, project: project, title: 'In Review') } let(:inreview_label) { create(:label, project: project, title: 'In Review') }
it_behaves_like 'empty command' do it_behaves_like 'empty command' do
let(:content) { '/copy_metadata' } let(:content) { '/copy_metadata' }
...@@ -799,6 +799,17 @@ describe QuickActions::InterpretService do ...@@ -799,6 +799,17 @@ describe QuickActions::InterpretService do
end end
end end
context 'when more than one issuable is passed' do
it_behaves_like 'copy_metadata command' do
let(:source_issuable) { create(:labeled_issue, project: project, labels: [inreview_label, todo_label]) }
let(:other_label) { create(:label, project: project, title: 'Other') }
let(:other_source_issuable) { create(:labeled_issue, project: project, labels: [other_label]) }
let(:content) { "/copy_metadata #{source_issuable.to_reference} #{other_source_issuable.to_reference}" }
let(:issuable) { issue }
end
end
context 'cross project references' do context 'cross project references' do
it_behaves_like 'empty command' do it_behaves_like 'empty command' do
let(:other_project) { create(:project, :public) } let(:other_project) { create(:project, :public) }
......
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