Class: AutoMerge::BaseService

Inherits:
BaseService show all
Includes:
Gitlab::Utils::StrongMemoize, MergeRequests::AssignsMergeParams
Defined in:
app/services/auto_merge/base_service.rb

Direct Known Subclasses

MergeWhenPipelineSucceedsService

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MergeRequests::AssignsMergeParams

#assign_allowed_merge_params, included

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

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?

Constructor Details

This class inherits a constructor from BaseService

Class Method Details

.can_add_to_merge_train?(merge_request) ⇒ Boolean

NOTE: This method is to be removed when `disallow_to_create_merge_request_pipelines_in_target_project` feature flag is removed.

Returns:

  • (Boolean)

66
67
68
69
70
71
72
# File 'app/services/auto_merge/base_service.rb', line 66

def self.can_add_to_merge_train?(merge_request)
  if Gitlab::Ci::Features.disallow_to_create_merge_request_pipelines_in_target_project?(merge_request.target_project)
    merge_request.for_same_project?
  else
    true
  end
end

Instance Method Details

#abort(merge_request, reason) ⇒ Object


43
44
45
46
47
48
49
50
51
52
53
# File 'app/services/auto_merge/base_service.rb', line 43

def abort(merge_request, reason)
  ActiveRecord::Base.transaction do
    clear_auto_merge_parameters!(merge_request)
    yield if block_given?
  end

  success
rescue => e
  track_exception(e, merge_request)
  error("Can't abort the automatic merge", 406)
end

#available_for?(merge_request) ⇒ Boolean

Returns:

  • (Boolean)

55
56
57
58
59
60
61
# File 'app/services/auto_merge/base_service.rb', line 55

def available_for?(merge_request)
  strong_memoize("available_for_#{merge_request.id}") do
    merge_request.can_be_merged_by?(current_user) &&
      merge_request.mergeable_state?(skip_ci_check: true) &&
      yield
  end
end

#can_add_to_merge_train?(merge_request) ⇒ Boolean

Returns:

  • (Boolean)

74
75
76
# File 'app/services/auto_merge/base_service.rb', line 74

def can_add_to_merge_train?(merge_request)
  self.class.can_add_to_merge_train?(merge_request)
end

#cancel(merge_request) ⇒ Object


31
32
33
34
35
36
37
38
39
40
41
# File 'app/services/auto_merge/base_service.rb', line 31

def cancel(merge_request)
  ActiveRecord::Base.transaction do
    clear_auto_merge_parameters!(merge_request)
    yield if block_given?
  end

  success
rescue => e
  track_exception(e, merge_request)
  error("Can't cancel the automatic merge", 406)
end

#execute(merge_request) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/services/auto_merge/base_service.rb', line 8

def execute(merge_request)
  ActiveRecord::Base.transaction do
    register_auto_merge_parameters!(merge_request)
    yield if block_given?
  end

  notify(merge_request)
  AutoMergeProcessWorker.perform_async(merge_request.id)

  strategy.to_sym
rescue => e
  track_exception(e, merge_request)
  :failed
end

#update(merge_request) ⇒ Object


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

def update(merge_request)
  assign_allowed_merge_params(merge_request, params.merge(auto_merge_strategy: strategy))

  return :failed unless merge_request.save

  strategy.to_sym
end