debian-mirror-gitlab/app/models/ci/unit_test_failure.rb

34 lines
908 B
Ruby
Raw Normal View History

2021-04-29 21:17:54 +05:30
# frozen_string_literal: true
module Ci
2021-10-27 15:23:28 +05:30
class UnitTestFailure < Ci::ApplicationRecord
2023-03-04 22:38:38 +05:30
include Ci::Partitionable
2021-04-29 21:17:54 +05:30
REPORT_WINDOW = 14.days
validates :unit_test, :build, :failed_at, presence: true
belongs_to :unit_test, class_name: "Ci::UnitTest", foreign_key: :unit_test_id
belongs_to :build, class_name: "Ci::Build", foreign_key: :build_id
2023-03-04 22:38:38 +05:30
partitionable scope: :build
2021-06-08 01:23:25 +05:30
scope :deletable, -> { where('failed_at < ?', REPORT_WINDOW.ago) }
2021-04-29 21:17:54 +05:30
def self.recent_failures_count(project:, unit_test_keys:, date_range: REPORT_WINDOW.ago..Time.current)
joins(:unit_test)
.where(
ci_unit_tests: {
project_id: project.id,
key_hash: unit_test_keys
},
ci_unit_test_failures: {
failed_at: date_range
}
)
.group(:key_hash)
.count('ci_unit_test_failures.id')
end
end
end