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
end
desc 'Copy labels and milestone from other issue or merge request'
explanation do |issuable_id|
"Copy labels and milestone from issue or merge_request #{issuable_id}."
explanation do |source_issuable|
"Copy labels and milestone from #{source_issuable.to_reference}."
end
params '#issue | !merge_request'
condition do
issuable.persisted? &&
current_user.can?(:"update_#{issuable.to_ability_name}", issuable)
end
command :copy_metadata do |issuable_id|
source_issuable = extract_references(issuable_id, :issue).first
source_issuable ||= extract_references(issuable_id, :merge_request).first
parse_params do |issuable_param|
extract_references(issuable_param, :issue).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
@updates[:add_label_ids] = source_issuable.labels.map(&:id)
@updates[:milestone_id] = source_issuable.milestone.id if source_issuable.milestone
end
end
......
......@@ -38,7 +38,7 @@ do.
| `/award :emoji:` | Toggle award for :emoji: |
| `/board_move ~column` | Move issue to column on the board |
| `/duplicate #issue` | Closes this issue and marks it as a duplicate of another issue |
| `/move path/to/project` | Moves issue to another project |
| `/tableflip` | 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 |
| `/move path/to/project` | Moves issue to another project |
| `/tableflip` | 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 |
......@@ -775,8 +775,8 @@ describe QuickActions::InterpretService do
end
context '/copy_metadata command' do
let!(:todo_label) { create(:label, project: project, title: 'To Do') }
let!(:inreview_label) { create(:label, project: project, title: 'In Review') }
let(:todo_label) { create(:label, project: project, title: 'To Do') }
let(:inreview_label) { create(:label, project: project, title: 'In Review') }
it_behaves_like 'empty command' do
let(:content) { '/copy_metadata' }
......@@ -799,6 +799,17 @@ describe QuickActions::InterpretService do
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
it_behaves_like 'empty command' do
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