Commit 4cbe87d5 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Rewrite references in issue description when moving it

parent 5ed8a1e1
......@@ -45,7 +45,8 @@ module Issues
end
def open_new_issue
@issue_new.update(project: @project_new)
new_description = rewrite_references(@issue_old, @issue_old.description)
@issue_new.update(project: @project_new, description: new_description)
end
def rewrite_notes
......@@ -69,5 +70,19 @@ module Issues
def add_moved_to_note
SystemNoteService.noteable_moved(:to, @issue_old, @project_old, @issue_new, @current_user)
end
def rewrite_references(mentionable, text)
new_content = text.dup
references = mentionable.all_references
[:issues, :merge_requests, :milestones].each do |type|
references.public_send(type).each do |mentioned|
new_content.gsub!(mentioned.to_reference,
mentioned.to_reference(@project_new))
end
end
new_content
end
end
end
......@@ -4,8 +4,8 @@ describe Issues::MoveService, services: true do
let(:user) { create(:user) }
let(:title) { 'Some issue' }
let(:description) { 'Some issue description' }
let(:old_issue) { create(:issue, title: title, description: description) }
let(:old_project) { old_issue.project }
let(:old_project) { create(:project) }
let(:old_issue) { create(:issue, title: title, description: description, project: old_project) }
let(:new_project) { create(:project) }
let(:move_service) { described_class.new(old_project, user, move_params, old_issue) }
......@@ -61,13 +61,12 @@ describe Issues::MoveService, services: true do
expect(old_issue.closed?).to be true
end
it 'persists changes to old and new issue' do
expect(new_issue.changed?).to be false
expect(old_issue.changed?).to be false
it 'persists new issue' do
expect(new_issue.persisted?).to be true
end
end
context 'notes exist' do
context 'issue with notes' do
let(:note_contents) do
['Some system note 1', 'Some comment', 'Some system note 2']
end
......@@ -91,6 +90,20 @@ describe Issues::MoveService, services: true do
expect(new_notes.last).to match /^Moved from/
end
end
describe 'rewritting references' do
include_context 'issue move executed'
context 'issue reference' do
let(:another_issue) { create(:issue, project: old_project) }
let(:description) { "Some description #{another_issue.to_reference}" }
it 'rewrites referenced issues creating cross project reference' do
expect(new_issue.description)
.to eq "Some description #{old_project.to_reference}#{another_issue.to_reference}"
end
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