debian-mirror-gitlab/app/models/cycle_analytics.rb

39 lines
910 B
Ruby
Raw Normal View History

2016-09-29 09:46:39 +05:30
class CycleAnalytics
2017-08-17 22:00:37 +05:30
STAGES = %i[issue plan code test review staging production].freeze
2016-09-29 09:46:39 +05:30
2017-08-17 22:00:37 +05:30
def initialize(project, options)
2016-09-29 09:46:39 +05:30
@project = project
2017-08-17 22:00:37 +05:30
@options = options
2016-09-29 09:46:39 +05:30
end
def summary
2017-08-17 22:00:37 +05:30
@summary ||= ::Gitlab::CycleAnalytics::StageSummary.new(@project,
from: @options[:from],
current_user: @options[:current_user]).data
2016-09-29 09:46:39 +05:30
end
2017-08-17 22:00:37 +05:30
def stats
@stats ||= stats_per_stage
2016-09-29 09:46:39 +05:30
end
2017-08-17 22:00:37 +05:30
def no_stats?
stats.all? { |hash| hash[:value].nil? }
2016-09-29 09:46:39 +05:30
end
2017-08-17 22:00:37 +05:30
def permissions(user:)
Gitlab::CycleAnalytics::Permissions.get(user: user, project: @project)
2016-09-29 09:46:39 +05:30
end
2017-08-17 22:00:37 +05:30
def [](stage_name)
Gitlab::CycleAnalytics::Stage[stage_name].new(project: @project, options: @options)
2016-09-29 09:46:39 +05:30
end
private
2017-08-17 22:00:37 +05:30
def stats_per_stage
STAGES.map do |stage_name|
self[stage_name].as_json
2016-11-03 12:29:30 +05:30
end
2016-09-29 09:46:39 +05:30
end
end