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
f92e7c0a
Commit
f92e7c0a
authored
Jul 10, 2020
by
Vitali Tatarintev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add PagerDuty incident management worker
parent
24d4cebd
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
0 deletions
+98
-0
app/workers/incident_management/pager_duty/process_incident_worker.rb
...incident_management/pager_duty/process_incident_worker.rb
+42
-0
spec/workers/incident_management/pager_duty/process_incident_worker_spec.rb
...ent_management/pager_duty/process_incident_worker_spec.rb
+56
-0
No files found.
app/workers/incident_management/pager_duty/process_incident_worker.rb
0 → 100644
View file @
f92e7c0a
# frozen_string_literal: true
module
IncidentManagement
module
PagerDuty
class
ProcessIncidentWorker
# rubocop:disable Scalability/IdempotentWorker
include
ApplicationWorker
queue_namespace
:incident_management
feature_category
:incident_management
def
perform
(
project_id
,
incident_payload
)
return
unless
project_id
project
=
find_project
(
project_id
)
return
unless
project
result
=
create_issue
(
project
,
incident_payload
)
log_error
(
result
)
if
result
.
error?
end
private
def
find_project
(
project_id
)
Project
.
find_by_id
(
project_id
)
end
def
create_issue
(
project
,
incident_payload
)
::
IncidentManagement
::
PagerDuty
::
CreateIncidentIssueService
.
new
(
project
,
incident_payload
)
.
execute
end
def
log_error
(
result
)
Gitlab
::
AppLogger
.
warn
(
message:
'Cannot create issue for PagerDuty incident'
,
issue_errors:
result
.
message
)
end
end
end
end
spec/workers/incident_management/pager_duty/process_incident_worker_spec.rb
0 → 100644
View file @
f92e7c0a
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
IncidentManagement
::
PagerDuty
::
ProcessIncidentWorker
do
let_it_be
(
:project
)
{
create
(
:project
)
}
describe
'#perform'
do
subject
(
:perform
)
{
described_class
.
new
.
perform
(
project
.
id
,
incident_payload
)
}
context
'with valid incident payload'
do
let
(
:incident_payload
)
do
{
'url'
=>
'https://webdemo.pagerduty.com/incidents/PRORDTY'
,
'incident_number'
=>
33
,
'title'
=>
'My new incident'
,
'status'
=>
'triggered'
,
'created_at'
=>
'2017-09-26T15:14:36Z'
,
'urgency'
=>
'high'
,
'incident_key'
=>
nil
,
'assignees'
=>
[{
'summary'
=>
'Laura Haley'
,
'url'
=>
'https://webdemo.pagerduty.com/users/P553OPV'
}],
'impacted_services'
=>
[{
'summary'
=>
'Production XDB Cluster'
,
'url'
=>
'https://webdemo.pagerduty.com/services/PN49J75'
}]
}
end
it
'creates a GitLab issue'
do
expect
{
perform
}.
to
change
(
Issue
,
:count
).
by
(
1
)
end
end
context
'with invalid incident payload'
do
let
(
:incident_payload
)
{
{}
}
before
do
allow
(
Gitlab
::
AppLogger
).
to
receive
(
:warn
).
and_call_original
end
it
'does not create a GitLab issue'
do
expect
{
perform
}.
not_to
change
(
Issue
,
:count
)
end
it
'logs a warning'
do
perform
expect
(
Gitlab
::
AppLogger
).
to
have_received
(
:warn
).
with
(
message:
'Cannot create issue for PagerDuty incident'
,
issue_errors:
"Title can't be blank"
)
end
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