Plugin/Codeberg.pm

filter: Statementstmt 50.0% 46 / 92 Branchbran 10.0% 3 / 30 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 73.3% 11 / 15 Podpod n/a totaltotal 41.1% 60 / 146 CC 18 SCAR 29.0
CC
18
Cov
38%
_get_repo_name
42.0
_build_login
30.0
_build_credentials
20.0
CRAP 18.1
↑ Summary Plugin/Codeberg/Create.pm »
1 package Dist::Zilla::Plugin::Codeberg 2.0102;
2  
3 10 ▶use Modern::Perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 10 ▶use Git::Wrapper;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 ▶use Class::Load qw(try_load_class);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 10 our $AUTHORITY = 'cpan:GEEKRUTH'; # AUTHORITY
12 10 has api => (
13 is => 'ro',
14 isa => 'Str',
15 default => 'https://codeberg.org/api/v1',
16 );
17  
18 10 has remote => (
19 is => 'ro',
20 isa => 'Maybe[Str]',
21 default => 'origin',
22 );
23  
24 10 has repo => (
25 is => 'ro',
26 isa => 'Maybe[Str]',
27 );
28  
29 10 has _credentials => (
30 is => 'ro',
31 isa => 'HashRef',
32 lazy => 1,
33 builder => '_build_credentials',
34 );
35  
36 10 has _login => (
37 is => 'ro',
38 isa => 'Maybe[Str]',
39 lazy => 1,
40 builder => '_build_login',
41 );
42  
43 0 ▶sub _build_login {
Subroutine _build_login: not called CC=5 SCAR=34.0
44 0 my $self = shift;
45  
46 0 my ( $login, %identity );
47  
48 0 ▶ %identity = Config::Identity::Codeberg->load
Branch: 1 branch
BranchTrueFalseTotal
if try_load_class("Config::Identity::Codeberg") 0 0 0
49 if try_load_class('Config::Identity::Codeberg');
50  
51 0 ▶ if (%identity) {
Branch: 1 branch
BranchTrueFalseTotal
if (%identity) { } 0 0 0
52 0 $login = $identity{login};
53 }
54 else {
55 0 $login = qx{git config codeberg.user};
56 0 chomp $login;
57 }
58  
59 0 ▶ if ( !$login ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($login) 0 0 0
60 0 ▶ my $error
Branch: 1 branch
BranchTrueFalseTotal
%identity ? : 0 0 0
61 = %identity
62 ? 'Err: missing value \'user\' in ~/.codeberg'
63 : 'Err: Missing value \'codeberg.user\' in git config';
64  
65 0 $self->log($error);
66 0 return undef;
67 }
68  
69 0 return $login;
70 }
71  
72 0 ▶sub _build_credentials {
Subroutine _build_credentials: not called CC=4 SCAR=30.0
73 0 my $self = shift;
74  
75 0 my ( $login, $token );
76  
77 0 $login = $self->_login;
78  
79 0 ▶ if ( !$login ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($login) 0 0 0
80 0 return {};
81 }
82 0 my %identity;
83 0 ▶ %identity = Config::Identity::Codeberg->load
Branch: 1 branch
BranchTrueFalseTotal
if try_load_class("Config::Identity::Codeberg") 0 0 0
84 if try_load_class('Config::Identity::Codeberg');
85  
86 0 ▶ if (%identity) {
Branch: 1 branch
BranchTrueFalseTotal
if (%identity) { } 0 0 0
87 0 $token = $identity{token};
88 }
89 else {
90 0 $token = qx{git config codeberg.token};
91 0 chomp $token;
92 }
93  
94 0 return { login => $login, token => $token };
95 }
96  
97 2 ▶sub _has_credentials {
Subroutine _has_credentials: called CC=1 SCAR=0.0
98 2 my $self = shift;
99 2 return keys %{ $self->_credentials };
100 }
101  
102 10 ▶sub _auth_headers {
Subroutine _auth_headers: called CC=2 SCAR=7.0
103 10 my $self = shift;
104  
105 10 my $credentials = $self->_credentials;
106 10 my %headers = ();
107 10 ▶ if ( $credentials->{token} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($credentials->{"token"}) 10 0 10
108 10 $headers{'Authorization'} = 'token ' . $credentials->{token};
109 }
110  
111 10 return \%headers;
112 }
113  
114 0 ▶sub _get_repo_name {
Subroutine _get_repo_name: not called CC=6 SCAR=37.4
115 0 my ( $self, $login ) = @_;
116  
117 0 my $repo;
118 0 my $git = Git::Wrapper->new('./');
119  
120 0 ▶ $repo = $self->repo if $self->repo;
Branch: 1 branch
BranchTrueFalseTotal
if $self->repo 0 0 0
121  
122 0 my $url;
123 {
124 0 local $ENV{LANG} = 'C';
125 0 ($url) = map /Fetch URL: (.*)/,
126 $git->remote( 'show', '-n', $self->remote );
127 }
128 0 ▶ if ( !$repo ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($repo) 0 0 0
129 0 ($repo) = $url =~ /codeberg\.org.*?[:\/](.*)\.git$/;
130 }
131  
132 0 ▶ $repo = $self->zilla->name unless $repo;
Branch: 1 branch
BranchTrueFalseTotal
unless $repo 0 0 0
133  
134 0 ▶ if ( $repo !~ /.*\/.*/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($repo =~ m[.*/.*]u) 0 0 0
135 0 $login = $self->_login;
136 0 ▶ if ( defined $login ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $login) 0 0 0
137 0 $repo = "$login/$repo";
138 }
139 }
140  
141 0 return $repo;
142 }
143  
144 14 ▶sub _check_response {
Subroutine _check_response: called CC=1 SCAR=1.8
145 14 my ( $self, $response ) = @_;
146  
147 14 ▶ try {
Subroutine __ANON__: called CC=2 SCAR=6.9
148 14 my $json_text = decode_json( $response->{content} );
149  
150 14 ▶ if ( !$response->{success} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->{"success"}) 1 13 14
151  
152 1 require Data::Dumper;
153 1 $self->log(
154 'Err: ',
155 Data::Dumper->new( [$response] )
156 ->Indent(2)
157 ->Terse(1)
158 ->Sortkeys(1)
159 ->Dump
160 );
161 1 return;
162 }
163  
164 13 return $json_text;
165 }
166 0 ▶ catch {
Subroutine __ANON__: not called CC=4 SCAR=30.0
167 0 $self->log("Error: $_");
168 0 ▶ if ( $response
Branch: 1 branch
BranchTrueFalseTotal
if ($response and not $response->{"success"} and $response->{"status"} eq 599) 0 0 0
Condition0%0/6
$response and not $response->{"success"} and $response->{"status"} eq 599
!ll&&!rl&&r
000
$response and not $response->{"success"}
!ll&&!rl&&r
000
MC/DC0%0/3
$response and not $response->{"success"} and $response->{"status"} eq 599
$response not $response->{"success"} $response->{"status"} eq 599
Truth table0%0/4
A and not(B) and C
A= $responseB= not $response->{"success"}C= $response->{"status"} eq 599
ABCresult
0XX0
10X0
1100
1111
169 && !$response->{success}
170 && $response->{status} eq '599' ) {
171  
172 #possibly HTTP::Tiny error
173 0 $self->log( 'Err: ', $response->{content} );
174 0 return;
175 }
176  
177 0 $self->log("Error communicating with Codeberg: $_");
178  
179 0 return;
180 14 };
181 }
182  
183 10 __PACKAGE__->meta->make_immutable;
184  
185 10 1;
186  
187 =pod
188  
189 =encoding UTF-8
190  
191 =head1 NAME
192  
193 Dist::Zilla::Plugin::Codeberg - Plugins to integrate Dist::Zilla with Codeberg
194  
195 =head1 VERSION
196  
197 version 2.0102
198  
199 =head1 DESCRIPTION
200  
201 B<Dist-Zilla-Plugin-Codeberg> is a set of plugins for L<Dist::Zilla> intended
202 to more easily integrate L<Codeberg|https://codeberg.org> in the C<dzil> workflow.
203  
204 The following is the list of the plugins shipped in this distribution:
205  
206 =over 4
207  
208 =item * L<Dist::Zilla::Plugin::Codeberg::Create> Create Codeberg repo on C<dzil new>
209  
210 =item * L<Dist::Zilla::Plugin::Codeberg::Update> Update Codeberg repo info on release
211  
212 =item * L<Dist::Zilla::Plugin::Codeberg::Meta> Add Codeberg repo info to F<META.{yml,json}>
213  
214 =back
215  
216 This distribution also provides a plugin bundle, L<Dist::Zilla::PluginBundle::Codeberg>,
217 which provides L<Codeberg::Meta|Dist::Zilla::Plugin::Codeberg::Meta> and
218 L<Codeberg::Update|Dist::Zilla::Plugin::Codeberg::Update> together in one convenient bundle.
219  
220 This distribution also provides an additional C<dzil> command (L<dzil
221 codeberg|Dist::Zilla::App::Command::codeberg>).
222  
223 =head1 AUTHOR
224  
225 D Ruth Holloway <ruth@hiruthie.me>
226  
227 =head1 COPYRIGHT AND LICENSE
228  
229 This software is copyright (c) 2026 by D Ruth Holloway.
230  
231 This is free software; you can redistribute it and/or modify it under
232 the same terms as the Perl 5 programming language system itself.
233  
234 =cut
235  
236 __END__
↑ Summary Plugin/Codeberg/Create.pm »