Commit 7e83f244 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'bugfix/fix_v3_project_hooks_build_events' into 'master'

Fixup POST /v3/:id/hooks and PUT /v3/:id/hooks/:hook_id

See merge request !12673
parents 699a30f0 e77e9b00
---
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 ...@@ -56,7 +56,9 @@ module API
use :project_hook_properties use :project_hook_properties
end end
post ":id/hooks" do 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 if hook.save
present hook, with: ::API::V3::Entities::ProjectHook present hook, with: ::API::V3::Entities::ProjectHook
...@@ -77,7 +79,9 @@ module API ...@@ -77,7 +79,9 @@ module API
put ":id/hooks/:hook_id" do put ":id/hooks/:hook_id" do
hook = user_project.hooks.find(params.delete(:hook_id)) 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 present hook, with: ::API::V3::Entities::ProjectHook
else else
error!("Invalid url given", 422) if hook.errors[:url].present? error!("Invalid url given", 422) if hook.errors[:url].present?
......
...@@ -87,7 +87,7 @@ describe API::ProjectHooks, 'ProjectHooks' do ...@@ -87,7 +87,7 @@ describe API::ProjectHooks, 'ProjectHooks' do
it "adds hook to project" do it "adds hook to project" do
expect do expect do
post v3_api("/projects/#{project.id}/hooks", user), 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) end.to change {project.hooks.count}.by(1)
expect(response).to have_http_status(201) expect(response).to have_http_status(201)
...@@ -97,7 +97,7 @@ describe API::ProjectHooks, 'ProjectHooks' do ...@@ -97,7 +97,7 @@ describe API::ProjectHooks, 'ProjectHooks' do
expect(json_response['merge_requests_events']).to eq(false) expect(json_response['merge_requests_events']).to eq(false)
expect(json_response['tag_push_events']).to eq(false) expect(json_response['tag_push_events']).to eq(false)
expect(json_response['note_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['pipeline_events']).to eq(false)
expect(json_response['wiki_page_events']).to eq(true) expect(json_response['wiki_page_events']).to eq(true)
expect(json_response['enable_ssl_verification']).to eq(true) expect(json_response['enable_ssl_verification']).to eq(true)
...@@ -135,7 +135,7 @@ describe API::ProjectHooks, 'ProjectHooks' do ...@@ -135,7 +135,7 @@ describe API::ProjectHooks, 'ProjectHooks' do
describe "PUT /projects/:id/hooks/:hook_id" do describe "PUT /projects/:id/hooks/:hook_id" do
it "updates an existing project hook" do it "updates an existing project hook" do
put v3_api("/projects/#{project.id}/hooks/#{hook.id}", user), 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(response).to have_http_status(200)
expect(json_response['url']).to eq('http://example.org') expect(json_response['url']).to eq('http://example.org')
expect(json_response['issues_events']).to eq(hook.issues_events) expect(json_response['issues_events']).to eq(hook.issues_events)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment