Skip to content

Instantly share code, notes, and snippets.

@aantix
Created April 10, 2018 16:28
Show Gist options
  • Save aantix/9602580f770528d930e90b58d7b3b095 to your computer and use it in GitHub Desktop.
Save aantix/9602580f770528d930e90b58d7b3b095 to your computer and use it in GitHub Desktop.
require 'rugged'
require 'time'
require 'active_support/all'
DATE_FORMAT = "%-m/%-d/%Y"
puts "repo = #{ARGV[0]}"
puts "branch = #{ARGV[1]}"
puts "email = #{ARGV[2]}"
puts '=========================='
2.times { puts }
email = ARGV[2].strip
repo = Rugged::Repository.new(ARGV[0])
walker = Rugged::Walker.new(repo)
walker.sorting(Rugged::SORT_DATE)
walker.push("refs/heads/#{ARGV[1]}")
commit_counts = Hash.new(0)
walker.each do |commit|
next unless commit.author[:email] == email
d = commit.author[:time].to_date.strftime(DATE_FORMAT)
commit_counts[d]+=1
end
prev_date = nil
prev_date_obj = nil
commits = []
walker.reset
walker.push("refs/heads/#{ARGV[1]}")
walker.each do |commit|
next unless commit.author[:email] == email
d = commit.author[:time].to_date.strftime(DATE_FORMAT)
prev_date||=d
prev_date_obj||=commit.author[:time].to_date
if prev_date != commit.author[:time].to_date.strftime(DATE_FORMAT)
commits << ""
# Fill in the missing dates
s = prev_date_obj - 1.day
e = commit.author[:time].to_date
# puts "s = #{s.inspect} -- #{e.inspect}"
# puts "prev_date = #{prev_date}"
# puts "author[:time] = #{commit.author[:time].strftime("%m/%d/%Y")}"
while s > e
unless [6, 0].include?(s.wday) # Skip Sat/Sunday
commits << "Task\t--#{s.strftime("%A")}--\t#{s.strftime(DATE_FORMAT)}\t\t8:00:00"
commits << ""
end
s = s - 1.day
end
end
prev_date = d
prev_date_obj = commit.author[:time].to_date
t = 8 / commit_counts[d].to_i
commits << "Task\t#{commit.message.strip}\t#{d}\t\t#{t}:00:00"
end
walker.reset
commits.reverse.each do |commit|
puts commit
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment