Class: AutoMergeProcessWorker

Inherits:
Object
  • Object
show all
Includes:
ApplicationWorker
Defined in:
app/workers/auto_merge_process_worker.rb

Overview

rubocop:disable Scalability/IdempotentWorker

Constant Summary collapse

PROJECT_MR_LIMIT =
30

Constants included from ApplicationWorker

ApplicationWorker::LOGGING_EXTRA_KEY, ApplicationWorker::SAFE_PUSH_BULK_LIMIT

Constants included from Gitlab::Loggable

Gitlab::Loggable::ANONYMOUS

Constants included from WorkerAttributes

WorkerAttributes::DEFAULT_CONCURRENCY_LIMIT_PERCENTAGE_BY_URGENCY, WorkerAttributes::DEFAULT_DATA_CONSISTENCY, WorkerAttributes::DEFAULT_DATA_CONSISTENCY_PER_DB, WorkerAttributes::DEFAULT_DEFER_DELAY, WorkerAttributes::LOAD_BALANCED_DATA_CONSISTENCIES, WorkerAttributes::NAMESPACE_WEIGHTS, WorkerAttributes::VALID_DATA_CONSISTENCIES, WorkerAttributes::VALID_RESOURCE_BOUNDARIES, WorkerAttributes::VALID_URGENCIES

Instance Method Summary collapse

Methods included from Gitlab::Loggable

#build_structured_payload

Methods included from Gitlab::SidekiqVersioning::Worker

#job_version

Methods included from WorkerContext

#with_context

Instance Method Details

#perform(params = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/workers/auto_merge_process_worker.rb', line 19

def perform(params = {})
  # Passing an integer id to AutoMergeProcessWorker is deprecated.
  # This is here to support existing implementations while we transition
  # to a params hash. https://gitlab.com/gitlab-org/gitlab/-/issues/497247
  params = { 'merge_request_id' => params } unless params.is_a?(Hash)

  merge_requests = params['merge_request_id'].try do |mr_id|
    MergeRequest.id_in(mr_id)
  end

  pipeline_merge_requests = params['pipeline_id'].try do |pipe_id|
    Ci::Pipeline.id_in(pipe_id).flat_map do |pipeline|
      pipeline.all_merge_requests.with_auto_merge_enabled
    end
  end

  project_merge_requests = params['project_id'].try do |proj_id|
    project = Project.id_in(proj_id).first

    break [] unless project
    break [] unless Feature.enabled?(:merge_request_title_regex, project)

    project.merge_requests&.with_auto_merge_enabled&.take(PROJECT_MR_LIMIT)
  end

  all_merge_requests = (merge_requests.to_a + pipeline_merge_requests.to_a + project_merge_requests.to_a).uniq

  all_merge_requests.each do |merge_request|
    AutoMergeService.new(merge_request.project, merge_request.merge_user).process(merge_request)
  end
end