Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

See Your Github Contributions chart #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions git-cal
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,23 @@ use Getopt::Long;
use Pod::Usage;
use Time::Local;
use Data::Dumper;
use LWP::UserAgent;
use HTTP::Request::Common;
use JSON;

binmode(STDOUT, ":utf8");
#command line options
my ( $help, $period, $use_ascii, $use_ansi, $use_unicode, $format, $author, $filepath );
my ( $help, $period, $use_ascii, $use_ansi, $use_unicode, $format, $author, $filepath, $github );

GetOptions(
'help|?' => \$help,
'period|p=n' => \$period,
'ascii' => \$use_ascii,
'ansi' => \$use_ansi,
'unicode' => \$use_unicode,
'author=s' => \$author
'author=s' => \$author,
'github=s' => \$github

) or pod2usage(2);

pod2usage(1) if $help;
Expand Down Expand Up @@ -58,11 +63,39 @@ sub process {
: 'ansi';
}
init_cal_stuff();
process_current_repo();
if ($github) {
process_contributions_calendar();
}
else {
process_current_repo();
}
my %stats = compute_stats();
print_grid(%stats);
}

sub process_contributions_calendar {

my $ua = LWP::UserAgent->new;
my $req = GET 'https://github.com/users/' . $github . '/contributions_calendar_data';
my $res = $ua->request($req);

if ($res->code == 404) {
print 'Username ' . $github . ' is may be invalid.\n';
exit(1);
}

my @decodedContent = @{decode_json($res->content)};
my $status;
foreach (@decodedContent) {
my ($year,$mon,$mday,$hour,$min,$sec) = split(/[\s\/:]+/, $_->[0] . ' 12:00:00');
my $time = timelocal($sec,$min,$hour,$mday,$mon-1,$year);
my $i;
for ($i=0; $i<$_->[1]; $i++) {
$status = add_epoch($time);
}
}
}

sub process_current_repo {
my $git_command = git_command();
my @epochs = qx/$git_command/;
Expand Down