blib/lib/App/gh/Command/Issue/Show.pm untested

filter: Statementstmt 0.0% 0 / 53 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 87 CC 6 SCAR 21.3
CC
6
Cov
0%
run
20.0
parse_uri
12.0
get_remote
2.0
CRAP 8.4
1 package App::gh::Command::Issue::Show;
2 use warnings;
3 use strict;
4 use base qw(App::gh::Command);
5 use App::gh::Utils;
6 use File::stat;
7 use File::Temp;
8 use Text::Wrap;
9 require App::gh::Git;
10  
11  
12 =head1 NAME
13  
14 App::gh::Command::Issue::Show - show the issue.
15  
16 =head1 DESCRIPTION
17  
18 =head1 USAGE
19  
20 =pod
21  
22 $ gh issue show [number]
23  
24 =cut
25  
26 sub parse_uri {
27 my ($uri) = @_;
28 if ( $uri =~ m{(git|https?)://github.com/(.*?)/(.*?).git} ) {
29 return ($2,$3,$1);
30 } elsif ( $uri =~ m{git\@github.com:(.*?)/(.*?).git} ) {
31 return ($1,$2,'git');
32 }
33 return undef;
34 }
35  
36 sub get_remote {
37 my $self = shift;
38 my $config = App::gh->config->current();
39 my %remotes = %{ $config->{remote} };
40 # try to get origin remote
41 return $remotes{origin} || (values( %remotes ))[0];
42 }
43  
44 sub run {
45 my ($self, $number) = @_;
46 return App::gh::Command->invoke('help', 'issue', 'show')
47 unless defined $number;
48  
49 my $remote = $self->get_remote();
50  
51 die "Remote not found\n." unless $remote;
52 my ( $user, $repo, $uri_type ) = parse_uri( $remote->{url} );
53  
54 my $gh_id = App::gh->config->github_id;
55 my $gh_token = App::gh->config->github_token;
56 unless( $gh_id && $gh_token ) {
57 die "Github authtoken not found. Can not get issue.\n";
58 }
59  
60 my $data = App::gh->api->issue_get($user, $repo, $number);
61 my $issue = $data->{issue};
62 printf "Title: %s\n", $issue->{title};
63 printf "Author: %s\n", $issue->{user};
64 printf "\n%s\n\n", $issue->{body};
65  
66 $data = App::gh->api->issue_get_comments($user, $repo, $number);
67 for my $d (@{$data->{comments}}) {
68 print "-" x 78 . "\n";
69 printf "%s:\n%s\n", $d->{user}, $d->{body};
70 }
71 }
72  
73 1;