Plugin/GitLab/Meta.pm

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