Class: Gpr::Commands::Contrib
Constant Summary
Constants included from Gpr
Instance Method Summary collapse
-
#initialize(thor) ⇒ Contrib
constructor
A new instance of Contrib.
Methods inherited from Base
Constructor Details
#initialize(thor) ⇒ Contrib
Returns a new instance of Contrib.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/gpr/commands/contrib.rb', line 9 def initialize(thor) thor.class_eval do include UtilsDrawer include ::Gpr::Actions::Contrib desc 'contrib', 'Show your contributions of registered repositories' def contrib(path = nil) user = detect_git_user || ENV['USER'] if path.nil? repositories = repository_list dates = repositories.each_with_object([]) { |repository, ary| ary << GitHelper.log_by_date(repository, user) }.flatten! else dates = GitHelper.log_by_date(path, user) end first_date = Time.parse(dates.sort.first) diff = ((Time.now - first_date).to_i / 86400) + 1 # Initialize a hash commit_counts = diff.times.each_with_object({}) do |index, hash| date = Time.at(first_date + (86400 * index)).strftime('%Y-%m-%d') hash[date] = 0 end # Count commits dates.each do |date| commit_counts[date] += 1 if commit_counts[date] end graph do commit_counts.sort.each do |date, value| data(date, value) end end end end end |