Commit 0d98f1bb authored by Christian Couder's avatar Christian Couder

Refactor create_params and update_params

Let's move shared code between create_params and update_params
into a new base_params.

update_params becomes very thin, but it still may be clearer that
the params are being shared if we have a method called
base_params, rather than have create_params merge in
update_params.
parent 8256d407
......@@ -117,14 +117,8 @@ module MergeRequests
collect_errors_from_merge_request(merge_request) unless merge_request.valid?
end
def create_params(branch)
params = {
assignees: [current_user],
source_branch: branch,
source_project: project,
target_branch: push_options[:target] || target_project.default_branch,
target_project: target_project
}
def base_params
params = {}
if push_options.key?(:merge_when_pipeline_succeeds)
params.merge!(
......@@ -137,30 +131,32 @@ module MergeRequests
params[:force_remove_source_branch] = push_options[:remove_source_branch]
end
if push_options.key?(:target)
params[:target_branch] = push_options[:target]
end
params
end
def update_params
params = {}
if push_options.key?(:merge_when_pipeline_succeeds)
params.merge!(
merge_when_pipeline_succeeds: push_options[:merge_when_pipeline_succeeds],
merge_user: current_user
)
end
def create_params(branch)
params = base_params
if push_options.key?(:remove_source_branch)
params[:force_remove_source_branch] = push_options[:remove_source_branch]
end
params.merge!(
assignees: [current_user],
source_branch: branch,
source_project: project,
target_project: target_project
)
if push_options.key?(:target)
params[:target_branch] = push_options[:target]
end
params[:target_branch] ||= target_project.default_branch
params
end
def update_params
base_params
end
def collect_errors_from_merge_request(merge_request)
merge_request.errors.full_messages.each do |error|
errors << error
......
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