line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::GitGot::Command::fork; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:GENEHACK'; |
3
|
|
|
|
|
|
|
$App::GitGot::Command::fork::VERSION = '1.336'; |
4
|
|
|
|
|
|
|
# ABSTRACT: fork a github repo |
5
|
15
|
|
|
15
|
|
7527
|
use 5.014; |
|
15
|
|
|
|
|
54
|
|
6
|
|
|
|
|
|
|
|
7
|
15
|
|
|
15
|
|
67
|
use autodie; |
|
15
|
|
|
|
|
27
|
|
|
15
|
|
|
|
|
218
|
|
8
|
15
|
|
|
15
|
|
69577
|
use Class::Load 'try_load_class'; |
|
15
|
|
|
|
|
29
|
|
|
15
|
|
|
|
|
753
|
|
9
|
15
|
|
|
15
|
|
79
|
use Cwd; |
|
15
|
|
|
|
|
26
|
|
|
15
|
|
|
|
|
763
|
|
10
|
15
|
|
|
15
|
|
84
|
use File::HomeDir; |
|
15
|
|
|
|
|
24
|
|
|
15
|
|
|
|
|
841
|
|
11
|
15
|
|
|
15
|
|
87
|
use Path::Tiny; |
|
15
|
|
|
|
|
30
|
|
|
15
|
|
|
|
|
887
|
|
12
|
15
|
|
|
15
|
|
82
|
use Types::Standard -types; |
|
15
|
|
|
|
|
25
|
|
|
15
|
|
|
|
|
144
|
|
13
|
|
|
|
|
|
|
|
14
|
15
|
|
|
15
|
|
53912
|
use App::GitGot -command; |
|
15
|
|
|
|
|
39
|
|
|
15
|
|
|
|
|
126
|
|
15
|
15
|
|
|
15
|
|
3989
|
use App::GitGot::Repo::Git; |
|
15
|
|
|
|
|
28
|
|
|
15
|
|
|
|
|
496
|
|
16
|
|
|
|
|
|
|
|
17
|
15
|
|
|
15
|
|
82
|
use Moo; |
|
15
|
|
|
|
|
26
|
|
|
15
|
|
|
|
|
74
|
|
18
|
|
|
|
|
|
|
extends 'App::GitGot::Command'; |
19
|
15
|
|
|
15
|
|
6181
|
use namespace::autoclean; |
|
15
|
|
|
|
|
29
|
|
|
15
|
|
|
|
|
78
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub options { |
22
|
4
|
|
|
4
|
0
|
276
|
my( $class , $app ) = @_; |
23
|
|
|
|
|
|
|
return ( |
24
|
4
|
|
|
|
|
30
|
[ '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
|
|
|
|
|
|
|
sub _execute { |
30
|
4
|
|
|
4
|
|
9
|
my( $self, $opt, $args ) = @_; |
31
|
|
|
|
|
|
|
|
32
|
4
|
50
|
0
|
|
|
10
|
try_load_class('Net::GitHub') or |
33
|
|
|
|
|
|
|
say "Sorry, Net::GitHub is required for 'got fork'. Please install it." |
34
|
|
|
|
|
|
|
and exit(1); |
35
|
|
|
|
|
|
|
|
36
|
4
|
100
|
33
|
|
|
233
|
my $github_url = shift @$args |
37
|
|
|
|
|
|
|
or say STDERR "ERROR: Need the URL of a repo to fork!" and exit(1); |
38
|
|
|
|
|
|
|
|
39
|
3
|
|
|
|
|
7
|
my( $owner , $repo_name ) = _parse_github_url( $github_url ); |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
4
|
my %gh_args = _parse_github_identity(); |
42
|
|
|
|
|
|
|
|
43
|
1
|
50
|
|
|
|
27
|
say "Forking '$owner/$repo_name'..." unless $self->quiet; |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
44
|
my $resp = Net::GitHub->new( %gh_args )->repos->create_fork( $owner , $repo_name ); |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
|
|
3252
|
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
|
|
|
|
|
90
|
type => 'git' , |
54
|
|
|
|
|
|
|
}}); |
55
|
|
|
|
|
|
|
|
56
|
1
|
50
|
|
|
|
101
|
if ( ! $self->opt->noclone ) { |
57
|
0
|
0
|
|
|
|
0
|
say "Cloning into $path" unless $self->quiet; |
58
|
0
|
|
|
|
|
0
|
$new_repo->clone( $resp->{ssh_url} ); |
59
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
0
|
if ( ! $self->opt->noremoteadd ) { |
61
|
0
|
0
|
|
|
|
0
|
say "Adding '$github_url' as remote 'upstream'..." |
62
|
|
|
|
|
|
|
unless $self->quiet; |
63
|
0
|
|
|
|
|
0
|
$new_repo->remote( add => upstream => $github_url ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
1
|
|
|
|
|
43
|
$self->add_repo( $new_repo ); |
68
|
1
|
|
|
|
|
112
|
$self->write_config; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub _parse_github_identity { |
72
|
1
|
|
|
1
|
|
4
|
my $file = path( File::HomeDir->my_home() , '.github-identity' ); |
73
|
|
|
|
|
|
|
|
74
|
1
|
50
|
0
|
|
|
72
|
$file->exists or |
75
|
|
|
|
|
|
|
say STDERR "ERROR: Can't find $file" and exit(1); |
76
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
57
|
my @lines = $file->lines; |
78
|
|
|
|
|
|
|
|
79
|
1
|
|
|
|
|
175
|
my %config; |
80
|
1
|
|
|
|
|
3
|
foreach ( @lines ) { |
81
|
2
|
|
|
|
|
4
|
chomp; |
82
|
2
|
50
|
|
|
|
4
|
next unless $_; |
83
|
2
|
|
|
|
|
10
|
my( $k , $v ) = split /\s/; |
84
|
2
|
|
|
|
|
7
|
$config{$k} = $v; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
1
|
50
|
33
|
|
|
9
|
if ( defined $config{access_token} ) { |
|
|
50
|
|
|
|
|
|
88
|
|
|
|
|
|
|
return ( access_token => $config{access_token} ) |
89
|
0
|
|
|
|
|
0
|
} |
90
|
|
|
|
|
|
|
elsif ( defined $config{pass} and defined $config{user} ) { |
91
|
|
|
|
|
|
|
return ( login => $config{user} , pass => $config{pass} ) |
92
|
1
|
|
|
|
|
6
|
} |
93
|
|
|
|
|
|
|
else { |
94
|
0
|
0
|
|
|
|
0
|
say STDERR "Couldn't parse password or access_token info from ~/.github-identity" |
95
|
|
|
|
|
|
|
and exit(1); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub _parse_github_url { |
100
|
3
|
|
|
3
|
|
4
|
my $url = shift; |
101
|
|
|
|
|
|
|
|
102
|
3
|
100
|
33
|
|
|
24
|
my( $owner , $repo ) = $url =~ m|/github.com/([^/]+)/([^/]+?)(?:\.git)?$| |
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
|
|
|
|
|
3
|
return( $owner , $repo ); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
__END__ |