summaryrefslogtreecommitdiff
path: root/app/models/ci/daily_build_group_report_result.rb
blob: e6f02f2e4f3fe9a0a2992d95b8fc1cef6890a6dd (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
# frozen_string_literal: true

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

    PARAM_TYPES = %w[coverage].freeze

    belongs_to :last_pipeline, class_name: 'Ci::Pipeline', foreign_key: :last_pipeline_id
    belongs_to :project

    validates :data, json_schema: { filename: "daily_build_group_report_result_data" }

    scope :with_included_projects, -> { includes(:project) }

    def self.upsert_reports(data)
      upsert_all(data, unique_by: :index_daily_build_group_report_results_unique_columns) if data.any?
    end

    def self.recent_results(attrs, limit: nil)
      where(attrs).order(date: :desc, group_name: :asc).limit(limit)
    end
  end
end