| 1 | package App::gh::Command::Fork; | ||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use base qw(App::gh::Command); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use App::gh::Utils; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | App::gh::Command::Fork - fork current repository. | ||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | =head1 USAGE | ||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | =pod | ||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | curl -F 'login=schacon' -F 'token=XXX' http://github.com/api/v2/yaml/repos/fork/dim/retrospectiva | ||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | $VAR1 = { | ||||||||||||||||||||||||||||||||
| 21 | 'repository' => { | ||||||||||||||||||||||||||||||||
| 22 | 'has_downloads' => bless( do{\(my $o = 1)}, 'JSON::Boolean' ), | ||||||||||||||||||||||||||||||||
| 23 | 'owner' => 'c9s', | ||||||||||||||||||||||||||||||||
| 24 | 'has_issues' => bless( do{\(my $o = 0)}, 'JSON::Boolean' ), | ||||||||||||||||||||||||||||||||
| 25 | 'name' => 'AnyMQ', | ||||||||||||||||||||||||||||||||
| 26 | 'private' => $VAR1->{'repository'}{'has_issues'}, | ||||||||||||||||||||||||||||||||
| 27 | 'has_wiki' => $VAR1->{'repository'}{'has_downloads'}, | ||||||||||||||||||||||||||||||||
| 28 | 'pushed_at' => '2010/04/06 00:40:45 -0700', | ||||||||||||||||||||||||||||||||
| 29 | 'description' => 'Simple message queue based on AnyEvent', | ||||||||||||||||||||||||||||||||
| 30 | 'watchers' => 1, | ||||||||||||||||||||||||||||||||
| 31 | 'forks' => 0, | ||||||||||||||||||||||||||||||||
| 32 | 'homepage' => '', | ||||||||||||||||||||||||||||||||
| 33 | 'created_at' => '2010/07/21 06:08:11 -0700', | ||||||||||||||||||||||||||||||||
| 34 | 'fork' => $VAR1->{'repository'}{'has_downloads'}, | ||||||||||||||||||||||||||||||||
| 35 | 'url' => 'http://github.com/c9s/AnyMQ', | ||||||||||||||||||||||||||||||||
| 36 | 'open_issues' => 0 | ||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||
| 38 | }; | ||||||||||||||||||||||||||||||||
| 39 | =cut | ||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub options { ( | ||||||||||||||||||||||||||||||
|
Subroutine
options: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 42 | 0 | "verbose" => "verbose", | |||||||||||||||||||||||||||||||
| 43 | "ssh" => "protocol_ssh", # git@github.com:c9s/repo.git | ||||||||||||||||||||||||||||||||
| 44 | "http" => "protocol_http", # http://github.com/c9s/repo.git | ||||||||||||||||||||||||||||||||
| 45 | "https" => "protocol_https", # https://github.com/c9s/repo.git | ||||||||||||||||||||||||||||||||
| 46 | "git|ro" => "protocol_git" # git://github.com/c9s/repo.git | ||||||||||||||||||||||||||||||||
| 47 | ) } | ||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||||||
|
Subroutine
run: not called CC=18 SCAR=57.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 51 | 0 | my $self=shift; | |||||||||||||||||||||||||||||||
| 52 | 0 | my $user; | |||||||||||||||||||||||||||||||
| 53 | my $repo; | ||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 56 | 0 | $user = shift; | |||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | # copied from Github::Fork::Parent | ||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if ($user && $user=~m{^(?:\Qgit://github.com/\E|git\@github\.com:\E|\Qhttp://github.com/\E)([^/]+)/([^/]+)(?:\.git)?$}) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$user and $user =~ m[^(?:git\:\/\/github\.com\/|git\@github\.com:|http\:\/\/github\.com\/)([^/]+)/([^/]+)(?:\.git)?$]
MC/DC0%0/2
$user and $user =~ m[^(?:git\:\/\/github\.com\/|git\@github\.com:|http\:\/\/github\.com\/)([^/]+)/([^/]+)(?:\.git)?$]
$user
$user =~ m[^(?:git\:\/\/github\.com\/|git\@github\.com:|http\:\/\/github\.com\/)([^/]+)/([^/]+)(?:\.git)?$]
Truth table0%0/3
A and B
A= $userB= $user =~ m[^(?:git\:\/\/github\.com\/|git\@github\.com:|http\:\/\/github\.com\/)([^/]+)/([^/]+)(?:\.git)?$]
| |||||||||||||||||||||||||||||||||
| 60 | 0 | ($user,$repo)=($1,$2); | |||||||||||||||||||||||||||||||
| 61 | ▶ | } elsif( $user && $user =~ /\// ) { | |||||||||||||||||||||||||||||||
|
Condition0%0/3
$user and $user =~ m[/]
MC/DC0%0/2
$user and $user =~ m[/]
$user
$user =~ m[/]
Truth table0%0/3
A and B
A= $userB= $user =~ m[/]
| |||||||||||||||||||||||||||||||||
| 62 | 0 | ($user,$repo) = split /\//,$user; | |||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||
| 64 | else { | ||||||||||||||||||||||||||||||||
| 65 | 0 | $repo = shift; | |||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | 0 | my $gh_id = App::gh->config->github_id; | |||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | my $gh_token = App::gh->config->github_token | ||||||||||||||||||||||||||||||
|
Condition0%0/3
'App::gh'->config->github_token || 'App::gh'->config->github_password
MC/DC0%0/2
'App::gh'->config->github_token || 'App::gh'->config->github_password
'App::gh'->config->github_token
'App::gh'->config->github_password
Truth table0%0/3
A || B
A= 'App::gh'->config->github_tokenB= 'App::gh'->config->github_password
| |||||||||||||||||||||||||||||||||
| 72 | || App::gh->config->github_password; | ||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | unless( $gh_id && $gh_token ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$gh_id and $gh_token
MC/DC0%0/2
$gh_id and $gh_token
$gh_id
$gh_token
Truth table0%0/3
A and B
A= $gh_idB= $gh_token
| |||||||||||||||||||||||||||||||||
| 74 | 0 | die "Github credentials not found. Cannot fork repository.\n"; | |||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | unless ( $repo ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 79 | # detect .git directory | ||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | if ( -e ".git/config" ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 81 | 0 | my $config = App::gh->config->current(); | |||||||||||||||||||||||||||||||
| 82 | 0 | for my $remote ( values %{ $config->{remote} } ) { | |||||||||||||||||||||||||||||||
| 83 | # git://github.com/miyagawa/Tatsumaki.git | ||||||||||||||||||||||||||||||||
| 84 | # http://github.com/miyagawa/Tatsumaki.git | ||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if ( $remote->{url} =~ m{(?:git|https?)://github.com/(.*?)/(.*?)\.git} | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$remote->{"url"} =~ m[(?:git|https?)://github.com/(.*?)/(.*?)\.git] or $remote->{"url"} =~ m[git\@github.com:(.*?)/(.*?)\.git]
MC/DC0%0/2
$remote->{"url"} =~ m[(?:git|https?)://github.com/(.*?)/(.*?)\.git] or $remote->{"url"} =~ m[git\@github.com:(.*?)/(.*?)\.git]
$remote->{"url"} =~ m[(?:git|https?)://github.com/(.*?)/(.*?)\.git]
$remote->{"url"} =~ m[git\@github.com:(.*?)/(.*?)\.git]
Truth table0%0/3
A or B
A= $remote->{"url"} =~ m[(?:git|https?)://github.com/(.*?)/(.*?)\.git]B= $remote->{"url"} =~ m[git\@github.com:(.*?)/(.*?)\.git]
| |||||||||||||||||||||||||||||||||
| 86 | || $remote->{url} =~ m{git\@github.com:(.*?)/(.*?)\.git} ) | ||||||||||||||||||||||||||||||||
| 87 | { | ||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | die unless( $1 || $2 ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$1 or $2
MC/DC0%0/2
$1 or $2
$1
$2
Truth table0%0/3
A or B
A= $1B= $2
| |||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | 0 | ($user,$repo) = ( $1 , $2 ); | |||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | 0 | info "Found GitHub repository of $user/$repo"; | |||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | 0 | my $_remotes = qx(git remote | grep @{[ $gh_id ]}); | |||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if( $_remotes ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 96 | 0 | die "Remote @{[ $gh_id ]} exists.\n"; | |||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | 0 | my $remote_uri; | |||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | if ( $self->{protocol_https} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 101 | 0 | $remote_uri = qq( https://@{[ $gh_id ]}\@github.com/@{[ $gh_id ]}/$repo.git); | |||||||||||||||||||||||||||||||
| 102 | } else { | ||||||||||||||||||||||||||||||||
| 103 | 0 | $remote_uri = qq( git\@github.com:@{[ $gh_id ]}/$repo.git); | |||||||||||||||||||||||||||||||
| 104 | }; | ||||||||||||||||||||||||||||||||
| 105 | 0 | info "Adding remote '@{[ $gh_id ]}' => $remote_uri"; | |||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||
| 107 | # url = git@github.com:c9s/App-gh.git | ||||||||||||||||||||||||||||||||
| 108 | 0 | my $cmd = qq( git remote add @{[ $gh_id ]} $remote_uri); | |||||||||||||||||||||||||||||||
| 109 | 0 | _debug $cmd; | |||||||||||||||||||||||||||||||
| 110 | 0 | qx($cmd); | |||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||
| 112 | 0 | info "Remote added."; | |||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||
| 118 | 0 | info "Forking..."; | |||||||||||||||||||||||||||||||
| 119 | 0 | my $data = App::gh::API->fork($user, $repo); | |||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 122 | 0 | _debug Dumper( $data ); | |||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | 0 | info "Repository forked:"; | |||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | 0 | App::gh::Utils->print_repo_info($data->{repository}); | |||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||
| 128 | # $data = $data->{repository}; | ||||||||||||||||||||||||||||||||
| 129 | # print " Name: " . $data->{name} . "\n"; | ||||||||||||||||||||||||||||||||
| 130 | # print " Description: " . $data->{description} . "\n"; | ||||||||||||||||||||||||||||||||
| 131 | # print " Owner: " . $data->{owner} . "\n"; | ||||||||||||||||||||||||||||||||
| 132 | # print " Watchers: " . $data->{watchers} . "\n"; | ||||||||||||||||||||||||||||||||
| 133 | # print " Created at: " . $data->{created_at} . "\n"; | ||||||||||||||||||||||||||||||||
| 134 | # print " Pushed at: " . $data->{pushed_at} . "\n"; | ||||||||||||||||||||||||||||||||
| 135 | # print " Fork: " . $data->{'fork'} . "\n"; | ||||||||||||||||||||||||||||||||
| 136 | # print " URL: " . $data->{url} . "\n"; | ||||||||||||||||||||||||||||||||
| 137 | # print " Homepage: " . ($data->{homepage}||'') . "\n"; | ||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||
| 142 | 1 | 1; | |||||||||||||||||||||||||||||||