Commit 89a349f9a525a7fa131d0ac3704b9b770f6850d2
Exists in
master
and in
4 other branches
Merge pull request #1685 from jozefvaclavik/master
Hooks API (List one hook & edit)
Showing
4 changed files
with
90 additions
and
4 deletions
Show diff stats
CHANGELOG
1 | master | 1 | master |
2 | + - [API] list one project hook | ||
3 | + - [API] edit project hook | ||
2 | - [API] add project snippets list | 4 | - [API] add project snippets list |
3 | - [API] allow to authorize using private token in HTTP header | 5 | - [API] allow to authorize using private token in HTTP header |
4 | - [API] add user creation | 6 | - [API] add user creation |
doc/api/projects.md
@@ -196,9 +196,9 @@ Parameters: | @@ -196,9 +196,9 @@ Parameters: | ||
196 | 196 | ||
197 | Status code `200` will be returned on success. | 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 | GET /projects/:id/hooks | 204 | GET /projects/:id/hooks |
@@ -210,6 +210,21 @@ Parameters: | @@ -210,6 +210,21 @@ Parameters: | ||
210 | 210 | ||
211 | Will return hooks with status `200 OK` on success, or `404 Not found` on fail. | 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 | ## Add project hook | 228 | ## Add project hook |
214 | 229 | ||
215 | Add hook to project | 230 | Add hook to project |
@@ -225,6 +240,23 @@ Parameters: | @@ -225,6 +240,23 @@ Parameters: | ||
225 | 240 | ||
226 | Will return status `201 Created` on success, or `404 Not found` on fail. | 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 | ## Delete project hook | 260 | ## Delete project hook |
229 | 261 | ||
230 | Delete hook from project | 262 | Delete hook from project |
lib/api/projects.rb
@@ -147,6 +147,19 @@ module Gitlab | @@ -147,6 +147,19 @@ module Gitlab | ||
147 | @hooks = paginate user_project.hooks | 147 | @hooks = paginate user_project.hooks |
148 | present @hooks, with: Entities::Hook | 148 | present @hooks, with: Entities::Hook |
149 | end | 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 | # Add hook to project | 164 | # Add hook to project |
152 | # | 165 | # |
@@ -164,6 +177,27 @@ module Gitlab | @@ -164,6 +177,27 @@ module Gitlab | ||
164 | error!({'message' => '404 Not found'}, 404) | 177 | error!({'message' => '404 Not found'}, 404) |
165 | end | 178 | end |
166 | end | 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 | # Delete project hook | 202 | # Delete project hook |
169 | # | 203 | # |
spec/requests/api/projects_spec.rb
@@ -172,7 +172,15 @@ describe Gitlab::API do | @@ -172,7 +172,15 @@ describe Gitlab::API do | ||
172 | end | 172 | end |
173 | end | 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 | it "should add hook to project" do | 184 | it "should add hook to project" do |
177 | expect { | 185 | expect { |
178 | post api("/projects/#{project.code}/hooks", user), | 186 | post api("/projects/#{project.code}/hooks", user), |
@@ -180,6 +188,16 @@ describe Gitlab::API do | @@ -180,6 +188,16 @@ describe Gitlab::API do | ||
180 | }.to change {project.hooks.count}.by(1) | 188 | }.to change {project.hooks.count}.by(1) |
181 | end | 189 | end |
182 | end | 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 | describe "DELETE /projects/:id/hooks" do | 202 | describe "DELETE /projects/:id/hooks" do |
185 | it "should delete hook from project" do | 203 | it "should delete hook from project" do |
@@ -246,7 +264,7 @@ describe Gitlab::API do | @@ -246,7 +264,7 @@ describe Gitlab::API do | ||
246 | end | 264 | end |
247 | end | 265 | end |
248 | 266 | ||
249 | - describe "PUT /projects/:id/snippets" do | 267 | + describe "PUT /projects/:id/snippets/:shippet_id" do |
250 | it "should update an existing project snippet" do | 268 | it "should update an existing project snippet" do |
251 | put api("/projects/#{project.code}/snippets/#{snippet.id}", user), | 269 | put api("/projects/#{project.code}/snippets/#{snippet.id}", user), |
252 | code: 'updated code' | 270 | code: 'updated code' |