Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test_failure_history.rb « reports « ci « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c110dbf98be82ce4d84a6ba5059720e9a57ae40e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# frozen_string_literal: true

module Gitlab
  module Ci
    module Reports
      class TestFailureHistory
        include Gitlab::Utils::StrongMemoize

        def initialize(failed_junit_tests, project)
          @failed_junit_tests = build_map(failed_junit_tests)
          @project = project
        end

        def load!
          recent_failures_count.each do |key_hash, count|
            failed_junit_tests[key_hash].set_recent_failures(count, project.default_branch_or_main)
          end
        end

        private

        attr_reader :report, :project, :failed_junit_tests

        def recent_failures_count
          ::Ci::UnitTestFailure.recent_failures_count(
            project: project,
            unit_test_keys: failed_junit_tests.keys
          )
        end

        def build_map(junit_tests)
          {}.tap do |hash|
            junit_tests.each do |test|
              hash[test.key] = test
            end
          end
        end
      end
    end
  end
end