summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Couder <chriscool@tuxfamily.org>2019-07-17 09:19:16 +0200
committerChristian Couder <chriscool@tuxfamily.org>2019-07-17 13:33:09 +0200
commit0d98f1bba2caf7ee5056510781c61db030551a66 (patch)
tree372460bd31941ded1da6b071ed3b7341d0ea31bc
parent8256d4075db4ee2d00897f21d34b78f092571f2c (diff)
downloadgitlab-ce-0d98f1bba2caf7ee5056510781c61db030551a66.tar.gz
Refactor create_params and update_paramsrm-src-branch
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.
-rw-r--r--app/services/merge_requests/push_options_handler_service.rb42
1 files changed, 19 insertions, 23 deletions
diff --git a/app/services/merge_requests/push_options_handler_service.rb b/app/services/merge_requests/push_options_handler_service.rb
index 7ca8e1d76a3..6d70b5106c7 100644
--- a/app/services/merge_requests/push_options_handler_service.rb
+++ b/app/services/merge_requests/push_options_handler_service.rb
@@ -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