Class: MergeRequests::MergeService

Inherits:
MergeBaseService show all
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

Constants inherited from MergeBaseService

MergeRequests::MergeBaseService::MergeError

Instance Attribute Summary

Attributes inherited from MergeBaseService

#merge_request

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from MergeBaseService

#hooks_validation_error, #hooks_validation_pass?, #source

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, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Instance Method Details

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


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/services/merge_requests/merge_service.rb', line 13

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

  @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)
end