Commit 77f2d364 authored by Toon Claes's avatar Toon Claes

Move specs to interpret_service_spec.rb

And some other little cleanups.
parent 87ed4efa
...@@ -57,7 +57,7 @@ discussions, and descriptions: ...@@ -57,7 +57,7 @@ discussions, and descriptions:
| `/approve` | Approve the merge request | | ✓ | | `/approve` | Approve the merge request | | ✓ |
| `/merge` | Merge (when pipeline succeeds) | | ✓ | | `/merge` | Merge (when pipeline succeeds) | | ✓ |
| `/create_merge_request <branch name>` | Create a new merge request starting from the current issue | ✓ | | | `/create_merge_request <branch name>` | Create a new merge request starting from the current issue | ✓ | |
| `/relate #issue [#issue...]`| Mark issues as related | ✓ | | | `/relate #issue1 #issue2` | Mark issues as related **[STARTER]** | ✓ | |
## Quick actions for commit messages ## Quick actions for commit messages
......
...@@ -8,7 +8,6 @@ module EE ...@@ -8,7 +8,6 @@ module EE
override :execute override :execute
def execute(issue) def execute(issue)
handle_epic(issue) handle_epic(issue)
handle_relate(issue)
result = super result = super
if issue.previous_changes.include?(:milestone_id) && issue.epic if issue.previous_changes.include?(:milestone_id) && issue.epic
...@@ -35,18 +34,6 @@ module EE ...@@ -35,18 +34,6 @@ module EE
EpicIssues::DestroyService.new(link, current_user).execute EpicIssues::DestroyService.new(link, current_user).execute
end end
end end
def handle_relate(issue)
return unless params.key?(:related_issues)
relate_param = params.delete(:related_issues)
if relate_param
relate_param.each do |issuable|
IssueLinks::CreateService.new(issuable, current_user, { target_issue: issue }).execute
end
end
end
end end
end end
end end
...@@ -10,7 +10,7 @@ module EE ...@@ -10,7 +10,7 @@ module EE
included do included do
desc _('Mark this issue as related to another issue') desc _('Mark this issue as related to another issue')
explanation do |related_reference| explanation do |related_reference|
_('Marks this issue related to %{issue_ref}.') % { issue_ref: related_reference } _('Marks this issue as related to %{issue_ref}.') % { issue_ref: related_reference }
end end
params '#issue' params '#issue'
types Issue types Issue
......
...@@ -258,93 +258,43 @@ describe Notes::QuickActionsService do ...@@ -258,93 +258,43 @@ describe Notes::QuickActionsService do
end end
end end
context '/relate command' do context '/relate' do
shared_examples 'relate command' do let(:other_issue) { create(:issue, project: project) }
let(:note) { create(:note_on_issue, noteable: issue, project: project, note: note_text) } let(:note_text) { "/relate #{other_issue.to_reference}" }
let(:note) { create(:note_on_issue, noteable: issue, project: project, note: note_text) }
it 'relates issues' do context 'user cannot relate issues' do
execute(note) before do
project.update(visibility: Gitlab::VisibilityLevel::PUBLIC)
end
expect(issue.related_issues(user)).to match_array(issues_related) it 'does not create issue relation' do
expect { execute(note) }.not_to change { IssueLink.count }
end end
end end
context 'user is member of project' do context 'user is allowed to relate issues' do
before do before do
group.add_developer(user) group.add_developer(user)
end end
context 'relate a single issue' do context 'related issues are not enabled' do
let(:other_issue) { create(:issue, project: project) }
let(:issues_related) { [other_issue] }
let(:note_text) { "/relate #{other_issue.to_reference}" }
it_behaves_like 'relate command'
end
context 'relate multiple issues at once' do
let(:second_issue) { create(:issue, project: project) }
let(:third_issue) { create(:issue, project: project) }
let(:issues_related) { [second_issue, third_issue] }
let(:note_text) { "/relate #{second_issue.to_reference} #{third_issue.to_reference}" }
it_behaves_like 'relate command'
end
context 'empty relate command' do
let(:issues_related) { [] }
let(:note_text) { '/relate' }
it_behaves_like 'relate command'
end
context 'already having related issues' do
let(:second_issue) { create(:issue, project: project) }
let(:third_issue) { create(:issue, project: project) }
let(:issues_related) { [second_issue, third_issue] }
let(:note_text) { "/relate #{third_issue.to_reference(project)}" }
before do before do
create(:issue_link, source: issue, target: second_issue) stub_licensed_features(related_issues: false)
end
it_behaves_like 'relate command'
end
context 'cross project' do
let(:other_project) { create(:project, group: group) }
context 'relate a cross project issue' do
let(:other_issue) { create(:issue, project: other_project) }
let(:issues_related) { [other_issue] }
let(:note_text) { "/relate #{other_issue.to_reference(project)}" }
it_behaves_like 'relate command'
end end
context 'relate multiple cross projects issues at once' do it 'does not create issue relation' do
let(:second_issue) { create(:issue, project: other_project) } expect { execute(note) }.not_to change { IssueLink.count }
let(:third_issue) { create(:issue, project: other_project) }
let(:issues_related) { [second_issue, third_issue] }
let(:note_text) { "/relate #{second_issue.to_reference(project)} #{third_issue.to_reference(project)}" }
it_behaves_like 'relate command'
end end
end
context 'relate an non-existing issue' do context 'related issues are enabled' do
let(:issues_related) { [] } before do
let(:note_text) { "/relate imaginary#1234" } stub_licensed_features(related_issues: true)
it_behaves_like 'relate command'
end end
context 'relate a private issue' do it 'creates issue relation' do
let(:private_project) { create(:project, :private) } expect { execute(note) }.to change { IssueLink.count }.by(1)
let(:other_issue) { create(:issue, project: private_project) }
let(:issues_related) { [] }
let(:note_text) { "/relate #{other_issue.to_reference(project)}" }
it_behaves_like 'relate command'
end end
end end
end end
......
...@@ -753,6 +753,101 @@ describe QuickActions::InterpretService do ...@@ -753,6 +753,101 @@ describe QuickActions::InterpretService do
let(:issuable) { build(:merge_request, source_project: project) } let(:issuable) { build(:merge_request, source_project: project) }
end end
end end
context 'relate command' do
shared_examples 'relate command' do
it 'relates issues' do
service.execute(content, issue)
expect(IssueLink.where(source: issue).map(&:target)).to match_array(issues_related)
end
end
context 'user is member of group' do
before do
group.add_developer(user)
end
context 'relate a single issue' do
let(:other_issue) { create(:issue, project: project) }
let(:issues_related) { [other_issue] }
let(:content) { "/relate #{other_issue.to_reference}" }
it_behaves_like 'relate command'
end
context 'relate multiple issues at once' do
let(:second_issue) { create(:issue, project: project) }
let(:third_issue) { create(:issue, project: project) }
let(:issues_related) { [second_issue, third_issue] }
let(:content) { "/relate #{second_issue.to_reference} #{third_issue.to_reference}" }
it_behaves_like 'relate command'
end
context 'empty relate command' do
let(:issues_related) { [] }
let(:content) { '/relate' }
it_behaves_like 'relate command'
end
context 'already having related issues' do
let(:second_issue) { create(:issue, project: project) }
let(:third_issue) { create(:issue, project: project) }
let(:issues_related) { [second_issue, third_issue] }
let(:content) { "/relate #{third_issue.to_reference(project)}" }
before do
create(:issue_link, source: issue, target: second_issue)
end
it_behaves_like 'relate command'
end
context 'cross project' do
let(:another_group) { create(:group, :public) }
let(:other_project) { create(:project, group: another_group) }
before do
another_group.add_developer(current_user)
end
context 'relate a cross project issue' do
let(:other_issue) { create(:issue, project: other_project) }
let(:issues_related) { [other_issue] }
let(:content) { "/relate #{other_issue.to_reference(project)}" }
it_behaves_like 'relate command'
end
context 'relate multiple cross projects issues at once' do
let(:second_issue) { create(:issue, project: other_project) }
let(:third_issue) { create(:issue, project: other_project) }
let(:issues_related) { [second_issue, third_issue] }
let(:content) { "/relate #{second_issue.to_reference(project)} #{third_issue.to_reference(project)}" }
it_behaves_like 'relate command'
end
context 'relate a non-existing issue' do
let(:issues_related) { [] }
let(:content) { "/relate imaginary#1234" }
it_behaves_like 'relate command'
end
context 'relate a private issue' do
let(:private_project) { create(:project, :private) }
let(:other_issue) { create(:issue, project: private_project) }
let(:issues_related) { [] }
let(:content) { "/relate #{other_issue.to_reference(project)}" }
it_behaves_like 'relate command'
end
end
end
end
end end
describe '#explain' do describe '#explain' do
......
...@@ -8178,6 +8178,9 @@ msgstr "" ...@@ -8178,6 +8178,9 @@ msgstr ""
msgid "Mark this issue as a duplicate of another issue" msgid "Mark this issue as a duplicate of another issue"
msgstr "" msgstr ""
msgid "Mark this issue as related to another issue"
msgstr ""
msgid "Mark todo as done" msgid "Mark todo as done"
msgstr "" msgstr ""
...@@ -8193,6 +8196,9 @@ msgstr "" ...@@ -8193,6 +8196,9 @@ msgstr ""
msgid "Marks this issue as a duplicate of %{duplicate_reference}." msgid "Marks this issue as a duplicate of %{duplicate_reference}."
msgstr "" msgstr ""
msgid "Marks this issue as related to %{issue_ref}."
msgstr ""
msgid "Marks todo as done." msgid "Marks todo as done."
msgstr "" msgstr ""
......
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