| 1 | package Module::Setup::Plugin::Site::GitHub; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use base 'Module::Setup::Plugin'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use JSON; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | sub register { | ||||||||||||||||||||||||||
|
Subroutine
register: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 9 | 3 | my($self, ) = @_; | |||||||||||||||||||||||||||
| 10 | 3 | $self->add_trigger( before_dump_config => \&before_dump_config ); | |||||||||||||||||||||||||||
| 11 | 3 | $self->add_trigger( finalize_create_skeleton => \&finalize_create_skeleton ); | |||||||||||||||||||||||||||
| 12 | } | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | sub before_dump_config { | ||||||||||||||||||||||||||
|
Subroutine
before_dump_config: called CC=5 SCAR=16.7
Pod
documented
| |||||||||||||||||||||||||||||
| 15 | 1 | my($self, $config) = @_; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | my %modules = ( | |||||||||||||||||||||||||||
| 18 | readme_from => 'Module::Install::ReadmeFromPod', | ||||||||||||||||||||||||||||
| 19 | readme_markdown_from => 'Module::Install::ReadmeMarkdownFromPod', | ||||||||||||||||||||||||||||
| 20 | readme_pod_from => 'Module::Install::ReadmePodFromPod', | ||||||||||||||||||||||||||||
| 21 | githubmeta => 'Module::Install::GithubMeta', | ||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | while (my($name, $module) = each %modules) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 4 | ▶ | my $version = eval "require $module; 'installed '.\$$module\::VERSION;" || 'not installed'; | ||||||||||||||||||||||||||
|
Condition50%1/2
eval "require $module; 'installed '.\$${module}::VERSION;" || 'not installed'
MC/DC0%0/1
eval "require $module; 'installed '.\$${module}::VERSION;" || 'not installed'
eval "require $module; 'installed '.\$${module}::VERSION;"
Truth table50%1/2
A
A= eval "require $module; 'installed '.\$${module}::VERSION;"
| |||||||||||||||||||||||||||||
| 26 | 4 | $config->{$name} = 0; | |||||||||||||||||||||||||||
| 27 | 4 | ▶ | if ($self->dialog("use $name? (depend $module, $version [Yn] ", 'y') =~ /[Yy]/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 0 | $config->{$name} = 1; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 1 | ▶ | $config->{github_format} ||= 'p5-%s'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$config->{"github_format"} ||= "p5-%s"
MC/DC0%0/1
$config->{"github_format"} ||= "p5-%s"
$config->{"github_format"}
Truth table50%1/2
A
A= $config->{"github_format"}
| |||||||||||||||||||||||||||||
| 33 | 1 | $config->{github_format} = $self->dialog("github repository name format: ", $config->{github_format}); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # run github developer api | ||||||||||||||||||||||||||||
| 37 | 2 | ▶ | sub finalize_create_skeleton { | ||||||||||||||||||||||||||
|
Subroutine
finalize_create_skeleton: called CC=16 SCAR=30.6
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 39 | 2 | my $user = $self->shell('git config --get github.user'); | |||||||||||||||||||||||||||
| 40 | 2 | chomp $user; | |||||||||||||||||||||||||||
| 41 | 2 | my $token = $self->shell('git config --get github.token'); | |||||||||||||||||||||||||||
| 42 | 2 | chomp $token; | |||||||||||||||||||||||||||
| 43 | 2 | ▶ | unless ($user && $token) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$user and $token
MC/DC50%1/2
$user and $token
$user
$token
Truth table66%2/3
A and B
A= $userB= $token
| |||||||||||||||||||||||||||||
| 44 | 1 | $self->log("set the github.token And github.user for git config if you wants the create github repository."); | |||||||||||||||||||||||||||
| 45 | 1 | return; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 1 | ▶ | if ($self->dialog("create GitHub repository? [Yn] ", 'y') =~ /[Yy]/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | # create repository | ||||||||||||||||||||||||||||
| 50 | 1 | my $name = sprintf $self->config->{github_format}, $self->distribute->dist_name; | |||||||||||||||||||||||||||
| 51 | 1 | $name = $self->dialog("github repository name: ", $name); | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 1 | my $description = 'Perl Module of ' . $self->distribute->module; | |||||||||||||||||||||||||||
| 54 | 1 | $description = $self->dialog("github repository description: ", $description); | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 1 | my $homepage = ''; | |||||||||||||||||||||||||||
| 57 | 1 | $homepage = $self->dialog("github repository homepage: ", $homepage); | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 1 | my $public = 1; | |||||||||||||||||||||||||||
| 60 | 1 | ▶ | if ($self->dialog("create private repository? [yN] ", 'n') =~ /[Yy]/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | $public = 0; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 1 | ▶ | unless (_create_repository( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | login => $user, | ||||||||||||||||||||||||||||
| 66 | token => $token, | ||||||||||||||||||||||||||||
| 67 | name => $name, | ||||||||||||||||||||||||||||
| 68 | description => $description, | ||||||||||||||||||||||||||||
| 69 | homepage => $homepage, | ||||||||||||||||||||||||||||
| 70 | public => $public, | ||||||||||||||||||||||||||||
| 71 | )) { | ||||||||||||||||||||||||||||
| 72 | 0 | $self->log('can not created on GitHub'); | |||||||||||||||||||||||||||
| 73 | 0 | return; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 1 | ▶ | !$self->system('perl', 'Makefile.PL') or die $?; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 1 | ▶ | !$self->system('make', 'test') or die $?; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 1 | ▶ | !$self->system('make', 'distclean') or die $?; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 1 | ▶ | unless (-d '.git') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 1 | ▶ | !$self->system('git', 'init') or die $?; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 1 | ▶ | !$self->system('git', 'add', '.') or die $?; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 1 | ▶ | !$self->system('git', 'commit', '-m', 'initial commit') or die $?; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | 1 | ▶ | !$self->system('git', 'remote', 'add', 'origin', "git\@github.com:${user}/${name}.git") or die $?; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 1 | ▶ | if ($self->dialog("try git push to GitHub? [Yn] ", 'y') =~ /[Yy]/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 1 | ▶ | !$self->system('git', 'push', 'origin', 'master') or die $?; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | sub _create_repository { | ||||||||||||||||||||||||||
|
Subroutine
_create_repository: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 93 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 94 | 0 | my $ua = LWP::UserAgent->new( | |||||||||||||||||||||||||||
| 95 | agent => join('/', __PACKAGE__, $Module::Setup::VERSION), | ||||||||||||||||||||||||||||
| 96 | cookie_jar => +{}, | ||||||||||||||||||||||||||||
| 97 | ); | ||||||||||||||||||||||||||||
| 98 | 0 | my $res = $ua->post( | |||||||||||||||||||||||||||
| 99 | 'https://github.com/api/v2/json/repos/create' => \%args | ||||||||||||||||||||||||||||
| 100 | ); | ||||||||||||||||||||||||||||
| 101 | 0 | $res->is_success; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 2 | 1; | |||||||||||||||||||||||||||