Class: MergeRequests::MergeService

Inherits:
BaseService 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

Instance Attribute Summary collapse

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#create_note, #create_title_change_note, #execute_hooks, #hook_data

Methods inherited from BaseService

#abilities, #can?, #deny_visibility_level, #event_service, #initialize, #log_info, #notification_service, #repository, #system_hook_service, #todo_service

Methods included from Gitlab::CurrentSettings

#current_application_settings, #fake_application_settings

Constructor Details

This class inherits a constructor from BaseService

Instance Attribute Details

#merge_requestObject (readonly)

Returns the value of attribute merge_request


9
10
11
# File 'app/services/merge_requests/merge_service.rb', line 9

def merge_request
  @merge_request
end

Instance Method Details

#execute(merge_request) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/services/merge_requests/merge_service.rb', line 11

def execute(merge_request)
  @merge_request = merge_request

  return error('Merge request is not mergeable') unless @merge_request.mergeable?

  merge_request.in_locked_state do
    if commit
      after_merge
      success
    else
      error('Can not merge changes')
    end
  end
end