Commit 5832102a authored by minghuan lei's avatar minghuan lei Committed by Heinrich Lee Yu

Relate issues when being marked as duplicate

parent dc7aadbf
...@@ -25,3 +25,5 @@ module Issues ...@@ -25,3 +25,5 @@ module Issues
end end
end end
end end
Issues::DuplicateService.prepend_if_ee('EE::Issues::DuplicateService')
---
title: Relate issues when they are marked as duplicated
merge_request: 20161
author: minghuan lei
type: added
...@@ -60,7 +60,7 @@ The following quick actions are applicable to descriptions, discussions and thre ...@@ -60,7 +60,7 @@ The following quick actions are applicable to descriptions, discussions and thre
| `/remove_epic` | ✓ | | | Remove from epic **(ULTIMATE)** | | `/remove_epic` | ✓ | | | Remove from epic **(ULTIMATE)** |
| `/promote` | ✓ | | | Promote issue to epic **(ULTIMATE)** | | `/promote` | ✓ | | | Promote issue to epic **(ULTIMATE)** |
| `/confidential` | ✓ | | | Make confidential | | `/confidential` | ✓ | | | Make confidential |
| `/duplicate <#issue>` | ✓ | | | Mark this issue as a duplicate of another issue | | `/duplicate <#issue>` | ✓ | | | Mark this issue as a duplicate of another issue and relate them for **(STARTER)** |
| `/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 #issue1 #issue2` | ✓ | | | Mark issues as related **(STARTER)** | | `/relate #issue1 #issue2` | ✓ | | | Mark issues as related **(STARTER)** |
| `/move <path/to/project>` | ✓ | | | Move this issue to another project | | `/move <path/to/project>` | ✓ | | | Move this issue to another project |
......
# frozen_string_literal: true
module EE
module Issues
module DuplicateService
extend ::Gitlab::Utils::Override
override :execute
def execute(duplicate_issue, canonical_issue)
super
relate_two_issues(duplicate_issue, canonical_issue)
end
private
def relate_two_issues(duplicate_issue, canonical_issue)
params = { target_issuable: canonical_issue }
IssueLinks::CreateService.new(duplicate_issue, current_user, params).execute
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Issues::DuplicateService do
let(:user) { create(:user) }
let(:canonical_project) { create(:project) }
let(:duplicate_project) { create(:project) }
let(:canonical_issue) { create(:issue, project: canonical_project) }
let(:duplicate_issue) { create(:issue, project: duplicate_project) }
subject { described_class.new(duplicate_project, user, {}) }
describe '#execute' do
it 'relates the duplicate issues' do
canonical_project.add_reporter(user)
duplicate_project.add_reporter(user)
subject.execute(duplicate_issue, canonical_issue)
issue_link = IssueLink.last
expect(issue_link.source).to eq(duplicate_issue)
expect(issue_link.target).to eq(canonical_issue)
end
end
end
...@@ -689,8 +689,9 @@ describe Issues::UpdateService, :mailer do ...@@ -689,8 +689,9 @@ describe Issues::UpdateService, :mailer do
context 'valid canonical_issue_id' do context 'valid canonical_issue_id' do
it 'calls the duplicate service with both issues' do it 'calls the duplicate service with both issues' do
expect_any_instance_of(Issues::DuplicateService) expect_next_instance_of(Issues::DuplicateService) do |service|
.to receive(:execute).with(issue, canonical_issue) expect(service).to receive(:execute).with(issue, canonical_issue)
end
update_issue(canonical_issue_id: canonical_issue.id) update_issue(canonical_issue_id: canonical_issue.id)
end end
......
# frozen_string_literal: true
shared_examples 'duplicate quick action' do
context 'mark issue as duplicate' do
let(:original_issue) { create(:issue, project: project) }
context 'when the current user can update issues' do
it 'does not create a note, and marks the issue as a duplicate' do
add_note("/duplicate ##{original_issue.to_reference}")
expect(page).not_to have_content "/duplicate #{original_issue.to_reference}"
expect(page).to have_content "marked this issue as a duplicate of #{original_issue.to_reference}"
expect(issue.reload).to be_closed
end
end
context 'when the current user cannot update the issue' do
let(:guest) { create(:user) }
before do
project.add_guest(guest)
gitlab_sign_out
sign_in(guest)
visit project_issue_path(project, issue)
end
it 'does not create a note, and does not mark the issue as a duplicate' do
add_note("/duplicate ##{original_issue.to_reference}")
expect(page).not_to have_content "marked this issue as a duplicate of #{original_issue.to_reference}"
expect(issue.reload).to be_open
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