2016-11-17 07:22:27 -05:00
|
|
|
module Gitlab
|
|
|
|
module CycleAnalytics
|
2016-12-02 11:09:29 -05:00
|
|
|
class PlanEventFetcher < BaseEventFetcher
|
2016-11-17 12:00:37 -05:00
|
|
|
def initialize(*args)
|
2017-06-16 10:00:58 -04:00
|
|
|
@projections = [mr_diff_table[:id],
|
|
|
|
mr_diff_table[:st_commits],
|
2016-11-17 12:00:37 -05:00
|
|
|
issue_metrics_table[:first_mentioned_in_commit_at]]
|
|
|
|
|
|
|
|
super(*args)
|
|
|
|
end
|
2016-11-17 07:22:27 -05:00
|
|
|
|
2016-12-09 06:41:15 -05:00
|
|
|
def events_query
|
2017-06-16 10:00:58 -04:00
|
|
|
base_query
|
|
|
|
.join(mr_diff_table)
|
|
|
|
.on(mr_diff_table[:merge_request_id].eq(mr_table[:id]))
|
2016-12-09 06:41:15 -05:00
|
|
|
|
|
|
|
super
|
2016-11-17 12:00:37 -05:00
|
|
|
end
|
2016-11-17 07:22:27 -05:00
|
|
|
|
2016-11-17 12:00:37 -05:00
|
|
|
private
|
2016-11-17 07:22:27 -05:00
|
|
|
|
2017-06-16 10:00:58 -04:00
|
|
|
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
|
|
|
|
|
2016-11-17 12:00:37 -05:00
|
|
|
def serialize(event)
|
2017-06-16 10:00:58 -04:00
|
|
|
commit = first_time_reference_commit(event)
|
2016-11-17 07:22:27 -05:00
|
|
|
|
2017-06-16 10:00:58 -04:00
|
|
|
return unless commit
|
2016-11-17 07:22:27 -05:00
|
|
|
|
2017-06-16 10:00:58 -04:00
|
|
|
serialize_commit(event, commit, query)
|
2016-11-17 12:00:37 -05:00
|
|
|
end
|
2016-11-17 07:22:27 -05:00
|
|
|
|
2017-06-16 10:00:58 -04:00
|
|
|
def first_time_reference_commit(event)
|
|
|
|
return nil unless event && merge_request_diff_commits
|
|
|
|
|
|
|
|
commits =
|
|
|
|
if event['st_commits'].present?
|
|
|
|
YAML.load(event['st_commits'])
|
|
|
|
else
|
|
|
|
merge_request_diff_commits[event['id'].to_i]
|
|
|
|
end
|
|
|
|
|
2016-11-23 03:10:04 -05:00
|
|
|
return nil if commits.blank?
|
|
|
|
|
2017-06-16 10:00:58 -04:00
|
|
|
commits.find do |commit|
|
2016-11-17 12:00:37 -05:00
|
|
|
next unless commit[:committed_date] && event['first_mentioned_in_commit_at']
|
2016-11-17 07:22:27 -05:00
|
|
|
|
2016-11-17 12:00:37 -05:00
|
|
|
commit[:committed_date].to_i == DateTime.parse(event['first_mentioned_in_commit_at'].to_s).to_i
|
2016-11-17 07:22:27 -05:00
|
|
|
end
|
2016-11-17 12:00:37 -05:00
|
|
|
end
|
2016-11-17 07:22:27 -05:00
|
|
|
|
2017-06-16 10:00:58 -04:00
|
|
|
def serialize_commit(event, commit, query)
|
2017-07-25 16:48:17 -04:00
|
|
|
commit = Commit.from_hash(commit.to_hash, @project)
|
2016-11-17 07:22:27 -05:00
|
|
|
|
2017-01-27 08:37:14 -05:00
|
|
|
AnalyticsCommitSerializer.new(project: @project, total_time: event['total_time']).represent(commit)
|
2016-11-17 07:22:27 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-11-17 08:14:23 -05:00
|
|
|
end
|