summaryrefslogtreecommitdiff
path: root/lib/gitlab/cycle_analytics/group_stage_summary.rb
blob: 09b33d01846053afe7e6b4df7dc25b223d40414c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# frozen_string_literal: true

module Gitlab
  module CycleAnalytics
    class GroupStageSummary
      attr_reader :group, :current_user, :options

      def initialize(group, options:)
        @group = group
        @current_user = options[:current_user]
        @options = options
      end

      def data
        [issue_stats,
         deploy_stats,
         deployment_frequency_stats]
      end

      private

      def issue_stats
        serialize(
          Summary::Group::Issue.new(
            group: group, current_user: current_user, options: options)
        )
      end

      def deployments_summary
        @deployments_summary ||=
          Summary::Group::Deploy.new(group: group, options: options)
      end

      def deploy_stats
        serialize deployments_summary
      end

      def deployment_frequency_stats
        serialize(
          Summary::Group::DeploymentFrequency.new(
            deployments: deployments_summary.value,
            group: group,
            options: options),
          with_unit: true
        )
      end

      def serialize(summary_object, with_unit: false)
        AnalyticsSummarySerializer.new.represent(
          summary_object, with_unit: with_unit)
      end
    end
  end
end