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
bcf9daa8
Commit
bcf9daa8
authored
Oct 20, 2021
by
Vitali Tatarintev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a system note on resolve an incident
Create a system note when manually created incident is closed
parent
cc875bcf
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
58 additions
and
3 deletions
+58
-3
app/services/issues/close_service.rb
app/services/issues/close_service.rb
+2
-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
+6
-0
spec/services/issues/close_service_spec.rb
spec/services/issues/close_service_spec.rb
+24
-2
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
+10
-0
No files found.
app/services/issues/close_service.rb
View file @
bcf9daa8
...
...
@@ -96,7 +96,8 @@ module Issues
return
unless
issue
.
incident?
status
=
issue
.
incident_management_issuable_escalation_status
||
issue
.
build_incident_management_issuable_escalation_status
status
.
resolve
SystemNoteService
.
resolve_incident_status
(
issue
,
current_user
)
if
status
.
resolve
end
def
store_first_mentioned_in_commit_at
(
issue
,
merge_request
,
max_commit_lookup:
100
)
...
...
app/services/system_note_service.rb
View file @
bcf9daa8
...
...
@@ -327,6 +327,10 @@ module SystemNoteService
::
SystemNotes
::
IncidentService
.
new
(
noteable:
incident
,
project:
incident
.
project
,
author:
author
).
change_incident_severity
end
def
resolve_incident_status
(
incident
,
author
)
::
SystemNotes
::
IncidentService
.
new
(
noteable:
incident
,
project:
incident
.
project
,
author:
author
).
resolve_incident_status
end
def
log_resolving_alert
(
alert
,
monitoring_tool
)
::
SystemNotes
::
AlertManagementService
.
new
(
noteable:
alert
,
project:
alert
.
project
).
log_resolving_alert
(
monitoring_tool
)
end
...
...
app/services/system_notes/incident_service.rb
View file @
bcf9daa8
...
...
@@ -25,5 +25,11 @@ module SystemNotes
)
end
end
def
resolve_incident_status
body
=
'changed the status to **Resolved** by closing the incident'
create_note
(
NoteSummary
.
new
(
noteable
,
project
,
author
,
body
,
action:
'status'
))
end
end
end
spec/services/issues/close_service_spec.rb
View file @
bcf9daa8
...
...
@@ -84,7 +84,11 @@ RSpec.describe Issues::CloseService do
end
it
'does not change escalation status'
do
expect
{
service
.
execute
(
issue
)
}.
not_to
change
{
IncidentManagement
::
IssuableEscalationStatus
.
where
(
issue:
issue
).
count
}
resolved
=
IncidentManagement
::
Escalatable
::
STATUSES
[
:resolved
]
expect
{
service
.
execute
(
issue
)
}
.
to
not_change
{
IncidentManagement
::
IssuableEscalationStatus
.
where
(
issue:
issue
).
count
}
.
and
not_change
{
IncidentManagement
::
IssuableEscalationStatus
.
where
(
status:
resolved
).
count
}
end
context
'issue is incident type'
do
...
...
@@ -96,7 +100,7 @@ RSpec.describe Issues::CloseService do
it_behaves_like
'an incident management tracked event'
,
:incident_management_incident_closed
it
'creates a new escalation resolved escalation status'
,
:aggregate_failures
do
expect
{
service
.
execute
(
issue
)
}.
to
change
{
IncidentManagement
::
IssuableEscalationStatus
.
where
(
issue:
issue
).
count
}.
to
(
1
)
expect
{
service
.
execute
(
issue
)
}.
to
change
{
IncidentManagement
::
IssuableEscalationStatus
.
where
(
issue:
issue
).
count
}.
by
(
1
)
expect
(
issue
.
incident_management_issuable_escalation_status
).
to
be_resolved
end
...
...
@@ -109,6 +113,24 @@ RSpec.describe Issues::CloseService do
it
'changes escalations status to resolved'
do
expect
{
service
.
execute
(
issue
)
}.
to
change
{
issue
.
incident_management_issuable_escalation_status
.
reload
.
resolved?
}.
to
(
true
)
end
it
'adds a system note'
,
:aggregate_failures
do
expect
{
service
.
execute
(
issue
)
}.
to
change
{
issue
.
notes
.
count
}.
by
(
1
)
new_note
=
issue
.
notes
.
last
expect
(
new_note
.
note
).
to
eq
(
'changed the status to **Resolved** by closing the incident'
)
expect
(
new_note
.
author
).
to
eq
(
user
)
end
context
'when the escalation status did not change to resolved'
do
let
(
:escalation_status
)
{
instance_double
(
'IncidentManagement::IssuableEscalationStatus'
,
resolve:
false
)
}
it
'does not create a system note'
do
allow
(
issue
).
to
receive
(
:incident_management_issuable_escalation_status
).
and_return
(
escalation_status
)
expect
{
service
.
execute
(
issue
)
}.
not_to
change
{
issue
.
notes
.
count
}
end
end
end
end
end
...
...
spec/services/system_note_service_spec.rb
View file @
bcf9daa8
...
...
@@ -781,6 +781,18 @@ RSpec.describe SystemNoteService do
end
end
describe
'.resolve_incident_status'
do
let
(
:incident
)
{
build
(
:incident
,
:closed
)
}
it
'calls IncidentService'
do
expect_next_instance_of
(
SystemNotes
::
IncidentService
)
do
|
service
|
expect
(
service
).
to
receive
(
:resolve_incident_status
)
end
described_class
.
resolve_incident_status
(
incident
,
author
)
end
end
describe
'.log_resolving_alert'
do
let
(
:alert
)
{
build
(
:alert_management_alert
)
}
let
(
:monitoring_tool
)
{
'Prometheus'
}
...
...
spec/services/system_notes/incident_service_spec.rb
View file @
bcf9daa8
...
...
@@ -56,4 +56,14 @@ RSpec.describe ::SystemNotes::IncidentService do
end
end
end
describe
'#resolve_incident_status'
do
subject
(
:resolve_incident_status
)
{
described_class
.
new
(
noteable:
noteable
,
project:
project
,
author:
author
).
resolve_incident_status
}
it
'creates a new note about resolved incident'
,
:aggregate_failures
do
expect
{
resolve_incident_status
}.
to
change
{
noteable
.
notes
.
count
}.
by
(
1
)
expect
(
noteable
.
notes
.
last
.
note
).
to
eq
(
'changed the status to **Resolved** by closing the incident'
)
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