blib/lib/App/gh/Command/Issue/List.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::List;
2 use warnings;
3 use strict;
4 use base qw(App::gh::Command);
5 use App::gh::Utils;
6 use Text::Wrap;
7 use File::stat;
8 use File::Temp;
9 require App::gh::Git;
10  
11  
12 =head1 NAME
13  
14 App::gh::Command::Issue::List - show list of issues.
15  
16 =head1 DESCRIPTION
17  
18 =head1 USAGE
19  
20 =pod
21  
22 $ gh issue list
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 = shift;
46  
47 my $remote = $self->get_remote();
48  
49 die "Remote not found\n." unless $remote;
50 my ( $user, $repo, $uri_type ) = parse_uri( $remote->{url} );
51  
52 my $gh_id = App::gh->config->github_id;
53 my $gh_token = App::gh->config->github_token;
54 unless( $gh_id && $gh_token ) {
55 die "Github authtoken not found. Can not get issues.\n";
56 }
57  
58 my $data = App::gh->api->issue_list($user, $repo);
59 unless (@{$data->{issues}}) {
60 info "No issues found.";
61 } else {
62 for my $issue (@{$data->{issues}}) {
63 printf "* Issue %-4d [%s] %s - %s\n" ,
64 $issue->{number},
65 ucfirst($issue->{state}),
66 $issue->{title},
67 $issue->{user};
68 printf " Date %s\n", $issue->{created_at};
69 printf " Url %s\n", $issue->{html_url};
70 # use Data::Dumper; warn Dumper( $issue->{body} );
71 printf "\n%s",wrap " " x 6," " x 6,$issue->{body};
72 printf "\n\n";
73 # printf "%04d:%s: %s\n", $issue->{number}, $issue->{user}, $issue->{title};
74 }
75 }
76 }
77  
78  
79 1;