BigW Consortium Gitlab

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

4
  def initialize(project, current_user, from:)
5
    @project = project
6
    @current_user = current_user
7
    @from = from
8
    @fetcher = Gitlab::CycleAnalytics::MetricsFetcher.new(project: project, from: from, branch: nil)
9 10 11
  end

  def summary
12
    @summary ||= Summary.new(@project, @current_user, from: @from)
13 14
  end

15 16
  def permissions(user:)
    Gitlab::CycleAnalytics::Permissions.get(user: user, project: @project)
17 18
  end

19
  def issue
20
    @fetcher.calculate_metric(:issue,
21 22 23
                     Issue.arel_table[:created_at],
                     [Issue::Metrics.arel_table[:first_associated_with_milestone_at],
                      Issue::Metrics.arel_table[:first_added_to_board_at]])
24 25 26
  end

  def plan
27
    @fetcher.calculate_metric(:plan,
28 29 30
                     [Issue::Metrics.arel_table[:first_associated_with_milestone_at],
                      Issue::Metrics.arel_table[:first_added_to_board_at]],
                     Issue::Metrics.arel_table[:first_mentioned_in_commit_at])
31
  end
32

33
  def code
34
    @fetcher.calculate_metric(:code,
35 36
                     Issue::Metrics.arel_table[:first_mentioned_in_commit_at],
                     MergeRequest.arel_table[:created_at])
37 38
  end

39
  def test
40
    @fetcher.calculate_metric(:test,
41 42
                     MergeRequest::Metrics.arel_table[:latest_build_started_at],
                     MergeRequest::Metrics.arel_table[:latest_build_finished_at])
43 44
  end

45
  def review
46
    @fetcher.calculate_metric(:review,
47 48
                     MergeRequest.arel_table[:created_at],
                     MergeRequest::Metrics.arel_table[:merged_at])
49 50
  end

51
  def staging
52
    @fetcher.calculate_metric(:staging,
53 54
                     MergeRequest::Metrics.arel_table[:merged_at],
                     MergeRequest::Metrics.arel_table[:first_deployed_to_production_at])
55 56
  end

57
  def production
58
    @fetcher.calculate_metric(:production,
59 60
                     Issue.arel_table[:created_at],
                     MergeRequest::Metrics.arel_table[:first_deployed_to_production_at])
61
  end
62
end