summaryrefslogtreecommitdiff
path: root/lib/gitlab/cycle_analytics/summary/deploy.rb
blob: aaa2554dbfa3d18fb09c0e5c4752326fcbdc58e5 (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
# frozen_string_literal: true

module Gitlab
  module CycleAnalytics
    module Summary
      class Deploy < Base
        def title
          n_('Deploy', 'Deploys', value.to_i)
        end

        def value
          @value ||= Value::PrettyNumeric.new(deployments_count)
        end

        private

        def deployments_count
          if Feature.enabled?(:query_deploymenys_via_finished_at_in_vsa, default_enabled: :yaml)
            DeploymentsFinder
              .new(project: @project, finished_after: @from, finished_before: @to, status: :success)
              .execute
              .count
          else
            query = @project.deployments.success.where("created_at >= ?", @from)
            query = query.where("created_at <= ?", @to) if @to
            query.count
          end
        end
      end
    end
  end
end