BigW Consortium Gitlab

Commit ebc03833 by Timothy Andrew

Allow multiple queries for each cycle analytics section.

1. Pass in an array of queries - the first to return a value will be used. This makes it easier to add more heuristics later. 2. Convert all queries with 'or' in the title to two separate queries. 3. Rename all `mr_` methods to `merge_request_`
parent fc92d066
...@@ -2,51 +2,51 @@ class CycleAnalytics ...@@ -2,51 +2,51 @@ class CycleAnalytics
def issue def issue
calculate_metric(Queries::issues, calculate_metric(Queries::issues,
-> (data_point) { data_point[:issue].created_at }, -> (data_point) { data_point[:issue].created_at },
Queries::issue_first_associated_with_milestone_or_first_added_to_list_label_time) [Queries::issue_first_associated_with_milestone_at, Queries::issue_first_added_to_list_label_at])
end end
def plan def plan
calculate_metric(Queries::issues, calculate_metric(Queries::issues,
Queries::issue_first_associated_with_milestone_or_first_added_to_list_label_time, [Queries::issue_first_associated_with_milestone_at, Queries::issue_first_added_to_list_label_at],
Queries::issue_closing_merge_request_opened_time) Queries::issue_closing_merge_request_opened_at)
end end
def code def code
calculate_metric(Queries::merge_requests_closing_issues, calculate_metric(Queries::merge_requests_closing_issues,
-> (data_point) { data_point[:merge_request].created_at }, -> (data_point) { data_point[:merge_request].created_at },
Queries::mr_wip_flag_removed_or_assigned_to_user_other_than_author_time) [Queries::merge_request_first_assigned_to_user_other_than_author_at, Queries::merge_request_wip_flag_first_removed_at])
end end
def test def test
calculate_metric(Queries::merge_requests_closing_issues, calculate_metric(Queries::merge_requests_closing_issues,
Queries::mr_build_started_at, Queries::merge_request_build_started_at,
Queries::mr_build_finished_at) Queries::merge_request_build_finished_at)
end end
def review def review
calculate_metric(Queries::merge_requests_closing_issues, calculate_metric(Queries::merge_requests_closing_issues,
Queries::mr_wip_flag_removed_or_assigned_to_user_other_than_author_time, [Queries::merge_request_first_assigned_to_user_other_than_author_at, Queries::merge_request_wip_flag_first_removed_at],
Queries::mr_first_closed_or_merged_at) [Queries::merge_request_first_closed_at, Queries::merge_request_merged_at])
end end
def staging def staging
calculate_metric(Queries::merge_requests_closing_issues, calculate_metric(Queries::merge_requests_closing_issues,
Queries::mr_merged_at, Queries::merge_request_merged_at,
Queries::mr_deployed_to_any_environment_at) Queries::merge_request_deployed_to_any_environment_at)
end end
def production def production
calculate_metric(Queries::merge_requests_closing_issues, calculate_metric(Queries::merge_requests_closing_issues,
-> (data_point) { data_point[:issue].created_at }, -> (data_point) { data_point[:issue].created_at },
Queries::mr_deployed_to_production_at) Queries::merge_request_deployed_to_production_at)
end end
private private
def calculate_metric(data, start_time_fn, end_time_fn) def calculate_metric(data, start_time_fns, end_time_fns)
times = data.map do |data_point| times = data.map do |data_point|
start_time = start_time_fn[data_point] start_time = Array.wrap(start_time_fns).map { |fn| fn[data_point] }.compact.first
end_time = end_time_fn[data_point] end_time = Array.wrap(end_time_fns).map { |fn| fn[data_point] }.compact.first
if start_time.present? && end_time.present? if start_time.present? && end_time.present?
end_time - start_time end_time - start_time
......
...@@ -12,35 +12,35 @@ class CycleAnalytics ...@@ -12,35 +12,35 @@ class CycleAnalytics
end.flatten end.flatten
end end
def issue_first_associated_with_milestone_or_first_added_to_list_label_time def issue_first_associated_with_milestone_at
lambda do |data_point| lambda do |data_point|
issue = data_point[:issue] issue = data_point[:issue]
if issue.metrics.present? issue.metrics.first_associated_with_milestone_at if issue.metrics.present?
issue.metrics.first_associated_with_milestone_at.presence ||
issue.metrics.first_added_to_board_at.presence
end end
end end
def issue_first_added_to_list_label_at
lambda do |data_point|
issue = data_point[:issue]
issue.metrics.first_added_to_board_at if issue.metrics.present?
end
end end
def mr_first_closed_or_merged_at def merge_request_first_closed_at
lambda do |data_point| lambda do |data_point|
merge_request = data_point[:merge_request] merge_request = data_point[:merge_request]
if merge_request.metrics.present? merge_request.metrics.first_closed_at if merge_request.metrics.present?
merge_request.metrics.merged_at.presence || merge_request.metrics.first_closed_at.presence
end
end end
end end
def mr_merged_at def merge_request_merged_at
lambda do |data_point| lambda do |data_point|
merge_request = data_point[:merge_request] merge_request = data_point[:merge_request]
if merge_request.metrics.present? merge_request.metrics.merged_at if merge_request.metrics.present?
merge_request.metrics.merged_at
end
end end
end end
def mr_build_started_at def merge_request_build_started_at
lambda do |data_point| lambda do |data_point|
merge_request = data_point[:merge_request] merge_request = data_point[:merge_request]
tip = merge_request.commits.first tip = merge_request.commits.first
...@@ -51,7 +51,7 @@ class CycleAnalytics ...@@ -51,7 +51,7 @@ class CycleAnalytics
end end
end end
def mr_build_finished_at def merge_request_build_finished_at
lambda do |data_point| lambda do |data_point|
merge_request = data_point[:merge_request] merge_request = data_point[:merge_request]
tip = merge_request.commits.first tip = merge_request.commits.first
...@@ -62,7 +62,7 @@ class CycleAnalytics ...@@ -62,7 +62,7 @@ class CycleAnalytics
end end
end end
def mr_deployed_to_any_environment_at def merge_request_deployed_to_any_environment_at
lambda do |data_point| lambda do |data_point|
merge_request = data_point[:merge_request] merge_request = data_point[:merge_request]
if merge_request.metrics.present? if merge_request.metrics.present?
...@@ -73,7 +73,7 @@ class CycleAnalytics ...@@ -73,7 +73,7 @@ class CycleAnalytics
end end
end end
def mr_deployed_to_production_at def merge_request_deployed_to_production_at
lambda do |data_point| lambda do |data_point|
merge_request = data_point[:merge_request] merge_request = data_point[:merge_request]
if merge_request.metrics.present? if merge_request.metrics.present?
...@@ -85,7 +85,7 @@ class CycleAnalytics ...@@ -85,7 +85,7 @@ class CycleAnalytics
end end
end end
def issue_closing_merge_request_opened_time def issue_closing_merge_request_opened_at
lambda do |data_point| lambda do |data_point|
issue = data_point[:issue] issue = data_point[: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)
...@@ -93,13 +93,17 @@ class CycleAnalytics ...@@ -93,13 +93,17 @@ class CycleAnalytics
end end
end end
def mr_wip_flag_removed_or_assigned_to_user_other_than_author_time def merge_request_wip_flag_first_removed_at
lambda do |data_point| lambda do |data_point|
merge_request = data_point[:merge_request] merge_request = data_point[:merge_request]
if merge_request.metrics.present? merge_request.metrics.wip_flag_first_removed_at if merge_request.metrics.present?
merge_request.metrics.wip_flag_first_removed_at.presence || end
merge_request.metrics.first_assigned_to_user_other_than_author.presence
end end
def merge_request_first_assigned_to_user_other_than_author_at
lambda do |data_point|
merge_request = data_point[:merge_request]
merge_request.metrics.first_assigned_to_user_other_than_author if merge_request.metrics.present?
end end
end end
end end
......
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