2018-11-20 20:47:30 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
class MergeRequest::Metrics < ApplicationRecord
|
2020-10-24 23:57:45 +05:30
|
|
|
belongs_to :merge_request, inverse_of: :metrics
|
2017-08-17 22:00:37 +05:30
|
|
|
belongs_to :pipeline, class_name: 'Ci::Pipeline', foreign_key: :pipeline_id
|
2018-03-17 18:26:18 +05:30
|
|
|
belongs_to :latest_closed_by, class_name: 'User'
|
|
|
|
belongs_to :merged_by, class_name: 'User'
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
before_save :ensure_target_project_id
|
|
|
|
|
|
|
|
scope :merged_after, ->(date) { where(arel_table[:merged_at].gteq(date)) }
|
|
|
|
scope :merged_before, ->(date) { where(arel_table[:merged_at].lteq(date)) }
|
2021-02-22 17:27:13 +05:30
|
|
|
scope :with_valid_time_to_merge, -> { where(arel_table[:merged_at].gt(arel_table[:created_at])) }
|
|
|
|
|
|
|
|
def self.time_to_merge_expression
|
|
|
|
Arel.sql('EXTRACT(epoch FROM SUM(AGE(merge_request_metrics.merged_at, merge_request_metrics.created_at)))')
|
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def ensure_target_project_id
|
|
|
|
self.target_project_id ||= merge_request.target_project_id
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
MergeRequest::Metrics.prepend_if_ee('EE::MergeRequest::Metrics')
|