| 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
Condition16%1/6
try_load_class('Net::GitHub') || say(q[Sorry, Net::GitHub is required for 'got fork'. Please install it.]) && exit 1
say "Sorry, Net::GitHub is required for 'got fork'. Please install it." and exit 1
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."
| ||||||||||||||||||||||||||||||||||
| 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
Condition50%3/6
(my $github_url = shift @$args) || say(STDERR 'ERROR: Need the URL of a repo to fork!') && exit 1
say STDERR "ERROR: Need the URL of a repo to fork!" and exit 1
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!"
| ||||||||||||||||||||||||||||||||||
| 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
| ||||||||||||||||||||||||||||||||||
| 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
| ||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | say "Cloning into $path" unless $self->quiet; | |||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||
| 58 | 0 | $new_repo->clone( $resp->{ssh_url} ); | ||||||||||||||||||||||||||||||||
| 59 | ||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if ( ! $self->opt->noremoteadd ) { | |||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | say "Adding '$github_url' as remote 'upstream'..." | |||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||
| 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
Condition16%1/6
$file->exists || say(STDERR "ERROR: Can't find $file") && exit 1
say STDERR "ERROR: Can't find $file" and exit 1
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"
| ||||||||||||||||||||||||||||||||||
| 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
| ||||||||||||||||||||||||||||||||||
| 83 | 2 | my( $k , $v ) = split /\s/; | ||||||||||||||||||||||||||||||||
| 84 | 2 | $config{$k} = $v; | ||||||||||||||||||||||||||||||||
| 85 | } | |||||||||||||||||||||||||||||||||
| 86 | ||||||||||||||||||||||||||||||||||
| 87 | 1 | ▶ | if ( defined $config{access_token} ) { | |||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||
| 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"}
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"}
| ||||||||||||||||||||||||||||||||||
| 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
| ||||||||||||||||||||||||||||||||||
| 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
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
say STDERR "ERROR: Can't parse '${url}'.\nURL needs to be of the form 'github.com/OWNER/REPO'.\n" and exit 1
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"
| ||||||||||||||||||||||||||||||||||
| 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__ | |||||||||||||||||||||||||||||||||