Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 105 lines (70 sloc) 2.21 KB
#!/usr/bin/env perl
use strict;
use warnings;
use 5.10.1;
use Getopt::Long;
use Pod::Usage;
use DateTime;
use JSON;
my $opts = get_options();
my $author = "";
if ($opts->{author}) { $author = $opts->{author}; }
# 366 tuples of 2 entries each, date + score
# ["2014/05/11",10]
# 0 is today, 1 is yesterday...
my @days;
for my $dir (@ARGV) {
for my $line (qx(git --git-dir=$dir/.git log --format="%at" --since="365 days ago" --author="$author")) {
my $log_entry = DateTime->from_epoch(epoch => $line, time_zone=>'local');
my $ago = DateTime->today(time_zone=>'local')->delta_days($log_entry)->in_units('days');
$days[$ago]->[0] ||= $log_entry->set_time_zone('local')->ymd('-');
# fill in the empty days
for my $day (0..365) {
$days[$day] ||= [DateTime->today(time_zone=>'local')->subtract(days=>$day)->set_time_zone('local')->ymd('-'), 0];
@days = reverse @days;
print encode_json(\@days);
sub get_options {
my %opts;
) or pod2usage(1);
pod2usage(1) if $opts{help};
return \%opts;
=head1 fakehubstats
Takes a list of git repos and generates a JSON feed similar to GitHub's
contribution data
=head1 USAGE
./ /path/to/git/repo
./ [options] /path/to/git/repo
-h, --help print help information
-a, --author restricts commits to specified author
=head1 OPTIONS
=over 4
=item B<-h>, B<--help>
Prints the help for this program
=item B<-a>, B<--author>
Restricts commits to the specified author
fakehubstats takes a list of git repositories and generates a JSON feed that
imitates GitHub's contribution data.
fakehubstats is written in Perl and uses the JSON and DateTime modules.
# print the simulated JSON feed for your personal git repo
./ /path/to/git/repo
# print the simulated JSON feed for your personal git repos
./ /path/to/git/repo/directory/*
# print the simulated JSON feed for commits made by Jon in your personal git repos
./ --author="Jon" /path/to/git/repo/directory/*
=head1 AUTHOR
Stan Schwertly (
You can’t perform that action at this time.