BigW Consortium Gitlab

cycle_analytics.rb 910 Bytes
Newer Older
1
class CycleAnalytics
2 3
  STAGES = %i[issue plan code test review staging production].freeze

4
  def initialize(project, options)
5
    @project = project
6
    @options = options
7 8 9
  end

  def summary
James Lopez committed
10 11 12
    @summary ||= ::Gitlab::CycleAnalytics::StageSummary.new(@project,
                                                            from: @options[:from],
                                                            current_user: @options[:current_user]).data
13 14
  end

15 16 17 18 19
  def stats
    @stats ||= stats_per_stage
  end

  def no_stats?
James Lopez committed
20
    stats.all? { |hash| hash[:value].nil? }
James Lopez committed
21 22
  end

23 24
  def permissions(user:)
    Gitlab::CycleAnalytics::Permissions.get(user: user, project: @project)
25 26
  end

27 28
  def [](stage_name)
    Gitlab::CycleAnalytics::Stage[stage_name].new(project: @project, options: @options)
James Lopez committed
29 30
  end

31 32 33 34
  private

  def stats_per_stage
    STAGES.map do |stage_name|
35
      self[stage_name].as_json
36
    end
37 38
  end
end