2018-11-06 04:45:35 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-22 10:46:02 +00:00
|
|
|
module Gitlab
|
|
|
|
module CycleAnalytics
|
2016-11-23 10:28:28 +00:00
|
|
|
class StageSummary
|
2021-06-14 12:10:13 +00:00
|
|
|
def initialize(project, options:, current_user:)
|
2016-11-22 10:46:02 +00:00
|
|
|
@project = project
|
2021-06-14 12:10:13 +00:00
|
|
|
@options = options
|
2016-12-01 12:28:24 +00:00
|
|
|
@current_user = current_user
|
2016-11-22 10:46:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def data
|
2019-11-06 16:07:11 +00:00
|
|
|
summary = [issue_stats]
|
|
|
|
summary << commit_stats if user_has_sufficient_access?
|
|
|
|
summary << deploy_stats
|
2020-04-21 15:21:10 +00:00
|
|
|
summary << deployment_frequency_stats
|
2016-11-22 10:46:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-11-06 16:07:11 +00:00
|
|
|
def issue_stats
|
2021-06-14 12:10:13 +00:00
|
|
|
serialize(Summary::Issue.new(project: @project, options: @options, current_user: @current_user))
|
2019-11-06 16:07:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def commit_stats
|
2021-06-14 12:10:13 +00:00
|
|
|
serialize(Summary::Commit.new(project: @project, options: @options))
|
2019-11-06 16:07:11 +00:00
|
|
|
end
|
|
|
|
|
2020-04-21 15:21:10 +00:00
|
|
|
def deployments_summary
|
2021-06-14 12:10:13 +00:00
|
|
|
@deployments_summary ||= Summary::Deploy.new(project: @project, options: @options)
|
2020-04-21 15:21:10 +00:00
|
|
|
end
|
|
|
|
|
2019-11-06 16:07:11 +00:00
|
|
|
def deploy_stats
|
2020-04-21 15:21:10 +00:00
|
|
|
serialize deployments_summary
|
|
|
|
end
|
|
|
|
|
|
|
|
def deployment_frequency_stats
|
|
|
|
serialize(
|
|
|
|
Summary::DeploymentFrequency.new(
|
2020-05-12 15:10:33 +00:00
|
|
|
deployments: deployments_summary.value.raw_value,
|
2021-06-14 12:10:13 +00:00
|
|
|
options: @options),
|
2020-04-21 15:21:10 +00:00
|
|
|
with_unit: true
|
|
|
|
)
|
2019-11-06 16:07:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def user_has_sufficient_access?
|
|
|
|
@project.team.member?(@current_user, Gitlab::Access::REPORTER)
|
|
|
|
end
|
|
|
|
|
2020-04-21 15:21:10 +00:00
|
|
|
def serialize(summary_object, with_unit: false)
|
2021-06-14 12:10:13 +00:00
|
|
|
AnalyticsSummarySerializer.new.represent(summary_object, with_unit: with_unit)
|
2016-11-22 10:46:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|