Commit 21f4e5d3ac80c319592ecedb8bbf0c162841beb7
1 parent
822dac87
Exists in
master
and in
4 other branches
ProjectHook API supports new event fields
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
3 changed files
with
15 additions
and
4 deletions
Show diff stats
doc/api/projects.md
... | ... | @@ -402,6 +402,10 @@ Parameters: |
402 | 402 | { |
403 | 403 | "id": 1, |
404 | 404 | "url": "http://example.com/hook", |
405 | + "project_id": 3, | |
406 | + "push_events": "true", | |
407 | + "issues_events": "true", | |
408 | + "merge_requests_events": "true", | |
405 | 409 | "created_at": "2012-10-12T17:04:47Z" |
406 | 410 | } |
407 | 411 | ``` |
... | ... | @@ -419,6 +423,9 @@ Parameters: |
419 | 423 | |
420 | 424 | + `id` (required) - The ID or NAME of a project |
421 | 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 | 431 | ### Edit project hook |
... | ... | @@ -434,6 +441,9 @@ Parameters: |
434 | 441 | + `id` (required) - The ID or NAME of a project |
435 | 442 | + `hook_id` (required) - The ID of a project hook |
436 | 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 | 449 | ### Delete project hook | ... | ... |
lib/api/project_hooks.rb
... | ... | @@ -47,8 +47,9 @@ module API |
47 | 47 | # POST /projects/:id/hooks |
48 | 48 | post ":id/hooks" do |
49 | 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 | 53 | if @hook.save |
53 | 54 | present @hook, with: Entities::ProjectHook |
54 | 55 | else |
... | ... | @@ -70,8 +71,8 @@ module API |
70 | 71 | put ":id/hooks/:hook_id" do |
71 | 72 | @hook = user_project.hooks.find(params[:hook_id]) |
72 | 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 | 76 | if @hook.update_attributes attrs |
76 | 77 | present @hook, with: Entities::ProjectHook |
77 | 78 | else | ... | ... |
spec/requests/api/project_hooks_spec.rb
... | ... | @@ -66,7 +66,7 @@ describe API::API, 'ProjectHooks' do |
66 | 66 | it "should add hook to project" do |
67 | 67 | expect { |
68 | 68 | post api("/projects/#{project.id}/hooks", user), |
69 | - url: "http://example.com" | |
69 | + url: "http://example.com", issues_events: true | |
70 | 70 | }.to change {project.hooks.count}.by(1) |
71 | 71 | response.status.should == 201 |
72 | 72 | end |
... | ... | @@ -85,7 +85,7 @@ describe API::API, 'ProjectHooks' do |
85 | 85 | describe "PUT /projects/:id/hooks/:hook_id" do |
86 | 86 | it "should update an existing project hook" do |
87 | 87 | put api("/projects/#{project.id}/hooks/#{hook.id}", user), |
88 | - url: 'http://example.org' | |
88 | + url: 'http://example.org', push_events: false | |
89 | 89 | response.status.should == 200 |
90 | 90 | json_response['url'].should == 'http://example.org' |
91 | 91 | end | ... | ... |