Improve system notes that are added when issue is moved
This commit is contained in:
parent
69b89d4ec8
commit
9882802a8b
4 changed files with 68 additions and 22 deletions
|
@ -4,6 +4,7 @@ module Issues
|
||||||
@issue_old = issue_old
|
@issue_old = issue_old
|
||||||
@issue_new = issue_old.dup
|
@issue_new = issue_old.dup
|
||||||
@project_new = project_new
|
@project_new = project_new
|
||||||
|
@project_old = @project
|
||||||
|
|
||||||
open_new_issue
|
open_new_issue
|
||||||
rewrite_notes
|
rewrite_notes
|
||||||
|
@ -33,10 +34,11 @@ module Issues
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_note_moved_from
|
def add_note_moved_from
|
||||||
|
SystemNoteService.noteable_moved(:from, @issue_new, @project_new, @issue_old, @current_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_note_moved_to
|
def add_note_moved_to
|
||||||
SystemNoteService.issue_moved_to_another_project(@issue_old, @project, @project_new, @current_user)
|
SystemNoteService.noteable_moved(:to, @issue_old, @project_old, @issue_new, @current_user)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
# Used for creating system notes (e.g., when a user references a merge request
|
# Used for creating system notes (e.g., when a user references a merge request
|
||||||
# from an issue, an issue's assignee changes, an issue is closed, etc.)
|
# from an issue, an issue's assignee changes, an issue is closed, etc.)
|
||||||
class SystemNoteService
|
class SystemNoteService
|
||||||
|
extend GitlabMarkdownHelper
|
||||||
# Called when commits are added to a Merge Request
|
# Called when commits are added to a Merge Request
|
||||||
#
|
#
|
||||||
# noteable - Noteable object
|
# noteable - Noteable object
|
||||||
|
@ -388,20 +389,26 @@ class SystemNoteService
|
||||||
create_note(noteable: noteable, project: project, author: author, note: body)
|
create_note(noteable: noteable, project: project, author: author, note: body)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Called when issue has been moved to another project
|
# Called when noteable has been moved to another project
|
||||||
#
|
#
|
||||||
# issue - Issue that has been moved to another project
|
# direction - symbol, :to or :from
|
||||||
# project_from - Source project of the issue
|
# noteable - Noteable object
|
||||||
# project_to - Destination project for the issue
|
# noteable_ref - Referenced noteable
|
||||||
# author - User performing the move
|
# author - User performing the move
|
||||||
#
|
#
|
||||||
# Example Note text:
|
# Example Note text:
|
||||||
#
|
#
|
||||||
# "This issue has been moved to SomeNamespace / SomeProject"
|
# "Moved to project_new/#11"
|
||||||
#
|
#
|
||||||
# Returns the created Note object
|
# Returns the created Note object
|
||||||
def self.issue_moved_to_another_project(issue, project_from, project_to, author)
|
def self.noteable_moved(direction, noteable, project, noteable_ref, author)
|
||||||
body = "This issue has been moved to #{project_to.to_reference} by #{author.to_reference}"
|
unless [:to, :from].include?(direction)
|
||||||
create_note(noteable: issue, project: project_from, author: author, note: body)
|
raise StandardError, "Invalid direction `#{direction}`"
|
||||||
|
end
|
||||||
|
|
||||||
|
cross_reference = cross_project_reference(noteable_ref.project, noteable_ref)
|
||||||
|
|
||||||
|
body = "Moved #{direction} #{cross_reference}"
|
||||||
|
create_note(noteable: noteable, project: project, author: author, note: body)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,7 +20,11 @@ describe Issues::MoveService, services: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should add system note to old issue' do
|
it 'should add system note to old issue' do
|
||||||
expect(issue.notes.last.note).to match /This issue has been moved to/
|
expect(issue.notes.last.note).to match /^Moved to/
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should add system note to new issue' do
|
||||||
|
expect(new_issue.notes.last.note).to match /^Moved from/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -441,23 +441,56 @@ describe SystemNoteService, services: true do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '.issue_moved_to_another_project' do
|
describe '.noteable_moved' do
|
||||||
subject do
|
|
||||||
described_class.issue_moved_to_another_project(noteable, project, new_project, author)
|
|
||||||
end
|
|
||||||
|
|
||||||
let(:new_project) { create(:project) }
|
let(:new_project) { create(:project) }
|
||||||
|
let(:new_noteable) { create(:issue, project: new_project) }
|
||||||
|
|
||||||
it 'should notify about issue being moved' do
|
subject do
|
||||||
expect(subject.note).to match /This issue has been moved to/
|
described_class.noteable_moved(direction, noteable, project, new_noteable, author)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should mention destination project' do
|
shared_examples 'cross project mentionable' do
|
||||||
expect(subject.note).to include new_project.to_reference
|
include GitlabMarkdownHelper
|
||||||
|
|
||||||
|
it 'should contain cross reference to new noteable' do
|
||||||
|
expect(subject.note).to include cross_project_reference(new_project, new_noteable)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should mention referenced noteable' do
|
||||||
|
expect(subject.note).to include new_noteable.to_reference
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should mention referenced project' do
|
||||||
|
expect(subject.note).to include new_project.to_reference
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should mention author of that change' do
|
context 'moved to' do
|
||||||
expect(subject.note).to include author.to_reference
|
let(:direction) { :to }
|
||||||
|
|
||||||
|
it_behaves_like 'cross project mentionable'
|
||||||
|
|
||||||
|
it 'should notify about noteable being moved to' do
|
||||||
|
expect(subject.note).to match /Moved to/
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'moved from' do
|
||||||
|
let(:direction) { :from }
|
||||||
|
|
||||||
|
it_behaves_like 'cross project mentionable'
|
||||||
|
|
||||||
|
it 'should notify about noteable being moved from' do
|
||||||
|
expect(subject.note).to match /Moved from/
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'invalid direction' do
|
||||||
|
let (:direction) { :invalid }
|
||||||
|
|
||||||
|
it 'should raise error' do
|
||||||
|
expect { subject }.to raise_error StandardError, /Invalid direction/
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue