diff options
author | Timothy Andrew <mail@timothyandrew.net> | 2016-08-25 14:36:01 +0530 |
---|---|---|
committer | Timothy Andrew <mail@timothyandrew.net> | 2016-08-26 16:28:20 +0530 |
commit | 3d5729a7008f4ae62190a7862873fc6f28f33425 (patch) | |
tree | 9fcf78c21f42053dc5820f4634f3bfb9f5f011d6 /app/models/cycle_analytics/queries.rb | |
parent | d3fef0fb18759076ae6d189437b323aadd03fcf1 (diff) | |
download | gitlab-ce-3d5729a7008f4ae62190a7862873fc6f28f33425.tar.gz |
Add the "Production" cycle analytics section.
1. Rewrite the `Queries` module to work off a `data_point` hash, with
`issue` and `merge_request` as keys. The "production" query needs
both an issue and a merge request to make it's calculation, so it
makes sense to keep things consistent and provide the same
data (issue + merge request) for all queries.
Diffstat (limited to 'app/models/cycle_analytics/queries.rb')
-rw-r--r-- | app/models/cycle_analytics/queries.rb | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/app/models/cycle_analytics/queries.rb b/app/models/cycle_analytics/queries.rb index 9970941837d..f14f44c3876 100644 --- a/app/models/cycle_analytics/queries.rb +++ b/app/models/cycle_analytics/queries.rb @@ -1,12 +1,20 @@ class CycleAnalytics module Queries class << self - def merge_requests_closing_issues(issues) - issues.map { |issue| issue.closed_by_merge_requests(nil, check_if_open: false) }.flatten + def issues + Issue.all.to_a.map { |issue| { issue: issue } } + end + + def merge_requests_closing_issues + issues.map do |data_point| + merge_requests = data_point[:issue].closed_by_merge_requests(nil, check_if_open: false) + merge_requests.map { |merge_request| { issue: data_point[:issue], merge_request: merge_request } } + end.flatten end def issue_first_associated_with_milestone_or_first_added_to_list_label_time - lambda do |issue| + lambda do |data_point| + issue = data_point[:issue] if issue.metrics.present? issue.metrics.first_associated_with_milestone_at.presence || issue.metrics.first_added_to_board_at.presence @@ -15,7 +23,8 @@ class CycleAnalytics end def mr_first_closed_or_merged_at - lambda do |merge_request| + lambda do |data_point| + merge_request = data_point[:merge_request] if merge_request.metrics.present? merge_request.metrics.merged_at.presence || merge_request.metrics.first_closed_at.presence end @@ -23,7 +32,8 @@ class CycleAnalytics end def mr_merged_at - lambda do |merge_request| + lambda do |data_point| + merge_request = data_point[:merge_request] if merge_request.metrics.present? merge_request.metrics.merged_at end @@ -31,7 +41,8 @@ class CycleAnalytics end def mr_deployed_to_any_environment_at - lambda do |merge_request| + lambda do |data_point| + merge_request = data_point[: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 @@ -40,15 +51,29 @@ class CycleAnalytics end end + def mr_deployed_to_production_at + lambda do |data_point| + merge_request = data_point[:merge_request] + if merge_request.metrics.present? + deployments = Deployment.joins(:environment).where(ref: merge_request.target_branch, "environments.name" => "production"). + where("deployments.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 - lambda do |issue| + lambda do |data_point| + issue = data_point[:issue] merge_requests = issue.closed_by_merge_requests(nil, check_if_open: false) merge_requests.map(&:created_at).min if merge_requests.present? end end def mr_wip_flag_removed_or_assigned_to_user_other_than_author_time - lambda do |merge_request| + lambda do |data_point| + merge_request = data_point[:merge_request] if merge_request.metrics.present? merge_request.metrics.wip_flag_first_removed_at.presence || merge_request.metrics.first_assigned_to_user_other_than_author.presence |