Creating or updating a MR returns more informative status codes.
Using the API library to create or update a merge request at the moment a 404 error is returned. This is fine when the merge request in question does not exist, but does not provide good information that for example a required attribute is missing. A status code of 400 (Bad request) is returned when creating or updating a merge request when either `source_branch` or `target_branch` is missing. A status code of 409 is returned when `source_branch` and `target_branch` are the same. Tests are added for these cases.
This commit is contained in:
parent
566de5ab06
commit
413952ff94
|
@ -60,6 +60,13 @@ module Gitlab
|
|||
merge_request.reload_code
|
||||
present merge_request, with: Entities::MergeRequest
|
||||
else
|
||||
if merge_request.errors[:target_branch].any?
|
||||
error!(merge_request.errors[:target_branch], 400)
|
||||
elsif merge_request.errors[:source_branch].any?
|
||||
error!(merge_request.errors[:source_branch], 400)
|
||||
elsif merge_request.errors[:base].any?
|
||||
error!(merge_request.errors[:base], 422)
|
||||
end
|
||||
not_found!
|
||||
end
|
||||
end
|
||||
|
@ -88,6 +95,13 @@ module Gitlab
|
|||
merge_request.mark_as_unchecked
|
||||
present merge_request, with: Entities::MergeRequest
|
||||
else
|
||||
if merge_request.errors[:target_branch].any?
|
||||
error!(merge_request.errors[:target_branch], 400)
|
||||
elsif merge_request.errors[:source_branch].any?
|
||||
error!(merge_request.errors[:source_branch], 400)
|
||||
elsif merge_request.errors[:base].any?
|
||||
error!(merge_request.errors[:base], 422)
|
||||
end
|
||||
not_found!
|
||||
end
|
||||
end
|
||||
|
|
|
@ -41,6 +41,24 @@ describe Gitlab::API do
|
|||
response.status.should == 201
|
||||
json_response['title'].should == 'Test merge_request'
|
||||
end
|
||||
|
||||
it "should return 422 when source_branch equals target_branch" do
|
||||
post api("/projects/#{project.id}/merge_requests", user),
|
||||
title: "Test merge_request", source_branch: "master", target_branch: "master", author: user
|
||||
response.status.should == 422
|
||||
end
|
||||
|
||||
it "should return 400 when source_branch is missing" do
|
||||
post api("/projects/#{project.id}/merge_requests", user),
|
||||
title: "Test merge_request", target_branch: "master", author: user
|
||||
response.status.should == 400
|
||||
end
|
||||
|
||||
it "should return 400 when target_branch is missing" do
|
||||
post api("/projects/#{project.id}/merge_requests", user),
|
||||
title: "Test merge_request", source_branch: "stable", author: user
|
||||
response.status.should == 400
|
||||
end
|
||||
end
|
||||
|
||||
describe "PUT /projects/:id/merge_request/:merge_request_id" do
|
||||
|
@ -49,6 +67,18 @@ describe Gitlab::API do
|
|||
response.status.should == 200
|
||||
json_response['title'].should == 'New title'
|
||||
end
|
||||
|
||||
it "should return 422 when source_branch and target_branch are renamed the same" do
|
||||
put api("/projects/#{project.id}/merge_request/#{merge_request.id}", user),
|
||||
source_branch: "master", target_branch: "master"
|
||||
response.status.should == 422
|
||||
end
|
||||
|
||||
it "should return merge_request with renamed target_branch" do
|
||||
put api("/projects/#{project.id}/merge_request/#{merge_request.id}", user), target_branch: "test"
|
||||
response.status.should == 200
|
||||
json_response['target_branch'].should == 'test'
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /projects/:id/merge_request/:merge_request_id/comments" do
|
||||
|
|
Loading…
Reference in New Issue