diff options
author | Michael Kozono <mkozono@gmail.com> | 2019-04-15 19:44:38 +0000 |
---|---|---|
committer | Michael Kozono <mkozono@gmail.com> | 2019-04-15 19:44:38 +0000 |
commit | db70b877512e5cdeb262c060a1a4dff1cf999a45 (patch) | |
tree | ba94fe9d979a003585ede0c8f499030c731fa3f1 | |
parent | 1a50801cd0801d3134b41e96ff2a6b27a96a1047 (diff) | |
parent | d3fa9c9539aac42844a297a99ef56254ce1c06a3 (diff) | |
download | gitlab-ce-db70b877512e5cdeb262c060a1a4dff1cf999a45.tar.gz |
Merge branch 'sh-fix-merge-requests-api-remove-branch-param' into 'master'
Fix remove_source_branch merge request API handling
Closes #60530
See merge request gitlab-org/gitlab-ce!27392
-rw-r--r-- | app/services/merge_requests/update_service.rb | 2 | ||||
-rw-r--r-- | changelogs/unreleased/sh-fix-merge-requests-api-remove-branch-param.yml | 5 | ||||
-rw-r--r-- | lib/api/merge_requests.rb | 2 | ||||
-rw-r--r-- | spec/requests/api/merge_requests_spec.rb | 26 |
4 files changed, 33 insertions, 2 deletions
diff --git a/app/services/merge_requests/update_service.rb b/app/services/merge_requests/update_service.rb index faaa4d66726..55546432ce4 100644 --- a/app/services/merge_requests/update_service.rb +++ b/app/services/merge_requests/update_service.rb @@ -16,7 +16,7 @@ module MergeRequests params.delete(:force_remove_source_branch) end - if params[:force_remove_source_branch].present? + if params.has_key?(:force_remove_source_branch) merge_request.merge_params['force_remove_source_branch'] = params.delete(:force_remove_source_branch) end diff --git a/changelogs/unreleased/sh-fix-merge-requests-api-remove-branch-param.yml b/changelogs/unreleased/sh-fix-merge-requests-api-remove-branch-param.yml new file mode 100644 index 00000000000..d13c972ccc9 --- /dev/null +++ b/changelogs/unreleased/sh-fix-merge-requests-api-remove-branch-param.yml @@ -0,0 +1,5 @@ +--- +title: Fix remove_source_branch merge request API handling +merge_request: 27392 +author: +type: fixed diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb index 1cc0ecc6df8..ce85772e4ed 100644 --- a/lib/api/merge_requests.rb +++ b/lib/api/merge_requests.rb @@ -336,7 +336,7 @@ module API merge_request = find_merge_request_with_access(params.delete(:merge_request_iid), :update_merge_request) mr_params = declared_params(include_missing: false) - mr_params[:force_remove_source_branch] = mr_params.delete(:remove_source_branch) if mr_params[:remove_source_branch].present? + mr_params[:force_remove_source_branch] = mr_params.delete(:remove_source_branch) if mr_params.has_key?(:remove_source_branch) mr_params = convert_parameters_from_legacy_format(mr_params) merge_request = ::MergeRequests::UpdateService.new(user_project, current_user, mr_params).execute(merge_request) diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb index 45818edbf68..5c94a87529b 100644 --- a/spec/requests/api/merge_requests_spec.rb +++ b/spec/requests/api/merge_requests_spec.rb @@ -1596,6 +1596,32 @@ describe API::MergeRequests do end describe "PUT /projects/:id/merge_requests/:merge_request_iid" do + context 'updates force_remove_source_branch properly' do + it 'sets to false' do + merge_request.update(merge_params: { 'force_remove_source_branch' => true } ) + + expect(merge_request.force_remove_source_branch?).to be_truthy + + put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: { state_event: "close", remove_source_branch: false } + + expect(response).to have_gitlab_http_status(200) + expect(json_response['state']).to eq('closed') + expect(json_response['force_remove_source_branch']).to be_falsey + end + + it 'sets to true' do + merge_request.update(merge_params: { 'force_remove_source_branch' => false } ) + + expect(merge_request.force_remove_source_branch?).to be_falsey + + put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: { state_event: "close", remove_source_branch: true } + + expect(response).to have_gitlab_http_status(200) + expect(json_response['state']).to eq('closed') + expect(json_response['force_remove_source_branch']).to be_truthy + end + end + context "to close a MR" do it "returns merge_request" do put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: { state_event: "close" } |