Skip to content

Instantly share code, notes, and snippets.

@hendricius
Created April 8, 2014 20:42
Show Gist options
  • Save hendricius/10188728 to your computer and use it in GitHub Desktop.
Save hendricius/10188728 to your computer and use it in GitHub Desktop.
require 'git'
require 'pry'
require 'date'
# Pretty print git commits for easy parsing to zeitkit
# [2014-01-12]
#
# First commit: 2014-01-12 15:55
# * make functions clearer
# * rename to parnter revenue
# * make partner revenues mor understandable
# * add some charts to the partner page
# * also allow admin to change bank account
# Last commit: 2014-01-12 17:39
class Zlog
attr_accessor :git_dir, :author, :start_date, :end_date
def initialize(git_dir: Dir.pwd, author: "Hendrik Kleinwaechter", start_date: "2014-01-01", end_date: "2014-01-31")
self.git_dir = git_dir
self.author = author
self.start_date = start_date
self.end_date = end_date
end
def git
@git ||= Git.open(git_dir)
end
def build_commits
commits = {}
git.log(10000).since(start_date).until(end_date).each do |commit|
if commit.author.name != author
next
end
date = commit.date.strftime("%F")
if commits[date].nil?
commits[date] = []
end
commits[date].push commit
end
commits
end
def print
build_commits.each do |date, commit_arr|
commit_arr = commit_arr.reverse
puts "[#{date}]\n\n"
commit_arr.each_with_index do |commit, index|
is_last = (commit_arr.length - 1) == index
is_first = index == 0
if is_first
puts "First commit: #{commit.date.strftime("%Y-%m-%d %H:%M")}"
end
puts "* " + commit.message
if is_last
puts "Last commit: #{commit.date.strftime("%Y-%m-%d %H:%M")}"
puts "\n\n"
end
end
end
end
end
z = Zlog.new(git_dir: "/Users/hendricius/code/easymarketing/robot")
z.print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment