BigW Consortium Gitlab

plan_event_fetcher.rb 1.23 KB
Newer Older
1 2
module Gitlab
  module CycleAnalytics
3
    class PlanEventFetcher < BaseEventFetcher
4 5 6 7 8 9
      def initialize(*args)
        @projections = [mr_diff_table[:st_commits].as('commits'),
                        issue_metrics_table[:first_mentioned_in_commit_at]]

        super(*args)
      end
10

11
      def events_query
12
        base_query.join(mr_diff_table).on(mr_diff_table[:merge_request_id].eq(mr_table[:id]))
13 14

        super
15
      end
16

17
      private
18

19 20
      def serialize(event)
        st_commit = first_time_reference_commit(event.delete('commits'), event)
21

22
        return unless st_commit
23

24 25
        serialize_commit(event, st_commit, query)
      end
26

27
      def first_time_reference_commit(commits, event)
28 29
        return nil if commits.blank?

30 31
        YAML.load(commits).find do |commit|
          next unless commit[:committed_date] && event['first_mentioned_in_commit_at']
32

33
          commit[:committed_date].to_i == DateTime.parse(event['first_mentioned_in_commit_at'].to_s).to_i
34
        end
35
      end
36

37 38
      def serialize_commit(event, st_commit, query)
        commit = Commit.new(Gitlab::Git::Commit.new(st_commit), @project)
39

40
        AnalyticsCommitSerializer.new(project: @project, total_time: event['total_time']).represent(commit)
41 42 43
      end
    end
  end
James Lopez committed
44
end