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
72b83885
Commit
72b83885
authored
Jul 15, 2020
by
Vitali Tatarintev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Call PagerDuty webhook processor from controller
parent
e82ebd5b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
50 deletions
+45
-50
app/controllers/projects/incident_management/pager_duty_incidents_controller.rb
...ts/incident_management/pager_duty_incidents_controller.rb
+9
-5
spec/controllers/projects/incident_management/pager_duty_incidents_controller_spec.rb
...cident_management/pager_duty_incidents_controller_spec.rb
+0
-45
spec/requests/projects/incident_management/pagerduty_incidents_spec.rb
.../projects/incident_management/pagerduty_incidents_spec.rb
+36
-0
No files found.
app/controllers/projects/incident_management/pager_duty_incidents_controller.rb
View file @
72b83885
...
...
@@ -11,11 +11,7 @@ module Projects
prepend_before_action
:project_without_auth
def
create
result
=
ServiceResponse
.
success
(
http_status: :accepted
)
unless
Feature
.
enabled?
(
:pagerduty_webhook
,
@project
)
result
=
ServiceResponse
.
error
(
message:
'Unauthorized'
,
http_status: :unauthorized
)
end
result
=
webhook_processor
.
execute
(
params
[
:token
])
head
result
.
http_status
end
...
...
@@ -26,6 +22,14 @@ module Projects
@project
||=
Project
.
find_by_full_path
(
"
#{
params
[
:namespace_id
]
}
/
#{
params
[
:project_id
]
}
"
)
end
def
webhook_processor
::
IncidentManagement
::
PagerDuty
::
ProcessWebhookService
.
new
(
project
,
nil
,
payload
)
end
def
payload
@payload
||=
params
.
permit!
[
:pager_duty_incident
].
to_h
end
end
end
end
spec/controllers/projects/incident_management/pager_duty_incidents_controller_spec.rb
deleted
100644 → 0
View file @
e82ebd5b
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Projects
::
IncidentManagement
::
PagerDutyIncidentsController
do
let_it_be
(
:project
)
{
create
(
:project
)
}
describe
'POST #create'
do
let
(
:payload
)
{
{
messages:
[]
}
}
def
make_request
post
:create
,
params:
project_params
,
body:
payload
.
to_json
,
as: :json
end
context
'when pagerduty_webhook feature enabled'
do
before
do
stub_feature_flags
(
pagerduty_webhook:
project
)
end
it
'responds with 202 Accepted'
do
make_request
expect
(
response
).
to
have_gitlab_http_status
(
:accepted
)
end
end
context
'when pagerduty_webhook feature disabled'
do
before
do
stub_feature_flags
(
pagerduty_webhook:
false
)
end
it
'responds with 401 Unauthorized'
do
make_request
expect
(
response
).
to
have_gitlab_http_status
(
:unauthorized
)
end
end
end
private
def
project_params
(
opts
=
{})
opts
.
reverse_merge
(
namespace_id:
project
.
namespace
,
project_id:
project
)
end
end
spec/requests/projects/incident_management/pagerduty_incidents_spec.rb
0 → 100644
View file @
72b83885
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
'PagerDuty webhook'
do
let_it_be
(
:project
)
{
create
(
:project
)
}
describe
'POST /incidents/pagerduty'
do
let
(
:payload
)
{
Gitlab
::
Json
.
parse
(
fixture_file
(
'pager_duty/webhook_incident_trigger.json'
))
}
let
(
:webhook_processor_class
)
{
::
IncidentManagement
::
PagerDuty
::
ProcessWebhookService
}
let
(
:webhook_processor
)
{
instance_double
(
webhook_processor_class
)
}
def
make_request
headers
=
{
'Content-Type'
=>
'application/json'
}
post
project_incidents_pagerduty_url
(
project
,
token:
'VALID-TOKEN'
),
params:
payload
.
to_json
,
headers:
headers
end
before
do
allow
(
webhook_processor_class
).
to
receive
(
:new
).
and_return
(
webhook_processor
)
allow
(
webhook_processor
).
to
receive
(
:execute
).
and_return
(
ServiceResponse
.
success
(
http_status: :accepted
))
end
it
'calls PagerDuty webhook processor with correct parameters'
do
make_request
expect
(
webhook_processor_class
).
to
have_received
(
:new
).
with
(
project
,
nil
,
payload
)
expect
(
webhook_processor
).
to
have_received
(
:execute
).
with
(
'VALID-TOKEN'
)
end
it
'responds with 202 Accepted'
do
make_request
expect
(
response
).
to
have_gitlab_http_status
(
:accepted
)
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