| 1 | package Dist::Zilla::Plugin::DBIO::CodebergMeta; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Add Codeberg (or a Forgejo instance via host=) repository metadata to META.{json,yml} | ||||||||||||||||||||||||||||
| 3 | 6 | our $VERSION = '0.900004'; | |||||||||||||||||||||||||||
| 4 | 6 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 6 | with 'Dist::Zilla::Role::MetaProvider'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 6 | has remote => ( | |||||||||||||||||||||||||||
| 10 | is => 'ro', | ||||||||||||||||||||||||||||
| 11 | isa => 'Str', | ||||||||||||||||||||||||||||
| 12 | default => 'origin', | ||||||||||||||||||||||||||||
| 13 | ); | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 6 | has host => ( | |||||||||||||||||||||||||||
| 17 | is => 'ro', | ||||||||||||||||||||||||||||
| 18 | isa => 'Str', | ||||||||||||||||||||||||||||
| 19 | default => 'codeberg.org', | ||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 6 | has repo => ( | |||||||||||||||||||||||||||
| 24 | is => 'ro', | ||||||||||||||||||||||||||||
| 25 | isa => 'Maybe[Str]', | ||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 6 | has issues => ( | |||||||||||||||||||||||||||
| 30 | is => 'ro', | ||||||||||||||||||||||||||||
| 31 | isa => 'Bool', | ||||||||||||||||||||||||||||
| 32 | default => 1, | ||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 6 | has homepage => ( | |||||||||||||||||||||||||||
| 37 | is => 'ro', | ||||||||||||||||||||||||||||
| 38 | isa => 'Str', | ||||||||||||||||||||||||||||
| 39 | default => 'repo', | ||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 6 | has _remote_info => ( | |||||||||||||||||||||||||||
| 43 | is => 'ro', | ||||||||||||||||||||||||||||
| 44 | isa => 'Maybe[HashRef]', | ||||||||||||||||||||||||||||
| 45 | lazy => 1, | ||||||||||||||||||||||||||||
| 46 | builder => '_build_remote_info', | ||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | sub _build_remote_info { | ||||||||||||||||||||||||||
|
Subroutine
_build_remote_info: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 50 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 51 | 0 | my $remote = $self->remote; | |||||||||||||||||||||||||||
| 52 | 0 | ▶ | chomp(my $url = `git config --get remote.$remote.url 2>/dev/null` // ''); | ||||||||||||||||||||||||||
|
Condition0%0/2
`git config --get remote.$remote.url 2>/dev/null` // ""
MC/DC0%0/1
`git config --get remote.$remote.url 2>/dev/null` // ""
`git config --get remote.$remote.url 2>/dev/null`
Truth table0%0/2
A
A= `git config --get remote.$remote.url 2>/dev/null`
| |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | return undef unless length $url; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | return $self->_parse_remote_url($url); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # Parse a git remote URL into { host => ..., slug => 'owner/repo' }, or undef. | ||||||||||||||||||||||||||||
| 58 | # Pure helper (no git), kept separate so the regex can be unit-tested. | ||||||||||||||||||||||||||||
| 59 | 7 | ▶ | sub _parse_remote_url { | ||||||||||||||||||||||||||
|
Subroutine
_parse_remote_url: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 60 | 7 | my ($self, $url) = @_; | |||||||||||||||||||||||||||
| 61 | # git@host:owner/repo.git | https://host/owner/repo(.git) | ssh://git@host/owner/repo.git | ||||||||||||||||||||||||||||
| 62 | 7 | my ($host, $slug) = $url =~ m{ | |||||||||||||||||||||||||||
| 63 | (?: ^ \w+ :// (?: [^/\@]+ \@ )? | ^ [^/\@]+ \@ ) # scheme[//user@] or user@ | ||||||||||||||||||||||||||||
| 64 | ( [^/:]+ ) # host | ||||||||||||||||||||||||||||
| 65 | [:/]+ | ||||||||||||||||||||||||||||
| 66 | ( .+? ) # owner/repo... | ||||||||||||||||||||||||||||
| 67 | (?: \.git )? /? $ | ||||||||||||||||||||||||||||
| 68 | }x; | ||||||||||||||||||||||||||||
| 69 | 7 | ▶ | return undef unless $host && $slug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$host and $slug
MC/DC50%1/2
$host and $slug
$host
$slug
Truth table66%2/3
A and B
A= $hostB= $slug
| |||||||||||||||||||||||||||||
| 70 | 6 | return { host => $host, slug => $slug }; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # Resolve the owner/repo slug for $self->host. An explicit repo= override is | ||||||||||||||||||||||||||||
| 74 | # trusted; otherwise the git remote must point at the expected host. Returns | ||||||||||||||||||||||||||||
| 75 | # undef (no usable target) if there is no remote or it points elsewhere. | ||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub _slug { | ||||||||||||||||||||||||||
|
Subroutine
_slug: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 77 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 78 | 0 | ▶ | return $self->repo if defined $self->repo && length $self->repo; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->repo and length $self->repo
MC/DC0%0/2
defined $self->repo and length $self->repo
defined $self->repo
length $self->repo
Truth table0%0/3
A and B
A= defined $self->repoB= length $self->repo
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | my $info = $self->_remote_info or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | return undef unless $info->{host} eq $self->host; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | return $info->{slug}; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub metadata { | ||||||||||||||||||||||||||
|
Subroutine
metadata: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 86 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | my $slug = $self->_slug; | |||||||||||||||||||||||||||
| 89 | 0 | ▶ | unless (defined $slug) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | $self->log_debug('no meta target found -- skipping repository metadata'); | |||||||||||||||||||||||||||
| 91 | 0 | return {}; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | return { | ||||||||||||||||||||||||||||
| 95 | 0 | resources => $self->_build_resources( | |||||||||||||||||||||||||||
| 96 | host => $self->host, | ||||||||||||||||||||||||||||
| 97 | slug => $slug, | ||||||||||||||||||||||||||||
| 98 | issues => $self->issues, | ||||||||||||||||||||||||||||
| 99 | homepage => $self->homepage, | ||||||||||||||||||||||||||||
| 100 | dist_name => $self->zilla->name, | ||||||||||||||||||||||||||||
| 101 | ), | ||||||||||||||||||||||||||||
| 102 | }; | ||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | # Pure assembly of the resources hashref. Kept free of zilla/git so it can be | ||||||||||||||||||||||||||||
| 106 | # unit-tested as a class method. | ||||||||||||||||||||||||||||
| 107 | 4 | ▶ | sub _build_resources { | ||||||||||||||||||||||||||
|
Subroutine
_build_resources: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 108 | 4 | my ($self, %a) = @_; | |||||||||||||||||||||||||||
| 109 | 4 | my $web = "https://$a{host}/$a{slug}"; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 4 | my %resources = ( | |||||||||||||||||||||||||||
| 112 | repository => { | ||||||||||||||||||||||||||||
| 113 | type => 'git', | ||||||||||||||||||||||||||||
| 114 | url => "$web.git", | ||||||||||||||||||||||||||||
| 115 | web => $web, | ||||||||||||||||||||||||||||
| 116 | }, | ||||||||||||||||||||||||||||
| 117 | ); | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 4 | ▶ | $resources{bugtracker} = { web => "$web/issues" } if $a{issues}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 4 | ▶ | if ($a{homepage} eq 'repo') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 122 | 2 | $resources{homepage} = $web; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | elsif ($a{homepage} eq 'metacpan') { | ||||||||||||||||||||||||||||
| 125 | 1 | $resources{homepage} = "https://metacpan.org/release/$a{dist_name}"; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | # 'none' -> leave homepage unset | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 4 | return \%resources; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 6 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 133 | 6 | ▶ | no Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 134 | 6 | 1; | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | __END__ | ||||||||||||||||||||||||||||