debian-mirror-gitlab/lib/gitlab/cycle_analytics/stage_summary.rb

56 lines
1.4 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module Gitlab
module CycleAnalytics
class StageSummary
2021-09-04 01:27:46 +05:30
def initialize(project, options:, current_user:)
2017-08-17 22:00:37 +05:30
@project = project
2021-09-04 01:27:46 +05:30
@options = options
2017-08-17 22:00:37 +05:30
@current_user = current_user
end
def data
2019-12-04 20:38:33 +05:30
summary = [issue_stats]
summary << commit_stats if user_has_sufficient_access?
summary << deploy_stats
2020-04-22 19:07:51 +05:30
summary << deployment_frequency_stats
2017-08-17 22:00:37 +05:30
end
private
2019-12-04 20:38:33 +05:30
def issue_stats
2021-09-04 01:27:46 +05:30
serialize(Summary::Issue.new(project: @project, options: @options, current_user: @current_user))
2019-12-04 20:38:33 +05:30
end
def commit_stats
2021-09-04 01:27:46 +05:30
serialize(Summary::Commit.new(project: @project, options: @options))
2019-12-04 20:38:33 +05:30
end
2020-04-22 19:07:51 +05:30
def deployments_summary
2021-09-04 01:27:46 +05:30
@deployments_summary ||= Summary::Deploy.new(project: @project, options: @options)
2020-04-22 19:07:51 +05:30
end
2019-12-04 20:38:33 +05:30
def deploy_stats
2020-04-22 19:07:51 +05:30
serialize deployments_summary
end
def deployment_frequency_stats
serialize(
Summary::DeploymentFrequency.new(
2020-05-24 23:13:21 +05:30
deployments: deployments_summary.value.raw_value,
2021-09-04 01:27:46 +05:30
options: @options),
2020-04-22 19:07:51 +05:30
with_unit: true
)
2019-12-04 20:38:33 +05:30
end
def user_has_sufficient_access?
@project.team.member?(@current_user, Gitlab::Access::REPORTER)
end
2020-04-22 19:07:51 +05:30
def serialize(summary_object, with_unit: false)
2021-09-04 01:27:46 +05:30
AnalyticsSummarySerializer.new.represent(summary_object, with_unit: with_unit)
2017-08-17 22:00:37 +05:30
end
end
end
end