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
f484f3f8
Commit
f484f3f8
authored
Sep 15, 2020
by
Vitali Tatarintev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add SystemNodes::IncidentService class
Allows to add system notes on change severity status for incidents
parent
18f3c62f
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
78 additions
and
2 deletions
+78
-2
app/helpers/system_note_helper.rb
app/helpers/system_note_helper.rb
+2
-1
app/models/issuable_severity.rb
app/models/issuable_severity.rb
+7
-0
app/models/system_note_metadata.rb
app/models/system_note_metadata.rb
+1
-1
app/services/system_note_service.rb
app/services/system_note_service.rb
+4
-0
app/services/system_notes/incident_service.rb
app/services/system_notes/incident_service.rb
+20
-0
spec/services/system_note_service_spec.rb
spec/services/system_note_service_spec.rb
+12
-0
spec/services/system_notes/incident_service_spec.rb
spec/services/system_notes/incident_service_spec.rb
+32
-0
No files found.
app/helpers/system_note_helper.rb
View file @
f484f3f8
...
...
@@ -34,7 +34,8 @@ module SystemNoteHelper
'designs_discussion_added'
=>
'doc-image'
,
'status'
=>
'status'
,
'alert_issue_added'
=>
'issues'
,
'new_alert_added'
=>
'warning'
'new_alert_added'
=>
'warning'
,
'severity'
=>
'information-o'
}.
freeze
def
system_note_icon_name
(
note
)
...
...
app/models/issuable_severity.rb
View file @
f484f3f8
...
...
@@ -2,6 +2,13 @@
class
IssuableSeverity
<
ApplicationRecord
DEFAULT
=
'unknown'
SEVERITY_LABELS
=
{
unknown:
'Unknown'
,
low:
'Low - S4'
,
medium:
'Medium - S3'
,
high:
'High - S2'
,
critical:
'Critical - S1'
}.
freeze
belongs_to
:issue
...
...
app/models/system_note_metadata.rb
View file @
f484f3f8
...
...
@@ -20,7 +20,7 @@ class SystemNoteMetadata < ApplicationRecord
title time_tracking branch milestone discussion task moved
opened closed merged duplicate locked unlocked outdated
tag due_date pinned_embed cherry_pick health_status approved unapproved
status alert_issue_added relate unrelate new_alert_added
status alert_issue_added relate unrelate new_alert_added
severity
]
.
freeze
validates
:note
,
presence:
true
...
...
app/services/system_note_service.rb
View file @
f484f3f8
...
...
@@ -308,6 +308,10 @@ module SystemNoteService
::
SystemNotes
::
AlertManagementService
.
new
(
noteable:
alert
,
project:
alert
.
project
).
create_new_alert
(
monitoring_tool
)
end
def
change_incident_severity
(
incident
,
author
)
::
SystemNotes
::
IncidentService
.
new
(
noteable:
incident
,
project:
incident
.
project
,
author:
author
).
change_incident_severity
end
private
def
merge_requests_service
(
noteable
,
project
,
author
)
...
...
app/services/system_notes/incident_service.rb
0 → 100644
View file @
f484f3f8
# frozen_string_literal: true
module
SystemNotes
class
IncidentService
<
::
SystemNotes
::
BaseService
# Called when the severity of an Incident has changed
#
# Example Note text:
#
# "changed the severity to Medium - S3"
#
# Returns the created Note object
def
change_incident_severity
severity
=
noteable
.
severity
severity_label
=
IssuableSeverity
::
SEVERITY_LABELS
.
fetch
(
severity
.
to_sym
)
body
=
"changed the severity to **
#{
severity_label
}
**"
create_note
(
NoteSummary
.
new
(
noteable
,
project
,
author
,
body
,
action:
'severity'
))
end
end
end
spec/services/system_note_service_spec.rb
View file @
f484f3f8
...
...
@@ -741,4 +741,16 @@ RSpec.describe SystemNoteService do
described_class
.
create_new_alert
(
alert
,
monitoring_tool
)
end
end
describe
'.change_incident_severity'
do
let
(
:incident
)
{
build
(
:incident
)
}
it
'calls IncidentService'
do
expect_next_instance_of
(
SystemNotes
::
IncidentService
)
do
|
service
|
expect
(
service
).
to
receive
(
:change_incident_severity
)
end
described_class
.
change_incident_severity
(
incident
,
author
)
end
end
end
spec/services/system_notes/incident_service_spec.rb
0 → 100644
View file @
f484f3f8
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
::
SystemNotes
::
IncidentService
do
let_it_be
(
:author
)
{
create
(
:user
)
}
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:noteable
)
{
create
(
:incident
,
project:
project
)
}
let_it_be
(
:issuable_severity
)
{
create
(
:issuable_severity
,
issue:
noteable
,
severity: :medium
)
}
describe
'#change_incident_severity'
do
subject
(
:change_severity
)
{
described_class
.
new
(
noteable:
noteable
,
project:
project
,
author:
author
).
change_incident_severity
}
it_behaves_like
'a system note'
do
let
(
:action
)
{
'severity'
}
end
IssuableSeverity
.
severities
.
keys
.
each
do
|
severity
|
context
"with
#{
severity
}
severity"
do
before
do
issuable_severity
.
update!
(
severity:
severity
)
end
it
'has the appropriate message'
do
severity_label
=
IssuableSeverity
::
SEVERITY_LABELS
.
fetch
(
severity
.
to_sym
)
expect
(
change_severity
.
note
).
to
eq
(
"changed the severity to **
#{
severity_label
}
**"
)
end
end
end
end
end
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