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
|
2019-12-21 20:55:43 +05:30
|
|
|
def initialize(project, from:, to: nil, current_user:)
|
2017-08-17 22:00:37 +05:30
|
|
|
@project = project
|
|
|
|
@from = from
|
2019-12-21 20:55:43 +05:30
|
|
|
@to = to
|
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
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
def issue_stats
|
2019-12-21 20:55:43 +05:30
|
|
|
serialize(Summary::Issue.new(project: @project, from: @from, to: @to, current_user: @current_user))
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def commit_stats
|
2019-12-21 20:55:43 +05:30
|
|
|
serialize(Summary::Commit.new(project: @project, from: @from, to: @to))
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def deploy_stats
|
2019-12-21 20:55:43 +05:30
|
|
|
serialize(Summary::Deploy.new(project: @project, from: @from, to: @to))
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def user_has_sufficient_access?
|
|
|
|
@project.team.member?(@current_user, Gitlab::Access::REPORTER)
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def serialize(summary_object)
|
|
|
|
AnalyticsSummarySerializer.new.represent(summary_object)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|