Commit e96d77d3dbd789981b8e85e7afba9a5908d79483

Authored by Sebastian Ziebell
1 parent dffc2b8a

API: issues documentation and API functions updated

The issues documentation is updated with infos to status codes and the deprecated `DELETE` function and
how to close an issue. A few more tests added to check status codes of API functions.
doc/api/issues.md
1 1 ## List issues
2 2  
3   -Get all issues created by authenticed user.
  3 +Get all issues created by authenticed user. This function takes pagination parameters
  4 +`page` and `per_page` to get a list of issues.
4 5  
5 6 ```
6 7 GET /issues
... ... @@ -68,9 +69,18 @@ GET /issues
68 69 ]
69 70 ```
70 71  
  72 +Return values:
  73 +
  74 ++ `200 Ok` on success and the list of issues
  75 ++ `401 Unauthorized` if user is not authenticated
  76 ++ `404 Not Found` if something fails
  77 +
  78 +
  79 +
71 80 ## List project issues
72 81  
73   -Get a list of project issues.
  82 +Get a list of project issues. This function accepts pagination parameters `page` and `per_page`
  83 +to return the list of project issues.
74 84  
75 85 ```
76 86 GET /projects/:id/issues
... ... @@ -80,9 +90,16 @@ Parameters:
80 90  
81 91 + `id` (required) - The ID of a project
82 92  
  93 +Return values:
  94 +
  95 ++ `200 Ok` on success and the list of project issues
  96 ++ `401 Unauthorized` if user is not authenticated
  97 ++ `404 Not Found` if project ID not found
  98 +
  99 +
83 100 ## Single issue
84 101  
85   -Get a project issue.
  102 +Gets a single project issue.
86 103  
87 104 ```
88 105 GET /projects/:id/issues/:issue_id
... ... @@ -133,9 +150,16 @@ Parameters:
133 150 }
134 151 ```
135 152  
  153 +Return values:
  154 +
  155 ++ `200 Ok` on success and the list of project issues
  156 ++ `401 Unauthorized` if user is not authenticated
  157 ++ `404 Not Found` if project ID or issue ID not found
  158 +
  159 +
136 160 ## New issue
137 161  
138   -Create a new project issue.
  162 +Creates a new project issue.
139 163  
140 164 ```
141 165 POST /projects/:id/issues
... ... @@ -150,11 +174,17 @@ Parameters:
150 174 + `milestone_id` (optional) - The ID of a milestone to assign issue
151 175 + `labels` (optional) - Comma-separated label names for an issue
152 176  
153   -Will return created issue with status `201 Created` on success, or `404 Not found` on fail.
  177 +Return values:
  178 +
  179 ++ `201 Created` on success and the newly created project issue
  180 ++ `400 Bad Request` if the required attribute title is not given
  181 ++ `401 Unauthorized` if user is not authenticated
  182 ++ `404 Not Found` if project ID not found
  183 +
154 184  
155 185 ## Edit issue
156 186  
157   -Update an existing project issue.
  187 +Updates an existing project issue. This function is also used to mark an issue as closed.
158 188  
159 189 ```
160 190 PUT /projects/:id/issues/:issue_id
... ... @@ -171,5 +201,28 @@ Parameters:
171 201 + `labels` (optional) - Comma-separated label names for an issue
172 202 + `closed` (optional) - The state of an issue (0 = false, 1 = true)
173 203  
174   -Will return updated issue with status `200 OK` on success, or `404 Not found` on fail.
  204 +Return values:
  205 +
  206 ++ `200 Ok` on success and the update project issue
  207 ++ `401 Unauthorized` if user is not authenticated
  208 ++ `404 Not Found` if project ID or issue ID not found
  209 +
  210 +
  211 +## Delete existing issue (**Deprecated**)
  212 +
  213 +The function is deprecated and returns a `405 Method Not Allowed`
  214 +error if called. An issue gets now closed and is done by calling `PUT /projects/:id/issues/:issue_id` with
  215 +parameter `closed` set to 1.
  216 +
  217 +```
  218 +DELETE /projects/:id/issues/:issue_id
  219 +```
  220 +
  221 +Parameters:
  222 +
  223 ++ `id` (required) - The project ID
  224 ++ `issue_id` (required) - The ID of the issue
  225 +
  226 +Return values:
175 227  
  228 ++ `405 Method Not Allowed` is always returned, because the function is deprecated
... ...
lib/api/issues.rb
... ... @@ -48,6 +48,7 @@ module Gitlab
48 48 # Example Request:
49 49 # POST /projects/:id/issues
50 50 post ":id/issues" do
  51 + bad_request!(:title) unless params[:title].present?
51 52 attrs = attributes_for_keys [:title, :description, :assignee_id, :milestone_id]
52 53 attrs[:label_list] = params[:labels] if params[:labels].present?
53 54 @issue = user_project.issues.new attrs
... ...
spec/requests/api/issues_spec.rb
... ... @@ -41,6 +41,11 @@ describe Gitlab::API do
41 41 response.status.should == 200
42 42 json_response['title'].should == issue.title
43 43 end
  44 +
  45 + it "should return 404 if issue id not found" do
  46 + get api("/projects/#{project.id}/issues/54321", user)
  47 + response.status.should == 404
  48 + end
44 49 end
45 50  
46 51 describe "POST /projects/:id/issues" do
... ... @@ -52,6 +57,11 @@ describe Gitlab::API do
52 57 json_response['description'].should be_nil
53 58 json_response['labels'].should == ['label', 'label2']
54 59 end
  60 +
  61 + it "should return a 400 bad request if title not given" do
  62 + post api("/projects/#{project.id}/issues", user), labels: 'label, label2'
  63 + response.status.should == 400
  64 + end
55 65 end
56 66  
57 67 describe "PUT /projects/:id/issues/:issue_id to update only title" do
... ... @@ -62,6 +72,12 @@ describe Gitlab::API do
62 72  
63 73 json_response['title'].should == 'updated title'
64 74 end
  75 +
  76 + it "should return 404 error if issue id not found" do
  77 + put api("/projects/#{project.id}/issues/44444", user),
  78 + title: 'updated title'
  79 + response.status.should == 404
  80 + end
65 81 end
66 82  
67 83 describe "PUT /projects/:id/issues/:issue_id to update state and label" do
... ...