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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
12cdc722
Commit
12cdc722
authored
Mar 27, 2020
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create system note when health status is updated
Create system note when issue health status is updated
parent
c3437e66
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
120 additions
and
6 deletions
+120
-6
app/models/system_note_metadata.rb
app/models/system_note_metadata.rb
+2
-2
ee/app/services/ee/issuable/common_system_notes_service.rb
ee/app/services/ee/issuable/common_system_notes_service.rb
+11
-1
ee/app/services/ee/system_note_service.rb
ee/app/services/ee/system_note_service.rb
+16
-0
ee/app/services/ee/system_notes/issuables_service.rb
ee/app/services/ee/system_notes/issuables_service.rb
+16
-0
ee/changelogs/unreleased/issue_212371.yml
ee/changelogs/unreleased/issue_212371.yml
+5
-0
ee/spec/services/ee/issuable/common_system_notes_service_spec.rb
.../services/ee/issuable/common_system_notes_service_spec.rb
+30
-3
ee/spec/services/ee/system_notes/issuables_service_spec.rb
ee/spec/services/ee/system_notes/issuables_service_spec.rb
+30
-0
ee/spec/services/system_note_service_spec.rb
ee/spec/services/system_note_service_spec.rb
+10
-0
No files found.
app/models/system_note_metadata.rb
View file @
12cdc722
...
...
@@ -16,8 +16,8 @@ class SystemNoteMetadata < ApplicationRecord
ICON_TYPES
=
%w[
commit description merge confidential visible label assignee cross_reference
title time_tracking branch milestone discussion task moved
opened closed merged duplicate locked unlocked
outdated tag due_date pinned_embed cherry_pick
opened closed merged duplicate locked unlocked
outdated
tag due_date pinned_embed cherry_pick health_status
]
.
freeze
validates
:note
,
presence:
true
...
...
ee/app/services/ee/issuable/common_system_notes_service.rb
View file @
12cdc722
...
...
@@ -12,7 +12,11 @@ module EE
ActiveRecord
::
Base
.
no_touching
do
handle_weight_change
(
is_update
)
handle_date_change_note
if
is_update
if
is_update
handle_date_change_note
handle_health_status_change
end
end
end
...
...
@@ -40,6 +44,12 @@ module EE
end
end
def
handle_health_status_change
return
unless
issuable
.
previous_changes
.
include?
(
'health_status'
)
::
SystemNoteService
.
change_health_status_note
(
issuable
,
issuable
.
project
,
current_user
)
end
def
weight_changes_tracking_enabled?
!
issuable
.
is_a?
(
Epic
)
&&
::
Feature
.
enabled?
(
:track_issue_weight_change_events
,
issuable
.
project
)
end
...
...
ee/app/services/ee/system_note_service.rb
View file @
12cdc722
...
...
@@ -110,6 +110,22 @@ module EE
::
SystemNotes
::
IssuablesService
.
new
(
noteable:
noteable
,
project:
project
,
author:
author
).
change_weight_note
end
# Called when the health_stauts of an Issue is changed
#
# noteable - Noteable object
# project - Project owning noteable
# author - User performing the change
#
# Example Note text:
#
# "removed the health status"
# "changed health status to 'at risk'"
#
# Returns the created Note object
def
change_health_status_note
(
noteable
,
project
,
author
)
::
SystemNotes
::
IssuablesService
.
new
(
noteable:
noteable
,
project:
project
,
author:
author
).
change_health_status_note
end
# Called when the start or end date of an Issuable is changed
#
# noteable - Noteable object
...
...
ee/app/services/ee/system_notes/issuables_service.rb
View file @
12cdc722
...
...
@@ -44,6 +44,22 @@ module EE
create_note
(
NoteSummary
.
new
(
noteable
,
project
,
author
,
body
,
action:
'weight'
))
end
# Called when the health_status of an Issue is changed
#
# Example Note text:
#
# "removed the health status"
#
# "changed health status to at risk"
#
# Returns the created Note object
def
change_health_status_note
health_status
=
noteable
.
health_status
&
.
humanize
(
capitalize:
false
)
body
=
health_status
?
"changed health status to **
#{
health_status
}
**"
:
'removed the health status'
create_note
(
NoteSummary
.
new
(
noteable
,
project
,
author
,
body
,
action:
'health_status'
))
end
end
end
end
ee/changelogs/unreleased/issue_212371.yml
0 → 100644
View file @
12cdc722
---
title
:
Create system note when health status is updated
merge_request
:
28232
author
:
type
:
added
ee/spec/services/ee/issuable/common_system_notes_service_spec.rb
View file @
12cdc722
...
...
@@ -23,6 +23,34 @@ describe Issuable::CommonSystemNotesService do
end
end
context
'when health status is updated'
do
before
do
issuable
.
update!
(
health_status:
2
)
end
context
'when setting a health_status'
do
it
'creates system note'
do
expect
do
described_class
.
new
(
project
,
user
).
execute
(
issuable
,
old_labels:
[])
end
.
to
change
{
Note
.
count
}.
from
(
0
).
to
(
1
)
expect
(
Note
.
last
.
note
).
to
eq
(
'changed health status to **needs attention**'
)
end
end
context
'when health status is removed'
do
it
'creates system note'
do
issuable
.
update!
(
health_status:
nil
)
expect
do
described_class
.
new
(
project
,
user
).
execute
(
issuable
,
old_labels:
[])
end
.
to
change
{
Note
.
count
}.
from
(
0
).
to
(
1
)
expect
(
Note
.
last
.
note
).
to
eq
(
'removed the health status'
)
end
end
end
context
'when issuable is an epic'
do
let
(
:timestamp
)
{
Time
.
now
}
let
(
:issuable
)
{
create
(
:epic
,
end_date:
timestamp
)
}
...
...
@@ -49,11 +77,10 @@ describe Issuable::CommonSystemNotesService do
subject
{
described_class
.
new
(
project
,
user
).
execute
(
issuable
,
old_labels:
[],
is_update:
false
)
}
before
do
issuable
.
weight
=
5
issuable
.
save
issuable
.
update
(
weight:
5
,
health_status:
'at_risk'
)
end
it
'does not create
a common system note for weight
'
do
it
'does not create
common system notes
'
do
expect
{
subject
}.
not_to
change
{
issuable
.
notes
.
count
}
end
...
...
ee/spec/services/ee/system_notes/issuables_service_spec.rb
View file @
12cdc722
...
...
@@ -74,4 +74,34 @@ describe ::SystemNotes::IssuablesService do
end
end
end
describe
'#change_health_status_note'
do
context
'when health_status changed'
do
let
(
:noteable
)
{
create
(
:issue
,
project:
project
,
title:
'Lorem ipsum'
,
health_status:
'at_risk'
)
}
subject
{
service
.
change_health_status_note
}
it_behaves_like
'a system note'
do
let
(
:action
)
{
'health_status'
}
end
it
'sets the note text'
do
expect
(
subject
.
note
).
to
eq
"changed health status to **at risk**"
end
end
context
'when health_status removed'
do
let
(
:noteable
)
{
create
(
:issue
,
project:
project
,
title:
'Lorem ipsum'
,
health_status:
nil
)
}
subject
{
service
.
change_health_status_note
}
it_behaves_like
'a system note'
do
let
(
:action
)
{
'health_status'
}
end
it
'sets the note text'
do
expect
(
subject
.
note
).
to
eq
'removed the health status'
end
end
end
end
ee/spec/services/system_note_service_spec.rb
View file @
12cdc722
...
...
@@ -103,6 +103,16 @@ describe SystemNoteService do
end
end
describe
'.change_health_status_note'
do
it
'calls IssuableService'
do
expect_next_instance_of
(
::
SystemNotes
::
IssuablesService
)
do
|
service
|
expect
(
service
).
to
receive
(
:change_health_status_note
)
end
described_class
.
change_health_status_note
(
noteable
,
project
,
author
)
end
end
describe
'.change_epic_date_note'
do
let
(
:date_type
)
{
double
}
let
(
:date
)
{
double
}
...
...
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