File Coverage

lib/App/gh/Command.pm
Criterion Covered Total %
statement 24 58 41.3
branch 0 24 0.0
condition 0 12 0.0
subroutine 8 16 50.0
pod 0 8 0.0
total 32 118 27.1


line stmt bran cond sub pod time code
1             package App::gh::Command;
2 2     2   3104 use warnings;
  2         4  
  2         67  
3 2     2   12 use strict;
  2         4  
  2         56  
4 2     2   12 use App::gh;
  2         5  
  2         39  
5 2     2   11 use App::gh::Config;
  2         5  
  2         41  
6 2     2   11 use App::gh::API;
  2         4  
  2         40  
7 2     2   12 use App::gh::Utils;
  2         4  
  2         420  
8 2     2   12 use base qw(App::CLI App::CLI::Command);
  2         5  
  2         1916  
9              
10 2     2   42599 use constant global_options => ( 'help' => 'help' );
  2         5  
  2         1140  
11              
12             sub alias { (
13 0     0 0   "a" => "all",
14             "ci" => "commit",
15             "fo" => "fork",
16             "is" => "issue",
17             "ne" => "network",
18             "pr" => "pullreq",
19             "pu" => "pull",
20             "se" => "search",
21             "up" => "update",
22              
23             # TODO:
24             # fetch should only do git fetch
25             # pull should only do git pull
26             # should wrap these commands with github features
27             #
28             # https://github.com/c9s/App-gh/pull/39
29             "fetch" => "pull",
30             ) }
31              
32             sub invoke {
33 0     0 0   my ($pkg, $cmd, @args) = @_;
34 0           local *ARGV = [$cmd, @args];
35 0           my $ret = eval {
36 0           $pkg->dispatch();
37             };
38 0 0         if( $@ ) {
39 0           warn $@;
40             }
41             }
42              
43             sub parse_remote_param {
44 0     0 0   my $uri = shift;
45 0 0 0       if ( $uri =~ m{(?:git|https?)://github.com/(.*?)/(.*?)\.git$}
46             || $uri =~ m{git\@github.com:(.*?)/(.*?)\.git$} )
47             {
48 0 0 0       return ( $1 , $2 )
49             if( $1 && $2 );
50             }
51 0           return undef;
52             }
53              
54              
55             sub get_current_repo {
56 0     0 0   my $self = shift;
57 0           my $config = App::gh->config->current();
58 0           for my $remote ( values %{ $config->{remote} } ) {
  0            
59 0 0         if( my ($my, $repo) = parse_remote_param( $remote->{url} ) )
60             {
61 0           return ($my,$repo);
62             }
63             }
64             }
65              
66             sub get_clone_protocol {
67 0     0 0   my $self = shift;
68 0 0         return 'git' if $self->{protocol_git} ;
69 0 0         return 'ssh' if $self->{protocol_ssh} ;
70 0 0         return 'http' if $self->{protocol_http};
71 0 0         return 'https' if $self->{protocol_https};
72 0           return;
73             }
74              
75             sub gen_uri {
76 0     0 0   my ($self,$acc,$repo) = @_;
77              
78 0 0 0       if( $self->{protocol_git} ) {
    0          
    0          
    0          
79 0           return sprintf( 'git://github.com/%s/%s.git', $acc, $repo );
80             }
81             elsif( $self->{protocol_ssh} || $self->is_mine($acc, $repo) ) {
82 0           return sprintf( 'git@github.com:%s/%s.git' , $acc, $repo );
83             }
84             elsif( $self->{protocol_http} ) {
85 0           return sprintf( 'http://github.com/%s/%s.git' , $acc , $repo );
86             }
87             elsif( $self->{protocol_https}) {
88 0           return sprintf( 'https://github.com/%s/%s.git' , $acc , $repo );
89             }
90 0           return sprintf( 'git://github.com/%s/%s.git', $acc, $repo );
91             }
92              
93             sub is_mine {
94 0     0 0   my($self, $acc, $repo) = @_;
95 0           my $gh_user = App::gh->config->github_id;
96 0   0       return defined($gh_user) && $gh_user eq $acc;
97             }
98              
99             sub global_help {
100             # XXX: scan command classes
101 0     0 0   print <<'END';
102             App::gh
103              
104              
105             help
106             - show help message
107              
108             list [userid]
109             - list all repository of an user:
110              
111             clone [userid] [repo] ([http|ro|ssh])
112             - clone repository from an user
113              
114             search [keyword]
115             - search repository:
116              
117             all [userid]
118             - to clone all repository of an user:
119              
120             fork [userid] [repo]
121             - to fork project:
122              
123             fork
124             - to fork current project:
125              
126             network
127             - to show fork network:
128              
129             pull [userid] ([branch])
130             - pull from other's fork:
131              
132             pullreq list
133             - show list of pull requests:
134              
135             pullreq show
136             - show the pull requests:
137              
138             pullreq send ([branch])
139             - send pull requests of current branch to branch:
140              
141             issue list
142             - show list of issues.
143              
144             issue show
145             - show the issue.
146              
147             issue edit ([issueid])
148             - to edit the issue.
149              
150             issue comment [issueid]
151             - to comment the issue.
152              
153             END
154             }
155              
156             1;