summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/api/projects.md10
-rw-r--r--lib/api/project_hooks.rb5
-rw-r--r--spec/requests/api/project_hooks_spec.rb4
3 files changed, 15 insertions, 4 deletions
diff --git a/doc/api/projects.md b/doc/api/projects.md
index 447c923b9b6..53acc4a025e 100644
--- a/doc/api/projects.md
+++ b/doc/api/projects.md
@@ -402,6 +402,10 @@ Parameters:
{
"id": 1,
"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"
}
```
@@ -419,6 +423,9 @@ Parameters:
+ `id` (required) - The ID or NAME of a project
+ `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
@@ -434,6 +441,9 @@ Parameters:
+ `id` (required) - The ID or NAME of a project
+ `hook_id` (required) - The ID of a project hook
+ `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
diff --git a/lib/api/project_hooks.rb b/lib/api/project_hooks.rb
index e5da15d3ea9..c271dd8b61b 100644
--- a/lib/api/project_hooks.rb
+++ b/lib/api/project_hooks.rb
@@ -47,8 +47,9 @@ module API
# POST /projects/:id/hooks
post ":id/hooks" do
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
present @hook, with: Entities::ProjectHook
else
@@ -70,8 +71,8 @@ module API
put ":id/hooks/:hook_id" do
@hook = user_project.hooks.find(params[:hook_id])
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
present @hook, with: Entities::ProjectHook
else
diff --git a/spec/requests/api/project_hooks_spec.rb b/spec/requests/api/project_hooks_spec.rb
index c2a60abb482..beccd61866e 100644
--- a/spec/requests/api/project_hooks_spec.rb
+++ b/spec/requests/api/project_hooks_spec.rb
@@ -66,7 +66,7 @@ describe API::API, 'ProjectHooks' do
it "should add hook to project" do
expect {
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)
response.status.should == 201
end
@@ -85,7 +85,7 @@ describe API::API, 'ProjectHooks' do
describe "PUT /projects/:id/hooks/:hook_id" do
it "should update an existing project hook" do
put api("/projects/#{project.id}/hooks/#{hook.id}", user),
- url: 'http://example.org'
+ url: 'http://example.org', push_events: false
response.status.should == 200
json_response['url'].should == 'http://example.org'
end