41

I realize I can hit https://api.github.com/users/:user_id/repos to get a list of all the repos I own or have forked. But what I would like to do is figure out all of the projects I have contributed to (commits, pull requests, issues, etc.) over the last year. The events API lets me get the last 300 events, but I have contributed a lot more than that in the last twelve months. Is this possible?

theory
  • 9,178
  • 10
  • 59
  • 129

1 Answers1

6

Thanks to a tweet from @caged, I wrote this Perl script to iterate over months in my contributions:

use v5.12;
use warnings;
use utf8;
my $uname = 'theory';

my %projects;
for my $year (2012..2014) {
    for my $month (1..12) {
        last if $year == 2014 && $month > 1;
        my $from = sprintf '%4d-%02d-01', $year, $month;
        my $to   = sprintf '%4d-%02d-01', $month == 12 ? ($year + 1, 1) : ($year, $month + 1);
        my $res = `curl 'https://github.com/$uname?tab=contributions&from=$from&to=$to' | grep 'class="title"'`;
        while ($res =~ /href="([^"?]+)/g) {
            my (undef, $user, $repo) = split m{/} => $1;
            $projects{"$user/$repo"}++;
        }
    }
}

say "$projects{$_}: $_" for sort keys %projects;

Yeah, HTML scraping is kind of ugly, but did the trick for my needs.

Community
  • 1
  • 1
theory
  • 9,178
  • 10
  • 59
  • 129
  • This works for public contributions only. Any way to get private contributions using curl? I've tried basic auth, but don't seem to be having any luck... – marcc Mar 04 '14 at 17:41
  • 4
    I needed this again, but sadly it doesn't work anymore, since various bits get loaded via JS now. :-( – theory Jun 28 '18 at 20:09