diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 10:34:06 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 10:34:06 +0000 |
commit | 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch) | |
tree | d7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /app/models/merge_request/metrics.rb | |
parent | 446d496a6d000c73a304be52587cd9bbc7493136 (diff) | |
download | gitlab-ce-859a6fb938bb9ee2a317c46dfa4fcc1af49608f0.tar.gz |
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'app/models/merge_request/metrics.rb')
-rw-r--r-- | app/models/merge_request/metrics.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/app/models/merge_request/metrics.rb b/app/models/merge_request/metrics.rb index d3fe256fb1b..5c611da0684 100644 --- a/app/models/merge_request/metrics.rb +++ b/app/models/merge_request/metrics.rb @@ -5,12 +5,14 @@ class MergeRequest::Metrics < ApplicationRecord belongs_to :pipeline, class_name: 'Ci::Pipeline', foreign_key: :pipeline_id belongs_to :latest_closed_by, class_name: 'User' belongs_to :merged_by, class_name: 'User' + belongs_to :target_project, class_name: 'Project', inverse_of: :merge_requests 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)) } scope :with_valid_time_to_merge, -> { where(arel_table[:merged_at].gt(arel_table[:created_at])) } + scope :by_target_project, ->(project) { where(target_project_id: project) } def self.time_to_merge_expression Arel.sql('EXTRACT(epoch FROM SUM(AGE(merge_request_metrics.merged_at, merge_request_metrics.created_at)))') @@ -21,6 +23,12 @@ class MergeRequest::Metrics < ApplicationRecord def ensure_target_project_id self.target_project_id ||= merge_request.target_project_id end + + def self.total_time_to_merge + with_valid_time_to_merge + .pluck(time_to_merge_expression) + .first + end end MergeRequest::Metrics.prepend_if_ee('EE::MergeRequest::Metrics') |