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

test_case_failure.rb « ci « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8867b954240badca3e4af0cfbf2dd82b82d311d2 (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
# frozen_string_literal: true

module Ci
  class TestCaseFailure < ApplicationRecord
    extend Gitlab::Ci::Model

    REPORT_WINDOW = 14.days

    validates :test_case, :build, :failed_at, presence: true

    belongs_to :test_case, class_name: "Ci::TestCase", foreign_key: :test_case_id
    belongs_to :build, class_name: "Ci::Build", foreign_key: :build_id

    def self.recent_failures_count(project:, test_case_keys:, date_range: REPORT_WINDOW.ago..Time.current)
      joins(:test_case)
        .where(
          ci_test_cases: {
            project_id: project.id,
            key_hash: test_case_keys
          },
          ci_test_case_failures: {
            failed_at: date_range
          }
        )
        .group(:key_hash)
        .count('ci_test_case_failures.id')
    end
  end
end