Plugin/Codeberg/Meta.pm

filter: Statementstmt 89.3% 59 / 66 Branchbran 76.9% 20 / 26 Conditioncond 77.7% 14 / 18 MC/DCmcdc 60.0% 6 / 10 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 81.8% 104 / 127 CC 20 SCAR 27.4
CC
20
Cov
85%
metadata
19.6
__ANON__
6.0
BEGIN
1.0
CRAP 15.5
« Plugin/Codeberg/Create.pm ↑ Summary Plugin/Codeberg/Update.pm »
1 package Dist::Zilla::Plugin::Codeberg::Meta 2.0102;
2  
3 3 ▶use Modern::Perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use URL::Encode qw(url_encode_utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 our $AUTHORITY = 'cpan:GEEKRUTH'; # AUTHORITY
9  
10 3 extends 'Dist::Zilla::Plugin::Codeberg';
11 3 with 'Dist::Zilla::Role::MetaProvider';
12  
13 3 has bugs => (
14 is => 'ro',
15 isa => 'Bool',
16 default => 1,
17 );
18  
19 3 has fork => (
20 is => 'ro',
21 isa => 'Bool',
22 default => 1,
23 );
24  
25 3 has wiki => (
26 is => 'ro',
27 isa => 'Bool',
28 default => 0,
29 );
30  
31 3 has p3rl => (
32 is => 'ro',
33 isa => 'Bool',
34 default => 0,
35 );
36  
37 3 has metacpan => (
38 is => 'ro',
39 isa => 'Bool',
40 default => 1,
41 );
42  
43 3 has meta_home => (
44 is => 'ro',
45 isa => 'Bool',
46 default => 0,
47 );
48  
49 0 ▶around dump_config => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
50 0 my ( $orig, $self ) = @_;
51 0 my $config = $self->$orig;
52  
53 0 my $option = first { $self->$_ } qw(meta_home metacpan p3rl);
54 0 ▶ $config->{ +__PACKAGE__ } = { $option => ( $self->$option ? 1 : 0 ), };
Branch: 1 branch
BranchTrueFalseTotal
$self->$option ? : 0 0 0
55 0 return $config;
56 3 };
57  
58 5 ▶sub metadata {
Subroutine metadata: called CC=19 SCAR=29.7
Pod undocumented
59 5 my $self = shift;
60 5 my $offline = 0;
61  
62 5 my $repo_name = $self->_get_repo_name;
63 5 ▶ return {} if ( !$repo_name );
Branch: 1 branch
BranchTrueFalseTotal
unless $repo_name 0 5 5
64 5 my $encoded_repo = $repo_name; # url_encode_utf8($repo_name);
65 5 my $http = HTTP::Tiny->new;
66  
67 5 $self->log('Getting Codeberg repository info');
68  
69 5 my $url = $self->api . "/repos/$encoded_repo";
70 5 $self->log_debug("Sending GET $url");
71 5 my $response
72 = $http->request( 'GET', $url, { headers => $self->_auth_headers } );
73  
74 5 my $repo = $self->_check_response($response);
75 5 ▶ $offline = 1 if not $repo;
Branch: 1 branch
BranchTrueFalseTotal
unless $repo 1 4 5
76  
77 5 ▶ $self->log('Using offline repository information') if $offline;
Branch: 1 branch
BranchTrueFalseTotal
if $offline 1 4 5
78  
79 5 ▶ if ( !$offline && $self->fork && defined $repo->{forked_from_project} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $offline and $self->fork and defined $repo->{"forked_from_project"}) 1 4 5
Condition83%5/6
not $offline and $self->fork and defined $repo->{"forked_from_project"}
!ll&&!rl&&r
131
not $offline and $self->fork
!ll&&!rl&&r
104
MC/DC66%2/3
not $offline and $self->fork and defined $repo->{"forked_from_project"}
not $offline $self->fork defined $repo->{"forked_from_project"}
Truth table75%3/4
not(A) and B and C
A= not $offlineB= $self->forkC= defined $repo->{"forked_from_project"}
ABCresult
0XX0
10X0
1100
1111
80 1 my $parent = $repo->{forked_from_project}{path_with_namespace};
81 1 $url = $self->api . '/repos/' . url_encode_utf8($parent);
82 1 $response = $http->request( 'GET', $url );
83  
84 1 $repo = $self->_check_response($response);
85 1 ▶ return if not $repo;
Branch: 1 branch
BranchTrueFalseTotal
unless $repo 0 1 1
86 }
87  
88 5 my ( $html_url, $git_url, $bugtracker );
89  
90 $html_url
91 = $offline
92 ? "https://codeberg.org/$repo_name"
93 5 ▶ : $repo->{html_url};
Branch: 1 branch
BranchTrueFalseTotal
$offline ? : 1 4 5
94  
95 $git_url
96 = $offline
97 ? "git://git\@codeberg.org/$repo_name.git"
98 5 ▶ : $repo->{ssh_url};
Branch: 1 branch
BranchTrueFalseTotal
$offline ? : 1 4 5
99  
100 5 ▶ if ( !$offline && $repo->{has_issues} == JSON->true() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $offline and $repo->{"has_issues"} == &JSON()->true) 3 2 5
Condition100%3/3
not $offline and $repo->{"has_issues"} == &JSON()->true
!ll&&!rl&&r
113
MC/DC100%2/2
not $offline and $repo->{"has_issues"} == &JSON()->true
not $offline $repo->{"has_issues"} == &JSON()->true
Truth table100%3/3
not(A) and B
A= not $offlineB= $repo->{"has_issues"} == &JSON()->true
ABresult
0X0
100
111
101 3 $bugtracker = "$html_url/issues";
102 }
103  
104 5 my $meta;
105 $meta->{resources} = {
106 5 repository => {
107 web => $html_url,
108 url => $git_url,
109 type => 'git'
110 }
111 };
112  
113 5 my $dist_name = $self->zilla->name;
114 5 ▶ if ( $self->meta_home
Branch: 3 branches
BranchTrueFalseTotal
if ($self->meta_home and my $meta_home = $self->zilla->distmeta->{'resources'}{'homepage'}) { } 0 5 5
elsif ($self->metacpan) { } 4 1 5
elsif ($self->p3rl) { } 1 0 1
Condition33%1/3
$self->meta_home and my $meta_home = $self->zilla->distmeta->{"resources"}{"homepage"}
!ll&&!rl&&r
500
MC/DC0%0/2
$self->meta_home and my $meta_home = $self->zilla->distmeta->{"resources"}{"homepage"}
$self->meta_home my $meta_home = $self->zilla->distmeta->{"resources"}{"homepage"}
Truth table33%1/3
A and B
A= $self->meta_homeB= my $meta_home = $self->zilla->distmeta->{"resources"}{"homepage"}
ABresult
0X0
100
111
115 && ( my $meta_home = $self->zilla->distmeta->{resources}{homepage} ) ) {
116 0 $meta->{resources}{homepage} = $meta_home;
117 }
118 elsif ( $self->metacpan ) {
119 $meta->{resources}{homepage}
120 4 = "https://metacpan.org/release/$dist_name/";
121 }
122 elsif ( $self->p3rl ) {
123 1 my $guess_name = $dist_name;
124 1 $guess_name =~ s/\-/\:\:/g;
125 1 $meta->{resources}{homepage} = "https://p3rl.org/$guess_name";
126 }
127  
128 5 ▶ if ( $self->bugs && $self->bugs == 1 && $bugtracker ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->bugs and $self->bugs == 1 and $bugtracker) 2 3 5
Condition83%5/6
$self->bugs and $self->bugs == 1 and $bugtracker
!ll&&!rl&&r
122
$self->bugs and $self->bugs == 1
!ll&&!rl&&r
104
MC/DC66%2/3
$self->bugs and $self->bugs == 1 and $bugtracker
$self->bugs $self->bugs == 1 $bugtracker
Truth table75%3/4
A and B and C
A= $self->bugsB= $self->bugs == 1C= $bugtracker
ABCresult
0XX0
10X0
1100
1111
129 2 $meta->{resources}{bugtracker} = { web => $bugtracker };
130 }
131  
132 5 return $meta;
133 }
134  
135 3 __PACKAGE__->meta->make_immutable;
136  
137 3 1;
138  
139 =pod
140  
141 =encoding UTF-8
142  
143 =head1 NAME
144  
145 Dist::Zilla::Plugin::Codeberg::Meta - Add a Codeberg repo's info to META.{yml,json}
146  
147 =head1 VERSION
148  
149 version 2.0102
150  
151 =head1 SYNOPSIS
152  
153 Configure git with your Codeberg login name:
154  
155 $ git config --global codeberg.user LoginName
156 $ git config --global codeberg.token AccessToken
157  
158 Set up an access token on Codeberg, in your profile under "Personal Access Tokens." You
159 must grant the token the C<api> scope!
160  
161 then, in your F<dist.ini>:
162  
163 # default config
164 [Codeberg::Meta]
165  
166 # to override the repo name
167 [Codeberg::Meta]
168 repo = SomeRepo
169  
170 See L</ATTRIBUTES> for more options.
171  
172 =head1 DESCRIPTION
173  
174 This Dist::Zilla plugin adds some information about the distribution's Codeberg
175 repository to the META.{yml,json} files, using the official L<CPAN::Meta>
176 specification.
177  
178 Note that, to work properly, L<Codeberg::Meta> needs the network to connect to
179 Codeberg itself. If the network is not available, it will try to come up with
180 sensible data, but it may be inaccurate.
181  
182 L<Codeberg::Meta> currently sets the following fields:
183  
184 =over 4
185  
186 =item C<homepage>
187  
188 The official home of this project on the web.
189  
190 =item C<repository>
191  
192 =over 4
193  
194 =item C<web>
195  
196 URL pointing to the Codeberg page of the project.
197  
198 =item C<url>
199  
200 URL pointing to the Codeberg repository (C<git://...>).
201  
202 =item C<type>
203  
204 This is set to C<git> by default.
205  
206 =back
207  
208 =item C<bugtracker>
209  
210 =over 4
211  
212 =item C<web>
213  
214 URL pointing to the Codeberg issues page of the project. If the C<bugs> option is
215 set to false (default is true) or the issues are disabled in the Codeberg
216 repository, this will be skipped.
217  
218 When offline, this is not set.
219  
220 =back
221  
222 =back
223  
224 =head1 ATTRIBUTES
225  
226 =over
227  
228 =item C<bugs>
229  
230 The META bugtracker web field will be set to the issue's page of the repository
231 on Codeberg, if this option is set to true (default) and if the Codeberg Issues happen to
232 be activated (see the Codeberg repository's C<General> settings panel).
233  
234 =item C<fork>
235  
236 If the repository is a Codeberg fork of another repository this option will make
237 all the information be taken from the original repository instead of the forked
238 one, if it's set to true (default).
239  
240 =item C<metacpan>
241  
242 The Codeberg homepage field will be set to the metacpan.org distribution URL
243 (e.g. C<https://metacpan.org/release/Dist-Zilla-Plugin-Codeberg>) if this option is set to true
244 (default).
245  
246 This takes precedence over the C<p3rl> options (if both are
247 true, metacpan will be used).
248  
249 =item C<meta_home>
250  
251 The Codeberg homepage field will be set to the value present in the dist meta
252 (e.g. the one set by other plugins) if this option is set to true (default is
253 false). If no value is present in the dist meta, this option is ignored.
254  
255 This takes precedence over the C<metacpan> and C<p3rl> options (if all
256 three are true, meta_home will be used).
257  
258 =item C<p3rl>
259  
260 The Codeberg homepage field will be set to the p3rl.org shortened URL
261 (e.g. C<https://p3rl.org/Dist::Zilla::Plugin::Codeberg>) if this option is set to true (default is
262 false).
263  
264 =item C<remote>
265  
266 Specifies the git remote name to be used when guessing the repo name (default C<origin>).
267  
268 =item C<repo>
269  
270 The name of the Codeberg repository. By default the name will be extracted from
271 the URL of the remote specified in the C<remote> option, and if that fails the
272 dist name (from dist.ini) is used. It can also be in the form C<user/repo>
273 when it belongs to another Codeberg user/organization.
274  
275 =item C<wiki>
276  
277 The META homepage field will be set to the URL of the wiki of the Codeberg
278 repository, if this option is set to true (default is false) and if the Codeberg
279 Wiki happens to be activated (see the Codeberg repository's C<Admin> panel).
280  
281 =back
282  
283 =head1 AUTHOR
284  
285 D Ruth Holloway <ruth@hiruthie.me>
286  
287 =head1 COPYRIGHT AND LICENSE
288  
289 This software is copyright (c) 2026 by D Ruth Holloway.
290  
291 This is free software; you can redistribute it and/or modify it under
292 the same terms as the Perl 5 programming language system itself.
293  
294 =cut
295  
296 __END__
« Plugin/Codeberg/Create.pm ↑ Summary Plugin/Codeberg/Update.pm »