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
86ea121d
Commit
86ea121d
authored
Jul 16, 2020
by
Sean Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move system note send into close service
- Update issue spec - Fix other specs
parent
04cf1dbb
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
45 additions
and
41 deletions
+45
-41
app/models/issue.rb
app/models/issue.rb
+1
-4
app/services/issues/close_service.rb
app/services/issues/close_service.rb
+7
-1
app/services/system_notes/alert_management_service.rb
app/services/system_notes/alert_management_service.rb
+0
-1
spec/models/issue_spec.rb
spec/models/issue_spec.rb
+35
-35
spec/services/issues/close_service_spec.rb
spec/services/issues/close_service_spec.rb
+2
-0
No files found.
app/models/issue.rb
View file @
86ea121d
...
...
@@ -362,10 +362,7 @@ class Issue < ApplicationRecord
def
resolve_associated_alert_management_alert
(
user
)
return
unless
alert_management_alert
if
alert_management_alert
.
resolve
SystemNoteService
.
closed_alert_issue
(
alert_management_alert
,
self
,
user
)
return
end
return
true
if
alert_management_alert
.
resolve
Gitlab
::
AppLogger
.
warn
(
message:
'Cannot resolve an associated Alert Management alert'
,
...
...
app/services/issues/close_service.rb
View file @
86ea121d
...
...
@@ -33,7 +33,7 @@ module Issues
notification_service
.
async
.
close_issue
(
issue
,
current_user
,
closed_via:
closed_via
)
if
notifications
todo_service
.
close_issue
(
issue
,
current_user
)
issue
.
resolve_associated_alert_management_alert
(
current_user
)
resolve_alert
(
issue
)
execute_hooks
(
issue
,
'close'
)
invalidate_cache_counts
(
issue
,
users:
issue
.
assignees
)
issue
.
update_project_counter_caches
...
...
@@ -59,6 +59,12 @@ module Issues
SystemNoteService
.
change_status
(
issue
,
issue
.
project
,
current_user
,
issue
.
state
,
current_commit
)
end
def
resolve_alert
(
issue
)
return
unless
issue
.
resolve_associated_alert_management_alert
(
current_user
)
SystemNoteService
.
closed_alert_issue
(
issue
.
alert_management_alert
,
issue
,
current_user
)
end
def
store_first_mentioned_in_commit_at
(
issue
,
merge_request
)
metrics
=
issue
.
metrics
return
if
metrics
.
nil?
||
metrics
.
first_mentioned_in_commit_at
...
...
app/services/system_notes/alert_management_service.rb
View file @
86ea121d
...
...
@@ -49,6 +49,5 @@ module SystemNotes
create_note
(
NoteSummary
.
new
(
noteable
,
project
,
author
,
body
,
action:
'alert_issue_added'
))
end
end
end
spec/models/issue_spec.rb
View file @
86ea121d
...
...
@@ -168,41 +168,6 @@ RSpec.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
(
user
)
}.
to
change
{
alert
.
reload
.
resolved?
}.
to
(
true
)
end
it
'creates a system note'
do
expect
(
SystemNoteService
).
to
receive
(
:closed_alert_issue
).
with
(
alert
,
issue
,
instance_of
(
User
))
issue
.
close
(
user
)
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
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
...
...
@@ -404,6 +369,41 @@ RSpec.describe Issue do
end
end
describe
'#resolve_associated_alert_management_alert'
do
let
(
:issue
)
{
create
(
:issue
)
}
subject
{
issue
.
resolve_associated_alert_management_alert
(
user
)
}
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
{
subject
}.
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
subject
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
'#suggested_branch_name'
do
let
(
:repository
)
{
double
}
...
...
spec/services/issues/close_service_spec.rb
View file @
86ea121d
...
...
@@ -255,6 +255,8 @@ RSpec.describe Issues::CloseService do
it
'resolves associated alert'
do
alert
=
create
(
:alert_management_alert
,
issue:
issue
,
project:
project
)
expect
(
SystemNoteService
).
to
receive
(
:closed_alert_issue
).
with
(
alert
,
issue
,
instance_of
(
User
))
close_issue
expect
(
alert
.
reload
.
resolved?
).
to
eq
(
true
)
...
...
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