Commit f9c6d8a45b080d6a0bc69221e570d6c102525670
Exists in
master
and in
4 other branches
Merge pull request #1142 from NARKOZ/api
API changes
Showing
7 changed files
with
55 additions
and
32 deletions
Show diff stats
doc/api/issues.md
@@ -10,6 +10,7 @@ GET /issues | @@ -10,6 +10,7 @@ GET /issues | ||
10 | [ | 10 | [ |
11 | { | 11 | { |
12 | "id": 43, | 12 | "id": 43, |
13 | + "project_id": 8, | ||
13 | "title": "4xx/5xx pages", | 14 | "title": "4xx/5xx pages", |
14 | "description": "", | 15 | "description": "", |
15 | "labels": [ ], | 16 | "labels": [ ], |
@@ -28,6 +29,7 @@ GET /issues | @@ -28,6 +29,7 @@ GET /issues | ||
28 | }, | 29 | }, |
29 | { | 30 | { |
30 | "id": 42, | 31 | "id": 42, |
32 | + "project_id": 8, | ||
31 | "title": "Add user settings", | 33 | "title": "Add user settings", |
32 | "description": "", | 34 | "description": "", |
33 | "labels": [ | 35 | "labels": [ |
@@ -73,7 +75,7 @@ GET /projects/:id/issues | @@ -73,7 +75,7 @@ GET /projects/:id/issues | ||
73 | 75 | ||
74 | Parameters: | 76 | Parameters: |
75 | 77 | ||
76 | -+ `id` (required) - The code name of a project | 78 | ++ `id` (required) - The ID or code name of a project |
77 | 79 | ||
78 | ## Single issue | 80 | ## Single issue |
79 | 81 | ||
@@ -85,12 +87,13 @@ GET /projects/:id/issues/:issue_id | @@ -85,12 +87,13 @@ GET /projects/:id/issues/:issue_id | ||
85 | 87 | ||
86 | Parameters: | 88 | Parameters: |
87 | 89 | ||
88 | -+ `id` (required) - The code name of a project | 90 | ++ `id` (required) - The ID or code name of a project |
89 | + `issue_id` (required) - The ID of a project issue | 91 | + `issue_id` (required) - The ID of a project issue |
90 | 92 | ||
91 | ```json | 93 | ```json |
92 | { | 94 | { |
93 | "id": 42, | 95 | "id": 42, |
96 | + "project_id": 8, | ||
94 | "title": "Add user settings", | 97 | "title": "Add user settings", |
95 | "description": "", | 98 | "description": "", |
96 | "labels": [ | 99 | "labels": [ |
@@ -135,7 +138,7 @@ POST /projects/:id/issues | @@ -135,7 +138,7 @@ POST /projects/:id/issues | ||
135 | 138 | ||
136 | Parameters: | 139 | Parameters: |
137 | 140 | ||
138 | -+ `id` (required) - The code name of a project | 141 | ++ `id` (required) - The ID or code name of a project |
139 | + `title` (required) - The title of an issue | 142 | + `title` (required) - The title of an issue |
140 | + `description` (optional) - The description of an issue | 143 | + `description` (optional) - The description of an issue |
141 | + `assignee_id` (optional) - The ID of a user to assign issue | 144 | + `assignee_id` (optional) - The ID of a user to assign issue |
@@ -154,7 +157,7 @@ PUT /projects/:id/issues/:issue_id | @@ -154,7 +157,7 @@ PUT /projects/:id/issues/:issue_id | ||
154 | 157 | ||
155 | Parameters: | 158 | Parameters: |
156 | 159 | ||
157 | -+ `id` (required) - The code name of a project | 160 | ++ `id` (required) - The ID or code name of a project |
158 | + `issue_id` (required) - The ID of a project's issue | 161 | + `issue_id` (required) - The ID of a project's issue |
159 | + `title` (optional) - The title of an issue | 162 | + `title` (optional) - The title of an issue |
160 | + `description` (optional) - The description of an issue | 163 | + `description` (optional) - The description of an issue |
@@ -175,7 +178,7 @@ DELETE /projects/:id/issues/:issue_id | @@ -175,7 +178,7 @@ DELETE /projects/:id/issues/:issue_id | ||
175 | 178 | ||
176 | Parameters: | 179 | Parameters: |
177 | 180 | ||
178 | -+ `id` (required) - The code name of a project | 181 | ++ `id` (required) - The ID or code name of a project |
179 | + `issue_id` (required) - The ID of a project's issue | 182 | + `issue_id` (required) - The ID of a project's issue |
180 | 183 | ||
181 | Status code `200` will be returned on success. | 184 | Status code `200` will be returned on success. |
doc/api/projects.md
1 | ## List projects | 1 | ## List projects |
2 | 2 | ||
3 | -Get a list of authenticated users' projects. | 3 | +Get a list of authenticated user's projects. |
4 | 4 | ||
5 | ``` | 5 | ``` |
6 | GET /projects | 6 | GET /projects |
@@ -63,7 +63,7 @@ GET /projects/:id | @@ -63,7 +63,7 @@ GET /projects/:id | ||
63 | 63 | ||
64 | Parameters: | 64 | Parameters: |
65 | 65 | ||
66 | -+ `id` (required) - The code name of a project | 66 | ++ `id` (required) - The ID or code name of a project |
67 | 67 | ||
68 | ```json | 68 | ```json |
69 | { | 69 | { |
@@ -91,7 +91,7 @@ Parameters: | @@ -91,7 +91,7 @@ Parameters: | ||
91 | 91 | ||
92 | ## Project repository branches | 92 | ## Project repository branches |
93 | 93 | ||
94 | -Get a list of project repository branches. | 94 | +Get a list of project repository branches sorted by name alphabetically. |
95 | 95 | ||
96 | ``` | 96 | ``` |
97 | GET /projects/:id/repository/branches | 97 | GET /projects/:id/repository/branches |
@@ -99,7 +99,7 @@ GET /projects/:id/repository/branches | @@ -99,7 +99,7 @@ GET /projects/:id/repository/branches | ||
99 | 99 | ||
100 | Parameters: | 100 | Parameters: |
101 | 101 | ||
102 | -+ `id` (required) - The code name of a project | 102 | ++ `id` (required) - The ID or code name of a project |
103 | 103 | ||
104 | ```json | 104 | ```json |
105 | [ | 105 | [ |
@@ -131,7 +131,7 @@ Parameters: | @@ -131,7 +131,7 @@ Parameters: | ||
131 | 131 | ||
132 | ## Project repository tags | 132 | ## Project repository tags |
133 | 133 | ||
134 | -Get a list of project repository tags. | 134 | +Get a list of project repository tags sorted by name in reverse alphabetical order. |
135 | 135 | ||
136 | ``` | 136 | ``` |
137 | GET /projects/:id/repository/tags | 137 | GET /projects/:id/repository/tags |
@@ -139,7 +139,7 @@ GET /projects/:id/repository/tags | @@ -139,7 +139,7 @@ GET /projects/:id/repository/tags | ||
139 | 139 | ||
140 | Parameters: | 140 | Parameters: |
141 | 141 | ||
142 | -+ `id` (required) - The code name of a project | 142 | ++ `id` (required) - The ID or code name of a project |
143 | 143 | ||
144 | ```json | 144 | ```json |
145 | [ | 145 | [ |
@@ -183,7 +183,7 @@ GET /projects/:id/snippets/:snippet_id | @@ -183,7 +183,7 @@ GET /projects/:id/snippets/:snippet_id | ||
183 | 183 | ||
184 | Parameters: | 184 | Parameters: |
185 | 185 | ||
186 | -+ `id` (required) - The code name of a project | 186 | ++ `id` (required) - The ID or code name of a project |
187 | + `snippet_id` (required) - The ID of a project's snippet | 187 | + `snippet_id` (required) - The ID of a project's snippet |
188 | 188 | ||
189 | ```json | 189 | ```json |
@@ -214,7 +214,7 @@ GET /projects/:id/snippets/:snippet_id/raw | @@ -214,7 +214,7 @@ GET /projects/:id/snippets/:snippet_id/raw | ||
214 | 214 | ||
215 | Parameters: | 215 | Parameters: |
216 | 216 | ||
217 | -+ `id` (required) - The code name of a project | 217 | ++ `id` (required) - The ID or code name of a project |
218 | + `snippet_id` (required) - The ID of a project's snippet | 218 | + `snippet_id` (required) - The ID of a project's snippet |
219 | 219 | ||
220 | ## New snippet | 220 | ## New snippet |
@@ -227,7 +227,7 @@ POST /projects/:id/snippets | @@ -227,7 +227,7 @@ POST /projects/:id/snippets | ||
227 | 227 | ||
228 | Parameters: | 228 | Parameters: |
229 | 229 | ||
230 | -+ `id` (required) - The code name of a project | 230 | ++ `id` (required) - The ID or code name of a project |
231 | + `title` (required) - The title of a snippet | 231 | + `title` (required) - The title of a snippet |
232 | + `file_name` (required) - The name of a snippet file | 232 | + `file_name` (required) - The name of a snippet file |
233 | + `lifetime` (optional) - The expiration date of a snippet | 233 | + `lifetime` (optional) - The expiration date of a snippet |
@@ -245,7 +245,7 @@ PUT /projects/:id/snippets/:snippet_id | @@ -245,7 +245,7 @@ PUT /projects/:id/snippets/:snippet_id | ||
245 | 245 | ||
246 | Parameters: | 246 | Parameters: |
247 | 247 | ||
248 | -+ `id` (required) - The code name of a project | 248 | ++ `id` (required) - The ID or code name of a project |
249 | + `snippet_id` (required) - The ID of a project's snippet | 249 | + `snippet_id` (required) - The ID of a project's snippet |
250 | + `title` (optional) - The title of a snippet | 250 | + `title` (optional) - The title of a snippet |
251 | + `file_name` (optional) - The name of a snippet file | 251 | + `file_name` (optional) - The name of a snippet file |
@@ -264,7 +264,7 @@ DELETE /projects/:id/snippets/:snippet_id | @@ -264,7 +264,7 @@ DELETE /projects/:id/snippets/:snippet_id | ||
264 | 264 | ||
265 | Parameters: | 265 | Parameters: |
266 | 266 | ||
267 | -+ `id` (required) - The code name of a project | 267 | ++ `id` (required) - The ID or code name of a project |
268 | + `snippet_id` (required) - The ID of a project's snippet | 268 | + `snippet_id` (required) - The ID of a project's snippet |
269 | 269 | ||
270 | Status code `200` will be returned on success. | 270 | Status code `200` will be returned on success. |
lib/api/entities.rb
@@ -31,7 +31,9 @@ module Gitlab | @@ -31,7 +31,9 @@ module Gitlab | ||
31 | end | 31 | end |
32 | 32 | ||
33 | class Issue < Grape::Entity | 33 | class Issue < Grape::Entity |
34 | - expose :id, :title, :description | 34 | + expose :id |
35 | + expose (:project_id) {|issue| issue.project.id} | ||
36 | + expose :title, :description | ||
35 | expose :label_list, :as => :labels | 37 | expose :label_list, :as => :labels |
36 | expose :milestone, :using => Entities::Milestone | 38 | expose :milestone, :using => Entities::Milestone |
37 | expose :assignee, :author, :using => Entities::UserBasic | 39 | expose :assignee, :author, :using => Entities::UserBasic |
lib/api/helpers.rb
@@ -5,7 +5,13 @@ module Gitlab | @@ -5,7 +5,13 @@ module Gitlab | ||
5 | end | 5 | end |
6 | 6 | ||
7 | def user_project | 7 | def user_project |
8 | - @project ||= current_user.projects.find_by_code(params[:id]) | 8 | + if @project ||= current_user.projects.find_by_id(params[:id]) || |
9 | + current_user.projects.find_by_code(params[:id]) | ||
10 | + else | ||
11 | + error!({'message' => '404 Not found'}, 404) | ||
12 | + end | ||
13 | + | ||
14 | + @project | ||
9 | end | 15 | end |
10 | 16 | ||
11 | def authenticate! | 17 | def authenticate! |
lib/api/issues.rb
@@ -17,7 +17,7 @@ module Gitlab | @@ -17,7 +17,7 @@ module Gitlab | ||
17 | # Get a list of project issues | 17 | # Get a list of project issues |
18 | # | 18 | # |
19 | # Parameters: | 19 | # Parameters: |
20 | - # id (required) - The code name of a project | 20 | + # id (required) - The ID or code name of a project |
21 | # Example Request: | 21 | # Example Request: |
22 | # GET /projects/:id/issues | 22 | # GET /projects/:id/issues |
23 | get ":id/issues" do | 23 | get ":id/issues" do |
@@ -27,7 +27,7 @@ module Gitlab | @@ -27,7 +27,7 @@ module Gitlab | ||
27 | # Get a single project issue | 27 | # Get a single project issue |
28 | # | 28 | # |
29 | # Parameters: | 29 | # Parameters: |
30 | - # id (required) - The code name of a project | 30 | + # id (required) - The ID or code name of a project |
31 | # issue_id (required) - The ID of a project issue | 31 | # issue_id (required) - The ID of a project issue |
32 | # Example Request: | 32 | # Example Request: |
33 | # GET /projects/:id/issues/:issue_id | 33 | # GET /projects/:id/issues/:issue_id |
@@ -39,7 +39,7 @@ module Gitlab | @@ -39,7 +39,7 @@ module Gitlab | ||
39 | # Create a new project issue | 39 | # Create a new project issue |
40 | # | 40 | # |
41 | # Parameters: | 41 | # Parameters: |
42 | - # id (required) - The code name of a project | 42 | + # id (required) - The ID or code name of a project |
43 | # title (required) - The title of an issue | 43 | # title (required) - The title of an issue |
44 | # description (optional) - The description of an issue | 44 | # description (optional) - The description of an issue |
45 | # assignee_id (optional) - The ID of a user to assign issue | 45 | # assignee_id (optional) - The ID of a user to assign issue |
@@ -67,7 +67,7 @@ module Gitlab | @@ -67,7 +67,7 @@ module Gitlab | ||
67 | # Update an existing issue | 67 | # Update an existing issue |
68 | # | 68 | # |
69 | # Parameters: | 69 | # Parameters: |
70 | - # id (required) - The code name of a project | 70 | + # id (required) - The ID or code name of a project |
71 | # issue_id (required) - The ID of a project issue | 71 | # issue_id (required) - The ID of a project issue |
72 | # title (optional) - The title of an issue | 72 | # title (optional) - The title of an issue |
73 | # description (optional) - The description of an issue | 73 | # description (optional) - The description of an issue |
@@ -98,7 +98,7 @@ module Gitlab | @@ -98,7 +98,7 @@ module Gitlab | ||
98 | # Delete a project issue | 98 | # Delete a project issue |
99 | # | 99 | # |
100 | # Parameters: | 100 | # Parameters: |
101 | - # id (required) - The code name of a project | 101 | + # id (required) - The ID or code name of a project |
102 | # issue_id (required) - The ID of a project issue | 102 | # issue_id (required) - The ID of a project issue |
103 | # Example Request: | 103 | # Example Request: |
104 | # DELETE /projects/:id/issues/:issue_id | 104 | # DELETE /projects/:id/issues/:issue_id |
lib/api/projects.rb
@@ -16,7 +16,7 @@ module Gitlab | @@ -16,7 +16,7 @@ module Gitlab | ||
16 | # Get a single project | 16 | # Get a single project |
17 | # | 17 | # |
18 | # Parameters: | 18 | # Parameters: |
19 | - # id (required) - The code of a project | 19 | + # id (required) - The ID or code name of a project |
20 | # Example Request: | 20 | # Example Request: |
21 | # GET /projects/:id | 21 | # GET /projects/:id |
22 | get ":id" do | 22 | get ":id" do |
@@ -26,7 +26,7 @@ module Gitlab | @@ -26,7 +26,7 @@ module Gitlab | ||
26 | # Get a project repository branches | 26 | # Get a project repository branches |
27 | # | 27 | # |
28 | # Parameters: | 28 | # Parameters: |
29 | - # id (required) - The code of a project | 29 | + # id (required) - The ID or code name of a project |
30 | # Example Request: | 30 | # Example Request: |
31 | # GET /projects/:id/repository/branches | 31 | # GET /projects/:id/repository/branches |
32 | get ":id/repository/branches" do | 32 | get ":id/repository/branches" do |
@@ -36,7 +36,7 @@ module Gitlab | @@ -36,7 +36,7 @@ module Gitlab | ||
36 | # Get a project repository tags | 36 | # Get a project repository tags |
37 | # | 37 | # |
38 | # Parameters: | 38 | # Parameters: |
39 | - # id (required) - The code of a project | 39 | + # id (required) - The ID or code name of a project |
40 | # Example Request: | 40 | # Example Request: |
41 | # GET /projects/:id/repository/tags | 41 | # GET /projects/:id/repository/tags |
42 | get ":id/repository/tags" do | 42 | get ":id/repository/tags" do |
@@ -46,7 +46,7 @@ module Gitlab | @@ -46,7 +46,7 @@ module Gitlab | ||
46 | # Get a project snippet | 46 | # Get a project snippet |
47 | # | 47 | # |
48 | # Parameters: | 48 | # Parameters: |
49 | - # id (required) - The code of a project | 49 | + # id (required) - The ID or code name of a project |
50 | # snippet_id (required) - The ID of a project snippet | 50 | # snippet_id (required) - The ID of a project snippet |
51 | # Example Request: | 51 | # Example Request: |
52 | # GET /projects/:id/snippets/:snippet_id | 52 | # GET /projects/:id/snippets/:snippet_id |
@@ -58,7 +58,7 @@ module Gitlab | @@ -58,7 +58,7 @@ module Gitlab | ||
58 | # Create a new project snippet | 58 | # Create a new project snippet |
59 | # | 59 | # |
60 | # Parameters: | 60 | # Parameters: |
61 | - # id (required) - The code name of a project | 61 | + # id (required) - The ID or code name of a project |
62 | # title (required) - The title of a snippet | 62 | # title (required) - The title of a snippet |
63 | # file_name (required) - The name of a snippet file | 63 | # file_name (required) - The name of a snippet file |
64 | # lifetime (optional) - The expiration date of a snippet | 64 | # lifetime (optional) - The expiration date of a snippet |
@@ -84,7 +84,7 @@ module Gitlab | @@ -84,7 +84,7 @@ module Gitlab | ||
84 | # Update an existing project snippet | 84 | # Update an existing project snippet |
85 | # | 85 | # |
86 | # Parameters: | 86 | # Parameters: |
87 | - # id (required) - The code name of a project | 87 | + # id (required) - The ID or code name of a project |
88 | # snippet_id (required) - The ID of a project snippet | 88 | # snippet_id (required) - The ID of a project snippet |
89 | # title (optional) - The title of a snippet | 89 | # title (optional) - The title of a snippet |
90 | # file_name (optional) - The name of a snippet file | 90 | # file_name (optional) - The name of a snippet file |
@@ -111,7 +111,7 @@ module Gitlab | @@ -111,7 +111,7 @@ module Gitlab | ||
111 | # Delete a project snippet | 111 | # Delete a project snippet |
112 | # | 112 | # |
113 | # Parameters: | 113 | # Parameters: |
114 | - # id (required) - The code of a project | 114 | + # id (required) - The ID or code name of a project |
115 | # snippet_id (required) - The ID of a project snippet | 115 | # snippet_id (required) - The ID of a project snippet |
116 | # Example Request: | 116 | # Example Request: |
117 | # DELETE /projects/:id/snippets/:snippet_id | 117 | # DELETE /projects/:id/snippets/:snippet_id |
@@ -123,7 +123,7 @@ module Gitlab | @@ -123,7 +123,7 @@ module Gitlab | ||
123 | # Get a raw project snippet | 123 | # Get a raw project snippet |
124 | # | 124 | # |
125 | # Parameters: | 125 | # Parameters: |
126 | - # id (required) - The code of a project | 126 | + # id (required) - The ID or code name of a project |
127 | # snippet_id (required) - The ID of a project snippet | 127 | # snippet_id (required) - The ID of a project snippet |
128 | # Example Request: | 128 | # Example Request: |
129 | # GET /projects/:id/snippets/:snippet_id/raw | 129 | # GET /projects/:id/snippets/:snippet_id/raw |
spec/api/projects_spec.rb
@@ -25,11 +25,23 @@ describe Gitlab::API do | @@ -25,11 +25,23 @@ describe Gitlab::API do | ||
25 | 25 | ||
26 | describe "GET /projects/:id" do | 26 | describe "GET /projects/:id" do |
27 | it "should return a project by id" do | 27 | it "should return a project by id" do |
28 | - get "#{api_prefix}/projects/#{project.code}?private_token=#{user.private_token}" | 28 | + get "#{api_prefix}/projects/#{project.id}?private_token=#{user.private_token}" |
29 | response.status.should == 200 | 29 | response.status.should == 200 |
30 | json_response['name'].should == project.name | 30 | json_response['name'].should == project.name |
31 | json_response['owner']['email'].should == user.email | 31 | json_response['owner']['email'].should == user.email |
32 | end | 32 | end |
33 | + | ||
34 | + it "should return a project by code name" do | ||
35 | + get "#{api_prefix}/projects/#{project.code}?private_token=#{user.private_token}" | ||
36 | + response.status.should == 200 | ||
37 | + json_response['name'].should == project.name | ||
38 | + end | ||
39 | + | ||
40 | + it "should return a 404 error if not found" do | ||
41 | + get "#{api_prefix}/projects/42?private_token=#{user.private_token}" | ||
42 | + response.status.should == 404 | ||
43 | + json_response['message'].should == '404 Not found' | ||
44 | + end | ||
33 | end | 45 | end |
34 | 46 | ||
35 | describe "GET /projects/:id/repository/branches" do | 47 | describe "GET /projects/:id/repository/branches" do |