Commit 0910868d authored by Timothy Andrew's avatar Timothy Andrew

Tweak cycle analytics query to match the current requirements.

- The `review` phase ends when a MR is merged, not "merged OR closed".
- The `code` phase starts when a MR is first mentioned in a commit, and
  ends when a merge request closing the issue is created.
- The `plan` phase ends when the issue first mentioned in a commit.

---

- Fix the `median` function so it sorts the incoming data points.
- A data point where `end_time` is prior to `start_time` is invalid.
parent 2f57eee7
...@@ -15,13 +15,13 @@ class CycleAnalytics ...@@ -15,13 +15,13 @@ class CycleAnalytics
def plan def plan
calculate_metric(Queries::issues(@project, created_after: @from), calculate_metric(Queries::issues(@project, created_after: @from),
[Queries::issue_first_associated_with_milestone_at, Queries::issue_first_added_to_list_label_at], [Queries::issue_first_associated_with_milestone_at, Queries::issue_first_added_to_list_label_at],
Queries::issue_closing_merge_request_opened_at) Queries::issue_first_mentioned_in_commit_at)
end end
def code def code
calculate_metric(Queries::merge_requests_closing_issues(@project, created_after: @from), calculate_metric(Queries::merge_requests_closing_issues(@project, created_after: @from),
-> (data_point) { data_point[:merge_request].created_at }, Queries::issue_first_mentioned_in_commit_at,
[Queries::merge_request_first_assigned_to_user_other_than_author_at, Queries::merge_request_wip_flag_first_removed_at]) -> (data_point) { data_point[:merge_request].created_at })
end end
def test def test
...@@ -32,14 +32,14 @@ class CycleAnalytics ...@@ -32,14 +32,14 @@ class CycleAnalytics
def review def review
calculate_metric(Queries::merge_requests_closing_issues(@project, created_after: @from), calculate_metric(Queries::merge_requests_closing_issues(@project, created_after: @from),
[Queries::merge_request_first_assigned_to_user_other_than_author_at, Queries::merge_request_wip_flag_first_removed_at], -> (data_point) { data_point[:merge_request].created_at },
[Queries::merge_request_first_closed_at, Queries::merge_request_merged_at]) Queries::merge_request_merged_at)
end end
def staging def staging
calculate_metric(Queries::merge_requests_closing_issues(@project, created_after: @from), calculate_metric(Queries::merge_requests_closing_issues(@project, created_after: @from),
Queries::merge_request_merged_at, Queries::merge_request_merged_at,
Queries::merge_request_deployed_to_any_environment_at) Queries::merge_request_deployed_to_production_at)
end end
def production def production
...@@ -55,12 +55,12 @@ class CycleAnalytics ...@@ -55,12 +55,12 @@ class CycleAnalytics
start_time = Array.wrap(start_time_fns).map { |fn| fn[data_point] }.compact.first start_time = Array.wrap(start_time_fns).map { |fn| fn[data_point] }.compact.first
end_time = Array.wrap(end_time_fns).map { |fn| fn[data_point] }.compact.first 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 end_time - start_time
end end
end end
median(times.compact) median(times.compact.sort)
end end
def median(coll) def median(coll)
......
...@@ -26,6 +26,14 @@ class CycleAnalytics ...@@ -26,6 +26,14 @@ class CycleAnalytics
end end
end end
def issue_first_mentioned_in_commit_at
lambda do |data_point|
issue = data_point[:issue]
commits_mentioning_issue = issue.notes.system.map { |note| note.all_references.commits }.flatten
commits_mentioning_issue.map(&:committed_date).min if commits_mentioning_issue.present?
end
end
def merge_request_first_closed_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]
......
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