lib/App/gh/Command/Pullreq/Show.pm

filter: Statementstmt 32.9% 26 / 79 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 66.6% 8 / 12 Podpod 0.0% 0 / 4 totaltotal 28.1% 34 / 121 CC 13 SCAR 38.8
CC
13
Cov
26%
run
110.0
parse_uri
12.0
get_remote
6.0
CRAP 48.2
« lib/App/gh/Git.pm ↑ Summary lib/App/gh/Command/Import.pm »
1 package App::gh::Command::Pullreq::Show;
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use base qw(App::gh::Command);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use App::gh::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use File::stat;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use File::Temp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Text::Wrap;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use IO::Pager;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 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 0 ▶sub options {
Subroutine options: not called CC=1 SCAR=6.9
Pod undocumented
30 0 "diff" => "with_diff",
31 }
32  
33 0 ▶sub parse_uri {
Subroutine parse_uri: not called CC=3 SCAR=24.8
Pod undocumented
34 0 my ($uri) = @_;
35 0 ▶ if ( $uri =~ m{(git|https?)://github.com/(.*?)/(.*?).git} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($uri =~ m[(git|https?)://github.com/(.*?)/(.*?).git]) { } 0 0 0
elsif ($uri =~ m[git\@github.com:(.*?)/(.*?).git]) { } 0 0 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 0 ▶sub get_remote {
Subroutine get_remote: not called CC=2 SCAR=17.9
Pod undocumented
44 0 my $self = shift;
45 0 my $config = App::gh->config->current();
46 0 my %remotes = %{ $config->{remote} };
47 # try to get origin remote
48 0 ▶ return $remotes{origin} || (values( %remotes ))[0];
Condition0%0/3
$remotes{'origin'} || (values %remotes)[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
$remotes{'origin'} || (values %remotes)[0]
$remotes{'origin'} (values %remotes)[0]
Truth table0%0/3
A || B
A= $remotes{'origin'}B= (values %remotes)[0]
ABresult
1X1
011
000
49 }
50  
51 0 ▶sub run {
Subroutine run: not called CC=10 SCAR=47.0
Pod undocumented
52 0 my ($self, $number) = @_;
53 0 ▶ return App::gh::Command->invoke('help', 'pullreq', 'show')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $number 0 0 0
54 unless defined $number;
55  
56 0 my $remote = $self->get_remote();
57  
58 0 ▶ die "Remote not found\n." unless $remote;
Branch: 1 branch
BranchTrueFalseTotal
unless $remote 0 0 0
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 ▶ unless( $gh_id && $gh_token ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($gh_id and $gh_token) 0 0 0
Condition0%0/3
$gh_id and $gh_token
!ll&&!rl&&r
000
MC/DC0%0/2
$gh_id and $gh_token
$gh_id $gh_token
Truth table0%0/3
A and B
A= $gh_idB= $gh_token
ABresult
0X0
100
111
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} };
80 0 my @commits = grep { $_->{type} eq 'Commit' } @discussions;
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 ▶ if ($d->{type} eq 'IssueComment') {
Branch: 1 branch
BranchTrueFalseTotal
if ($d->{"type"} eq "IssueComment") 0 0 0
92 0 printf "%s:\n%s\n", $d->{user}->{name}, $d->{body};
93 }
94 0 ▶ if ($d->{type} eq 'PullRequestReviewComment') {
Branch: 1 branch
BranchTrueFalseTotal
if ($d->{"type"} eq "PullRequestReviewComment") 0 0 0
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 ▶ if ($res->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) { } 0 0 0
112 0 print $res->decoded_content;
113 } else {
114 0 warn $res->message;
115 }
116 }
117 }
118  
119  
120 1 1;
« lib/App/gh/Git.pm ↑ Summary lib/App/gh/Command/Import.pm »