2016-10-13 11:11:28 -04:00
|
|
|
module Gitlab
|
|
|
|
module CycleAnalytics
|
|
|
|
class Events
|
2016-10-17 12:03:17 -04:00
|
|
|
include ActionView::Helpers::DateHelper
|
|
|
|
|
2016-10-13 11:11:28 -04:00
|
|
|
def initialize(project:, from:)
|
|
|
|
@project = project
|
|
|
|
@from = from
|
|
|
|
@fetcher = EventsFetcher.new(project: project, from: from)
|
|
|
|
end
|
|
|
|
|
2016-10-20 04:08:53 -04:00
|
|
|
# TODO: backend pagination - specially for commits, etc...
|
2016-10-19 06:47:09 -04:00
|
|
|
|
2016-10-13 11:11:28 -04:00
|
|
|
def issue_events
|
2016-10-20 04:08:53 -04:00
|
|
|
# TODO figure out what the frontend needs for displaying the avatar
|
2016-10-19 06:47:09 -04:00
|
|
|
@fetcher.fetch_issue_events.each do |event|
|
|
|
|
event['total_time'] = distance_of_time_in_words(event['total_time'].to_f)
|
2016-10-18 04:06:42 -04:00
|
|
|
event['created_at'] = interval_in_words(event['created_at'])
|
2016-10-17 12:03:17 -04:00
|
|
|
end
|
2016-10-13 11:11:28 -04:00
|
|
|
end
|
2016-10-18 04:06:42 -04:00
|
|
|
|
2016-10-19 06:47:09 -04:00
|
|
|
def plan_events
|
2016-10-19 09:40:14 -04:00
|
|
|
@fetcher.fetch_plan_events.each do |event|
|
|
|
|
event['total_time'] = distance_of_time_in_words(event['total_time'].to_f)
|
|
|
|
commits = event.delete('commits')
|
|
|
|
event['commit'] = first_time_reference_commit(commits, event)
|
|
|
|
end
|
2016-10-19 06:47:09 -04:00
|
|
|
end
|
|
|
|
|
2016-10-20 04:08:53 -04:00
|
|
|
def code_events
|
|
|
|
@fetcher.fetch_code_events.each do |event|
|
|
|
|
event['total_time'] = distance_of_time_in_words(event['total_time'].to_f)
|
|
|
|
event['created_at'] = interval_in_words(event['created_at'])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-19 06:47:09 -04:00
|
|
|
private
|
|
|
|
|
2016-10-19 09:40:14 -04:00
|
|
|
def first_time_reference_commit(commits, event)
|
|
|
|
st_commit = YAML.load(commits).detect do |commit|
|
|
|
|
commit['created_at'] == event['first_mentioned_in_commit_at']
|
|
|
|
end
|
|
|
|
|
|
|
|
Commit.new(Gitlab::Git::Commit.new(st_commit), @project)
|
|
|
|
end
|
|
|
|
|
2016-10-18 04:06:42 -04:00
|
|
|
def interval_in_words(diff)
|
2016-10-19 06:47:09 -04:00
|
|
|
"#{distance_of_time_in_words(diff.to_f)} ago"
|
2016-10-18 04:06:42 -04:00
|
|
|
end
|
2016-10-13 11:11:28 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|