GitGot/Command/fork.pm

filter: Statementstmt 90.1% 64 / 71 Branchbran 42.3% 11 / 26 Conditioncond 33.3% 9 / 27 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 100% 15 / 15 Podpod 0.0% 0 / 1 totaltotal 66.0% 99 / 150 CC 20 SCAR 24.9
CC
20
Cov
68%
_execute
23.4
_parse_github_identity
17.3
_parse_github_url
3.2
CRAP 12.1
« GitGot/Command/checkout.pm ↑ Summary GitGot/Command/clone.pm »
1 package App::GitGot::Command::fork;
2 16 our $AUTHORITY = 'cpan:GENEHACK';
3 16 $App::GitGot::Command::fork::VERSION = '1.339';
4 # ABSTRACT: fork a github repo
5 16 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 16 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 16 ▶use Class::Load 'try_load_class';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 16 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 16 ▶use File::HomeDir::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 16 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 16 ▶use Types::Standard -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 16 ▶use App::GitGot -command;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 16 ▶use App::GitGot::Repo::Git;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 16 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 16 extends 'App::GitGot::Command';
19 16 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 4 ▶sub options {
Subroutine options: called CC=1 SCAR=0.0
Pod undocumented
22 4 my( $class , $app ) = @_;
23 return (
24 4 [ 'noclone|n' => 'If set, do not check out a local working copy of the forked repo' ] ,
25 [ 'noremoteadd|N' => 'If set, do not add the forked repo as the "upstream" repo in the new working copy' ] ,
26 );
27 }
28  
29 4 ▶sub _execute {
Subroutine _execute: called CC=10 SCAR=31.5
30 4 my( $self, $opt, $args ) = @_;
31  
32 4 ▶ try_load_class('Net::GitHub') or
Branch: 1 branch
BranchTrueFalseTotal
try_load_class("Net::GitHub") or say "Sorry, Net::GitHub is required for 'got fork'. Please install it." and exit 1 4 0 4
Condition16%1/6
try_load_class('Net::GitHub') || say(q[Sorry, Net::GitHub is required for 'got fork'. Please install it.]) && exit 1
l!l&&r!l&&!r
400
say "Sorry, Net::GitHub is required for 'got fork'. Please install it." and exit 1
!ll
000
MC/DC0%0/2
try_load_class('Net::GitHub') || say(q[Sorry, Net::GitHub is required for 'got fork'. Please install it.]) && exit 1
try_load_class('Net::GitHub') say "Sorry, Net::GitHub is required for 'got fork'. Please install it."
Truth table33%1/3
A || B
A= try_load_class('Net::GitHub')B= say "Sorry, Net::GitHub is required for 'got fork'. Please install it."
ABresult
1X1
011
000
33 say "Sorry, Net::GitHub is required for 'got fork'. Please install it."
34 and exit(1);
35  
36 4 ▶ my $github_url = shift @$args
Branch: 1 branch
BranchTrueFalseTotal
my $github_url = shift @$args or say STDERR "ERROR: Need the URL of a repo to fork!" and exit 1 3 1 4
Condition50%3/6
(my $github_url = shift @$args) || say(STDERR 'ERROR: Need the URL of a repo to fork!') && exit 1
l!l&&r!l&&!r
310
say STDERR "ERROR: Need the URL of a repo to fork!" and exit 1
!ll
010
MC/DC0%0/2
(my $github_url = shift @$args) || say(STDERR 'ERROR: Need the URL of a repo to fork!') && exit 1
(my $github_url = shift @$args) say STDERR "ERROR: Need the URL of a repo to fork!"
Truth table66%2/3
A || B
A= (my $github_url = shift @$args)B= say STDERR "ERROR: Need the URL of a repo to fork!"
ABresult
1X1
011
000
37 or say STDERR "ERROR: Need the URL of a repo to fork!" and exit(1);
38  
39 3 my( $owner , $repo_name ) = _parse_github_url( $github_url );
40  
41 1 my %gh_args = _parse_github_identity();
42  
43 1 ▶ say "Forking '$owner/$repo_name'..." unless $self->quiet;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->quiet 0 1 1
44  
45 1 my $resp = Net::GitHub->new( %gh_args )->repos->create_fork( $owner , $repo_name );
46  
47 1 my $path = cwd() . "/$repo_name";
48  
49 my $new_repo = App::GitGot::Repo::Git->new({ entry => {
50 name => $repo_name ,
51 path => $path ,
52 repo => $resp->{ssh_url} ,
53 1 type => 'git' ,
54 }});
55  
56 1 ▶ if ( ! $self->opt->noclone ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->opt->noclone) 0 1 1
57 0 ▶ say "Cloning into $path" unless $self->quiet;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->quiet 0 0 0
58 0 $new_repo->clone( $resp->{ssh_url} );
59  
60 0 ▶ if ( ! $self->opt->noremoteadd ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->opt->noremoteadd) 0 0 0
61 0 ▶ say "Adding '$github_url' as remote 'upstream'..."
Branch: 1 branch
BranchTrueFalseTotal
unless $self->quiet 0 0 0
62 unless $self->quiet;
63 0 $new_repo->remote( add => upstream => $github_url );
64 }
65 }
66  
67 1 $self->add_repo( $new_repo );
68 1 $self->write_config;
69 }
70  
71 1 ▶sub _parse_github_identity {
Subroutine _parse_github_identity: called CC=9 SCAR=28.5
72 1 my $file = path( File::HomeDir::Tiny::home() , '.github-identity' );
73  
74 1 ▶ $file->exists or
Branch: 1 branch
BranchTrueFalseTotal
$file->exists or say STDERR "ERROR: Can't find $file" and exit 1 1 0 1
Condition16%1/6
$file->exists || say(STDERR "ERROR: Can't find $file") && exit 1
l!l&&r!l&&!r
100
say STDERR "ERROR: Can't find $file" and exit 1
!ll
000
MC/DC0%0/2
$file->exists || say(STDERR "ERROR: Can't find $file") && exit 1
$file->exists say STDERR "ERROR: Can't find $file"
Truth table33%1/3
A || B
A= $file->existsB= say STDERR "ERROR: Can't find $file"
ABresult
1X1
011
000
75 say STDERR "ERROR: Can't find $file" and exit(1);
76  
77 1 my @lines = $file->lines;
78  
79 1 my %config;
80 1 foreach ( @lines ) {
81 2 chomp;
82 2 ▶ next unless $_;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ 0 2 2
83 2 my( $k , $v ) = split /\s/;
84 2 $config{$k} = $v;
85 }
86  
87 1 ▶ if ( defined $config{access_token} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $config{'access_token'}) { } 0 1 1
elsif (defined $config{'pass'} and defined $config{'user'}) { } 1 0 1
88 return ( access_token => $config{access_token} )
89 0 }
90 ▶ elsif ( defined $config{pass} and defined $config{user} ) {
Condition33%1/3
defined $config{"pass"} and defined $config{"user"}
!ll&&!rl&&r
001
MC/DC0%0/2
defined $config{"pass"} and defined $config{"user"}
defined $config{"pass"} defined $config{"user"}
Truth table33%1/3
A and B
A= defined $config{"pass"}B= defined $config{"user"}
ABresult
0X0
100
111
91 return ( login => $config{user} , pass => $config{pass} )
92 1 }
93 else {
94 0 ▶ say STDERR "Couldn't parse password or access_token info from ~/.github-identity"
Branch: 1 branch
BranchTrueFalseTotal
say STDERR "Couldn't parse password or access_token info from ~/.github-identity" and exit 1 0 0 0
95 and exit(1);
96 }
97 }
98  
99 3 ▶sub _parse_github_url {
Subroutine _parse_github_url: called CC=3 SCAR=11.6
100 3 my $url = shift;
101  
102 3 ▶ my( $owner , $repo ) = $url =~ m|/github.com/([^/]+)/([^/]+?)(?:\.git)?$|
Branch: 1 branch
BranchTrueFalseTotal
() = $url =~ m[/github.com/([^/]+)/([^/]+?)(?:\.git)?$]u or say STDERR "ERROR: Can't parse '${url}'.\nURL needs to be of the form 'github.com/OWNER/REPO'.\n" and exit 1 1 2 3
Condition50%3/6
(() = $url =~ m[/github.com/([^/]+)/([^/]+?)(?:\.git)?$]u) || say(STDERR "ERROR: Can't parse '${url}'.\nURL needs to be of the form 'github.com/OWNER/REPO'.\n") && exit 1
l!l&&r!l&&!r
120
say STDERR "ERROR: Can't parse '${url}'.\nURL needs to be of the form 'github.com/OWNER/REPO'.\n" and exit 1
!ll
020
MC/DC0%0/2
(() = $url =~ m[/github.com/([^/]+)/([^/]+?)(?:\.git)?$]u) || say(STDERR "ERROR: Can't parse '${url}'.\nURL needs to be of the form 'github.com/OWNER/REPO'.\n") && exit 1
(() = $url =~ m[/github.com/([^/]+)/([^/]+?)(?:\.git)?$]u) say STDERR "ERROR: Can't parse '${url}'.\nURL needs to be of the form 'github.com/OWNER/REPO'.\n"
Truth table66%2/3
A || B
A= (() = $url =~ m[/github.com/([^/]+)/([^/]+?)(?:\.git)?$]u)B= say STDERR "ERROR: Can't parse '${url}'.\nURL needs to be of the form 'github.com/OWNER/REPO'.\n"
ABresult
1X1
011
000
103 or say STDERR "ERROR: Can't parse '$url'.\nURL needs to be of the form 'github.com/OWNER/REPO'.\n"
104 and exit(1);
105  
106 1 return( $owner , $repo );
107 }
108  
109 16 1;
110  
111 __END__
« GitGot/Command/checkout.pm ↑ Summary GitGot/Command/clone.pm »