Commit 3b3add35fb88578df96fe9b728ddac896ea9c944

Authored by Sebastian Ziebell
1 parent e96d77d3

API: merge request documentation updated, added return codes to functions

The API documentation of merge requests contains info to status codes for all functions.
Required arguments are now checked in the merge requests API functions and a `400 Bad Request` error is
returned if they are not given.
doc/api/issues.md
1 ## List issues 1 ## List issues
2 2
3 Get all issues created by authenticed user. This function takes pagination parameters 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 +`page` and `per_page` to restrict the list of issues.
5 5
6 ``` 6 ```
7 GET /issues 7 GET /issues
doc/api/merge_requests.md
1 ## List merge requests 1 ## List merge requests
2 2
3 -Get all MR for this project. 3 +Get all merge requests for this project. This function takes pagination parameters
  4 +`page` and `per_page` to restrict the list of merge requests.
4 5
5 ``` 6 ```
6 GET /projects/:id/merge_requests 7 GET /projects/:id/merge_requests
@@ -40,9 +41,16 @@ Parameters: @@ -40,9 +41,16 @@ Parameters:
40 ] 41 ]
41 ``` 42 ```
42 43
43 -## Show MR 44 +Return values:
44 45
45 -Show information about MR. 46 ++ `200 Ok` on success and the list of merge requests
  47 ++ `401 Unauthorized` if user is not authenticated
  48 ++ `404 Not Found` if project ID not found
  49 +
  50 +
  51 +## Get single MR
  52 +
  53 +Shows information about a single merge request.
46 54
47 ``` 55 ```
48 GET /projects/:id/merge_request/:merge_request_id 56 GET /projects/:id/merge_request/:merge_request_id
@@ -81,10 +89,16 @@ Parameters: @@ -81,10 +89,16 @@ Parameters:
81 } 89 }
82 ``` 90 ```
83 91
  92 +Return values:
  93 +
  94 ++ `200 Ok` on success and the single merge request
  95 ++ `401 Unauthorized` if user is not authenticated
  96 ++ `404 Not Found` if project ID or merge request ID not found
  97 +
84 98
85 ## Create MR 99 ## Create MR
86 100
87 -Create MR. 101 +Creates a new merge request.
88 102
89 ``` 103 ```
90 POST /projects/:id/merge_requests 104 POST /projects/:id/merge_requests
@@ -126,9 +140,18 @@ Parameters: @@ -126,9 +140,18 @@ Parameters:
126 } 140 }
127 ``` 141 ```
128 142
  143 +Return values:
  144 +
  145 ++ `201 Created` on success and the created merge request
  146 ++ `400 Bad Request` if one of the required attributes is missing
  147 ++ `401 Unauthorize` if user is not authenticated or not allowed
  148 ++ `403 Forbidden` if user is not allowed to create a merge request
  149 ++ `404 Not Found` if project ID not found or something else fails
  150 +
  151 +
129 ## Update MR 152 ## Update MR
130 153
131 -Update MR. You can change branches, title, or even close the MR. 154 +Updates an existing merge request. You can change branches, title, or even close the MR.
132 155
133 ``` 156 ```
134 PUT /projects/:id/merge_request/:merge_request_id 157 PUT /projects/:id/merge_request/:merge_request_id
@@ -172,9 +195,18 @@ Parameters: @@ -172,9 +195,18 @@ Parameters:
172 } 195 }
173 } 196 }
174 ``` 197 ```
  198 +
  199 +Return values:
  200 +
  201 ++ `200 Ok` on success and the updated merge request
  202 ++ `401 Unauthorize` if user is not authenticated or not allowed
  203 ++ `403 Forbidden` if user is not allowed to update the merge request
  204 ++ `404 Not Found` if project ID or merge request ID not found
  205 +
  206 +
175 ## Post comment to MR 207 ## Post comment to MR
176 208
177 -Post comment to MR 209 +Adds a comment to a merge request.
178 210
179 ``` 211 ```
180 POST /projects/:id/merge_request/:merge_request_id/comments 212 POST /projects/:id/merge_request/:merge_request_id/comments
@@ -183,10 +215,9 @@ POST /projects/:id/merge_request/:merge_request_id/comments @@ -183,10 +215,9 @@ POST /projects/:id/merge_request/:merge_request_id/comments
183 Parameters: 215 Parameters:
184 216
185 + `id` (required) - The ID of a project 217 + `id` (required) - The ID of a project
186 -+ `merge_request_id` (required) - ID of MR 218 ++ `merge_request_id` (required) - ID of merge request
187 + `note` (required) - Text of comment 219 + `note` (required) - Text of comment
188 220
189 -Will return created note with status `201 Created` on success, or `404 Not found` on fail.  
190 221
191 ```json 222 ```json
192 { 223 {
@@ -201,3 +232,10 @@ Will return created note with status `201 Created` on success, or `404 Not found @@ -201,3 +232,10 @@ Will return created note with status `201 Created` on success, or `404 Not found
201 "note":"text1" 232 "note":"text1"
202 } 233 }
203 ``` 234 ```
  235 +
  236 +Return values:
  237 +
  238 ++ `201 Created` on success and the new comment
  239 ++ `400 Bad Request` if the required attribute note is not given
  240 ++ `401 Unauthorized` if user is not authenticated
  241 ++ `404 Not Found` if project ID or merge request ID not found
lib/api/merge_requests.rb
@@ -69,6 +69,10 @@ module Gitlab @@ -69,6 +69,10 @@ module Gitlab
69 post ":id/merge_requests" do 69 post ":id/merge_requests" do
70 authorize! :write_merge_request, user_project 70 authorize! :write_merge_request, user_project
71 71
  72 + bad_request!(:source_branch) unless params[:source_branch].present?
  73 + bad_request!(:target_branch) unless params[:target_branch].present?
  74 + bad_request!(:title) unless params[:title].present?
  75 +
72 attrs = attributes_for_keys [:source_branch, :target_branch, :assignee_id, :title] 76 attrs = attributes_for_keys [:source_branch, :target_branch, :assignee_id, :title]
73 merge_request = user_project.merge_requests.new(attrs) 77 merge_request = user_project.merge_requests.new(attrs)
74 merge_request.author = current_user 78 merge_request.author = current_user
@@ -121,6 +125,8 @@ module Gitlab @@ -121,6 +125,8 @@ module Gitlab
121 # POST /projects/:id/merge_request/:merge_request_id/comments 125 # POST /projects/:id/merge_request/:merge_request_id/comments
122 # 126 #
123 post ":id/merge_request/:merge_request_id/comments" do 127 post ":id/merge_request/:merge_request_id/comments" do
  128 + bad_request!(:note) unless params[:note].present?
  129 +
124 merge_request = user_project.merge_requests.find(params[:merge_request_id]) 130 merge_request = user_project.merge_requests.find(params[:merge_request_id])
125 note = merge_request.notes.new(note: params[:note], project_id: user_project.id) 131 note = merge_request.notes.new(note: params[:note], project_id: user_project.id)
126 note.author = current_user 132 note.author = current_user
@@ -128,9 +134,6 @@ module Gitlab @@ -128,9 +134,6 @@ module Gitlab
128 if note.save 134 if note.save
129 present note, with: Entities::MRNote 135 present note, with: Entities::MRNote
130 else 136 else
131 - if note.errors[:note].any?  
132 - bad_request!(:note)  
133 - end  
134 not_found! 137 not_found!
135 end 138 end
136 end 139 end
spec/requests/api/merge_requests_spec.rb
@@ -64,6 +64,12 @@ describe Gitlab::API do @@ -64,6 +64,12 @@ describe Gitlab::API do
64 title: "Test merge_request", source_branch: "stable", author: user 64 title: "Test merge_request", source_branch: "stable", author: user
65 response.status.should == 400 65 response.status.should == 400
66 end 66 end
  67 +
  68 + it "should return 400 when title is missing" do
  69 + post api("/projects/#{project.id}/merge_requests", user),
  70 + target_branch: 'master', source_branch: 'stable'
  71 + response.status.should == 400
  72 + end
67 end 73 end
68 74
69 describe "PUT /projects/:id/merge_request/:merge_request_id to close MR" do 75 describe "PUT /projects/:id/merge_request/:merge_request_id to close MR" do
@@ -82,7 +88,6 @@ describe Gitlab::API do @@ -82,7 +88,6 @@ describe Gitlab::API do
82 end 88 end
83 end 89 end
84 90
85 -  
86 describe "PUT /projects/:id/merge_request/:merge_request_id" do 91 describe "PUT /projects/:id/merge_request/:merge_request_id" do
87 it "should return merge_request" do 92 it "should return merge_request" do
88 put api("/projects/#{project.id}/merge_request/#{merge_request.id}", user), title: "New title" 93 put api("/projects/#{project.id}/merge_request/#{merge_request.id}", user), title: "New title"