debian-mirror-gitlab/lib/gitlab/ci/reports/test_failure_history.rb

42 lines
992 B
Ruby
Raw Normal View History

2021-01-29 00:20:46 +05:30
# frozen_string_literal: true
module Gitlab
module Ci
module Reports
class TestFailureHistory
include Gitlab::Utils::StrongMemoize
2021-04-29 21:17:54 +05:30
def initialize(failed_junit_tests, project)
@failed_junit_tests = build_map(failed_junit_tests)
2021-01-29 00:20:46 +05:30
@project = project
end
def load!
recent_failures_count.each do |key_hash, count|
2021-06-08 01:23:25 +05:30
failed_junit_tests[key_hash].set_recent_failures(count, project.default_branch_or_main)
2021-01-29 00:20:46 +05:30
end
end
private
2021-04-29 21:17:54 +05:30
attr_reader :report, :project, :failed_junit_tests
2021-01-29 00:20:46 +05:30
def recent_failures_count
2021-04-29 21:17:54 +05:30
::Ci::UnitTestFailure.recent_failures_count(
2021-01-29 00:20:46 +05:30
project: project,
2021-04-29 21:17:54 +05:30
unit_test_keys: failed_junit_tests.keys
2021-01-29 00:20:46 +05:30
)
end
2021-04-29 21:17:54 +05:30
def build_map(junit_tests)
2021-01-29 00:20:46 +05:30
{}.tap do |hash|
2021-04-29 21:17:54 +05:30
junit_tests.each do |test|
hash[test.key] = test
2021-01-29 00:20:46 +05:30
end
end
end
end
end
end
end