Class: AutoMerge::BaseService

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

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods included from MergeRequests::AssignsMergeParams

#assign_allowed_merge_params, included

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?, #can_all?, #can_any?

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#abort(merge_request, reason) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'app/services/auto_merge/base_service.rb', line 47

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

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

#available_for?(merge_request) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
62
63
64
65
# File 'app/services/auto_merge/base_service.rb', line 59

def available_for?(merge_request)
  strong_memoize("available_for_#{merge_request.id}") do
    merge_request.can_be_merged_by?(current_user) &&
      merge_request.mergeability_checks_pass?(**skippable_available_for_checks(merge_request)) &&
      yield
  end
end

#cancel(merge_request) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'app/services/auto_merge/base_service.rb', line 35

def cancel(merge_request)
  ApplicationRecord.transaction do
    clear_auto_merge_parameters!(merge_request)
    yield if block_given?
  end

  success
rescue StandardError => 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)
  ApplicationRecord.transaction do
    register_auto_merge_parameters!(merge_request)
    yield if block_given?
  end

  notify(merge_request)
  AutoMergeProcessWorker.perform_async({ 'merge_request_id' => merge_request.id })

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

#process(_) ⇒ Object

Raises:

  • (NotImplementedError)


23
24
25
# File 'app/services/auto_merge/base_service.rb', line 23

def process(_)
  raise NotImplementedError
end

#update(merge_request) ⇒ Object



27
28
29
30
31
32
33
# File 'app/services/auto_merge/base_service.rb', line 27

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