Module: MergeRequestMetricsHelper

Included in:
MergeRequestPollCachedWidgetEntity
Defined in:
app/serializers/merge_request_metrics_helper.rb

Instance Method Summary collapse

Instance Method Details

#build_metrics(merge_request) ⇒ Object

There are cases where where metrics object doesn't exist and it needs to be rebuilt. TODO: Once gitlab.com/gitlab-org/gitlab/-/issues/342508 has been resolved and all merge requests have metrics we can remove this helper method.


7
8
9
10
11
12
13
14
15
# File 'app/serializers/merge_request_metrics_helper.rb', line 7

def build_metrics(merge_request)
  # There's no need to query and serialize metrics data for merge requests that are not
  # merged or closed.
  return unless merge_request.merged? || merge_request.closed?
  return merge_request.metrics if merge_request.merged? && merge_request.metrics&.merged_by_id
  return merge_request.metrics if merge_request.closed? && merge_request.metrics&.latest_closed_by_id

  build_metrics_from_events(merge_request)
end