2016-11-17 07:22:27 -05:00
|
|
|
module Gitlab
|
|
|
|
module CycleAnalytics
|
|
|
|
class PlanEvent < BaseEvent
|
2016-11-17 12:00:37 -05:00
|
|
|
def initialize(*args)
|
|
|
|
@stage = :plan
|
|
|
|
@start_time_attrs = issue_metrics_table[:first_associated_with_milestone_at]
|
|
|
|
@end_time_attrs = [issue_metrics_table[:first_added_to_board_at],
|
|
|
|
issue_metrics_table[:first_mentioned_in_commit_at]]
|
|
|
|
@projections = [mr_diff_table[:st_commits].as('commits'),
|
|
|
|
issue_metrics_table[:first_mentioned_in_commit_at]]
|
|
|
|
|
|
|
|
super(*args)
|
|
|
|
end
|
2016-11-17 07:22:27 -05:00
|
|
|
|
2016-11-17 12:00:37 -05:00
|
|
|
def custom_query(base_query)
|
|
|
|
base_query.join(mr_diff_table).on(mr_diff_table[:merge_request_id].eq(mr_table[:id]))
|
|
|
|
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
|
|
|
|
2016-11-17 12:00:37 -05:00
|
|
|
def serialize(event)
|
|
|
|
st_commit = first_time_reference_commit(event.delete('commits'), event)
|
2016-11-17 07:22:27 -05:00
|
|
|
|
2016-11-17 12:00:37 -05:00
|
|
|
return unless st_commit
|
2016-11-17 07:22:27 -05:00
|
|
|
|
2016-11-17 12:00:37 -05:00
|
|
|
serialize_commit(event, st_commit, query)
|
|
|
|
end
|
2016-11-17 07:22:27 -05:00
|
|
|
|
2016-11-17 12:00:37 -05:00
|
|
|
def first_time_reference_commit(commits, event)
|
|
|
|
YAML.load(commits).find do |commit|
|
|
|
|
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
|
|
|
|
2016-11-17 12:00:37 -05:00
|
|
|
def serialize_commit(event, st_commit, query)
|
|
|
|
commit = Commit.new(Gitlab::Git::Commit.new(st_commit), @project)
|
2016-11-17 07:22:27 -05:00
|
|
|
|
2016-11-17 12:00:37 -05:00
|
|
|
AnalyticsCommitSerializer.new(project: @project, total_time: event['total_time']).represent(commit).as_json
|
2016-11-17 07:22:27 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-11-17 08:14:23 -05:00
|
|
|
end
|