Skip to content

Instantly share code, notes, and snippets.

@hlee
Created April 19, 2013 23:18
Show Gist options
  • Save hlee/5423905 to your computer and use it in GitHub Desktop.
Save hlee/5423905 to your computer and use it in GitHub Desktop.
git report
#! /usr/bin/perl -w
use strict;
my $since;
if ($ARGV[0]) {
$since = $ARGV[0];
} else {
$since = "1 week ago";
}
my $until;
if ($ARGV[1]) {
$until = "--until=\"$ARGV[1]\"";
} else {
$until = "";
}
print "Lines added and deleted per developer --since=\"$since\" $until" . "\n";
my @devs = ("Ken");
my @dev_log;
my $d;
my @results = ();
foreach $d (@devs) {
@dev_log = `git log --since=\"$since\" $until --author=$d --no-merges --numstat`;
my $l;
my $addition_accumulator = 0;
my $deletion_accumulator = 0;
my $js_addition_accumulator = 0;
my $js_deletion_accumulator = 0;
my $css_addition_accumulator = 0;
my $css_deletion_accumulator = 0;
foreach $l (@dev_log) {
if ($l =~ /(\d+)\s+(\d+)\s+(app|spec|lib|config).+/) {
my $additions = $1;
my $deletions = $2;
if ($l =~ /\.js/) {
# The intent here is that we treat 3rd party libraries as their own metric
# They show that activity is happening but it somehow different.
$js_addition_accumulator += $additions;
$js_deletion_accumulator += $deletions;
} else {
$addition_accumulator += $additions;
$deletion_accumulator += $deletions;
}
}
}
my $dev_results = {
'Name' => $d,
'Additions' => $addition_accumulator,
'Deletions' => $deletion_accumulator,
'JS Additions' => $js_addition_accumulator,
'JS Deletions' => $js_deletion_accumulator,
'Refactor Ratio' => sprintf("%.2f", ($deletion_accumulator + $js_deletion_accumulator) / ($addition_accumulator + $js_addition_accumulator + 0.001))
};
push @results, $dev_results
}
my @sorted = sort { $b->{'Additions'} <=> $a->{'Additions'} } @results;
my $pad_len = 19;
my $padded = sprintf("%-${pad_len}s", " Developer") . sprintf("%-${pad_len}s", "| Additions") . sprintf("%-${pad_len}s", "| Deletions") . sprintf("%-${pad_len}s", "| JS Lib Additions") . sprintf("%-${pad_len}s", "| JS Lib Deletions") . sprintf("%-${pad_len}s", "| Refactor Ratio") . "\n";
my $border = "-----------------------------------------------------------------------------------------------------------------\n";
print $padded;
print $border;
for my $r ( @sorted ) {
for my $column ( ('Name', 'Additions', 'Deletions', 'JS Additions', 'JS Deletions', 'Refactor Ratio') ) {
my $data = sprintf("%-${pad_len}s", " " . $r->{$column});
print $data;
# my $row = sprintf("%-${pad_len}s", " " . $r->{'Name'}) . sprintf("%-${pad_len}s", "| " . $r->{'Additions'}) . sprintf("%-${pad_len}s", "| " . $r->{'Deletions'}) . sprintf("%-${pad_len}s", "| " . $r->{'JS Additions'}) . sprintf("%-${pad_len}s", "| " . $r->{'JS Deletions'}) . "\n";
}
print "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment