Commit 21f4e5d3 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

ProjectHook API supports new event fields

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 822dac87
...@@ -402,6 +402,10 @@ Parameters: ...@@ -402,6 +402,10 @@ Parameters:
{ {
"id": 1, "id": 1,
"url": "http://example.com/hook", "url": "http://example.com/hook",
"project_id": 3,
"push_events": "true",
"issues_events": "true",
"merge_requests_events": "true",
"created_at": "2012-10-12T17:04:47Z" "created_at": "2012-10-12T17:04:47Z"
} }
``` ```
...@@ -419,6 +423,9 @@ Parameters: ...@@ -419,6 +423,9 @@ Parameters:
+ `id` (required) - The ID or NAME of a project + `id` (required) - The ID or NAME of a project
+ `url` (required) - The hook URL + `url` (required) - The hook URL
+ `push_events` - Trigger hook on push events
+ `issues_events` - Trigger hook on issues events
+ `merge_requests_events` - Trigger hook on merge_requests events
### Edit project hook ### Edit project hook
...@@ -434,6 +441,9 @@ Parameters: ...@@ -434,6 +441,9 @@ Parameters:
+ `id` (required) - The ID or NAME of a project + `id` (required) - The ID or NAME of a project
+ `hook_id` (required) - The ID of a project hook + `hook_id` (required) - The ID of a project hook
+ `url` (required) - The hook URL + `url` (required) - The hook URL
+ `push_events` - Trigger hook on push events
+ `issues_events` - Trigger hook on issues events
+ `merge_requests_events` - Trigger hook on merge_requests events
### Delete project hook ### Delete project hook
......
...@@ -47,8 +47,9 @@ module API ...@@ -47,8 +47,9 @@ module API
# POST /projects/:id/hooks # POST /projects/:id/hooks
post ":id/hooks" do post ":id/hooks" do
required_attributes! [:url] required_attributes! [:url]
attrs = attributes_for_keys [:url, :push_events, :issues_events, :merge_requests_events]
@hook = user_project.hooks.new(attrs)
@hook = user_project.hooks.new({"url" => params[:url]})
if @hook.save if @hook.save
present @hook, with: Entities::ProjectHook present @hook, with: Entities::ProjectHook
else else
...@@ -70,8 +71,8 @@ module API ...@@ -70,8 +71,8 @@ module API
put ":id/hooks/:hook_id" do put ":id/hooks/:hook_id" do
@hook = user_project.hooks.find(params[:hook_id]) @hook = user_project.hooks.find(params[:hook_id])
required_attributes! [:url] required_attributes! [:url]
attrs = attributes_for_keys [:url, :push_events, :issues_events, :merge_requests_events]
attrs = attributes_for_keys [:url]
if @hook.update_attributes attrs if @hook.update_attributes attrs
present @hook, with: Entities::ProjectHook present @hook, with: Entities::ProjectHook
else else
......
...@@ -66,7 +66,7 @@ describe API::API, 'ProjectHooks' do ...@@ -66,7 +66,7 @@ describe API::API, 'ProjectHooks' do
it "should add hook to project" do it "should add hook to project" do
expect { expect {
post api("/projects/#{project.id}/hooks", user), post api("/projects/#{project.id}/hooks", user),
url: "http://example.com" url: "http://example.com", issues_events: true
}.to change {project.hooks.count}.by(1) }.to change {project.hooks.count}.by(1)
response.status.should == 201 response.status.should == 201
end end
...@@ -85,7 +85,7 @@ describe API::API, 'ProjectHooks' do ...@@ -85,7 +85,7 @@ describe API::API, 'ProjectHooks' do
describe "PUT /projects/:id/hooks/:hook_id" do describe "PUT /projects/:id/hooks/:hook_id" do
it "should update an existing project hook" do it "should update an existing project hook" do
put api("/projects/#{project.id}/hooks/#{hook.id}", user), put api("/projects/#{project.id}/hooks/#{hook.id}", user),
url: 'http://example.org' url: 'http://example.org', push_events: false
response.status.should == 200 response.status.should == 200
json_response['url'].should == 'http://example.org' json_response['url'].should == 'http://example.org'
end end
......
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