Module: MergeRequests::AssignsMergeParams

Included in:
AutoMerge::BaseService, BaseService
Defined in:
app/services/concerns/merge_requests/assigns_merge_params.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object


5
6
7
# File 'app/services/concerns/merge_requests/assigns_merge_params.rb', line 5

def self.included(klass)
  raise "#{self} can not be included in #{klass} without implementing #current_user" unless klass.method_defined?(:current_user)
end

Instance Method Details

#assign_allowed_merge_params(merge_request, merge_params) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/services/concerns/merge_requests/assigns_merge_params.rb', line 9

def assign_allowed_merge_params(merge_request, merge_params)
  known_merge_params = merge_params.to_h.with_indifferent_access.slice(*MergeRequest::KNOWN_MERGE_PARAMS)

  # Not checking `MergeRequest#can_remove_source_branch` as that includes
  # other checks that aren't needed here.
  known_merge_params.delete(:force_remove_source_branch) unless current_user.can?(:push_code, merge_request.source_project)

  merge_request.merge_params.merge!(known_merge_params)

  # Delete the known params now that they're assigned, so we don't try to
  # assign them through an `#assign_attributes` later.
  # They could be coming in as strings or symbols
  merge_params.to_h.with_indifferent_access.except!(*MergeRequest::KNOWN_MERGE_PARAMS)
end