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
a58295c3
Commit
a58295c3
authored
Jul 16, 2019
by
syasonik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support an alert template field to allow for customization
parent
c833bf01
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
14 deletions
+56
-14
ee/app/presenters/projects/prometheus/alert_presenter.rb
ee/app/presenters/projects/prometheus/alert_presenter.rb
+7
-0
ee/app/services/incident_management/create_issue_service.rb
ee/app/services/incident_management/create_issue_service.rb
+9
-3
ee/spec/services/incident_management/create_issue_service_spec.rb
...services/incident_management/create_issue_service_spec.rb
+40
-11
No files found.
ee/app/presenters/projects/prometheus/alert_presenter.rb
View file @
a58295c3
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
module
Projects
module
Projects
module
Prometheus
module
Prometheus
class
AlertPresenter
<
Gitlab
::
View
::
Presenter
::
Delegated
class
AlertPresenter
<
Gitlab
::
View
::
Presenter
::
Delegated
RESERVED_ANNOTATIONS
=
%w(gitlab_incident_markdown)
def
full_title
def
full_title
[
environment_name
,
alert_title
].
compact
.
join
(
': '
)
[
environment_name
,
alert_title
].
compact
.
join
(
': '
)
end
end
...
@@ -40,6 +42,10 @@ module Projects
...
@@ -40,6 +42,10 @@ module Projects
MARKDOWN
MARKDOWN
end
end
def
alert_markdown
annotations
.
find
{
|
annotation
|
annotation
.
label
==
'gitlab_incident_markdown'
}
&
.
value
end
private
private
def
alert_title
def
alert_title
...
@@ -64,6 +70,7 @@ module Projects
...
@@ -64,6 +70,7 @@ module Projects
def
annotation_list
def
annotation_list
strong_memoize
(
:annotation_list
)
do
strong_memoize
(
:annotation_list
)
do
annotations
annotations
.
reject
{
|
annotation
|
RESERVED_ANNOTATIONS
.
include?
(
annotation
.
label
)
}
.
map
{
|
annotation
|
bullet
(
annotation
.
label
,
annotation
.
value
)
}
.
map
{
|
annotation
|
bullet
(
annotation
.
label
,
annotation
.
value
)
}
.
join
(
"
\n
"
)
.
join
(
"
\n
"
)
end
end
...
...
ee/app/services/incident_management/create_issue_service.rb
View file @
a58295c3
...
@@ -33,17 +33,23 @@ module IncidentManagement
...
@@ -33,17 +33,23 @@ module IncidentManagement
end
end
def
issue_description
def
issue_description
return
alert_summary
unless
issue_template_content
horizontal_line
=
"
\n
---
\n\n
"
horizontal_line
=
"
\n
---
\n\n
"
alert_summary
+
horizontal_line
+
issue_template_content
[
alert_summary
,
alert_markdown
,
issue_template_content
].
compact
.
join
(
horizontal_line
)
end
end
def
alert_summary
def
alert_summary
alert
.
issue_summary_markdown
alert
.
issue_summary_markdown
end
end
def
alert_markdown
alert
.
alert_markdown
end
def
alert
def
alert
strong_memoize
(
:alert
)
do
strong_memoize
(
:alert
)
do
Gitlab
::
Alerting
::
Alert
.
new
(
project:
project
,
payload:
params
).
present
Gitlab
::
Alerting
::
Alert
.
new
(
project:
project
,
payload:
params
).
present
...
...
ee/spec/services/incident_management/create_issue_service_spec.rb
View file @
a58295c3
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
require
'spec_helper'
require
'spec_helper'
describe
IncidentManagement
::
CreateIssueService
do
describe
IncidentManagement
::
CreateIssueService
do
l
et
(
:project
)
{
create
(
:project
,
:repository
)
}
s
et
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:service
)
{
described_class
.
new
(
project
,
nil
,
alert_payload
)
}
let
(
:service
)
{
described_class
.
new
(
project
,
nil
,
alert_payload
)
}
let
(
:alert_starts_at
)
{
Time
.
now
}
let
(
:alert_starts_at
)
{
Time
.
now
}
let
(
:alert_title
)
{
'TITLE'
}
let
(
:alert_title
)
{
'TITLE'
}
...
@@ -20,7 +20,7 @@ describe IncidentManagement::CreateIssueService do
...
@@ -20,7 +20,7 @@ describe IncidentManagement::CreateIssueService do
Gitlab
::
Alerting
::
Alert
.
new
(
project:
project
,
payload:
alert_payload
).
present
Gitlab
::
Alerting
::
Alert
.
new
(
project:
project
,
payload:
alert_payload
).
present
end
end
let!
(
:setting
)
do
set
(
:setting
)
do
create
(
:project_incident_management_setting
,
project:
project
)
create
(
:project_incident_management_setting
,
project:
project
)
end
end
...
@@ -45,21 +45,16 @@ describe IncidentManagement::CreateIssueService do
...
@@ -45,21 +45,16 @@ describe IncidentManagement::CreateIssueService do
end
end
end
end
context
'with issue_template_content'
do
shared_examples
'GFM template'
do
before
do
create_issue_template
(
'bug'
,
issue_template_content
)
setting
.
update!
(
issue_template_key:
'bug'
)
end
context
'plain content'
do
context
'plain content'
do
let
(
:
issue_
template_content
)
{
'some content'
}
let
(
:template_content
)
{
'some content'
}
it
'creates an issue appending issue template'
do
it
'creates an issue appending issue template'
do
expect
(
subject
).
to
include
(
status: :success
)
expect
(
subject
).
to
include
(
status: :success
)
expect
(
issue
.
description
).
to
include
(
alert_presenter
.
issue_summary_markdown
)
expect
(
issue
.
description
).
to
include
(
alert_presenter
.
issue_summary_markdown
)
expect
(
issue
.
description
).
to
include
(
summary_separator
)
expect
(
issue
.
description
).
to
include
(
summary_separator
)
expect
(
issue
.
description
).
to
include
(
issue_
template_content
)
expect
(
issue
.
description
).
to
include
(
template_content
)
end
end
end
end
...
@@ -67,7 +62,7 @@ describe IncidentManagement::CreateIssueService do
...
@@ -67,7 +62,7 @@ describe IncidentManagement::CreateIssueService do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:plain_text
)
{
'some content'
}
let
(
:plain_text
)
{
'some content'
}
let
(
:
issue_
template_content
)
do
let
(
:template_content
)
do
<<~
CONTENT
<<~
CONTENT
#{
plain_text
}
#{
plain_text
}
/due tomorrow
/due tomorrow
...
@@ -87,6 +82,40 @@ describe IncidentManagement::CreateIssueService do
...
@@ -87,6 +82,40 @@ describe IncidentManagement::CreateIssueService do
expect
(
issue
.
assignees
).
to
eq
([
user
])
expect
(
issue
.
assignees
).
to
eq
([
user
])
end
end
end
end
end
context
'with gitlab_incident_markdown'
do
let
(
:alert_annotations
)
do
{
title:
alert_title
,
gitlab_incident_markdown:
template_content
}
end
it_behaves_like
'GFM template'
end
context
'with issue_template_content'
do
before
do
create_issue_template
(
'bug'
,
template_content
)
setting
.
update!
(
issue_template_key:
'bug'
)
end
it_behaves_like
'GFM template'
context
'and gitlab_incident_markdown'
do
let
(
:template_content
)
{
'plain text'
}
let
(
:alt_template
)
{
'alernate text'
}
let
(
:alert_annotations
)
do
{
title:
alert_title
,
gitlab_incident_markdown:
alt_template
}
end
it
'includes both templates'
do
expect
(
subject
).
to
include
(
status: :success
)
expect
(
issue
.
description
).
to
include
(
alert_presenter
.
issue_summary_markdown
)
expect
(
issue
.
description
).
to
include
(
template_content
)
expect
(
issue
.
description
).
to
include
(
alt_template
)
expect
(
issue
.
description
.
count
(
summary_separator
)).
to
eq
(
2
)
end
end
private
private
...
...
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