Class: MergeRequests::MergeService

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

Overview

MergeService class

Do git merge and in case of success mark merge request as merged and execute all hooks and notifications Executed when you do merge via GitLab UI

Direct Known Subclasses

FfMergeService

Constant Summary collapse

GENERIC_ERROR_MESSAGE =
'An error occurred while merging'
LEASE_TIMEOUT =
15.minutes.to_i

Constants inherited from MergeBaseService

MergeRequests::MergeBaseService::MergeError

Instance Attribute Summary

Attributes inherited from MergeBaseService

#merge_request

Attributes inherited from BaseProjectService

#project

Attributes inherited from BaseContainerService

#container, #current_user, #params

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods inherited from MergeBaseService

#hooks_validation_error, #hooks_validation_pass?, #source

Methods inherited from BaseService

#cancel_review_app_jobs!, #cleanup_environments, #create_note, #execute_external_hooks, #execute_hooks, #handle_assignees_change, #handle_changes, #handle_reviewers_change, #hook_data, #inspect, #merge_request_activity_counter, #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 BaseProjectService

#initialize

Methods inherited from BaseContainerService

#group_container?, #initialize, #namespace_container?, #project_container?

Methods included from BaseServiceUtility

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

Methods included from Gitlab::Allowable

#can?

Instance Method Details

#execute(merge_request, options = {}) ⇒ Object


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
# File 'app/services/merge_requests/merge_service.rb', line 18

def execute(merge_request, options = {})
  if project.merge_requests_ff_only_enabled && !self.is_a?(FfMergeService)
    FfMergeService.new(project: project, current_user: current_user, params: params).execute(merge_request)
    return
  end

  return if merge_request.merged?
  return unless exclusive_lease(merge_request.id).try_obtain

  @merge_request = merge_request
  @options = options

  validate!

  merge_request.in_locked_state do
    if commit
      after_merge
      clean_merge_jid
      success
    end
  end

  log_info("Merge process finished on JID #{merge_jid} with state #{state}")
rescue MergeError => e
  handle_merge_error(log_message: e.message, save_message_on_model: true)
ensure
  exclusive_lease(merge_request.id).cancel
end