Plugin/GitLab.pm

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