public
Last active

  • Download Gist
github-list-pulls
Perl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
#!/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;

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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.