diff --git a/CHANGELOG b/CHANGELOG index 1c9f3bba..f626f49d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,6 @@ master + - [API] list one project hook + - [API] edit project hook - [API] add project snippets list - [API] allow to authorize using private token in HTTP header - [API] add user creation diff --git a/doc/api/projects.md b/doc/api/projects.md index d06a41c2..fdedf904 100644 --- a/doc/api/projects.md +++ b/doc/api/projects.md @@ -196,9 +196,9 @@ Parameters: Status code `200` will be returned on success. -## Get project hooks +## List project hooks -Get hooks for project +Get list for project hooks ``` GET /projects/:id/hooks @@ -210,6 +210,21 @@ Parameters: Will return hooks with status `200 OK` on success, or `404 Not found` on fail. +## Get project hook + +Get hook for project + +``` +GET /projects/:id/hooks/:hook_id +``` + +Parameters: + ++ `id` (required) - The ID or code name of a project ++ `hook_id` (required) - The ID of a project hook + +Will return hook with status `200 OK` on success, or `404 Not found` on fail. + ## Add project hook Add hook to project @@ -225,6 +240,23 @@ Parameters: Will return status `201 Created` on success, or `404 Not found` on fail. +## Edit project hook + +Edit hook for project + +``` +PUT /projects/:id/hooks/:hook_id +``` + +Parameters: + ++ `id` (required) - The ID or code name of a project ++ `hook_id` (required) - The ID of a project hook ++ `url` (required) - The hook URL + +Will return status `201 Created` on success, or `404 Not found` on fail. + + ## Delete project hook Delete hook from project diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 0f013883..8f094e0c 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -147,6 +147,19 @@ module Gitlab @hooks = paginate user_project.hooks present @hooks, with: Entities::Hook end + + # Get a project hook + # + # Parameters: + # id (required) - The ID or code name of a project + # hook_id (required) - The ID of a project hook + # Example Request: + # GET /projects/:id/hooks/:hook_id + get ":id/hooks/:hook_id" do + @hook = user_project.hooks.find(params[:hook_id]) + present @hook, with: Entities::Hook + end + # Add hook to project # @@ -164,6 +177,27 @@ module Gitlab error!({'message' => '404 Not found'}, 404) end end + + # Update an existing project hook + # + # Parameters: + # id (required) - The ID or code name of a project + # hook_id (required) - The ID of a project hook + # url (required) - The hook URL + # Example Request: + # PUT /projects/:id/hooks/:hook_id + put ":id/hooks/:hook_id" do + @hook = user_project.hooks.find(params[:hook_id]) + authorize! :admin_project, user_project + + attrs = attributes_for_keys [:url] + + if @hook.update_attributes attrs + present @hook, with: Entities::Hook + else + not_found! + end + end # Delete project hook # diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 94c9abb3..51526f89 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -172,7 +172,15 @@ describe Gitlab::API do end end - describe "POST /projects/:id/users" do + describe "GET /projects/:id/hooks/:hook_id" do + it "should return a project hook" do + get api("/projects/#{project.code}/hooks/#{hook.id}", user) + response.status.should == 200 + json_response['url'].should == hook.url + end + end + + describe "POST /projects/:id/hooks" do it "should add hook to project" do expect { post api("/projects/#{project.code}/hooks", user), @@ -180,6 +188,16 @@ describe Gitlab::API do }.to change {project.hooks.count}.by(1) end end + + describe "PUT /projects/:id/hooks/:hook_id" do + it "should update an existing project hook" do + put api("/projects/#{project.code}/hooks/#{hook.id}", user), + url: 'http://example.com' + response.status.should == 200 + json_response['url'].should == 'http://example.com' + end + end + describe "DELETE /projects/:id/hooks" do it "should delete hook from project" do @@ -246,7 +264,7 @@ describe Gitlab::API do end end - describe "PUT /projects/:id/snippets" do + describe "PUT /projects/:id/snippets/:shippet_id" do it "should update an existing project snippet" do put api("/projects/#{project.code}/snippets/#{snippet.id}", user), code: 'updated code'