Commit 4c4c8532 authored by Stan Hu's avatar Stan Hu

Handle force_remove_source_branch when creating merge request

Creating a merge request with
`merge_request[force_remove_source_branch]` parameter would result in an
Error 500 since this attribute was passed directly to the merge request.
Fix this by properly parsing this attribute into `merge_params`.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/51220
parent ac6673dd
...@@ -10,6 +10,7 @@ module MergeRequests ...@@ -10,6 +10,7 @@ module MergeRequests
# TODO: this should handle all quick actions that don't have side effects # TODO: this should handle all quick actions that don't have side effects
# https://gitlab.com/gitlab-org/gitlab-ce/issues/53658 # https://gitlab.com/gitlab-org/gitlab-ce/issues/53658
merge_quick_actions_into_params!(merge_request, only: [:target_branch]) merge_quick_actions_into_params!(merge_request, only: [:target_branch])
merge_request.merge_params['force_remove_source_branch'] = params.delete(:force_remove_source_branch) if params.has_key?(:force_remove_source_branch)
merge_request.assign_attributes(params) merge_request.assign_attributes(params)
merge_request.author = current_user merge_request.author = current_user
......
---
title: Handle force_remove_source_branch when creating merge request
merge_request: 23281
author:
type: fixed
...@@ -21,15 +21,20 @@ describe MergeRequests::BuildService do ...@@ -21,15 +21,20 @@ describe MergeRequests::BuildService do
let(:commit_2) { double(:commit_2, sha: 'f00ba7', safe_message: 'This is a bad commit message!') } let(:commit_2) { double(:commit_2, sha: 'f00ba7', safe_message: 'This is a bad commit message!') }
let(:commits) { nil } let(:commits) { nil }
let(:params) do
{
description: description,
source_branch: source_branch,
target_branch: target_branch,
source_project: source_project,
target_project: target_project,
milestone_id: milestone_id,
label_ids: label_ids
}
end
let(:service) do let(:service) do
described_class.new(project, user, described_class.new(project, user, params)
description: description,
source_branch: source_branch,
target_branch: target_branch,
source_project: source_project,
target_project: target_project,
milestone_id: milestone_id,
label_ids: label_ids)
end end
before do before do
...@@ -56,6 +61,19 @@ describe MergeRequests::BuildService do ...@@ -56,6 +61,19 @@ describe MergeRequests::BuildService do
merge_request merge_request
end end
it 'does not assign force_remove_source_branch' do
expect(merge_request.force_remove_source_branch?).to be_falsey
end
context 'with force_remove_source_branch parameter' do
let(:mr_params) { params.merge(force_remove_source_branch: '1') }
let(:merge_request) { described_class.new(project, user, mr_params).execute }
it 'assigns force_remove_source_branch' do
expect(merge_request.force_remove_source_branch?).to be_truthy
end
end
context 'missing source branch' do context 'missing source branch' do
let(:source_branch) { '' } let(:source_branch) { '' }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment