-
-
Save splattael/6edff7de7919bf145786 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
def extract_log(dir) | |
`(cd #{dir} && git log --oneline --shortstat --pretty=format:%aE)` | |
end | |
def extract_stats(log_string) | |
log_string.split(/\n\n/).map do |log_entry| | |
StatEntry.new log_entry | |
end | |
end | |
def log(msg) | |
$stderr.puts msg | |
end | |
class StatEntry | |
def initialize(log_entry) | |
self.author, self.stats = log_entry.split(/\n/) | |
end | |
def changes | |
splitted_numbers[0] || 0 | |
end | |
def insertions | |
splitted_numbers[1] || 0 | |
end | |
def deletions | |
splitted_numbers[2] || 0 | |
end | |
def to_hash | |
{} | |
end | |
def inspect | |
"#<StatEntry #{author}: c#{changes} +#{insertions} -#{deletions}>" | |
end | |
public | |
attr_reader :author | |
protected | |
attr_writer :author | |
attr_accessor :stats | |
private | |
def splitted_numbers | |
@_stats ||= (stats || "").scan(/\d+/).map(&:to_i) | |
end | |
end | |
class AccumulatedEntry | |
def initialize(author) | |
self.author = author | |
self.commits = 0 | |
self.changes = 0 | |
self.insertions = 0 | |
self.deletions = 0 | |
end | |
def accumulate(stat_entry) | |
self.commits += 1 | |
self.changes += stat_entry.changes | |
self.insertions += stat_entry.insertions | |
self.deletions += stat_entry.deletions | |
end | |
attr_reader :author, :commits, :changes, :insertions, :deletions | |
protected | |
attr_writer :author, :commits, :changes, :insertions, :deletions | |
end | |
statistics = Hash.new do |stats, author| | |
stats[author] = AccumulatedEntry.new(author) | |
end | |
total_count = ARGV.size | |
log "Running over #{total_count} repos" | |
ARGV.each.with_index do |bare_repo, i| | |
log " * #{bare_repo} (#{i+1}/#{total_count})" | |
stat_entries = extract_stats(extract_log(bare_repo)) | |
stat_entries.each do |stat_entry| | |
statistics[stat_entry.author].accumulate stat_entry | |
end | |
end | |
puts 'author,commits,changes,insertions,deletions' | |
statistics.values.each do |accumulated_entry| | |
puts [ | |
accumulated_entry.author, | |
accumulated_entry.commits, | |
accumulated_entry.changes, | |
accumulated_entry.insertions, | |
accumulated_entry.deletions | |
].join(',') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment