2015-01-28 16:18:22 -05:00
|
|
|
module Gitlab
|
|
|
|
class CommitsCalendar
|
2015-01-29 03:53:43 -05:00
|
|
|
attr_reader :timestamps
|
2015-01-28 16:18:22 -05:00
|
|
|
|
2015-01-29 20:07:44 -05:00
|
|
|
def initialize(projects, user)
|
2015-01-29 03:53:43 -05:00
|
|
|
@timestamps = {}
|
|
|
|
date_timestamps = []
|
2015-01-28 16:18:22 -05:00
|
|
|
|
2015-01-29 20:07:44 -05:00
|
|
|
projects.reject(&:forked?).each do |project|
|
|
|
|
date_timestamps << ProjectContributions.new(project, user).commits_log
|
2015-01-28 16:18:22 -05:00
|
|
|
end
|
|
|
|
|
2015-01-29 20:07:44 -05:00
|
|
|
# Sumarrize commits from all projects per days
|
2015-01-29 03:53:43 -05:00
|
|
|
date_timestamps = date_timestamps.inject do |collection, date|
|
|
|
|
collection.merge(date) { |k, old_v, new_v| old_v + new_v }
|
2015-01-28 16:18:22 -05:00
|
|
|
end
|
|
|
|
|
2015-01-29 03:53:43 -05:00
|
|
|
date_timestamps ||= []
|
|
|
|
date_timestamps.each do |date, commits|
|
2015-01-29 04:03:20 -05:00
|
|
|
timestamp = Date.parse(date).to_time.to_i.to_s rescue nil
|
|
|
|
@timestamps[timestamp] = commits if timestamp
|
2015-01-28 16:18:22 -05:00
|
|
|
end
|
|
|
|
end
|
2015-01-29 20:07:44 -05:00
|
|
|
|
2015-03-13 06:39:26 -04:00
|
|
|
def self.get_commits_for_date(projects, user, date)
|
|
|
|
user_commits = {}
|
|
|
|
projects.reject(&:forked?).each do |project|
|
|
|
|
user_commits[project] = ProjectContributions.new(project, user).user_commits_on_date(date)
|
|
|
|
end
|
|
|
|
user_commits
|
|
|
|
end
|
|
|
|
|
2015-01-29 20:07:44 -05:00
|
|
|
def starting_year
|
|
|
|
(Time.now - 1.year).strftime("%Y")
|
|
|
|
end
|
|
|
|
|
|
|
|
def starting_month
|
|
|
|
Date.today.strftime("%m").to_i
|
|
|
|
end
|
2015-01-28 16:18:22 -05:00
|
|
|
end
|
|
|
|
end
|