debian-mirror-gitlab/lib/gitlab/cycle_analytics/plan_event_fetcher.rb

62 lines
1.6 KiB
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
module Gitlab
module CycleAnalytics
class PlanEventFetcher < BaseEventFetcher
def initialize(*args)
2017-09-10 17:25:29 +05:30
@projections = [mr_diff_table[:id],
2017-08-17 22:00:37 +05:30
issue_metrics_table[:first_mentioned_in_commit_at]]
super(*args)
end
def events_query
2017-09-10 17:25:29 +05:30
base_query
.join(mr_diff_table)
.on(mr_diff_table[:merge_request_id].eq(mr_table[:id]))
2017-08-17 22:00:37 +05:30
super
end
private
2018-03-17 18:26:18 +05:30
def allowed_ids
nil
end
2017-09-10 17:25:29 +05:30
def merge_request_diff_commits
@merge_request_diff_commits ||=
MergeRequestDiffCommit
.where(merge_request_diff_id: event_result.map { |event| event['id'] })
.group_by(&:merge_request_diff_id)
end
2017-08-17 22:00:37 +05:30
def serialize(event)
2017-09-10 17:25:29 +05:30
commit = first_time_reference_commit(event)
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
return unless commit
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
serialize_commit(event, commit, query)
2017-08-17 22:00:37 +05:30
end
2017-09-10 17:25:29 +05:30
def first_time_reference_commit(event)
return nil unless event && merge_request_diff_commits
2018-03-17 18:26:18 +05:30
commits = merge_request_diff_commits[event['id'].to_i]
2017-09-10 17:25:29 +05:30
2017-08-17 22:00:37 +05:30
return nil if commits.blank?
2017-09-10 17:25:29 +05:30
commits.find do |commit|
2017-08-17 22:00:37 +05:30
next unless commit[:committed_date] && event['first_mentioned_in_commit_at']
commit[:committed_date].to_i == DateTime.parse(event['first_mentioned_in_commit_at'].to_s).to_i
end
end
2017-09-10 17:25:29 +05:30
def serialize_commit(event, commit, query)
commit = Commit.from_hash(commit.to_hash, @project)
2017-08-17 22:00:37 +05:30
AnalyticsCommitSerializer.new(project: @project, total_time: event['total_time']).represent(commit)
end
end
end
end