summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-02-23 14:18:54 +0100
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-03-17 07:39:15 +0100
commit4cbe87d50ecfad9b97ba76f05935124676c96052 (patch)
treea89e4334342f1f3095f2e98c98b41e0690b58ade
parent5ed8a1e107b9b6f91257e5afdd370f0552078786 (diff)
downloadgitlab-ce-4cbe87d50ecfad9b97ba76f05935124676c96052.tar.gz
Rewrite references in issue description when moving it
-rw-r--r--app/services/issues/move_service.rb17
-rw-r--r--spec/services/issues/move_service_spec.rb25
2 files changed, 35 insertions, 7 deletions
diff --git a/app/services/issues/move_service.rb b/app/services/issues/move_service.rb
index d818ed86020..bba972382d9 100644
--- a/app/services/issues/move_service.rb
+++ b/app/services/issues/move_service.rb
@@ -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
diff --git a/spec/services/issues/move_service_spec.rb b/spec/services/issues/move_service_spec.rb
index 3b81cc90c61..8d9cc09ffc7 100644
--- a/spec/services/issues/move_service_spec.rb
+++ b/spec/services/issues/move_service_spec.rb
@@ -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