line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::gh::Command::Pullreq::Show; |
2
|
1
|
|
|
1
|
|
1443
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
3
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
4
|
1
|
|
|
1
|
|
6
|
use base qw(App::gh::Command); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8694
|
|
5
|
1
|
|
|
1
|
|
16
|
use App::gh::Utils; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
109
|
|
6
|
1
|
|
|
1
|
|
23
|
use File::stat; |
|
1
|
|
|
|
|
185
|
|
|
1
|
|
|
|
|
14
|
|
7
|
1
|
|
|
1
|
|
66
|
use File::Temp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
102
|
|
8
|
1
|
|
|
1
|
|
7
|
use Text::Wrap; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
58
|
|
9
|
1
|
|
|
1
|
|
6
|
use IO::Pager; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
1054
|
|
10
|
|
|
|
|
|
|
require App::gh::Git; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
App::gh::Command::PullReq::Show - show the pull request. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 DESCRIPTION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 USAGE |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=pod |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
$ gh pullreq show [number] |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
--diff also print diff |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub options { |
30
|
0
|
|
|
0
|
0
|
|
"diff" => "with_diff", |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub parse_uri { |
34
|
0
|
|
|
0
|
0
|
|
my ($uri) = @_; |
35
|
0
|
0
|
|
|
|
|
if ( $uri =~ m{(git|https?)://github.com/(.*?)/(.*?).git} ) { |
|
|
0
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
return ($2,$3,$1); |
37
|
|
|
|
|
|
|
} elsif ( $uri =~ m{git\@github.com:(.*?)/(.*?).git} ) { |
38
|
0
|
|
|
|
|
|
return ($1,$2,'git'); |
39
|
|
|
|
|
|
|
} |
40
|
0
|
|
|
|
|
|
return undef; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub get_remote { |
44
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
45
|
0
|
|
|
|
|
|
my $config = App::gh->config->current(); |
46
|
0
|
|
|
|
|
|
my %remotes = %{ $config->{remote} }; |
|
0
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# try to get origin remote |
48
|
0
|
|
0
|
|
|
|
return $remotes{origin} || (values( %remotes ))[0]; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub run { |
52
|
0
|
|
|
0
|
0
|
|
my ($self, $number) = @_; |
53
|
0
|
0
|
|
|
|
|
return App::gh::Command->invoke('help', 'pullreq', 'show') |
54
|
|
|
|
|
|
|
unless defined $number; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
my $remote = $self->get_remote(); |
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
die "Remote not found\n." unless $remote; |
59
|
0
|
|
|
|
|
|
my ( $user, $repo, $uri_type ) = parse_uri( $remote->{url} ); |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $gh_id = App::gh->config->github_id; |
62
|
0
|
|
|
|
|
|
my $gh_token = App::gh->config->github_token; |
63
|
0
|
0
|
0
|
|
|
|
unless( $gh_id && $gh_token ) { |
64
|
0
|
|
|
|
|
|
die "Github authtoken not found. Can not get pull request.\n"; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
local $STDOUT = IO::Pager->new( *STDOUT ); |
69
|
0
|
|
|
|
|
|
my $data = App::gh->api->pullreq_get($user, $repo, $number); |
70
|
0
|
|
|
|
|
|
my $pull = $data->{pull}; |
71
|
0
|
|
|
|
|
|
printf "Title: [%s] %s\n", ucfirst($pull->{state}) , $pull->{title}; |
72
|
0
|
|
|
|
|
|
printf "Date: %s\n", $pull->{created_at}; |
73
|
0
|
|
|
|
|
|
printf "Author: %s (%s)\n", $pull->{user}->{name}, $pull->{user}->{login}; |
74
|
0
|
|
|
|
|
|
printf "Request: %s => %s\n", $pull->{base}->{label}, $pull->{head}->{label}; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
print wrap "\t","\t",$pull->{body}; |
77
|
0
|
|
|
|
|
|
print "\n\n"; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my @discussions = @{ $pull->{discussion} }; |
|
0
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
my @commits = grep { $_->{type} eq 'Commit' } @discussions; |
|
0
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
print scalar(@commits) , " Commits:\n\n"; |
83
|
0
|
|
|
|
|
|
for my $c ( @commits ) { |
84
|
0
|
|
|
|
|
|
printf "* Commit: %s\n",$c->{tree}; |
85
|
0
|
|
|
|
|
|
printf " Author: %s (%s) <%s>\n", $c->{author}->{name} , $c->{author}->{login} , $c->{author}->{email}; |
86
|
0
|
|
|
|
|
|
printf " Date: %s\n" , $c->{committed_date}; |
87
|
0
|
|
|
|
|
|
printf "\n%s\n\n",wrap "\t","\t", $c->{message}; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
for my $d ( @discussions ) { |
91
|
0
|
0
|
|
|
|
|
if ($d->{type} eq 'IssueComment') { |
92
|
0
|
|
|
|
|
|
printf "%s:\n%s\n", $d->{user}->{name}, $d->{body}; |
93
|
|
|
|
|
|
|
} |
94
|
0
|
0
|
|
|
|
|
if ($d->{type} eq 'PullRequestReviewComment') { |
95
|
0
|
|
|
|
|
|
printf "%s:\n%s\n", $d->{author}->{name}, $d->{body}; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# XXX: need to patch App::CLI for subcommand help message |
101
|
|
|
|
|
|
|
# eg, |
102
|
|
|
|
|
|
|
# |
103
|
|
|
|
|
|
|
# gh help pullreq show # this doesn't work |
104
|
|
|
|
|
|
|
# |
105
|
0
|
|
|
|
|
|
if( 1 || $self->{with_diff} ) { |
106
|
0
|
|
|
|
|
|
print "=" x 78 . "\n"; |
107
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
108
|
0
|
|
|
|
|
|
$ua->timeout(10); |
109
|
0
|
|
|
|
|
|
$ua->env_proxy; |
110
|
0
|
|
|
|
|
|
my $res = $ua->get($pull->{patch_url}); |
111
|
0
|
0
|
|
|
|
|
if ($res->is_success) { |
112
|
0
|
|
|
|
|
|
print $res->decoded_content; |
113
|
|
|
|
|
|
|
} else { |
114
|
0
|
|
|
|
|
|
warn $res->message; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |