debian-mirror-gitlab/app/services/merge_requests/mergeability/run_checks_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

49 lines
1.3 KiB
Ruby
Raw Normal View History

2021-11-18 22:05:49 +05:30
# frozen_string_literal: true
module MergeRequests
module Mergeability
class RunChecksService
include Gitlab::Utils::StrongMemoize
def initialize(merge_request:, params:)
@merge_request = merge_request
@params = params
end
def execute
2022-07-23 23:45:48 +05:30
merge_request.mergeability_checks.each_with_object([]) do |check_class, results|
2021-11-18 22:05:49 +05:30
check = check_class.new(merge_request: merge_request, params: params)
next if check.skip?
check_result = run_check(check)
results << check_result
break results if check_result.failed?
end
end
private
attr_reader :merge_request, :params
def run_check(check)
2022-07-16 23:28:13 +05:30
return check.execute unless Feature.enabled?(:mergeability_caching, merge_request.project)
2021-11-18 22:05:49 +05:30
return check.execute unless check.cacheable?
cached_result = results.read(merge_check: check)
return cached_result if cached_result.respond_to?(:status)
check.execute.tap do |result|
results.write(merge_check: check, result_hash: result.to_hash)
end
end
def results
strong_memoize(:results) do
Gitlab::MergeRequests::Mergeability::ResultsStore.new(merge_request: merge_request)
end
end
end
end
end