Commit 4afb7b7cb7b42688bea70298c80b4735f59dab22
Exists in
master
and in
4 other branches
Merge pull request #1522 from NARKOZ/api
API clean up
Showing
17 changed files
with
420 additions
and
458 deletions
Show diff stats
app/views/help/api.html.haml
... | ... | @@ -12,6 +12,8 @@ |
12 | 12 | %li |
13 | 13 | = link_to "Snippets", "#snippets", 'data-toggle' => 'tab' |
14 | 14 | %li |
15 | + = link_to "Repositories", "#repositories", 'data-toggle' => 'tab' | |
16 | + %li | |
15 | 17 | = link_to "Users", "#users", 'data-toggle' => 'tab' |
16 | 18 | %li |
17 | 19 | = link_to "Session", "#session", 'data-toggle' => 'tab' |
... | ... | @@ -19,8 +21,6 @@ |
19 | 21 | = link_to "Issues", "#issues", 'data-toggle' => 'tab' |
20 | 22 | %li |
21 | 23 | = link_to "Milestones", "#milestones", 'data-toggle' => 'tab' |
22 | - %li | |
23 | - = link_to "Commits", "#commits", 'data-toggle' => 'tab' | |
24 | 24 | |
25 | 25 | .tab-content |
26 | 26 | .tab-pane.active#README |
... | ... | @@ -50,6 +50,15 @@ |
50 | 50 | = preserve do |
51 | 51 | = markdown File.read(Rails.root.join("doc", "api", "snippets.md")) |
52 | 52 | |
53 | + .tab-pane#repositories | |
54 | + .file_holder | |
55 | + .file_title | |
56 | + %i.icon-file | |
57 | + Projects | |
58 | + .file_content.wiki | |
59 | + = preserve do | |
60 | + = markdown File.read(Rails.root.join("doc", "api", "repositories.md")) | |
61 | + | |
53 | 62 | .tab-pane#users |
54 | 63 | .file_holder |
55 | 64 | .file_title |
... | ... | @@ -85,12 +94,3 @@ |
85 | 94 | .file_content.wiki |
86 | 95 | = preserve do |
87 | 96 | = markdown File.read(Rails.root.join("doc", "api", "milestones.md")) |
88 | - | |
89 | - .tab-pane#commits | |
90 | - .file_holder | |
91 | - .file_title | |
92 | - %i.icon-file | |
93 | - Commits | |
94 | - .file_content.wiki | |
95 | - = preserve do | |
96 | - = markdown File.read(Rails.root.join("doc", "api", "commits.md")) | ... | ... |
doc/api/README.md
... | ... | @@ -33,6 +33,6 @@ When listing resources you can pass the following parameters: |
33 | 33 | + [Session](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/session.md) |
34 | 34 | + [Projects](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/projects.md) |
35 | 35 | + [Snippets](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/snippets.md) |
36 | ++ [Repositories](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/repositories.md) | |
36 | 37 | + [Issues](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/issues.md) |
37 | 38 | + [Milestones](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/milestones.md) |
38 | -+ [SSH Keys](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/keys.md) | ... | ... |
doc/api/commits.md
... | ... | @@ -1,38 +0,0 @@ |
1 | -## List Commits | |
2 | - | |
3 | -Get a list of project commits. | |
4 | - | |
5 | -``` | |
6 | -GET /projects/:id/commits | |
7 | -``` | |
8 | - | |
9 | -Parameters: | |
10 | - | |
11 | -+ `id` (required) - The ID or code name of a project | |
12 | -+ `ref_name` (optional) - branch/tag name | |
13 | -+ `page` (optional) | |
14 | -+ `per_page` (optional) | |
15 | - | |
16 | - | |
17 | -```json | |
18 | - | |
19 | -[ | |
20 | - { | |
21 | - "id": "ed899a2f4b50b4370feeea94676502b42383c746", | |
22 | - "short_id": "ed899a2f4b5", | |
23 | - "title": "Replace sanitize with escape once", | |
24 | - "author_name": "Dmitriy Zaporozhets", | |
25 | - "author_email": "dzaporozhets@sphereconsultinginc.com", | |
26 | - "created_at": "2012-09-20T11:50:22+03:00" | |
27 | - }, | |
28 | - { | |
29 | - "id": "6104942438c14ec7bd21c6cd5bd995272b3faff6", | |
30 | - "short_id": "6104942438c", | |
31 | - "title": "Sanitize for network graph", | |
32 | - "author_name": "randx", | |
33 | - "author_email": "dmitriy.zaporozhets@gmail.com", | |
34 | - "created_at": "2012-09-20T09:06:12+03:00" | |
35 | - } | |
36 | -] | |
37 | - | |
38 | -``` |
doc/api/keys.md
... | ... | @@ -1,79 +0,0 @@ |
1 | -## List keys | |
2 | - | |
3 | -Get a list of currently authenticated user's keys. | |
4 | - | |
5 | -``` | |
6 | -GET /keys | |
7 | -``` | |
8 | - | |
9 | -```json | |
10 | -[ | |
11 | - { | |
12 | - "id": 1, | |
13 | - "title" : "Public key" | |
14 | - "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4 | |
15 | - 596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4 | |
16 | - soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=", | |
17 | - }, | |
18 | - { | |
19 | - "id": 3, | |
20 | - "title" : "Another Public key" | |
21 | - "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4 | |
22 | - 596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4 | |
23 | - soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=" | |
24 | - } | |
25 | -] | |
26 | -``` | |
27 | - | |
28 | -## Single key | |
29 | - | |
30 | -Get a single key. | |
31 | - | |
32 | -``` | |
33 | -GET /keys/:id | |
34 | -``` | |
35 | - | |
36 | -Parameters: | |
37 | - | |
38 | -+ `id` (required) - The ID of a key | |
39 | - | |
40 | -```json | |
41 | -{ | |
42 | - "id": 1, | |
43 | - "title" : "Public key" | |
44 | - "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4 | |
45 | - 596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4 | |
46 | - soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=" | |
47 | -} | |
48 | -``` | |
49 | -## Add key | |
50 | - | |
51 | -Create new key owned by currently authenticated user | |
52 | - | |
53 | -``` | |
54 | -POST /keys | |
55 | -``` | |
56 | - | |
57 | -Parameters: | |
58 | - | |
59 | -+ `title` (required) - new SSH Key's title | |
60 | -+ `key` (required) - new SSH key | |
61 | - | |
62 | -Will return created key with status `201 Created` on success, or `404 Not | |
63 | -found` on fail. | |
64 | - | |
65 | -## Delete key | |
66 | - | |
67 | -Delete key owned by currently authenticated user | |
68 | - | |
69 | -``` | |
70 | -DELETE /keys/:id | |
71 | -``` | |
72 | - | |
73 | -Parameters: | |
74 | - | |
75 | -+ `id` (required) - key ID | |
76 | - | |
77 | -Will return `200 OK` on success, or `404 Not Found` on fail. | |
78 | - | |
79 | - |
doc/api/projects.md
... | ... | @@ -239,135 +239,3 @@ Parameters: |
239 | 239 | + `hook_id` (required) - The ID of hook to delete |
240 | 240 | |
241 | 241 | Will return status `200 OK` on success, or `404 Not found` on fail. |
242 | - | |
243 | -## Project repository branches | |
244 | - | |
245 | -Get a list of repository branches from a project, sorted by name alphabetically. | |
246 | - | |
247 | -``` | |
248 | -GET /projects/:id/repository/branches | |
249 | -``` | |
250 | - | |
251 | -Parameters: | |
252 | - | |
253 | -+ `id` (required) - The ID or code name of a project | |
254 | - | |
255 | -```json | |
256 | -[ | |
257 | - { | |
258 | - "name": "master", | |
259 | - "commit": { | |
260 | - "id": "7b5c3cc8be40ee161ae89a06bba6229da1032a0c", | |
261 | - "parents": [ | |
262 | - { | |
263 | - "id": "4ad91d3c1144c406e50c7b33bae684bd6837faf8" | |
264 | - } | |
265 | - ], | |
266 | - "tree": "46e82de44b1061621357f24c05515327f2795a95", | |
267 | - "message": "add projects API", | |
268 | - "author": { | |
269 | - "name": "John Smith", | |
270 | - "email": "john@example.com" | |
271 | - }, | |
272 | - "committer": { | |
273 | - "name": "John Smith", | |
274 | - "email": "john@example.com" | |
275 | - }, | |
276 | - "authored_date": "2012-06-27T05:51:39-07:00", | |
277 | - "committed_date": "2012-06-28T03:44:20-07:00" | |
278 | - } | |
279 | - } | |
280 | -] | |
281 | -``` | |
282 | - | |
283 | -Get a single project repository branch. | |
284 | - | |
285 | -``` | |
286 | -GET /projects/:id/repository/branches/:branch | |
287 | -``` | |
288 | - | |
289 | -Parameters: | |
290 | - | |
291 | -+ `id` (required) - The ID or code name of a project | |
292 | -+ `branch` (required) - The name of the branch | |
293 | - | |
294 | -```json | |
295 | -{ | |
296 | - "name": "master", | |
297 | - "commit": { | |
298 | - "id": "7b5c3cc8be40ee161ae89a06bba6229da1032a0c", | |
299 | - "parents": [ | |
300 | - { | |
301 | - "id": "4ad91d3c1144c406e50c7b33bae684bd6837faf8" | |
302 | - } | |
303 | - ], | |
304 | - "tree": "46e82de44b1061621357f24c05515327f2795a95", | |
305 | - "message": "add projects API", | |
306 | - "author": { | |
307 | - "name": "John Smith", | |
308 | - "email": "john@example.com" | |
309 | - }, | |
310 | - "committer": { | |
311 | - "name": "John Smith", | |
312 | - "email": "john@example.com" | |
313 | - }, | |
314 | - "authored_date": "2012-06-27T05:51:39-07:00", | |
315 | - "committed_date": "2012-06-28T03:44:20-07:00" | |
316 | - } | |
317 | -} | |
318 | -``` | |
319 | - | |
320 | -## Project repository tags | |
321 | - | |
322 | -Get a list of repository tags from a project, sorted by name in reverse alphabetical order. | |
323 | - | |
324 | -``` | |
325 | -GET /projects/:id/repository/tags | |
326 | -``` | |
327 | - | |
328 | -Parameters: | |
329 | - | |
330 | -+ `id` (required) - The ID or code name of a project | |
331 | - | |
332 | -```json | |
333 | -[ | |
334 | - { | |
335 | - "name": "v1.0.0", | |
336 | - "commit": { | |
337 | - "id": "2695effb5807a22ff3d138d593fd856244e155e7", | |
338 | - "parents": [ | |
339 | - | |
340 | - ], | |
341 | - "tree": "38017f2f189336fe4497e9d230c5bb1bf873f08d", | |
342 | - "message": "Initial commit", | |
343 | - "author": { | |
344 | - "name": "John Smith", | |
345 | - "email": "john@example.com" | |
346 | - }, | |
347 | - "committer": { | |
348 | - "name": "Jack Smith", | |
349 | - "email": "jack@example.com" | |
350 | - }, | |
351 | - "authored_date": "2012-05-28T04:42:42-07:00", | |
352 | - "committed_date": "2012-05-28T04:42:42-07:00" | |
353 | - } | |
354 | - } | |
355 | -] | |
356 | -``` | |
357 | - | |
358 | -## Raw blob content | |
359 | - | |
360 | -Get the raw file contents for a file. | |
361 | - | |
362 | -``` | |
363 | -GET /projects/:id/repository/commits/:sha/blob | |
364 | -``` | |
365 | - | |
366 | -Parameters: | |
367 | - | |
368 | -+ `id` (required) - The ID or code name of a project | |
369 | -+ `sha` (required) - The commit or branch name | |
370 | -+ `filepath` (required) - The path the file | |
371 | - | |
372 | -Will return the raw file contents. | |
373 | - | ... | ... |
... | ... | @@ -0,0 +1,166 @@ |
1 | +## Project repository branches | |
2 | + | |
3 | +Get a list of repository branches from a project, sorted by name alphabetically. | |
4 | + | |
5 | +``` | |
6 | +GET /projects/:id/repository/branches | |
7 | +``` | |
8 | + | |
9 | +Parameters: | |
10 | + | |
11 | ++ `id` (required) - The ID or code name of a project | |
12 | + | |
13 | +```json | |
14 | +[ | |
15 | + { | |
16 | + "name": "master", | |
17 | + "commit": { | |
18 | + "id": "7b5c3cc8be40ee161ae89a06bba6229da1032a0c", | |
19 | + "parents": [ | |
20 | + { | |
21 | + "id": "4ad91d3c1144c406e50c7b33bae684bd6837faf8" | |
22 | + } | |
23 | + ], | |
24 | + "tree": "46e82de44b1061621357f24c05515327f2795a95", | |
25 | + "message": "add projects API", | |
26 | + "author": { | |
27 | + "name": "John Smith", | |
28 | + "email": "john@example.com" | |
29 | + }, | |
30 | + "committer": { | |
31 | + "name": "John Smith", | |
32 | + "email": "john@example.com" | |
33 | + }, | |
34 | + "authored_date": "2012-06-27T05:51:39-07:00", | |
35 | + "committed_date": "2012-06-28T03:44:20-07:00" | |
36 | + } | |
37 | + } | |
38 | +] | |
39 | +``` | |
40 | + | |
41 | +## Project repository branch | |
42 | + | |
43 | +Get a single project repository branch. | |
44 | + | |
45 | +``` | |
46 | +GET /projects/:id/repository/branches/:branch | |
47 | +``` | |
48 | + | |
49 | +Parameters: | |
50 | + | |
51 | ++ `id` (required) - The ID or code name of a project | |
52 | ++ `branch` (required) - The name of the branch | |
53 | + | |
54 | +```json | |
55 | +{ | |
56 | + "name": "master", | |
57 | + "commit": { | |
58 | + "id": "7b5c3cc8be40ee161ae89a06bba6229da1032a0c", | |
59 | + "parents": [ | |
60 | + { | |
61 | + "id": "4ad91d3c1144c406e50c7b33bae684bd6837faf8" | |
62 | + } | |
63 | + ], | |
64 | + "tree": "46e82de44b1061621357f24c05515327f2795a95", | |
65 | + "message": "add projects API", | |
66 | + "author": { | |
67 | + "name": "John Smith", | |
68 | + "email": "john@example.com" | |
69 | + }, | |
70 | + "committer": { | |
71 | + "name": "John Smith", | |
72 | + "email": "john@example.com" | |
73 | + }, | |
74 | + "authored_date": "2012-06-27T05:51:39-07:00", | |
75 | + "committed_date": "2012-06-28T03:44:20-07:00" | |
76 | + } | |
77 | +} | |
78 | +``` | |
79 | + | |
80 | +## Project repository tags | |
81 | + | |
82 | +Get a list of repository tags from a project, sorted by name in reverse alphabetical order. | |
83 | + | |
84 | +``` | |
85 | +GET /projects/:id/repository/tags | |
86 | +``` | |
87 | + | |
88 | +Parameters: | |
89 | + | |
90 | ++ `id` (required) - The ID or code name of a project | |
91 | + | |
92 | +```json | |
93 | +[ | |
94 | + { | |
95 | + "name": "v1.0.0", | |
96 | + "commit": { | |
97 | + "id": "2695effb5807a22ff3d138d593fd856244e155e7", | |
98 | + "parents": [ | |
99 | + | |
100 | + ], | |
101 | + "tree": "38017f2f189336fe4497e9d230c5bb1bf873f08d", | |
102 | + "message": "Initial commit", | |
103 | + "author": { | |
104 | + "name": "John Smith", | |
105 | + "email": "john@example.com" | |
106 | + }, | |
107 | + "committer": { | |
108 | + "name": "Jack Smith", | |
109 | + "email": "jack@example.com" | |
110 | + }, | |
111 | + "authored_date": "2012-05-28T04:42:42-07:00", | |
112 | + "committed_date": "2012-05-28T04:42:42-07:00" | |
113 | + } | |
114 | + } | |
115 | +] | |
116 | +``` | |
117 | + | |
118 | +## Project repository commits | |
119 | + | |
120 | +Get a list of repository commits in a project. | |
121 | + | |
122 | +``` | |
123 | +GET /projects/:id/repository/commits | |
124 | +``` | |
125 | + | |
126 | +Parameters: | |
127 | + | |
128 | ++ `id` (required) - The ID or code name of a project | |
129 | ++ `ref_name` (optional) - The name of a repository branch or tag | |
130 | + | |
131 | +```json | |
132 | +[ | |
133 | + { | |
134 | + "id": "ed899a2f4b50b4370feeea94676502b42383c746", | |
135 | + "short_id": "ed899a2f4b5", | |
136 | + "title": "Replace sanitize with escape once", | |
137 | + "author_name": "Dmitriy Zaporozhets", | |
138 | + "author_email": "dzaporozhets@sphereconsultinginc.com", | |
139 | + "created_at": "2012-09-20T11:50:22+03:00" | |
140 | + }, | |
141 | + { | |
142 | + "id": "6104942438c14ec7bd21c6cd5bd995272b3faff6", | |
143 | + "short_id": "6104942438c", | |
144 | + "title": "Sanitize for network graph", | |
145 | + "author_name": "randx", | |
146 | + "author_email": "dmitriy.zaporozhets@gmail.com", | |
147 | + "created_at": "2012-09-20T09:06:12+03:00" | |
148 | + } | |
149 | +] | |
150 | +``` | |
151 | + | |
152 | +## Raw blob content | |
153 | + | |
154 | +Get the raw file contents for a file. | |
155 | + | |
156 | +``` | |
157 | +GET /projects/:id/repository/commits/:sha/blob | |
158 | +``` | |
159 | + | |
160 | +Parameters: | |
161 | + | |
162 | ++ `id` (required) - The ID or code name of a project | |
163 | ++ `sha` (required) - The commit or branch name | |
164 | ++ `filepath` (required) - The path the file | |
165 | + | |
166 | +Will return the raw file contents. | ... | ... |
doc/api/users.md
... | ... | @@ -88,3 +88,81 @@ GET /user |
88 | 88 | "theme_id": 1 |
89 | 89 | } |
90 | 90 | ``` |
91 | + | |
92 | +## List SSH keys | |
93 | + | |
94 | +Get a list of currently authenticated user's SSH keys. | |
95 | + | |
96 | +``` | |
97 | +GET /user/keys | |
98 | +``` | |
99 | + | |
100 | +```json | |
101 | +[ | |
102 | + { | |
103 | + "id": 1, | |
104 | + "title" : "Public key" | |
105 | + "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4 | |
106 | + 596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4 | |
107 | + soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=", | |
108 | + }, | |
109 | + { | |
110 | + "id": 3, | |
111 | + "title" : "Another Public key" | |
112 | + "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4 | |
113 | + 596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4 | |
114 | + soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=" | |
115 | + } | |
116 | +] | |
117 | +``` | |
118 | + | |
119 | +## Single SSH key | |
120 | + | |
121 | +Get a single key. | |
122 | + | |
123 | +``` | |
124 | +GET /user/keys/:id | |
125 | +``` | |
126 | + | |
127 | +Parameters: | |
128 | + | |
129 | ++ `id` (required) - The ID of an SSH key | |
130 | + | |
131 | +```json | |
132 | +{ | |
133 | + "id": 1, | |
134 | + "title" : "Public key" | |
135 | + "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4 | |
136 | + 596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4 | |
137 | + soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=" | |
138 | +} | |
139 | +``` | |
140 | +## Add SSH key | |
141 | + | |
142 | +Create new key owned by currently authenticated user | |
143 | + | |
144 | +``` | |
145 | +POST /user/keys | |
146 | +``` | |
147 | + | |
148 | +Parameters: | |
149 | + | |
150 | ++ `title` (required) - new SSH Key's title | |
151 | ++ `key` (required) - new SSH key | |
152 | + | |
153 | +Will return created key with status `201 Created` on success, or `404 Not | |
154 | +found` on fail. | |
155 | + | |
156 | +## Delete SSH key | |
157 | + | |
158 | +Delete key owned by currently authenticated user | |
159 | + | |
160 | +``` | |
161 | +DELETE /user/keys/:id | |
162 | +``` | |
163 | + | |
164 | +Parameters: | |
165 | + | |
166 | ++ `id` (required) - SSH key ID | |
167 | + | |
168 | +Will return `200 OK` on success, or `404 Not Found` on fail. | ... | ... |
lib/api.rb
lib/api/commits.rb
... | ... | @@ -1,29 +0,0 @@ |
1 | -module Gitlab | |
2 | - # Commits API | |
3 | - class Commits < Grape::API | |
4 | - before { authenticate! } | |
5 | - | |
6 | - resource :projects do | |
7 | - # Get a list of project commits | |
8 | - # | |
9 | - # Parameters: | |
10 | - # id (required) - The ID or code name of a project | |
11 | - # ref_name (optional) - Name of branch or tag | |
12 | - # page (optional) - default is 0 | |
13 | - # per_page (optional) - default is 20 | |
14 | - # Example Request: | |
15 | - # GET /projects/:id/commits | |
16 | - get ":id/commits" do | |
17 | - authorize! :download_code, user_project | |
18 | - | |
19 | - page = params[:page] || 0 | |
20 | - per_page = params[:per_page] || 20 | |
21 | - ref = params[:ref_name] || user_project.try(:default_branch) || 'master' | |
22 | - | |
23 | - commits = user_project.commits(ref, nil, per_page, page * per_page) | |
24 | - | |
25 | - present CommitDecorator.decorate(commits), with: Entities::Commit | |
26 | - end | |
27 | - end | |
28 | - end | |
29 | -end |
lib/api/entities.rb
... | ... | @@ -17,11 +17,6 @@ module Gitlab |
17 | 17 | expose :id, :url |
18 | 18 | end |
19 | 19 | |
20 | - class Commit < Grape::Entity | |
21 | - expose :id, :short_id, :title, | |
22 | - :author_name, :author_email, :created_at | |
23 | - end | |
24 | - | |
25 | 20 | class Project < Grape::Entity |
26 | 21 | expose :id, :code, :name, :description, :path, :default_branch |
27 | 22 | expose :owner, using: Entities::UserBasic |
... | ... | @@ -39,6 +34,10 @@ module Gitlab |
39 | 34 | expose :name, :commit |
40 | 35 | end |
41 | 36 | |
37 | + class RepoCommit < Grape::Entity | |
38 | + expose :id, :short_id, :title, :author_name, :author_email, :created_at | |
39 | + end | |
40 | + | |
42 | 41 | class ProjectSnippet < Grape::Entity |
43 | 42 | expose :id, :title, :file_name |
44 | 43 | expose :author, using: Entities::UserBasic |
... | ... | @@ -61,8 +60,8 @@ module Gitlab |
61 | 60 | expose :closed, :updated_at, :created_at |
62 | 61 | end |
63 | 62 | |
64 | - class Key < Grape::Entity | |
65 | - expose :id, :title, :key | |
63 | + class SSHKey < Grape::Entity | |
64 | + expose :id, :title, :key | |
66 | 65 | end |
67 | 66 | end |
68 | 67 | end | ... | ... |
lib/api/keys.rb
... | ... | @@ -1,50 +0,0 @@ |
1 | -module Gitlab | |
2 | - # Keys API | |
3 | - class Keys < Grape::API | |
4 | - before { authenticate! } | |
5 | - resource :keys do | |
6 | - # Get currently authenticated user's keys | |
7 | - # | |
8 | - # Example Request: | |
9 | - # GET /keys | |
10 | - get do | |
11 | - present current_user.keys, with: Entities::Key | |
12 | - end | |
13 | - # Get single key owned by currently authenticated user | |
14 | - # | |
15 | - # Example Request: | |
16 | - # GET /keys/:id | |
17 | - get "/:id" do | |
18 | - key = current_user.keys.find params[:id] | |
19 | - present key, with: Entities::Key | |
20 | - end | |
21 | - # Add new ssh key to currently authenticated user | |
22 | - # | |
23 | - # Parameters: | |
24 | - # key (required) - New SSH Key | |
25 | - # title (required) - New SSH Key's title | |
26 | - # Example Request: | |
27 | - # POST /keys | |
28 | - post do | |
29 | - attrs = attributes_for_keys [:title, :key] | |
30 | - key = current_user.keys.new attrs | |
31 | - if key.save | |
32 | - present key, with: Entities::Key | |
33 | - else | |
34 | - not_found! | |
35 | - end | |
36 | - end | |
37 | - # Delete existed ssh key of currently authenticated user | |
38 | - # | |
39 | - # Parameters: | |
40 | - # id (required) - SSH Key ID | |
41 | - # Example Request: | |
42 | - # DELETE /keys/:id | |
43 | - delete "/:id" do | |
44 | - key = current_user.keys.find params[:id] | |
45 | - key.delete | |
46 | - end | |
47 | - end | |
48 | - end | |
49 | -end | |
50 | - |
lib/api/projects.rb
... | ... | @@ -211,6 +211,24 @@ module Gitlab |
211 | 211 | present user_project.repo.tags.sort_by(&:name).reverse, with: Entities::RepoObject |
212 | 212 | end |
213 | 213 | |
214 | + # Get a project repository commits | |
215 | + # | |
216 | + # Parameters: | |
217 | + # id (required) - The ID or code name of a project | |
218 | + # ref_name (optional) - The name of a repository branch or tag | |
219 | + # Example Request: | |
220 | + # GET /projects/:id/repository/commits | |
221 | + get ":id/repository/commits" do | |
222 | + authorize! :download_code, user_project | |
223 | + | |
224 | + page = params[:page] || 0 | |
225 | + per_page = params[:per_page] || 20 | |
226 | + ref = params[:ref_name] || user_project.try(:default_branch) || 'master' | |
227 | + | |
228 | + commits = user_project.commits(ref, nil, per_page, page * per_page) | |
229 | + present CommitDecorator.decorate(commits), with: Entities::RepoCommit | |
230 | + end | |
231 | + | |
214 | 232 | # Get a project snippet |
215 | 233 | # |
216 | 234 | # Parameters: | ... | ... |
lib/api/users.rb
... | ... | @@ -25,12 +25,59 @@ module Gitlab |
25 | 25 | end |
26 | 26 | end |
27 | 27 | |
28 | - # Get currently authenticated user | |
29 | - # | |
30 | - # Example Request: | |
31 | - # GET /user | |
32 | - get "/user" do | |
33 | - present @current_user, with: Entities::User | |
28 | + resource :user do | |
29 | + # Get currently authenticated user | |
30 | + # | |
31 | + # Example Request: | |
32 | + # GET /user | |
33 | + get do | |
34 | + present @current_user, with: Entities::User | |
35 | + end | |
36 | + | |
37 | + # Get currently authenticated user's keys | |
38 | + # | |
39 | + # Example Request: | |
40 | + # GET /user/keys | |
41 | + get "keys" do | |
42 | + present current_user.keys, with: Entities::SSHKey | |
43 | + end | |
44 | + | |
45 | + # Get single key owned by currently authenticated user | |
46 | + # | |
47 | + # Example Request: | |
48 | + # GET /user/keys/:id | |
49 | + get "keys/:id" do | |
50 | + key = current_user.keys.find params[:id] | |
51 | + present key, with: Entities::SSHKey | |
52 | + end | |
53 | + | |
54 | + # Add new ssh key to currently authenticated user | |
55 | + # | |
56 | + # Parameters: | |
57 | + # key (required) - New SSH Key | |
58 | + # title (required) - New SSH Key's title | |
59 | + # Example Request: | |
60 | + # POST /user/keys | |
61 | + post "keys" do | |
62 | + attrs = attributes_for_keys [:title, :key] | |
63 | + key = current_user.keys.new attrs | |
64 | + if key.save | |
65 | + present key, with: Entities::SSHKey | |
66 | + else | |
67 | + not_found! | |
68 | + end | |
69 | + end | |
70 | + | |
71 | + # Delete existed ssh key of currently authenticated user | |
72 | + # | |
73 | + # Parameters: | |
74 | + # id (required) - SSH Key ID | |
75 | + # Example Request: | |
76 | + # DELETE /user/keys/:id | |
77 | + delete "keys/:id" do | |
78 | + key = current_user.keys.find params[:id] | |
79 | + key.delete | |
80 | + end | |
34 | 81 | end |
35 | 82 | end |
36 | 83 | end | ... | ... |
spec/requests/api/commits_spec.rb
... | ... | @@ -1,29 +0,0 @@ |
1 | -require 'spec_helper' | |
2 | - | |
3 | -describe Gitlab::API do | |
4 | - include ApiHelpers | |
5 | - | |
6 | - let(:user) { Factory :user } | |
7 | - let!(:project) { Factory :project, owner: user } | |
8 | - | |
9 | - describe "GET /projects/:id/commits" do | |
10 | - context "authorized user" do | |
11 | - before { project.add_access(user, :read) } | |
12 | - | |
13 | - it "should return project commits" do | |
14 | - get api("/projects/#{project.code}/commits", user) | |
15 | - response.status.should == 200 | |
16 | - | |
17 | - json_response.should be_an Array | |
18 | - json_response.first['id'].should == project.commit.id | |
19 | - end | |
20 | - end | |
21 | - | |
22 | - context "unauthorized user" do | |
23 | - it "should return project commits" do | |
24 | - get api("/projects/#{project.code}/commits") | |
25 | - response.status.should == 401 | |
26 | - end | |
27 | - end | |
28 | - end | |
29 | -end |
spec/requests/api/projects_spec.rb
... | ... | @@ -199,6 +199,27 @@ describe Gitlab::API do |
199 | 199 | end |
200 | 200 | end |
201 | 201 | |
202 | + describe "GET /projects/:id/repository/commits" do | |
203 | + context "authorized user" do | |
204 | + before { project.add_access(user2, :read) } | |
205 | + | |
206 | + it "should return project commits" do | |
207 | + get api("/projects/#{project.code}/repository/commits", user) | |
208 | + response.status.should == 200 | |
209 | + | |
210 | + json_response.should be_an Array | |
211 | + json_response.first['id'].should == project.commit.id | |
212 | + end | |
213 | + end | |
214 | + | |
215 | + context "unauthorized user" do | |
216 | + it "should not return project commits" do | |
217 | + get api("/projects/#{project.code}/repository/commits") | |
218 | + response.status.should == 401 | |
219 | + end | |
220 | + end | |
221 | + end | |
222 | + | |
202 | 223 | describe "GET /projects/:id/snippets/:snippet_id" do |
203 | 224 | it "should return a project snippet" do |
204 | 225 | get api("/projects/#{project.code}/snippets/#{snippet.id}", user) | ... | ... |
spec/requests/api/ssh_keys_spec.rb
... | ... | @@ -1,73 +0,0 @@ |
1 | -require 'spec_helper' | |
2 | - | |
3 | -describe Gitlab::Keys do | |
4 | - include ApiHelpers | |
5 | - let(:user) { | |
6 | - user = Factory.create :user | |
7 | - user.reset_authentication_token! | |
8 | - user | |
9 | - } | |
10 | - let(:key) { Factory.create :key, { user: user}} | |
11 | - | |
12 | - describe "GET /keys" do | |
13 | - context "when unauthenticated" do | |
14 | - it "should return authentication error" do | |
15 | - get api("/keys") | |
16 | - response.status.should == 401 | |
17 | - end | |
18 | - end | |
19 | - context "when authenticated" do | |
20 | - it "should return array of ssh keys" do | |
21 | - user.keys << key | |
22 | - user.save | |
23 | - get api("/keys", user) | |
24 | - response.status.should == 200 | |
25 | - json_response.should be_an Array | |
26 | - json_response.first["title"].should == key.title | |
27 | - end | |
28 | - end | |
29 | - end | |
30 | - | |
31 | - describe "GET /keys/:id" do | |
32 | - it "should returm single key" do | |
33 | - user.keys << key | |
34 | - user.save | |
35 | - get api("/keys/#{key.id}", user) | |
36 | - response.status.should == 200 | |
37 | - json_response["title"].should == key.title | |
38 | - end | |
39 | - it "should return 404 Not Found within invalid ID" do | |
40 | - get api("/keys/42", user) | |
41 | - response.status.should == 404 | |
42 | - end | |
43 | - end | |
44 | - | |
45 | - describe "POST /keys" do | |
46 | - it "should not create invalid ssh key" do | |
47 | - post api("/keys", user), { title: "invalid key" } | |
48 | - response.status.should == 404 | |
49 | - end | |
50 | - it "should create ssh key" do | |
51 | - key_attrs = Factory.attributes :key | |
52 | - expect { | |
53 | - post api("/keys", user), key_attrs | |
54 | - }.to change{ user.keys.count }.by(1) | |
55 | - end | |
56 | - end | |
57 | - | |
58 | - describe "DELETE /keys/:id" do | |
59 | - it "should delete existed key" do | |
60 | - user.keys << key | |
61 | - user.save | |
62 | - expect { | |
63 | - delete api("/keys/#{key.id}", user) | |
64 | - }.to change{user.keys.count}.by(-1) | |
65 | - end | |
66 | - it "should return 404 Not Found within invalid ID" do | |
67 | - delete api("/keys/42", user) | |
68 | - response.status.should == 404 | |
69 | - end | |
70 | - end | |
71 | - | |
72 | -end | |
73 | - |
spec/requests/api/users_spec.rb
... | ... | @@ -3,7 +3,8 @@ require 'spec_helper' |
3 | 3 | describe Gitlab::API do |
4 | 4 | include ApiHelpers |
5 | 5 | |
6 | - let(:user) { Factory :user } | |
6 | + let(:user) { Factory :user } | |
7 | + let(:key) { Factory :key, user: user } | |
7 | 8 | |
8 | 9 | describe "GET /users" do |
9 | 10 | context "when unauthenticated" do |
... | ... | @@ -38,4 +39,68 @@ describe Gitlab::API do |
38 | 39 | json_response['email'].should == user.email |
39 | 40 | end |
40 | 41 | end |
42 | + | |
43 | + describe "GET /user/keys" do | |
44 | + context "when unauthenticated" do | |
45 | + it "should return authentication error" do | |
46 | + get api("/user/keys") | |
47 | + response.status.should == 401 | |
48 | + end | |
49 | + end | |
50 | + | |
51 | + context "when authenticated" do | |
52 | + it "should return array of ssh keys" do | |
53 | + user.keys << key | |
54 | + user.save | |
55 | + get api("/user/keys", user) | |
56 | + response.status.should == 200 | |
57 | + json_response.should be_an Array | |
58 | + json_response.first["title"].should == key.title | |
59 | + end | |
60 | + end | |
61 | + end | |
62 | + | |
63 | + describe "GET /user/keys/:id" do | |
64 | + it "should returm single key" do | |
65 | + user.keys << key | |
66 | + user.save | |
67 | + get api("/user/keys/#{key.id}", user) | |
68 | + response.status.should == 200 | |
69 | + json_response["title"].should == key.title | |
70 | + end | |
71 | + | |
72 | + it "should return 404 Not Found within invalid ID" do | |
73 | + get api("/user/keys/42", user) | |
74 | + response.status.should == 404 | |
75 | + end | |
76 | + end | |
77 | + | |
78 | + describe "POST /user/keys" do | |
79 | + it "should not create invalid ssh key" do | |
80 | + post api("/user/keys", user), { title: "invalid key" } | |
81 | + response.status.should == 404 | |
82 | + end | |
83 | + | |
84 | + it "should create ssh key" do | |
85 | + key_attrs = Factory.attributes :key | |
86 | + expect { | |
87 | + post api("/user/keys", user), key_attrs | |
88 | + }.to change{ user.keys.count }.by(1) | |
89 | + end | |
90 | + end | |
91 | + | |
92 | + describe "DELETE /user/keys/:id" do | |
93 | + it "should delete existed key" do | |
94 | + user.keys << key | |
95 | + user.save | |
96 | + expect { | |
97 | + delete api("/user/keys/#{key.id}", user) | |
98 | + }.to change{user.keys.count}.by(-1) | |
99 | + end | |
100 | + | |
101 | + it "should return 404 Not Found within invalid ID" do | |
102 | + delete api("/user/keys/42", user) | |
103 | + response.status.should == 404 | |
104 | + end | |
105 | + end | |
41 | 106 | end | ... | ... |