-
-
Save michaeldv/215550 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GitProductive | |
attr_accessor :directory, :lines, :commits | |
def initialize(directory = Dir.pwd) | |
raise "#{directory} is not a git repository" unless Dir.entries(directory).include?(".git") | |
@directory = directory | |
@lines, @commits = 0, 0 | |
end | |
def check!(duration = "1 days") | |
Dir.chdir(@directory) | |
output = `git log --shortstat --since="#{duration} ago" | grep insertions`.split("\n") | |
@commits = output.size | |
output.each do |commit| | |
@lines += commit.match(/(\d+) insertions/)[0].to_i | |
end | |
end | |
def stats(duration = "1 days") | |
check!(duration) | |
'%.2f' % (@commits == 0 ? 0 : @lines / @commits.to_f) | |
end | |
end | |
# Example | |
# git_productive = GitProductive.new(ARGV[0] || Dir.pwd) | |
# puts "#{git_productive.stats} lines per commit today" | |
# puts "#{git_productive.stats('3 weeks')} lines per commit in the last 3 weeks" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment