Commit 21f4e5d3ac80c319592ecedb8bbf0c162841beb7

Authored by Dmitriy Zaporozhets
1 parent 822dac87

ProjectHook API supports new event fields

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
doc/api/projects.md
@@ -402,6 +402,10 @@ Parameters: @@ -402,6 +402,10 @@ Parameters:
402 { 402 {
403 "id": 1, 403 "id": 1,
404 "url": "http://example.com/hook", 404 "url": "http://example.com/hook",
  405 + "project_id": 3,
  406 + "push_events": "true",
  407 + "issues_events": "true",
  408 + "merge_requests_events": "true",
405 "created_at": "2012-10-12T17:04:47Z" 409 "created_at": "2012-10-12T17:04:47Z"
406 } 410 }
407 ``` 411 ```
@@ -419,6 +423,9 @@ Parameters: @@ -419,6 +423,9 @@ Parameters:
419 423
420 + `id` (required) - The ID or NAME of a project 424 + `id` (required) - The ID or NAME of a project
421 + `url` (required) - The hook URL 425 + `url` (required) - The hook URL
  426 ++ `push_events` - Trigger hook on push events
  427 ++ `issues_events` - Trigger hook on issues events
  428 ++ `merge_requests_events` - Trigger hook on merge_requests events
422 429
423 430
424 ### Edit project hook 431 ### Edit project hook
@@ -434,6 +441,9 @@ Parameters: @@ -434,6 +441,9 @@ Parameters:
434 + `id` (required) - The ID or NAME of a project 441 + `id` (required) - The ID or NAME of a project
435 + `hook_id` (required) - The ID of a project hook 442 + `hook_id` (required) - The ID of a project hook
436 + `url` (required) - The hook URL 443 + `url` (required) - The hook URL
  444 ++ `push_events` - Trigger hook on push events
  445 ++ `issues_events` - Trigger hook on issues events
  446 ++ `merge_requests_events` - Trigger hook on merge_requests events
437 447
438 448
439 ### Delete project hook 449 ### Delete project hook
lib/api/project_hooks.rb
@@ -47,8 +47,9 @@ module API @@ -47,8 +47,9 @@ module API
47 # POST /projects/:id/hooks 47 # POST /projects/:id/hooks
48 post ":id/hooks" do 48 post ":id/hooks" do
49 required_attributes! [:url] 49 required_attributes! [:url]
  50 + attrs = attributes_for_keys [:url, :push_events, :issues_events, :merge_requests_events]
  51 + @hook = user_project.hooks.new(attrs)
50 52
51 - @hook = user_project.hooks.new({"url" => params[:url]})  
52 if @hook.save 53 if @hook.save
53 present @hook, with: Entities::ProjectHook 54 present @hook, with: Entities::ProjectHook
54 else 55 else
@@ -70,8 +71,8 @@ module API @@ -70,8 +71,8 @@ module API
70 put ":id/hooks/:hook_id" do 71 put ":id/hooks/:hook_id" do
71 @hook = user_project.hooks.find(params[:hook_id]) 72 @hook = user_project.hooks.find(params[:hook_id])
72 required_attributes! [:url] 73 required_attributes! [:url]
  74 + attrs = attributes_for_keys [:url, :push_events, :issues_events, :merge_requests_events]
73 75
74 - attrs = attributes_for_keys [:url]  
75 if @hook.update_attributes attrs 76 if @hook.update_attributes attrs
76 present @hook, with: Entities::ProjectHook 77 present @hook, with: Entities::ProjectHook
77 else 78 else
spec/requests/api/project_hooks_spec.rb
@@ -66,7 +66,7 @@ describe API::API, &#39;ProjectHooks&#39; do @@ -66,7 +66,7 @@ describe API::API, &#39;ProjectHooks&#39; do
66 it "should add hook to project" do 66 it "should add hook to project" do
67 expect { 67 expect {
68 post api("/projects/#{project.id}/hooks", user), 68 post api("/projects/#{project.id}/hooks", user),
69 - url: "http://example.com" 69 + url: "http://example.com", issues_events: true
70 }.to change {project.hooks.count}.by(1) 70 }.to change {project.hooks.count}.by(1)
71 response.status.should == 201 71 response.status.should == 201
72 end 72 end
@@ -85,7 +85,7 @@ describe API::API, &#39;ProjectHooks&#39; do @@ -85,7 +85,7 @@ describe API::API, &#39;ProjectHooks&#39; do
85 describe "PUT /projects/:id/hooks/:hook_id" do 85 describe "PUT /projects/:id/hooks/:hook_id" do
86 it "should update an existing project hook" do 86 it "should update an existing project hook" do
87 put api("/projects/#{project.id}/hooks/#{hook.id}", user), 87 put api("/projects/#{project.id}/hooks/#{hook.id}", user),
88 - url: 'http://example.org' 88 + url: 'http://example.org', push_events: false
89 response.status.should == 200 89 response.status.should == 200
90 json_response['url'].should == 'http://example.org' 90 json_response['url'].should == 'http://example.org'
91 end 91 end