diff options
Diffstat (limited to 'app/services/merge_requests/build_service.rb')
-rw-r--r-- | app/services/merge_requests/build_service.rb | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/app/services/merge_requests/build_service.rb b/app/services/merge_requests/build_service.rb index e4d3c91d13e..ecc55eae5de 100644 --- a/app/services/merge_requests/build_service.rb +++ b/app/services/merge_requests/build_service.rb @@ -16,17 +16,7 @@ module MergeRequests merge_request.source_project = find_source_project merge_request.target_project = find_target_project - # Force remove the 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) - - # Filter out params that are either not allowed or invalid - filter_params(merge_request) - - # Filter out :add_label_ids and :remove_label_ids params - filter_label_id_params + process_params merge_request.compare_commits = [] set_merge_request_target_branch @@ -70,21 +60,41 @@ module MergeRequests end end - def filter_label_id_params + def filter_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 + # in the database for :add_label_ids, :remove_label_ids, + # :add_assignee_ids and :remove_assignee_ids, we # need to remove them from the params before the call to # merge_request.assign_attributes(...) # - # IssuableBaseService#process_label_ids takes care + # IssuableBaseService#process_label_ids and + # IssuableBaseService#process_assignee_ids take care # of the removal. params[:label_ids] = process_label_ids(params, extra_label_ids: merge_request.label_ids.to_a) + params[:assignee_ids] = process_assignee_ids(params, extra_assignee_ids: merge_request.assignee_ids.to_a) + merge_request.assign_attributes(params.to_h.compact) end + def process_params + # Force remove the 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) + + # Filter out params that are either not allowed or invalid + filter_params(merge_request) + + # Filter out the following from params: + # - :add_label_ids and :remove_label_ids + # - :add_assignee_ids and :remove_assignee_ids + filter_id_params + end + def find_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) |