| 1 | package Yukki::Model::Root; | ||||||||||||||||||||||||||||||||
| 2 | 6 | $Yukki::Model::Root::VERSION = '0.991_007'; # TRIAL | |||||||||||||||||||||||||||||||
| 3 | 6 | $Yukki::Model::Root::VERSION = '0.991007'; | |||||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use v5.24; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use utf8; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use Moo; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 6 | extends 'Yukki::Model'; | |||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use Type::Params qw( validate ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use Type::Utils; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 6 | ▶ | use Types::Standard qw( Bool Optional Maybe Str Dict slurpy ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 6 | ▶ | use Types::URI qw( Uri ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | 6 | ▶ | use Yukki::Error qw( http_throw ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | 6 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | # ABSTRACT: model for accessing the git repositories | ||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | 33 | ▶ | sub repository { | ||||||||||||||||||||||||||||||
|
Subroutine
repository: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 22 | 33 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||
| 23 | 33 | $self->app->model('Repository', { name => $name }) | |||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub list_repositories { | ||||||||||||||||||||||||||||||
|
Subroutine
list_repositories: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 28 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | 0 | my @repos; | |||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | 0 | my $masters = $self->app->settings->repositories; | |||||||||||||||||||||||||||||||
| 33 | 0 | for my $name (keys %$masters) { | |||||||||||||||||||||||||||||||
| 34 | 0 | push @repos, $self->repository($name); | |||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | 0 | my $repo_dir = $self->locate('repo_path'); | |||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | return @repos unless $repo_dir->is_dir; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | 0 | for my $config ($repo_dir->children) { | |||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | next if $config->basename =~ /^\./; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 42 | 0 | push @repos, $self->repository($config->basename); | |||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | 0 | return @repos; | |||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | sub attach_repository { | ||||||||||||||||||||||||||||||
|
Subroutine
attach_repository: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 50 | 0 | my ($self, %opt) = @_; | |||||||||||||||||||||||||||||||
| 51 | my $key = delete $opt{key} | ||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | // http_throw "missing key in attach_repository"; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
delete $opt{"key"} // http_throw("missing key in attach_repository")
MC/DC0%0/2
delete $opt{"key"} // http_throw("missing key in attach_repository")
delete $opt{"key"}
http_throw("missing key in attach_repository")
Truth table0%0/3
A // B
A= delete $opt{"key"}B= http_throw("missing key in attach_repository")
| |||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | 0 | my $repo = Yukki::Settings::Repository->new(\%opt); | |||||||||||||||||||||||||||||||
| 55 | 0 | my $repo_file = $self->locate('repo_path', $key); | |||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if ($self->app->settings->repositories->{$key}) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 58 | 0 | http_throw "repository with key '$key' is already defined in the master configuraiton file, cannot attach it again"; | |||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||
| 60 | elsif (-e $self->locate('repo_path', $key)) { | ||||||||||||||||||||||||||||||||
| 61 | 0 | http_throw "repository with key '$key' is already configured, cannot attach it again"; | |||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | 0 | $repo_file->parent->mkpath; | |||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | $repo_file->chmod(0600) if $repo_file->exists; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 66 | 0 | $repo_file->spew_utf8($repo->dump_yaml); | |||||||||||||||||||||||||||||||
| 67 | 0 | $repo_file->chmod(0400); | |||||||||||||||||||||||||||||||
| 68 | 0 | return; | |||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub detach_repository { | ||||||||||||||||||||||||||||||
|
Subroutine
detach_repository: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 73 | 0 | my ($self, %opt) = @_; | |||||||||||||||||||||||||||||||
| 74 | my $key = delete $opt{key} | ||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | // http_throw "missing key in detach_repository"; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
delete $opt{"key"} // http_throw("missing key in detach_repository")
MC/DC0%0/2
delete $opt{"key"} // http_throw("missing key in detach_repository")
delete $opt{"key"}
http_throw("missing key in detach_repository")
Truth table0%0/3
A // B
A= delete $opt{"key"}B= http_throw("missing key in detach_repository")
| |||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | 0 | my $repo = $self->repository($key); | |||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | http_throw "no repository named '$key' found" | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 80 | unless $repo; | ||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | http_throw "cannot detach repository in master configuration" | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 83 | if $repo->is_master_repository; | ||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | 0 | my $repo_config = $self->locate('repo_path', $key); | |||||||||||||||||||||||||||||||
| 86 | 0 | $repo_config->chmod(0600); | |||||||||||||||||||||||||||||||
| 87 | 0 | $repo_config->remove; | |||||||||||||||||||||||||||||||
| 88 | 0 | return; | |||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | 5 | ▶ | sub init_repository { | ||||||||||||||||||||||||||||||
|
Subroutine
init_repository: called CC=6 SCAR=21.5
Pod
documented
| |||||||||||||||||||||||||||||||||
| 93 | 5 | my ($self, $opt) | |||||||||||||||||||||||||||||||
| 94 | = validate(\@_, class_type(__PACKAGE__), | ||||||||||||||||||||||||||||||||
| 95 | slurpy Dict[ | ||||||||||||||||||||||||||||||||
| 96 | key => Str, | ||||||||||||||||||||||||||||||||
| 97 | origin => Optional[Maybe[Uri]], | ||||||||||||||||||||||||||||||||
| 98 | init_from_settings => Optional[Maybe[Bool]], | ||||||||||||||||||||||||||||||||
| 99 | ], | ||||||||||||||||||||||||||||||||
| 100 | ); | ||||||||||||||||||||||||||||||||
| 101 | 5 | my ($key, $origin, $init_from_settings) = @{$opt}{qw( | |||||||||||||||||||||||||||||||
| 102 | key origin init_from_settings | ||||||||||||||||||||||||||||||||
| 103 | )}; | ||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||
| 105 | 5 | my $repo_config = $self->app->settings->repositories->{$key}; | |||||||||||||||||||||||||||||||
| 106 | 5 | ▶ | if ($repo_config && !$init_from_settings) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$repo_config and not $init_from_settings
MC/DC0%0/2
$repo_config and not $init_from_settings
$repo_config
not $init_from_settings
Truth table33%1/3
A and not(B)
A= $repo_configB= not $init_from_settings
| |||||||||||||||||||||||||||||||||
| 107 | 0 | http_throw "unable to initialize repository '$key' found in settings, please use the command-line tools"; | |||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | elsif (!$repo_config) { | ||||||||||||||||||||||||||||||||
| 111 | 0 | my $repo_file = $self->locate('repo_path', $key); | |||||||||||||||||||||||||||||||
| 112 | 0 | $repo_config = Yukki::Settings::Repository->load_yaml( | |||||||||||||||||||||||||||||||
| 113 | $repo_file->slurp_utf8 | ||||||||||||||||||||||||||||||||
| 114 | ); | ||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | 5 | ▶ | http_throw "repository '$key' not yet attached" if !$repo_config; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||
| 119 | 5 | my $repository = $self->repository($key); | |||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | 5 | ▶ | if ($origin) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 122 | 0 | $repository->clone_repository($origin); | |||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||
| 124 | else { | ||||||||||||||||||||||||||||||||
| 125 | 5 | $repository->initialize_repository; | |||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | sub kill_repository { | ||||||||||||||||||||||||||||||
|
Subroutine
kill_repository: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 131 | 0 | my ($self, $opt) | |||||||||||||||||||||||||||||||
| 132 | = validate(\@_, class_type(__PACKAGE__), | ||||||||||||||||||||||||||||||||
| 133 | slurpy Dict[ | ||||||||||||||||||||||||||||||||
| 134 | key => Str, | ||||||||||||||||||||||||||||||||
| 135 | ] | ||||||||||||||||||||||||||||||||
| 136 | ); | ||||||||||||||||||||||||||||||||
| 137 | 0 | my $key = $opt->{key}; | |||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||
| 139 | 0 | my $repo_config = $self->app->settings->repositories->{$key}; | |||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | if ($repo_config) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 141 | 0 | http_throw "unable to kill repository '$key' found in settings, please use the command-line"; | |||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | elsif (!$repo_config) { | ||||||||||||||||||||||||||||||||
| 145 | 0 | my $repo_file = $self->locate('repo_path', $key); | |||||||||||||||||||||||||||||||
| 146 | 0 | $repo_config = Yukki::Settings::Repository->load_yaml( | |||||||||||||||||||||||||||||||
| 147 | $repo_file->slurp_utf8 | ||||||||||||||||||||||||||||||||
| 148 | ); | ||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | http_throw "repository '$key' not yet attached" if !$repo_config; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||
| 153 | 0 | my $repository = $self->repository($key); | |||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||
| 155 | 0 | my $git_dir = $repository->repository_path; | |||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | http_throw "repository '$key' has no git repository" | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 157 | unless $git_dir->is_dir; | ||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||
| 159 | 0 | $git_dir->remove_tree({ safe => 0 }); | |||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||
| 161 | 0 | return; | |||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||
| 164 | 6 | 1; | |||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||
| 166 | __END__ | ||||||||||||||||||||||||||||||||