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
721175ec
Commit
721175ec
authored
Jun 02, 2020
by
Vitali Tatarintev
Committed by
James Lopez
Jun 02, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Automatically resolve alert when associated issue closes
parent
04d6297d
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
0 deletions
+53
-0
app/models/issue.rb
app/models/issue.rb
+16
-0
changelogs/unreleased/216142-resolve-alert-when-associated-issue-closes.yml
...sed/216142-resolve-alert-when-associated-issue-closes.yml
+5
-0
doc/user/project/operations/alert_management.md
doc/user/project/operations/alert_management.md
+3
-0
spec/models/issue_spec.rb
spec/models/issue_spec.rb
+29
-0
No files found.
app/models/issue.rb
View file @
721175ec
...
...
@@ -139,6 +139,10 @@ class Issue < ApplicationRecord
issue
.
closed_at
=
nil
issue
.
closed_by
=
nil
end
after_transition
any
=>
:closed
do
|
issue
|
issue
.
resolve_associated_alert_management_alert
end
end
# Alias to state machine .with_state_id method
...
...
@@ -352,6 +356,18 @@ class Issue < ApplicationRecord
@design_collection
||=
::
DesignManagement
::
DesignCollection
.
new
(
self
)
end
def
resolve_associated_alert_management_alert
return
unless
alert_management_alert
return
if
alert_management_alert
.
resolve
Gitlab
::
AppLogger
.
warn
(
message:
'Cannot resolve an associated Alert Management alert'
,
issue_id:
id
,
alert_id:
alert_management_alert
.
id
,
alert_errors:
alert_management_alert
.
errors
.
messages
)
end
private
def
ensure_metrics
...
...
changelogs/unreleased/216142-resolve-alert-when-associated-issue-closes.yml
0 → 100644
View file @
721175ec
---
title
:
Automatically resolve alert when associated issue closes
merge_request
:
33278
author
:
type
:
added
doc/user/project/operations/alert_management.md
View file @
721175ec
...
...
@@ -89,3 +89,6 @@ The Alert Management detail view enables you to create an issue with a
description automatically populated from an alert. To create the issue,
click the
**Create Issue**
button. You can then view the issue from the
alert by clicking the
**View Issue**
button.
Closing a GitLab issue associated with an alert changes the alert's status to Resolved.
See
[
Alert Management statuses
](
#alert-management-statuses
)
for more details about statuses.
spec/models/issue_spec.rb
View file @
721175ec
...
...
@@ -186,6 +186,35 @@ describe Issue do
expect
{
issue
.
close
}.
to
change
{
issue
.
state_id
}.
from
(
open_state
).
to
(
closed_state
)
end
context
'when there is an associated Alert Management Alert'
do
context
'when alert can be resolved'
do
let!
(
:alert
)
{
create
(
:alert_management_alert
,
project:
issue
.
project
,
issue:
issue
)
}
it
'resolves an alert'
do
expect
{
issue
.
close
}.
to
change
{
alert
.
reload
.
resolved?
}.
to
(
true
)
end
end
context
'when alert cannot be resolved'
do
let!
(
:alert
)
{
create
(
:alert_management_alert
,
:with_validation_errors
,
project:
issue
.
project
,
issue:
issue
)
}
before
do
allow
(
Gitlab
::
AppLogger
).
to
receive
(
:warn
).
and_call_original
end
it
'writes a warning into the log'
do
issue
.
close
expect
(
Gitlab
::
AppLogger
).
to
have_received
(
:warn
).
with
(
message:
'Cannot resolve an associated Alert Management alert'
,
issue_id:
issue
.
id
,
alert_id:
alert
.
id
,
alert_errors:
{
hosts:
[
'hosts array is over 255 chars'
]
}
)
end
end
end
end
describe
'#reopen'
do
...
...
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