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
22637ca6
Commit
22637ca6
authored
Jul 09, 2020
by
Sarah Yasonik
Committed by
Douglas Barbosa Alexandre
Jul 09, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add system note for alert when creating issue
parent
7e4b0297
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
61 additions
and
4 deletions
+61
-4
app/helpers/system_note_helper.rb
app/helpers/system_note_helper.rb
+2
-1
app/models/system_note_metadata.rb
app/models/system_note_metadata.rb
+1
-1
app/services/alert_management/create_alert_issue_service.rb
app/services/alert_management/create_alert_issue_service.rb
+2
-0
app/services/system_note_service.rb
app/services/system_note_service.rb
+4
-0
app/services/system_notes/alert_management_service.rb
app/services/system_notes/alert_management_service.rb
+16
-0
changelogs/unreleased/sy-alert-issue-system-notes.yml
changelogs/unreleased/sy-alert-issue-system-notes.yml
+5
-0
spec/services/alert_management/create_alert_issue_service_spec.rb
...vices/alert_management/create_alert_issue_service_spec.rb
+4
-0
spec/services/system_note_service_spec.rb
spec/services/system_note_service_spec.rb
+12
-0
spec/services/system_notes/alert_management_service_spec.rb
spec/services/system_notes/alert_management_service_spec.rb
+15
-2
No files found.
app/helpers/system_note_helper.rb
View file @
22637ca6
...
...
@@ -32,7 +32,8 @@ module SystemNoteHelper
'designs_modified'
=>
'doc-image'
,
'designs_removed'
=>
'doc-image'
,
'designs_discussion_added'
=>
'doc-image'
,
'status'
=>
'status'
'status'
=>
'status'
,
'alert_issue_added'
=>
'issues'
}.
freeze
def
system_note_icon_name
(
note
)
...
...
app/models/system_note_metadata.rb
View file @
22637ca6
...
...
@@ -19,7 +19,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
status
alert_issue_added
]
.
freeze
validates
:note
,
presence:
true
...
...
app/services/alert_management/create_alert_issue_service.rb
View file @
22637ca6
...
...
@@ -21,6 +21,8 @@ module AlertManagement
return
error
(
result
.
message
,
issue
)
if
result
.
error?
return
error
(
object_errors
(
alert
),
issue
)
unless
associate_alert_with_issue
(
issue
)
SystemNoteService
.
new_alert_issue
(
alert
,
issue
,
user
)
result
end
...
...
app/services/system_note_service.rb
View file @
22637ca6
...
...
@@ -296,6 +296,10 @@ module SystemNoteService
::
SystemNotes
::
AlertManagementService
.
new
(
noteable:
alert
,
project:
alert
.
project
,
author:
author
).
change_alert_status
(
alert
)
end
def
new_alert_issue
(
alert
,
issue
,
author
)
::
SystemNotes
::
AlertManagementService
.
new
(
noteable:
alert
,
project:
alert
.
project
,
author:
author
).
new_alert_issue
(
alert
,
issue
)
end
private
def
merge_requests_service
(
noteable
,
project
,
author
)
...
...
app/services/system_notes/alert_management_service.rb
View file @
22637ca6
...
...
@@ -17,5 +17,21 @@ module SystemNotes
create_note
(
NoteSummary
.
new
(
noteable
,
project
,
author
,
body
,
action:
'status'
))
end
# Called when an issue is created based on an AlertManagement::Alert
#
# alert - AlertManagement::Alert object.
# issue - Issue object.
#
# Example Note text:
#
# "created issue #17 for this alert"
#
# Returns the created Note object
def
new_alert_issue
(
alert
,
issue
)
body
=
"created issue
#{
issue
.
to_reference
(
project
)
}
for this alert"
create_note
(
NoteSummary
.
new
(
noteable
,
project
,
author
,
body
,
action:
'alert_issue_added'
))
end
end
end
changelogs/unreleased/sy-alert-issue-system-notes.yml
0 → 100644
View file @
22637ca6
---
title
:
Add system note for alert when creating issue
merge_request
:
36370
author
:
type
:
added
spec/services/alert_management/create_alert_issue_service_spec.rb
View file @
22637ca6
...
...
@@ -46,6 +46,10 @@ RSpec.describe AlertManagement::CreateAlertIssueService do
expect
(
alert
.
reload
.
issue_id
).
to
eq
(
created_issue
.
id
)
end
it
'creates a system note'
do
expect
{
execute
}.
to
change
{
alert
.
reload
.
notes
.
count
}.
by
(
1
)
end
end
shared_examples
'setting an issue attributes'
do
...
...
spec/services/system_note_service_spec.rb
View file @
22637ca6
...
...
@@ -693,4 +693,16 @@ RSpec.describe SystemNoteService do
described_class
.
change_alert_status
(
alert
,
author
)
end
end
describe
'.new_alert_issue'
do
let
(
:alert
)
{
build
(
:alert_management_alert
,
:with_issue
)
}
it
'calls AlertManagementService'
do
expect_next_instance_of
(
SystemNotes
::
AlertManagementService
)
do
|
service
|
expect
(
service
).
to
receive
(
:new_alert_issue
).
with
(
alert
,
alert
.
issue
)
end
described_class
.
new_alert_issue
(
alert
,
alert
.
issue
,
author
)
end
end
end
spec/services/system_notes/alert_management_service_spec.rb
View file @
22637ca6
...
...
@@ -5,8 +5,7 @@ require 'spec_helper'
RSpec
.
describe
::
SystemNotes
::
AlertManagementService
do
let_it_be
(
:author
)
{
create
(
:user
)
}
let_it_be
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:noteable
)
{
create
(
:alert_management_alert
,
:acknowledged
,
project:
project
)
}
let_it_be
(
:noteable
)
{
create
(
:alert_management_alert
,
:with_issue
,
:acknowledged
,
project:
project
)
}
describe
'#change_alert_status'
do
subject
{
described_class
.
new
(
noteable:
noteable
,
project:
project
,
author:
author
).
change_alert_status
(
noteable
)
}
...
...
@@ -19,4 +18,18 @@ RSpec.describe ::SystemNotes::AlertManagementService do
expect
(
subject
.
note
).
to
eq
(
"changed the status to **Acknowledged**"
)
end
end
describe
'#new_alert_issue'
do
let_it_be
(
:issue
)
{
noteable
.
issue
}
subject
{
described_class
.
new
(
noteable:
noteable
,
project:
project
,
author:
author
).
new_alert_issue
(
noteable
,
issue
)
}
it_behaves_like
'a system note'
do
let
(
:action
)
{
'alert_issue_added'
}
end
it
'has the appropriate message'
do
expect
(
subject
.
note
).
to
eq
(
"created issue
#{
issue
.
to_reference
(
project
)
}
for this alert"
)
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