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
129dfa33
Commit
129dfa33
authored
Jul 13, 2020
by
Vitali Tatarintev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check whether PagerDuty setting is active
Check whether PagerDuty setting is active when creating incident issue
parent
60fa2032
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
36 deletions
+63
-36
app/services/concerns/incident_management/settings.rb
app/services/concerns/incident_management/settings.rb
+2
-0
app/services/incident_management/pager_duty/create_incident_issue_service.rb
...nt_management/pager_duty/create_incident_issue_service.rb
+4
-1
spec/services/incident_management/pager_duty/create_incident_issue_service_spec.rb
...nagement/pager_duty/create_incident_issue_service_spec.rb
+56
-35
spec/workers/incident_management/pager_duty/process_incident_worker_spec.rb
...ent_management/pager_duty/process_incident_worker_spec.rb
+1
-0
No files found.
app/services/concerns/incident_management/settings.rb
View file @
129dfa33
# frozen_string_literal: true
# frozen_string_literal: true
module
IncidentManagement
module
IncidentManagement
module
Settings
module
Settings
include
Gitlab
::
Utils
::
StrongMemoize
def
incident_management_setting
def
incident_management_setting
strong_memoize
(
:incident_management_setting
)
do
strong_memoize
(
:incident_management_setting
)
do
project
.
incident_management_setting
||
project
.
incident_management_setting
||
...
...
app/services/incident_management/pager_duty/create_incident_issue_service.rb
View file @
129dfa33
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
module
IncidentManagement
module
IncidentManagement
module
PagerDuty
module
PagerDuty
class
CreateIncidentIssueService
<
BaseService
class
CreateIncidentIssueService
<
BaseService
include
IncidentManagement
::
Settings
def
initialize
(
project
,
incident_payload
)
def
initialize
(
project
,
incident_payload
)
super
(
project
,
User
.
alert_bot
,
incident_payload
)
super
(
project
,
User
.
alert_bot
,
incident_payload
)
end
end
...
@@ -38,7 +40,8 @@ module IncidentManagement
...
@@ -38,7 +40,8 @@ module IncidentManagement
end
end
def
webhook_available?
def
webhook_available?
Feature
.
enabled?
(
:pagerduty_webhook
,
project
)
Feature
.
enabled?
(
:pagerduty_webhook
,
project
)
&&
incident_management_setting
.
pagerduty_active?
end
end
def
forbidden
def
forbidden
...
...
spec/services/incident_management/pager_duty/create_incident_issue_service_spec.rb
View file @
129dfa33
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
require
'spec_helper'
require
'spec_helper'
RSpec
.
describe
IncidentManagement
::
PagerDuty
::
CreateIncidentIssueService
do
RSpec
.
describe
IncidentManagement
::
PagerDuty
::
CreateIncidentIssueService
do
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:project
,
reload:
true
)
{
create
(
:project
)
}
let_it_be
(
:user
)
{
User
.
alert_bot
}
let_it_be
(
:user
)
{
User
.
alert_bot
}
let
(
:webhook_payload
)
{
Gitlab
::
Json
.
parse
(
fixture_file
(
'pager_duty/webhook_incident_trigger.json'
))
}
let
(
:webhook_payload
)
{
Gitlab
::
Json
.
parse
(
fixture_file
(
'pager_duty/webhook_incident_trigger.json'
))
}
let
(
:parsed_payload
)
{
::
PagerDuty
::
WebhookPayloadParser
.
call
(
webhook_payload
)
}
let
(
:parsed_payload
)
{
::
PagerDuty
::
WebhookPayloadParser
.
call
(
webhook_payload
)
}
...
@@ -17,50 +17,71 @@ RSpec.describe IncidentManagement::PagerDuty::CreateIncidentIssueService do
...
@@ -17,50 +17,71 @@ RSpec.describe IncidentManagement::PagerDuty::CreateIncidentIssueService do
stub_feature_flags
(
pagerduty_webhook:
project
)
stub_feature_flags
(
pagerduty_webhook:
project
)
end
end
context
'when issue can be created'
do
context
'when PagerDuty webhook setting is active'
do
it
'creates a new issue'
do
let_it_be
(
:incident_management_setting
)
{
create
(
:project_incident_management_setting
,
project:
project
,
pagerduty_active:
true
)
}
expect
{
execute
}.
to
change
(
Issue
,
:count
).
by
(
1
)
context
'when issue can be created'
do
it
'creates a new issue'
do
expect
{
execute
}.
to
change
(
Issue
,
:count
).
by
(
1
)
end
it
'responds with success'
do
response
=
execute
expect
(
response
).
to
be_success
expect
(
response
.
payload
[
:issue
]).
to
be_kind_of
(
Issue
)
end
it
'the issue author is Alert bot'
do
expect
(
execute
.
payload
[
:issue
].
author
).
to
eq
(
User
.
alert_bot
)
end
it
'issue has a correct title'
do
expect
(
execute
.
payload
[
:issue
].
title
).
to
eq
(
incident_payload
[
'title'
])
end
it
'issue has a correct description'
do
markdown_line_break
=
' '
expect
(
execute
.
payload
[
:issue
].
description
).
to
eq
(
<<~
MARKDOWN
.
chomp
**Incident:** [My new incident](https://webdemo.pagerduty.com/incidents/PRORDTY)
#{
markdown_line_break
}
**Incident number:** 33
#{
markdown_line_break
}
**Urgency:** high
#{
markdown_line_break
}
**Status:** triggered
#{
markdown_line_break
}
**Incident key:**
#{
markdown_line_break
}
**Created at:** 26 September 2017, 3:14PM (UTC)
#{
markdown_line_break
}
**Assignees:** [Laura Haley](https://webdemo.pagerduty.com/users/P553OPV)
#{
markdown_line_break
}
**Impacted services:** [Production XDB Cluster](https://webdemo.pagerduty.com/services/PN49J75)
MARKDOWN
)
end
end
end
it
'responds with success
'
do
context
'when the payload does not contain a title
'
do
response
=
execute
let
(
:incident_payload
)
{
{}
}
expect
(
response
).
to
be_success
it
'does not create a GitLab issue'
do
expect
(
response
.
payload
[
:issue
]).
to
be_kind_of
(
Issue
)
expect
{
execute
}.
not_to
change
(
Issue
,
:count
)
end
end
it
'the issue author is Alert bot'
do
it
'responds with error'
do
expect
(
execute
.
payload
[
:issue
].
author
).
to
eq
(
User
.
alert_bot
)
expect
(
execute
).
to
be_error
expect
(
execute
.
message
).
to
eq
(
"Title can't be blank"
)
end
end
end
end
it
'issue has a correct title'
do
context
'when PagerDuty webhook setting is not active'
do
expect
(
execute
.
payload
[
:issue
].
title
).
to
eq
(
incident_payload
[
'title'
])
let_it_be
(
:incident_management_setting
)
{
create
(
:project_incident_management_setting
,
project:
project
,
pagerduty_active:
false
)
}
end
it
'issue has a correct description'
do
it
'does not create a GitLab issue'
do
markdown_line_break
=
' '
expect
{
execute
}.
not_to
change
(
Issue
,
:count
)
expect
(
execute
.
payload
[
:issue
].
description
).
to
eq
(
<<~
MARKDOWN
.
chomp
**Incident:** [My new incident](https://webdemo.pagerduty.com/incidents/PRORDTY)
#{
markdown_line_break
}
**Incident number:** 33
#{
markdown_line_break
}
**Urgency:** high
#{
markdown_line_break
}
**Status:** triggered
#{
markdown_line_break
}
**Incident key:**
#{
markdown_line_break
}
**Created at:** 26 September 2017, 3:14PM (UTC)
#{
markdown_line_break
}
**Assignees:** [Laura Haley](https://webdemo.pagerduty.com/users/P553OPV)
#{
markdown_line_break
}
**Impacted services:** [Production XDB Cluster](https://webdemo.pagerduty.com/services/PN49J75)
MARKDOWN
)
end
end
end
context
'when issue cannot be created'
do
let
(
:incident_payload
)
{
{}
}
it
'responds with
error
'
do
it
'responds with
forbidden
'
do
expect
(
execute
).
to
be_error
expect
(
execute
).
to
be_error
expect
(
execute
.
message
).
to
eq
(
"Title can't be blank"
)
expect
(
execute
.
http_status
).
to
eq
(
:forbidden
)
end
end
end
end
end
end
...
...
spec/workers/incident_management/pager_duty/process_incident_worker_spec.rb
View file @
129dfa33
...
@@ -4,6 +4,7 @@ require 'spec_helper'
...
@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec
.
describe
IncidentManagement
::
PagerDuty
::
ProcessIncidentWorker
do
RSpec
.
describe
IncidentManagement
::
PagerDuty
::
ProcessIncidentWorker
do
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:incident_management_setting
)
{
create
(
:project_incident_management_setting
,
project:
project
,
pagerduty_active:
true
)
}
describe
'#perform'
do
describe
'#perform'
do
subject
(
:perform
)
{
described_class
.
new
.
perform
(
project
.
id
,
incident_payload
)
}
subject
(
:perform
)
{
described_class
.
new
.
perform
(
project
.
id
,
incident_payload
)
}
...
...
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