Commit 1aa3921d authored by Robert Speicher's avatar Robert Speicher

Add a note when an Issue or Merge Request's title changes

parent 0ec1e4c0
...@@ -15,6 +15,7 @@ v 7.12.0 (unreleased) ...@@ -15,6 +15,7 @@ v 7.12.0 (unreleased)
- Default extention for wiki pages is now .md instead of .markdown (Jeroen van Baarsen) - Default extention for wiki pages is now .md instead of .markdown (Jeroen van Baarsen)
- Add validation to wiki page creation (only [a-zA-Z0-9/_-] are allowed) (Jeroen van Baarsen) - Add validation to wiki page creation (only [a-zA-Z0-9/_-] are allowed) (Jeroen van Baarsen)
- Fix new/empty milestones showing 100% completion value (Jonah Bishop) - Fix new/empty milestones showing 100% completion value (Jonah Bishop)
- Add a note when an Issue or Merge Request's title changes
v 7.11.2 v 7.11.2
- no changes - no changes
......
...@@ -15,4 +15,9 @@ class IssuableBaseService < BaseService ...@@ -15,4 +15,9 @@ class IssuableBaseService < BaseService
SystemNoteService.change_label( SystemNoteService.change_label(
issuable, issuable.project, current_user, added_labels, removed_labels) issuable, issuable.project, current_user, added_labels, removed_labels)
end end
def create_title_change_note(issuable, old_title)
SystemNoteService.change_title(
issuable, issuable.project, current_user, old_title)
end
end end
...@@ -37,6 +37,10 @@ module Issues ...@@ -37,6 +37,10 @@ module Issues
notification_service.reassigned_issue(issue, current_user) notification_service.reassigned_issue(issue, current_user)
end end
if issue.previous_changes.include?('title')
create_title_change_note(issue, issue.previous_changes['title'].first)
end
issue.notice_added_references(issue.project, current_user) issue.notice_added_references(issue.project, current_user)
execute_hooks(issue, 'update') execute_hooks(issue, 'update')
end end
......
...@@ -50,6 +50,10 @@ module MergeRequests ...@@ -50,6 +50,10 @@ module MergeRequests
notification_service.reassigned_merge_request(merge_request, current_user) notification_service.reassigned_merge_request(merge_request, current_user)
end end
if merge_request.previous_changes.include?('title')
create_title_change_note(merge_request, merge_request.previous_changes['title'].first)
end
merge_request.notice_added_references(merge_request.project, current_user) merge_request.notice_added_references(merge_request.project, current_user)
execute_hooks(merge_request, 'update') execute_hooks(merge_request, 'update')
end end
......
...@@ -130,6 +130,25 @@ class SystemNoteService ...@@ -130,6 +130,25 @@ 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 the title of a Noteable is changed
#
# noteable - Noteable object that responds to `title`
# project - Project owning noteable
# author - User performing the change
# old_title - Previous String title
#
# Example Note text:
#
# "Title changed from **Old** to **New**"
#
# Returns the created Note object
def self.change_title(noteable, project, author, old_title)
return unless noteable.respond_to?(:title)
body = "Title changed from **#{old_title}** to **#{noteable.title}**"
create_note(noteable: noteable, project: project, author: author, note: body)
end
# Called when a Mentionable references a Noteable # Called when a Mentionable references a Noteable
# #
# noteable - Noteable object being referenced # noteable - Noteable object being referenced
......
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
describe Issues::UpdateService do describe Issues::UpdateService do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:user2) { create(:user) } let(:user2) { create(:user) }
let(:issue) { create(:issue) } let(:issue) { create(:issue, title: 'Old title') }
let(:label) { create(:label) } let(:label) { create(:label) }
let(:project) { issue.project } let(:project) { issue.project }
...@@ -12,7 +12,7 @@ describe Issues::UpdateService do ...@@ -12,7 +12,7 @@ describe Issues::UpdateService do
project.team << [user2, :developer] project.team << [user2, :developer]
end end
describe :execute do describe 'execute' do
context "valid params" do context "valid params" do
before do before do
opts = { opts = {
...@@ -40,15 +40,32 @@ describe Issues::UpdateService do ...@@ -40,15 +40,32 @@ describe Issues::UpdateService do
expect(email.subject).to include(issue.title) expect(email.subject).to include(issue.title)
end end
def find_note(starting_with)
@issue.notes.find do |n|
n && n.note.start_with?(starting_with)
end
end
it 'should create system note about issue reassign' do it 'should create system note about issue reassign' do
note = @issue.notes.last note = find_note('Reassigned to')
expect(note).not_to be_nil
expect(note.note).to include "Reassigned to \@#{user2.username}" expect(note.note).to include "Reassigned to \@#{user2.username}"
end end
it 'should create system note about issue label edit' do it 'should create system note about issue label edit' do
note = @issue.notes[1] note = find_note('Added ~')
expect(note).not_to be_nil
expect(note.note).to include "Added ~#{label.id} label" expect(note.note).to include "Added ~#{label.id} label"
end end
it 'creates system note about title change' do
note = find_note('Title changed')
expect(note).not_to be_nil
expect(note.note).to eq 'Title changed from **Old title** to **New title**'
end
end end
end end
end end
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
describe MergeRequests::UpdateService do describe MergeRequests::UpdateService do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:user2) { create(:user) } let(:user2) { create(:user) }
let(:merge_request) { create(:merge_request, :simple) } let(:merge_request) { create(:merge_request, :simple, title: 'Old title') }
let(:project) { merge_request.project } let(:project) { merge_request.project }
let(:label) { create(:label) } let(:label) { create(:label) }
...@@ -12,7 +12,7 @@ describe MergeRequests::UpdateService do ...@@ -12,7 +12,7 @@ describe MergeRequests::UpdateService do
project.team << [user2, :developer] project.team << [user2, :developer]
end end
describe :execute do describe 'execute' do
context 'valid params' do context 'valid params' do
let(:opts) do let(:opts) do
{ {
...@@ -51,15 +51,32 @@ describe MergeRequests::UpdateService do ...@@ -51,15 +51,32 @@ describe MergeRequests::UpdateService do
expect(email.subject).to include(merge_request.title) expect(email.subject).to include(merge_request.title)
end end
def find_note(starting_with)
@merge_request.notes.find do |n|
n && n.note.start_with?(starting_with)
end
end
it 'should create system note about merge_request reassign' do it 'should create system note about merge_request reassign' do
note = @merge_request.notes.last note = find_note('Reassigned to')
expect(note).not_to be_nil
expect(note.note).to include "Reassigned to \@#{user2.username}" expect(note.note).to include "Reassigned to \@#{user2.username}"
end end
it 'should create system note about merge_request label edit' do it 'should create system note about merge_request label edit' do
note = @merge_request.notes[1] note = find_note('Added ~')
expect(note).not_to be_nil
expect(note.note).to include "Added ~#{label.id} label" expect(note.note).to include "Added ~#{label.id} label"
end end
it 'creates system note about title change' do
note = find_note('Title changed')
expect(note).not_to be_nil
expect(note.note).to eq 'Title changed from **Old title** to **New title**'
end
end end
end end
end end
...@@ -207,6 +207,27 @@ describe SystemNoteService do ...@@ -207,6 +207,27 @@ describe SystemNoteService do
end end
end end
describe '.change_title' do
subject { described_class.change_title(noteable, project, author, 'Old title') }
context 'when noteable responds to `title`' do
it_behaves_like 'a system note'
it 'sets the note text' do
expect(subject.note).
to eq "Title changed from **Old title** to **#{noteable.title}**"
end
end
context 'when noteable does not respond to `title' do
let(:noteable) { double('noteable') }
it 'returns nil' do
expect(subject).to be_nil
end
end
end
describe '.cross_reference' do describe '.cross_reference' do
subject { described_class.cross_reference(noteable, mentioner, author) } subject { described_class.cross_reference(noteable, mentioner, author) }
......
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