Commit d3fef0fb authored by Timothy Andrew's avatar Timothy Andrew

Add the "Staging" cycle analytics section.

parent 14d6317e
...@@ -15,18 +15,25 @@ class CycleAnalytics ...@@ -15,18 +15,25 @@ class CycleAnalytics
def code def code
issues = Issue.all.to_a issues = Issue.all.to_a
start_time_fn = -> (merge_request) { merge_request.created_at } start_time_fn = -> (merge_request) { merge_request.created_at }
calculate_metric(issues.map { |issue| issue.closed_by_merge_requests(nil, check_if_open: false) }.flatten, calculate_metric(Queries::merge_requests_closing_issues(issues),
start_time_fn, start_time_fn,
Queries::mr_wip_flag_removed_or_assigned_to_user_other_than_author_time) Queries::mr_wip_flag_removed_or_assigned_to_user_other_than_author_time)
end end
def review def review
issues = Issue.all.to_a issues = Issue.all.to_a
calculate_metric(issues.map { |issue| issue.closed_by_merge_requests(nil, check_if_open: false) }.flatten, calculate_metric(Queries::merge_requests_closing_issues(issues),
Queries::mr_wip_flag_removed_or_assigned_to_user_other_than_author_time, Queries::mr_wip_flag_removed_or_assigned_to_user_other_than_author_time,
Queries::mr_first_closed_or_merged_at) Queries::mr_first_closed_or_merged_at)
end end
def staging
issues = Issue.all.to_a
calculate_metric(Queries::merge_requests_closing_issues(issues),
Queries::mr_merged_at,
Queries::mr_deployed_to_any_environment_at)
end
private private
def calculate_metric(data, start_time_fn, end_time_fn) def calculate_metric(data, start_time_fn, end_time_fn)
......
class CycleAnalytics class CycleAnalytics
module Queries module Queries
class << self class << self
def merge_requests_closing_issues(issues)
issues.map { |issue| issue.closed_by_merge_requests(nil, check_if_open: false) }.flatten
end
def issue_first_associated_with_milestone_or_first_added_to_list_label_time def issue_first_associated_with_milestone_or_first_added_to_list_label_time
lambda do |issue| lambda do |issue|
if issue.metrics.present? if issue.metrics.present?
...@@ -18,6 +22,24 @@ class CycleAnalytics ...@@ -18,6 +22,24 @@ class CycleAnalytics
end end
end end
def mr_merged_at
lambda do |merge_request|
if merge_request.metrics.present?
merge_request.metrics.merged_at
end
end
end
def mr_deployed_to_any_environment_at
lambda do |merge_request|
if merge_request.metrics.present?
deployments = Deployment.where(ref: merge_request.target_branch).where("created_at > ?", merge_request.metrics.merged_at)
deployment = deployments.order(:created_at).first
deployment.created_at if deployment
end
end
end
def issue_closing_merge_request_opened_time def issue_closing_merge_request_opened_time
lambda do |issue| lambda do |issue|
merge_requests = issue.closed_by_merge_requests(nil, check_if_open: false) merge_requests = issue.closed_by_merge_requests(nil, check_if_open: false)
......
...@@ -26,3 +26,10 @@ ...@@ -26,3 +26,10 @@
= distance_of_time_in_words review = distance_of_time_in_words review
- else - else
= "<Not enough data>" = "<Not enough data>"
%li.list-group-item
Staging:
- if staging = @cycle_analytics.staging.presence
= distance_of_time_in_words staging
- else
= "<Not enough data>"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment