Commit 89a349f9a525a7fa131d0ac3704b9b770f6850d2

Authored by Valeriy Sizov
2 parents 3950b8e8 96abbf02

Merge pull request #1685 from jozefvaclavik/master

Hooks API (List one hook & edit)
CHANGELOG
1 1 master
  2 + - [API] list one project hook
  3 + - [API] edit project hook
2 4 - [API] add project snippets list
3 5 - [API] allow to authorize using private token in HTTP header
4 6 - [API] add user creation
... ...
doc/api/projects.md
... ... @@ -196,9 +196,9 @@ Parameters:
196 196  
197 197 Status code `200` will be returned on success.
198 198  
199   -## Get project hooks
  199 +## List project hooks
200 200  
201   -Get hooks for project
  201 +Get list for project hooks
202 202  
203 203 ```
204 204 GET /projects/:id/hooks
... ... @@ -210,6 +210,21 @@ Parameters:
210 210  
211 211 Will return hooks with status `200 OK` on success, or `404 Not found` on fail.
212 212  
  213 +## Get project hook
  214 +
  215 +Get hook for project
  216 +
  217 +```
  218 +GET /projects/:id/hooks/:hook_id
  219 +```
  220 +
  221 +Parameters:
  222 +
  223 ++ `id` (required) - The ID or code name of a project
  224 ++ `hook_id` (required) - The ID of a project hook
  225 +
  226 +Will return hook with status `200 OK` on success, or `404 Not found` on fail.
  227 +
213 228 ## Add project hook
214 229  
215 230 Add hook to project
... ... @@ -225,6 +240,23 @@ Parameters:
225 240  
226 241 Will return status `201 Created` on success, or `404 Not found` on fail.
227 242  
  243 +## Edit project hook
  244 +
  245 +Edit hook for project
  246 +
  247 +```
  248 +PUT /projects/:id/hooks/:hook_id
  249 +```
  250 +
  251 +Parameters:
  252 +
  253 ++ `id` (required) - The ID or code name of a project
  254 ++ `hook_id` (required) - The ID of a project hook
  255 ++ `url` (required) - The hook URL
  256 +
  257 +Will return status `201 Created` on success, or `404 Not found` on fail.
  258 +
  259 +
228 260 ## Delete project hook
229 261  
230 262 Delete hook from project
... ...
lib/api/projects.rb
... ... @@ -147,6 +147,19 @@ module Gitlab
147 147 @hooks = paginate user_project.hooks
148 148 present @hooks, with: Entities::Hook
149 149 end
  150 +
  151 + # Get a project hook
  152 + #
  153 + # Parameters:
  154 + # id (required) - The ID or code name of a project
  155 + # hook_id (required) - The ID of a project hook
  156 + # Example Request:
  157 + # GET /projects/:id/hooks/:hook_id
  158 + get ":id/hooks/:hook_id" do
  159 + @hook = user_project.hooks.find(params[:hook_id])
  160 + present @hook, with: Entities::Hook
  161 + end
  162 +
150 163  
151 164 # Add hook to project
152 165 #
... ... @@ -164,6 +177,27 @@ module Gitlab
164 177 error!({'message' => '404 Not found'}, 404)
165 178 end
166 179 end
  180 +
  181 + # Update an existing project hook
  182 + #
  183 + # Parameters:
  184 + # id (required) - The ID or code name of a project
  185 + # hook_id (required) - The ID of a project hook
  186 + # url (required) - The hook URL
  187 + # Example Request:
  188 + # PUT /projects/:id/hooks/:hook_id
  189 + put ":id/hooks/:hook_id" do
  190 + @hook = user_project.hooks.find(params[:hook_id])
  191 + authorize! :admin_project, user_project
  192 +
  193 + attrs = attributes_for_keys [:url]
  194 +
  195 + if @hook.update_attributes attrs
  196 + present @hook, with: Entities::Hook
  197 + else
  198 + not_found!
  199 + end
  200 + end
167 201  
168 202 # Delete project hook
169 203 #
... ...
spec/requests/api/projects_spec.rb
... ... @@ -172,7 +172,15 @@ describe Gitlab::API do
172 172 end
173 173 end
174 174  
175   - describe "POST /projects/:id/users" do
  175 + describe "GET /projects/:id/hooks/:hook_id" do
  176 + it "should return a project hook" do
  177 + get api("/projects/#{project.code}/hooks/#{hook.id}", user)
  178 + response.status.should == 200
  179 + json_response['url'].should == hook.url
  180 + end
  181 + end
  182 +
  183 + describe "POST /projects/:id/hooks" do
176 184 it "should add hook to project" do
177 185 expect {
178 186 post api("/projects/#{project.code}/hooks", user),
... ... @@ -180,6 +188,16 @@ describe Gitlab::API do
180 188 }.to change {project.hooks.count}.by(1)
181 189 end
182 190 end
  191 +
  192 + describe "PUT /projects/:id/hooks/:hook_id" do
  193 + it "should update an existing project hook" do
  194 + put api("/projects/#{project.code}/hooks/#{hook.id}", user),
  195 + url: 'http://example.com'
  196 + response.status.should == 200
  197 + json_response['url'].should == 'http://example.com'
  198 + end
  199 + end
  200 +
183 201  
184 202 describe "DELETE /projects/:id/hooks" do
185 203 it "should delete hook from project" do
... ... @@ -246,7 +264,7 @@ describe Gitlab::API do
246 264 end
247 265 end
248 266  
249   - describe "PUT /projects/:id/snippets" do
  267 + describe "PUT /projects/:id/snippets/:shippet_id" do
250 268 it "should update an existing project snippet" do
251 269 put api("/projects/#{project.code}/snippets/#{snippet.id}", user),
252 270 code: 'updated code'
... ...