Class: MergeRequests::BaseService

Inherits:
IssuableBaseService show all
Extended by:
Gitlab::Utils::Override
Includes:
AssignsMergeParams
Defined in:
app/services/merge_requests/base_service.rb

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

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

Methods included from Gitlab::Allowable

#can?

Instance Method Details

#cancel_review_app_jobs!(merge_request) ⇒ Object


35
36
37
38
# File 'app/services/merge_requests/base_service.rb', line 35

def cancel_review_app_jobs!(merge_request)
  environments = merge_request.environments.in_review_folder.available
  environments.each { |environment| environment.cancel_deployment_jobs! }
end

#cleanup_environments(merge_request) ⇒ Object


30
31
32
33
# File 'app/services/merge_requests/base_service.rb', line 30

def cleanup_environments(merge_request)
  Ci::StopEnvironmentsService.new(merge_request.source_project, current_user)
                             .execute_for_merge_request(merge_request)
end

#create_note(merge_request, state = merge_request.state) ⇒ Object


8
9
10
# File 'app/services/merge_requests/base_service.rb', line 8

def create_note(merge_request, state = merge_request.state)
  SystemNoteService.change_status(merge_request, merge_request.target_project, current_user, state, nil)
end

#execute_hooks(merge_request, action = 'open', old_rev: nil, old_associations: {}) ⇒ Object


22
23
24
25
26
27
28
# File 'app/services/merge_requests/base_service.rb', line 22

def execute_hooks(merge_request, action = 'open', old_rev: nil, old_associations: {})
  merge_data = hook_data(merge_request, action, old_rev: old_rev, old_associations: old_associations)
  merge_request.project.execute_hooks(merge_data, :merge_request_hooks)
  merge_request.project.execute_services(merge_data, :merge_request_hooks)

  enqueue_jira_connect_messages_for(merge_request)
end

#hook_data(merge_request, action, old_rev: nil, old_associations: {}) ⇒ Object


12
13
14
15
16
17
18
19
20
# File 'app/services/merge_requests/base_service.rb', line 12

def hook_data(merge_request, action, old_rev: nil, old_associations: {})
  hook_data = merge_request.to_hook_data(current_user, old_associations: old_associations)
  hook_data[:object_attributes][:action] = action
  if old_rev && !Gitlab::Git.blank_ref?(old_rev)
    hook_data[:object_attributes][:oldrev] = old_rev
  end

  hook_data
end

#inspectObject

Don't try to print expensive instance variables.


49
50
51
52
53
# File 'app/services/merge_requests/base_service.rb', line 49

def inspect
  return "#<#{self.class}>" unless respond_to?(:merge_request)

  "#<#{self.class} #{merge_request.to_reference(full: true)}>"
end

#source_projectObject


40
41
42
# File 'app/services/merge_requests/base_service.rb', line 40

def source_project
  @source_project ||= merge_request.source_project
end

#target_projectObject


44
45
46
# File 'app/services/merge_requests/base_service.rb', line 44

def target_project
  @target_project ||= merge_request.target_project
end