2016-08-25 01:02:27 -04:00
|
|
|
class CycleAnalytics
|
2016-11-21 04:48:07 -05:00
|
|
|
STAGES = %i[issue plan code test review staging production].freeze
|
|
|
|
|
2016-11-18 08:51:52 -05:00
|
|
|
def initialize(project, current_user, from:)
|
2016-09-16 02:04:49 -04:00
|
|
|
@project = project
|
2016-11-18 08:51:52 -05:00
|
|
|
@current_user = current_user
|
2016-08-26 06:48:52 -04:00
|
|
|
@from = from
|
2016-11-17 07:22:27 -05:00
|
|
|
@fetcher = Gitlab::CycleAnalytics::MetricsFetcher.new(project: project, from: from, branch: nil)
|
2016-09-19 05:30:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def summary
|
2016-11-18 08:51:52 -05:00
|
|
|
@summary ||= Summary.new(@project, @current_user, from: @from)
|
2016-08-26 06:15:00 -04:00
|
|
|
end
|
|
|
|
|
2016-11-21 08:09:26 -05:00
|
|
|
def permissions(user:)
|
|
|
|
Gitlab::CycleAnalytics::Permissions.get(user: user, project: @project)
|
2016-11-21 04:48:07 -05:00
|
|
|
end
|
|
|
|
|
2016-08-25 01:02:27 -04:00
|
|
|
def issue
|
2016-11-17 07:22:27 -05:00
|
|
|
@fetcher.calculate_metric(:issue,
|
2016-09-20 15:17:37 -04:00
|
|
|
Issue.arel_table[:created_at],
|
|
|
|
[Issue::Metrics.arel_table[:first_associated_with_milestone_at],
|
|
|
|
Issue::Metrics.arel_table[:first_added_to_board_at]])
|
2016-08-25 01:02:27 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def plan
|
2016-11-17 07:22:27 -05:00
|
|
|
@fetcher.calculate_metric(:plan,
|
2016-09-20 15:17:37 -04:00
|
|
|
[Issue::Metrics.arel_table[:first_associated_with_milestone_at],
|
|
|
|
Issue::Metrics.arel_table[:first_added_to_board_at]],
|
|
|
|
Issue::Metrics.arel_table[:first_mentioned_in_commit_at])
|
2016-08-25 01:54:41 -04:00
|
|
|
end
|
2016-08-25 01:02:27 -04:00
|
|
|
|
2016-08-25 01:54:41 -04:00
|
|
|
def code
|
2016-11-17 07:22:27 -05:00
|
|
|
@fetcher.calculate_metric(:code,
|
2016-09-20 15:17:37 -04:00
|
|
|
Issue::Metrics.arel_table[:first_mentioned_in_commit_at],
|
|
|
|
MergeRequest.arel_table[:created_at])
|
2016-08-25 01:02:27 -04:00
|
|
|
end
|
|
|
|
|
2016-08-25 05:19:18 -04:00
|
|
|
def test
|
2016-11-17 07:22:27 -05:00
|
|
|
@fetcher.calculate_metric(:test,
|
2016-09-20 15:17:37 -04:00
|
|
|
MergeRequest::Metrics.arel_table[:latest_build_started_at],
|
|
|
|
MergeRequest::Metrics.arel_table[:latest_build_finished_at])
|
2016-08-25 05:19:18 -04:00
|
|
|
end
|
|
|
|
|
2016-08-25 02:25:07 -04:00
|
|
|
def review
|
2016-11-17 07:22:27 -05:00
|
|
|
@fetcher.calculate_metric(:review,
|
2016-09-20 15:17:37 -04:00
|
|
|
MergeRequest.arel_table[:created_at],
|
|
|
|
MergeRequest::Metrics.arel_table[:merged_at])
|
2016-08-25 02:25:07 -04:00
|
|
|
end
|
|
|
|
|
2016-08-25 04:39:48 -04:00
|
|
|
def staging
|
2016-11-17 07:22:27 -05:00
|
|
|
@fetcher.calculate_metric(:staging,
|
2016-09-20 15:17:37 -04:00
|
|
|
MergeRequest::Metrics.arel_table[:merged_at],
|
|
|
|
MergeRequest::Metrics.arel_table[:first_deployed_to_production_at])
|
2016-08-25 04:39:48 -04:00
|
|
|
end
|
|
|
|
|
2016-08-25 05:06:01 -04:00
|
|
|
def production
|
2016-11-17 07:22:27 -05:00
|
|
|
@fetcher.calculate_metric(:production,
|
2016-09-20 15:17:37 -04:00
|
|
|
Issue.arel_table[:created_at],
|
|
|
|
MergeRequest::Metrics.arel_table[:first_deployed_to_production_at])
|
2016-08-25 05:06:01 -04:00
|
|
|
end
|
2016-08-25 01:02:27 -04:00
|
|
|
end
|