Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
1aa3921d
Commit
1aa3921d
authored
May 26, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a note when an Issue or Merge Request's title changes
parent
0ec1e4c0
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
96 additions
and
8 deletions
+96
-8
CHANGELOG
CHANGELOG
+1
-0
app/services/issuable_base_service.rb
app/services/issuable_base_service.rb
+5
-0
app/services/issues/update_service.rb
app/services/issues/update_service.rb
+4
-0
app/services/merge_requests/update_service.rb
app/services/merge_requests/update_service.rb
+4
-0
app/services/system_note_service.rb
app/services/system_note_service.rb
+19
-0
spec/services/issues/update_service_spec.rb
spec/services/issues/update_service_spec.rb
+21
-4
spec/services/merge_requests/update_service_spec.rb
spec/services/merge_requests/update_service_spec.rb
+21
-4
spec/services/system_note_service_spec.rb
spec/services/system_note_service_spec.rb
+21
-0
No files found.
CHANGELOG
View file @
1aa3921d
...
...
@@ -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
...
...
app/services/issuable_base_service.rb
View file @
1aa3921d
...
...
@@ -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
app/services/issues/update_service.rb
View file @
1aa3921d
...
...
@@ -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
...
...
app/services/merge_requests/update_service.rb
View file @
1aa3921d
...
...
@@ -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
...
...
app/services/system_note_service.rb
View file @
1aa3921d
...
...
@@ -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
...
...
spec/services/issues/update_service_spec.rb
View file @
1aa3921d
...
...
@@ -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
spec/services/merge_requests/update_service_spec.rb
View file @
1aa3921d
...
...
@@ -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
spec/services/system_note_service_spec.rb
View file @
1aa3921d
...
...
@@ -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
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment