Fixup POST /v3/:id/hooks and PUT /v3/:id/hooks/:hook_id
This commit is contained in:
parent
699a30f06b
commit
e77e9b0077
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
title: "Fix v3 api project_hooks POST and PUT operations for build_events"
|
||||
merge_request: 12673
|
||||
author: Richard Clamp
|
|
@ -56,7 +56,9 @@ module API
|
|||
use :project_hook_properties
|
||||
end
|
||||
post ":id/hooks" do
|
||||
hook = user_project.hooks.new(declared_params(include_missing: false))
|
||||
attrs = declared_params(include_missing: false)
|
||||
attrs[:job_events] = attrs.delete(:build_events) if attrs.key?(:build_events)
|
||||
hook = user_project.hooks.new(attrs)
|
||||
|
||||
if hook.save
|
||||
present hook, with: ::API::V3::Entities::ProjectHook
|
||||
|
@ -77,7 +79,9 @@ module API
|
|||
put ":id/hooks/:hook_id" do
|
||||
hook = user_project.hooks.find(params.delete(:hook_id))
|
||||
|
||||
if hook.update_attributes(declared_params(include_missing: false))
|
||||
attrs = declared_params(include_missing: false)
|
||||
attrs[:job_events] = attrs.delete(:build_events) if attrs.key?(:build_events)
|
||||
if hook.update_attributes(attrs)
|
||||
present hook, with: ::API::V3::Entities::ProjectHook
|
||||
else
|
||||
error!("Invalid url given", 422) if hook.errors[:url].present?
|
||||
|
|
|
@ -87,7 +87,7 @@ describe API::ProjectHooks, 'ProjectHooks' do
|
|||
it "adds hook to project" do
|
||||
expect do
|
||||
post v3_api("/projects/#{project.id}/hooks", user),
|
||||
url: "http://example.com", issues_events: true, wiki_page_events: true
|
||||
url: "http://example.com", issues_events: true, wiki_page_events: true, build_events: true
|
||||
end.to change {project.hooks.count}.by(1)
|
||||
|
||||
expect(response).to have_http_status(201)
|
||||
|
@ -97,7 +97,7 @@ describe API::ProjectHooks, 'ProjectHooks' do
|
|||
expect(json_response['merge_requests_events']).to eq(false)
|
||||
expect(json_response['tag_push_events']).to eq(false)
|
||||
expect(json_response['note_events']).to eq(false)
|
||||
expect(json_response['build_events']).to eq(false)
|
||||
expect(json_response['build_events']).to eq(true)
|
||||
expect(json_response['pipeline_events']).to eq(false)
|
||||
expect(json_response['wiki_page_events']).to eq(true)
|
||||
expect(json_response['enable_ssl_verification']).to eq(true)
|
||||
|
@ -135,7 +135,7 @@ describe API::ProjectHooks, 'ProjectHooks' do
|
|||
describe "PUT /projects/:id/hooks/:hook_id" do
|
||||
it "updates an existing project hook" do
|
||||
put v3_api("/projects/#{project.id}/hooks/#{hook.id}", user),
|
||||
url: 'http://example.org', push_events: false
|
||||
url: 'http://example.org', push_events: false, build_events: true
|
||||
expect(response).to have_http_status(200)
|
||||
expect(json_response['url']).to eq('http://example.org')
|
||||
expect(json_response['issues_events']).to eq(hook.issues_events)
|
||||
|
|
Loading…
Reference in New Issue