Skip to content

Instantly share code, notes, and snippets.

@ctrueden
Created November 27, 2012 20:06
Show Gist options
  • Save ctrueden/4156679 to your computer and use it in GitHub Desktop.
Save ctrueden/4156679 to your computer and use it in GitHub Desktop.
Recent comments for open PRs
#!/usr/bin/perl
use strict;
# github-pr-comments.pl: Proof of concept for listing recent
# comments for open PRs of a given repo.
# NB: Remember to authenticate first before running, or else you will
# quickly hit the API rate limit of 60 unauthenticated requests per hour.
my $owner = 'openmicroscopy';
my $repo = 'bioformats';
my $dateMin = '2012-11-20T00:00:00Z';
my $urlPrefix = "https://api.github.com/repos/$owner/$repo";
my @prs = `curl -s $urlPrefix/pulls | grep '\"number\"'`;
# loop over open PRs
for my $pr (@prs) {
chop $pr;
$pr =~ s/[^\d]//g;
# get list of comments for the PR
# TODO: Make the request only once and parse the JSON instead of cheating.
my $commentsURL = "$urlPrefix/pulls/$pr/comments";
my $commentsFile = 'comments.tmp';
`curl -s $commentsURL > $commentsFile`;
my @commentTimes = `grep '\"updated_at\"' $commentsFile`;
my @commentAuthors = `grep '\"login\"' $commentsFile`;
unlink($commentsFile);
for (my $i = 0; $i < @commentTimes; $i++) {
my $date = $commentTimes[$i];
chop $date;
$date =~ s/^.*(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z).*$/\1/;
if ($date gt $dateMin) {
my $author = $commentAuthors[$i];
$author =~ s/^.*"login"\: "(.*)",.*$/\1/;
chop $author;
print "$pr : $author : $date\n";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment