Class: MergeRequests::BuildService

Inherits:
BaseService show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/services/merge_requests/build_service.rb

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods inherited from BaseService

#cancel_review_app_jobs!, #cleanup_environments, #create_note, #execute_hooks, #hook_data, #inspect, #source_project, #target_project

Methods included from Gitlab::Utils::Override

#extended, extensions, #included, #method_added, #override, #prepended, #queue_verification, verify!

Methods included from AssignsMergeParams

#assign_allowed_merge_params, included

Methods inherited from BaseService

#initialize

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Instance Method Details

#executeObject


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/services/merge_requests/build_service.rb', line 7

def execute
  @params_issue_iid = params.delete(:issue_iid)
  self.merge_request = MergeRequest.new
  # TODO: this should handle all quick actions that don't have side effects
  # https://gitlab.com/gitlab-org/gitlab-foss/issues/53658
  merge_quick_actions_into_params!(merge_request, only: [:target_branch])

  # Assign the projects first so we can use policies for `filter_params`
  merge_request.author = current_user
  merge_request.source_project = find_source_project
  merge_request.target_project = find_target_project

  # Source project sets the default source branch removal setting
  merge_request.merge_params['force_remove_source_branch'] =
    if params.key?(:force_remove_source_branch)
      params.delete(:force_remove_source_branch)
    else
      merge_request.source_project.remove_source_branch_after_merge?
    end

  self.params = assign_allowed_merge_params(merge_request, params)

  filter_params(merge_request)

  # 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)

  merge_request.compare_commits = []
  set_merge_request_target_branch

  merge_request.can_be_created = projects_and_branches_valid?

  # compare branches only if branches are valid, otherwise
  # compare_branches may raise an error
  if merge_request.can_be_created
    compare_branches
    assign_title_and_description
    assign_labels
    assign_milestone
  end

  merge_request
end