summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG1
-rw-r--r--app/services/issuable_base_service.rb5
-rw-r--r--app/services/issues/update_service.rb4
-rw-r--r--app/services/merge_requests/update_service.rb4
-rw-r--r--app/services/system_note_service.rb19
-rw-r--r--spec/services/issues/update_service_spec.rb25
-rw-r--r--spec/services/merge_requests/update_service_spec.rb25
-rw-r--r--spec/services/system_note_service_spec.rb21
8 files changed, 96 insertions, 8 deletions
diff --git a/CHANGELOG b/CHANGELOG
index df598502820..35f4d1f0c68 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -15,6 +15,7 @@ v 7.12.0 (unreleased)
- 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)
- 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
- no changes
diff --git a/app/services/issuable_base_service.rb b/app/services/issuable_base_service.rb
index 8960235b093..c5769a5ad27 100644
--- a/app/services/issuable_base_service.rb
+++ b/app/services/issuable_base_service.rb
@@ -15,4 +15,9 @@ class IssuableBaseService < BaseService
SystemNoteService.change_label(
issuable, issuable.project, current_user, added_labels, removed_labels)
end
+
+ def create_title_change_note(issuable, old_title)
+ SystemNoteService.change_title(
+ issuable, issuable.project, current_user, old_title)
+ end
end
diff --git a/app/services/issues/update_service.rb b/app/services/issues/update_service.rb
index 8f04a69287a..6af942a5ca4 100644
--- a/app/services/issues/update_service.rb
+++ b/app/services/issues/update_service.rb
@@ -37,6 +37,10 @@ module Issues
notification_service.reassigned_issue(issue, current_user)
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)
execute_hooks(issue, 'update')
end
diff --git a/app/services/merge_requests/update_service.rb b/app/services/merge_requests/update_service.rb
index 23af2656c37..34fd59d6927 100644
--- a/app/services/merge_requests/update_service.rb
+++ b/app/services/merge_requests/update_service.rb
@@ -50,6 +50,10 @@ module MergeRequests
notification_service.reassigned_merge_request(merge_request, current_user)
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)
execute_hooks(merge_request, 'update')
end
diff --git a/app/services/system_note_service.rb b/app/services/system_note_service.rb
index 0614f8689a4..1909ae0d6f1 100644
--- a/app/services/system_note_service.rb
+++ b/app/services/system_note_service.rb
@@ -130,6 +130,25 @@ class SystemNoteService
create_note(noteable: noteable, project: project, author: author, note: body)
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
#
# noteable - Noteable object being referenced
diff --git a/spec/services/issues/update_service_spec.rb b/spec/services/issues/update_service_spec.rb
index 6fc69e93628..b240d247e73 100644
--- a/spec/services/issues/update_service_spec.rb
+++ b/spec/services/issues/update_service_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
describe Issues::UpdateService do
let(:user) { create(:user) }
let(:user2) { create(:user) }
- let(:issue) { create(:issue) }
+ let(:issue) { create(:issue, title: 'Old title') }
let(:label) { create(:label) }
let(:project) { issue.project }
@@ -12,7 +12,7 @@ describe Issues::UpdateService do
project.team << [user2, :developer]
end
- describe :execute do
+ describe 'execute' do
context "valid params" do
before do
opts = {
@@ -40,15 +40,32 @@ describe Issues::UpdateService do
expect(email.subject).to include(issue.title)
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
- note = @issue.notes.last
+ note = find_note('Reassigned to')
+
+ expect(note).not_to be_nil
expect(note.note).to include "Reassigned to \@#{user2.username}"
end
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"
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
diff --git a/spec/services/merge_requests/update_service_spec.rb b/spec/services/merge_requests/update_service_spec.rb
index 916b01e1c45..bf9790c2beb 100644
--- a/spec/services/merge_requests/update_service_spec.rb
+++ b/spec/services/merge_requests/update_service_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
describe MergeRequests::UpdateService do
let(:user) { 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(:label) { create(:label) }
@@ -12,7 +12,7 @@ describe MergeRequests::UpdateService do
project.team << [user2, :developer]
end
- describe :execute do
+ describe 'execute' do
context 'valid params' do
let(:opts) do
{
@@ -51,15 +51,32 @@ describe MergeRequests::UpdateService do
expect(email.subject).to include(merge_request.title)
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
- 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}"
end
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"
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
diff --git a/spec/services/system_note_service_spec.rb b/spec/services/system_note_service_spec.rb
index 4e4cb6d19ed..6d8c71f94f9 100644
--- a/spec/services/system_note_service_spec.rb
+++ b/spec/services/system_note_service_spec.rb
@@ -207,6 +207,27 @@ describe SystemNoteService do
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
subject { described_class.cross_reference(noteable, mentioner, author) }