Commit a0adf877 authored by Mateusz Bajorski's avatar Mateusz Bajorski

Changed command name to copy_metadata and added MR support

parent 4f10cad9
...@@ -268,18 +268,20 @@ module QuickActions ...@@ -268,18 +268,20 @@ module QuickActions
end end
end end
desc 'Inherit (copy) labels and milestone from other issue' desc 'Copy labels and milestone from other issue or merge request'
explanation do |issue_id| explanation do |issueable_id|
"Inherit (copy) labels and milestone from issue \"#{issue_id}\"." "Copy labels and milestone from issue or merge_request \"#{issueable_id}\"."
end end
params '#issue' 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 :inherit do |issue_id| command :copy_metadata do |issueable_id|
issue = extract_references(issue_id, :issue).first reference_type = issueable_id.include?("#") ? :issue : :merge_request
if issue.present? && issue.project_id == issuable.project_id issue = extract_references(issueable_id, reference_type).first
if issue.present? && issue.project.id == issuable.project.id
@updates[:add_label_ids] = issue.labels.map(&:id) @updates[:add_label_ids] = issue.labels.map(&:id)
@updates[:milestone_id] = issue.milestone.id if issue.milestone @updates[:milestone_id] = issue.milestone.id if issue.milestone
......
--- ---
title: Add Inherit quick action title: Add Inherit quick action
merge_request: merge_request: 16473
author: Mateusz Bajorski author: Mateusz Bajorski
type: added type: added
...@@ -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 `¯\_(ツ)_/¯` |
| `/inherit #issue` | Inherit (copy) labels and milestone from other issue | | <code>/copy_metadata &lt; #issue &#124; !merge_request &gt;</code> | copy_metadata labels and milestone from other issue or merge request |
...@@ -306,17 +306,17 @@ describe QuickActions::InterpretService do ...@@ -306,17 +306,17 @@ describe QuickActions::InterpretService do
end end
end end
shared_examples 'inherit command' do shared_examples 'copy_metadata command' do
it 'fetches issue and copies labels and milestone if content contains /inherit issue_reference' do it 'fetches issue or merge request and copies labels and milestone if content contains /copy_metadata reference' do
issue_father # populate the issue issueable_father # populate the issue
todo_label # populate this label todo_label # populate this label
inreview_label # populate this label inreview_label # populate this label
_, updates = service.execute(content, issuable) _, updates = service.execute(content, issuable)
expect(updates[:add_label_ids]).to match_array([inreview_label.id, todo_label.id]) expect(updates[:add_label_ids]).to match_array([inreview_label.id, todo_label.id])
if issue_father.milestone if issueable_father.milestone
expect(updates[:milestone_id]).to eq(issue_father.milestone.id) expect(updates[:milestone_id]).to eq(issueable_father.milestone.id)
else else
expect(updates).not_to have_key(:milestone_id) expect(updates).not_to have_key(:milestone_id)
end end
...@@ -774,49 +774,49 @@ describe QuickActions::InterpretService do ...@@ -774,49 +774,49 @@ describe QuickActions::InterpretService do
let(:issuable) { issue } let(:issuable) { issue }
end end
context '/inherit 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 'inherit command' do it_behaves_like 'empty command' do
# Without milestone assignment let(:content) { '/copy_metadata' }
let(:issue_father) { create(:labeled_issue, project: project, labels: [inreview_label, todo_label]) }
let(:content) { "/inherit #{issue_father.to_reference}" }
let(:issuable) { issue } let(:issuable) { issue }
end end
it_behaves_like 'inherit command' do it_behaves_like 'copy_metadata command' do
# With milestone assignment let(:issueable_father) { create(:labeled_issue, project: project, labels: [inreview_label, todo_label]) }
let(:issue_father) { create(:labeled_issue, project: project, labels: [todo_label, inreview_label], milestone: milestone) }
let(:content) { "/inherit #{issue_father.to_reference(project)}" } let(:content) { "/copy_metadata #{issueable_father.to_reference}" }
let(:issuable) { issue } let(:issuable) { issue }
end end
it_behaves_like 'empty command' do context 'when the parent issueable has a milestone' do
let(:content) { '/inherit' } it_behaves_like 'copy_metadata command' do
let(:issuable) { issue } let(:issueable_father) { create(:labeled_issue, project: project, labels: [todo_label, inreview_label], milestone: milestone) }
let(:content) { "/copy_metadata #{issueable_father.to_reference(project)}" }
let(:issuable) { issue }
end
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) }
let(:issue_father) { create(:labeled_issue, project: other_project, labels: [todo_label, inreview_label]) } let(:issueable_father) { create(:labeled_issue, project: other_project, labels: [todo_label, inreview_label]) }
let(:content) { "/inherit #{issue_father.to_reference(project)}" } let(:content) { "/copy_metadata #{issueable_father.to_reference(project)}" }
let(:issuable) { issue } let(:issuable) { issue }
end end
it_behaves_like 'empty command' do it_behaves_like 'empty command' do
let(:content) { "/inherit imaginary#1234" } let(:content) { "/copy_metadata imaginary#1234" }
let(:issuable) { issue } let(:issuable) { issue }
end end
it_behaves_like 'empty command' do it_behaves_like 'empty command' do
let(:other_project) { create(:project, :private) } let(:other_project) { create(:project, :private) }
let(:issue_father) { create(:issue, project: other_project) } let(:issueable_father) { create(:issue, project: other_project) }
let(:content) { "/inherit #{issue_father.to_reference(project)}" } let(:content) { "/copy_metadata #{issueable_father.to_reference(project)}" }
let(:issuable) { issue } let(:issuable) { issue }
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