Commit dc59f4bd authored by Christian Couder's avatar Christian Couder Committed by Ash McKenzie

Refactor params processing in BuildService

In build_service.rb, let's refactor some param processing code
and comments from the execute() method into a new
filter_label_id_params() method.

While at it let's also add a few comments.
parent 4aa0c99f
...@@ -19,22 +19,14 @@ module MergeRequests ...@@ -19,22 +19,14 @@ module MergeRequests
# Force remove the source branch? # Force remove the source branch?
merge_request.merge_params['force_remove_source_branch'] = force_remove_source_branch merge_request.merge_params['force_remove_source_branch'] = force_remove_source_branch
# Only assign merge requests params that are allowed
self.params = assign_allowed_merge_params(merge_request, params) self.params = assign_allowed_merge_params(merge_request, params)
# Filter out params that are either not allowed or invalid
filter_params(merge_request) filter_params(merge_request)
# merge_request.assign_attributes(...) below is a Rails # Filter out :add_label_ids and :remove_label_ids params
# method that only work if all the params it is passed have filter_label_id_params
# corresponding fields in the database. As there are no fields
# in the database for :add_label_ids and :remove_label_ids, we
# need to remove them from the params before the call to
# merge_request.assign_attributes(...)
#
# IssuableBaseService#process_label_ids takes care
# of the removal.
params[:label_ids] = process_label_ids(params, extra_label_ids: merge_request.label_ids.to_a)
merge_request.assign_attributes(params.to_h.compact)
merge_request.compare_commits = [] merge_request.compare_commits = []
set_merge_request_target_branch set_merge_request_target_branch
...@@ -77,6 +69,21 @@ module MergeRequests ...@@ -77,6 +69,21 @@ module MergeRequests
end end
end end
def filter_label_id_params
# merge_request.assign_attributes(...) below is a Rails
# method that only work if all the params it is passed have
# corresponding fields in the database. As there are no fields
# in the database for :add_label_ids and :remove_label_ids, we
# need to remove them from the params before the call to
# merge_request.assign_attributes(...)
#
# IssuableBaseService#process_label_ids takes care
# of the removal.
params[:label_ids] = process_label_ids(params, extra_label_ids: merge_request.label_ids.to_a)
merge_request.assign_attributes(params.to_h.compact)
end
def find_source_project def find_source_project
source_project = project_from_params(:source_project) source_project = project_from_params(:source_project)
return source_project if source_project.present? && can?(current_user, :create_merge_request_from, source_project) return source_project if source_project.present? && can?(current_user, :create_merge_request_from, source_project)
......
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