Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#!/usr/bin/env perl
use v5.10;
use strict;
use warnings;
use autodie;
use Carp;
use Net::GitHub;
use Getopt::Lucid ':all';
use Text::Wrap qw/fill/;
my $opts = Getopt::Lucid->getopt(
[
Param('repo|r'),
Switch('all'),
]
);
$opts->validate;
sub _detect_repo {
my ($origin) = grep { /origin/ } `git remote -v`;
die "Couldn't determine origin\n" unless $origin;
chomp $origin;
$origin =~ s/^origin\s+//;
$origin =~ s/\s+\(.*$//;
my $repo;
if ( $origin =~ m{^.+?://github.com/[^/]+/(.+)\.git$} ) {
$repo = $1;
}
elsif ( $origin =~ m{^git\@github\.com:[^/]+/(.+)\.git$} ) {
$repo = $1;
}
else {
die "Can't determine repo name from '$origin'. Try manually with -r REPO\n"
}
return $repo;
}
sub _git_config {
my $key = shift;
chomp( my $value = `git config --get $key` );
croak "Unknown $key" unless $value;
return $value;
}
sub list_pulls {
my ($gh, $user, $repo) = @_;
my $pull_request = $gh->pull_request;
my @pulls = $pull_request->pulls($user, $repo);
return unless @pulls;
say "$user/$repo:\n";
for my $p ( @pulls ) {
my $title = " $p->{created_at} $p->{title}\n";
my $text = '';
$text .= fill('','',$p->{body}) . "\n\n" if $p->{body};
$text .= "$p->{html_url}\n\n";
$text .= "git-fetch-branch $p->{head}{repo}{git_url} $p->{head}{ref}\n";
$text =~ s/^/ /msg;
say "$title\n$text\n";
}
}
my $github_user = _git_config("github.user");
my $github_token = _git_config("github.token");
my $gh = Net::GitHub->new( access_token => $github_token );
my @repos;
if ( $opts->get_repo ) {
@repos = $opts->get_repo;
}
elsif ( $opts->get_all ) {
@repos = map { $_->{name} } $gh->repos->list;
while ($gh->repos->has_next_page) {
push @repos, map { $_->{name} } $gh->repos->next_page;
}
}
else {
@repos = _detect_repo();
}
list_pulls($gh, $github_user, $_) for @repos;
@ecocode

hi dagolden,

Nice script. I patched it so that it will now list repo pull requests for repos to which the user is a contributor too.
https://gist.github.com/ecocode/5520392/57f1cc1ba1ee8401bee3a987163f82fef9735d95

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.