Commit f9c6d8a45b080d6a0bc69221e570d6c102525670

Authored by Dmitriy Zaporozhets
2 parents 92d98f5a cb32e032

Merge pull request #1142 from NARKOZ/api

API changes
doc/api/issues.md
... ... @@ -10,6 +10,7 @@ GET /issues
10 10 [
11 11 {
12 12 "id": 43,
  13 + "project_id": 8,
13 14 "title": "4xx/5xx pages",
14 15 "description": "",
15 16 "labels": [ ],
... ... @@ -28,6 +29,7 @@ GET /issues
28 29 },
29 30 {
30 31 "id": 42,
  32 + "project_id": 8,
31 33 "title": "Add user settings",
32 34 "description": "",
33 35 "labels": [
... ... @@ -73,7 +75,7 @@ GET /projects/:id/issues
73 75  
74 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 80 ## Single issue
79 81  
... ... @@ -85,12 +87,13 @@ GET /projects/:id/issues/:issue_id
85 87  
86 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 91 + `issue_id` (required) - The ID of a project issue
90 92  
91 93 ```json
92 94 {
93 95 "id": 42,
  96 + "project_id": 8,
94 97 "title": "Add user settings",
95 98 "description": "",
96 99 "labels": [
... ... @@ -135,7 +138,7 @@ POST /projects/:id/issues
135 138  
136 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 142 + `title` (required) - The title of an issue
140 143 + `description` (optional) - The description of an issue
141 144 + `assignee_id` (optional) - The ID of a user to assign issue
... ... @@ -154,7 +157,7 @@ PUT /projects/:id/issues/:issue_id
154 157  
155 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 161 + `issue_id` (required) - The ID of a project's issue
159 162 + `title` (optional) - The title of an issue
160 163 + `description` (optional) - The description of an issue
... ... @@ -175,7 +178,7 @@ DELETE /projects/:id/issues/:issue_id
175 178  
176 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 182 + `issue_id` (required) - The ID of a project's issue
180 183  
181 184 Status code `200` will be returned on success.
... ...
doc/api/projects.md
1 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 6 GET /projects
... ... @@ -63,7 +63,7 @@ GET /projects/:id
63 63  
64 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 68 ```json
69 69 {
... ... @@ -91,7 +91,7 @@ Parameters:
91 91  
92 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 97 GET /projects/:id/repository/branches
... ... @@ -99,7 +99,7 @@ GET /projects/:id/repository/branches
99 99  
100 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 104 ```json
105 105 [
... ... @@ -131,7 +131,7 @@ Parameters:
131 131  
132 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 137 GET /projects/:id/repository/tags
... ... @@ -139,7 +139,7 @@ GET /projects/:id/repository/tags
139 139  
140 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 144 ```json
145 145 [
... ... @@ -183,7 +183,7 @@ GET /projects/:id/snippets/:snippet_id
183 183  
184 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 187 + `snippet_id` (required) - The ID of a project's snippet
188 188  
189 189 ```json
... ... @@ -214,7 +214,7 @@ GET /projects/:id/snippets/:snippet_id/raw
214 214  
215 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 218 + `snippet_id` (required) - The ID of a project's snippet
219 219  
220 220 ## New snippet
... ... @@ -227,7 +227,7 @@ POST /projects/:id/snippets
227 227  
228 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 231 + `title` (required) - The title of a snippet
232 232 + `file_name` (required) - The name of a snippet file
233 233 + `lifetime` (optional) - The expiration date of a snippet
... ... @@ -245,7 +245,7 @@ PUT /projects/:id/snippets/:snippet_id
245 245  
246 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 249 + `snippet_id` (required) - The ID of a project's snippet
250 250 + `title` (optional) - The title of a snippet
251 251 + `file_name` (optional) - The name of a snippet file
... ... @@ -264,7 +264,7 @@ DELETE /projects/:id/snippets/:snippet_id
264 264  
265 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 268 + `snippet_id` (required) - The ID of a project's snippet
269 269  
270 270 Status code `200` will be returned on success.
... ...
lib/api/entities.rb
... ... @@ -31,7 +31,9 @@ module Gitlab
31 31 end
32 32  
33 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 37 expose :label_list, :as => :labels
36 38 expose :milestone, :using => Entities::Milestone
37 39 expose :assignee, :author, :using => Entities::UserBasic
... ...
lib/api/helpers.rb
... ... @@ -5,7 +5,13 @@ module Gitlab
5 5 end
6 6  
7 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 15 end
10 16  
11 17 def authenticate!
... ...
lib/api/issues.rb
... ... @@ -17,7 +17,7 @@ module Gitlab
17 17 # Get a list of project issues
18 18 #
19 19 # Parameters:
20   - # id (required) - The code name of a project
  20 + # id (required) - The ID or code name of a project
21 21 # Example Request:
22 22 # GET /projects/:id/issues
23 23 get ":id/issues" do
... ... @@ -27,7 +27,7 @@ module Gitlab
27 27 # Get a single project issue
28 28 #
29 29 # Parameters:
30   - # id (required) - The code name of a project
  30 + # id (required) - The ID or code name of a project
31 31 # issue_id (required) - The ID of a project issue
32 32 # Example Request:
33 33 # GET /projects/:id/issues/:issue_id
... ... @@ -39,7 +39,7 @@ module Gitlab
39 39 # Create a new project issue
40 40 #
41 41 # Parameters:
42   - # id (required) - The code name of a project
  42 + # id (required) - The ID or code name of a project
43 43 # title (required) - The title of an issue
44 44 # description (optional) - The description of an issue
45 45 # assignee_id (optional) - The ID of a user to assign issue
... ... @@ -67,7 +67,7 @@ module Gitlab
67 67 # Update an existing issue
68 68 #
69 69 # Parameters:
70   - # id (required) - The code name of a project
  70 + # id (required) - The ID or code name of a project
71 71 # issue_id (required) - The ID of a project issue
72 72 # title (optional) - The title of an issue
73 73 # description (optional) - The description of an issue
... ... @@ -98,7 +98,7 @@ module Gitlab
98 98 # Delete a project issue
99 99 #
100 100 # Parameters:
101   - # id (required) - The code name of a project
  101 + # id (required) - The ID or code name of a project
102 102 # issue_id (required) - The ID of a project issue
103 103 # Example Request:
104 104 # DELETE /projects/:id/issues/:issue_id
... ...
lib/api/projects.rb
... ... @@ -16,7 +16,7 @@ module Gitlab
16 16 # Get a single project
17 17 #
18 18 # Parameters:
19   - # id (required) - The code of a project
  19 + # id (required) - The ID or code name of a project
20 20 # Example Request:
21 21 # GET /projects/:id
22 22 get ":id" do
... ... @@ -26,7 +26,7 @@ module Gitlab
26 26 # Get a project repository branches
27 27 #
28 28 # Parameters:
29   - # id (required) - The code of a project
  29 + # id (required) - The ID or code name of a project
30 30 # Example Request:
31 31 # GET /projects/:id/repository/branches
32 32 get ":id/repository/branches" do
... ... @@ -36,7 +36,7 @@ module Gitlab
36 36 # Get a project repository tags
37 37 #
38 38 # Parameters:
39   - # id (required) - The code of a project
  39 + # id (required) - The ID or code name of a project
40 40 # Example Request:
41 41 # GET /projects/:id/repository/tags
42 42 get ":id/repository/tags" do
... ... @@ -46,7 +46,7 @@ module Gitlab
46 46 # Get a project snippet
47 47 #
48 48 # Parameters:
49   - # id (required) - The code of a project
  49 + # id (required) - The ID or code name of a project
50 50 # snippet_id (required) - The ID of a project snippet
51 51 # Example Request:
52 52 # GET /projects/:id/snippets/:snippet_id
... ... @@ -58,7 +58,7 @@ module Gitlab
58 58 # Create a new project snippet
59 59 #
60 60 # Parameters:
61   - # id (required) - The code name of a project
  61 + # id (required) - The ID or code name of a project
62 62 # title (required) - The title of a snippet
63 63 # file_name (required) - The name of a snippet file
64 64 # lifetime (optional) - The expiration date of a snippet
... ... @@ -84,7 +84,7 @@ module Gitlab
84 84 # Update an existing project snippet
85 85 #
86 86 # Parameters:
87   - # id (required) - The code name of a project
  87 + # id (required) - The ID or code name of a project
88 88 # snippet_id (required) - The ID of a project snippet
89 89 # title (optional) - The title of a snippet
90 90 # file_name (optional) - The name of a snippet file
... ... @@ -111,7 +111,7 @@ module Gitlab
111 111 # Delete a project snippet
112 112 #
113 113 # Parameters:
114   - # id (required) - The code of a project
  114 + # id (required) - The ID or code name of a project
115 115 # snippet_id (required) - The ID of a project snippet
116 116 # Example Request:
117 117 # DELETE /projects/:id/snippets/:snippet_id
... ... @@ -123,7 +123,7 @@ module Gitlab
123 123 # Get a raw project snippet
124 124 #
125 125 # Parameters:
126   - # id (required) - The code of a project
  126 + # id (required) - The ID or code name of a project
127 127 # snippet_id (required) - The ID of a project snippet
128 128 # Example Request:
129 129 # GET /projects/:id/snippets/:snippet_id/raw
... ...
spec/api/projects_spec.rb
... ... @@ -25,11 +25,23 @@ describe Gitlab::API do
25 25  
26 26 describe "GET /projects/:id" do
27 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 29 response.status.should == 200
30 30 json_response['name'].should == project.name
31 31 json_response['owner']['email'].should == user.email
32 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 45 end
34 46  
35 47 describe "GET /projects/:id/repository/branches" do
... ...