line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package GitLab::API::v3::RESTClient; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
GitLab::API::v3::RESTClient - GitLab API v3 REST client. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head2 DESCRIPTION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
This module provides the actual REST communication with the GitLab |
10
|
|
|
|
|
|
|
server and is powered by L<Role::REST::Client>. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
The various HTTP verb methods are wrapped so that they throw an |
13
|
|
|
|
|
|
|
exception if an unexpected response is received, except for GET |
14
|
|
|
|
|
|
|
requests that respond with a 404 code; these return C<undef> |
15
|
|
|
|
|
|
|
instead. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
If the request was successful then the response data is returned |
18
|
|
|
|
|
|
|
rather than the response object itself. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
8
|
use Carp qw( confess ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
65
|
|
23
|
1
|
|
|
1
|
|
6
|
use Data::Dumper qw(); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
16
|
|
24
|
1
|
|
|
1
|
|
453
|
use Role::REST::Client::Response; |
|
1
|
|
|
|
|
52697
|
|
|
1
|
|
|
|
|
36
|
|
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
1
|
|
8
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
27
|
1
|
|
|
1
|
|
313
|
use Try::Tiny; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
69
|
|
28
|
1
|
|
|
1
|
|
6
|
use strictures 1; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
38
|
|
29
|
1
|
|
|
1
|
|
592
|
use namespace::clean; |
|
1
|
|
|
|
|
9418
|
|
|
1
|
|
|
|
|
10
|
|
30
|
1
|
|
|
1
|
|
334
|
use Log::Any qw( $log ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
10
|
|
31
|
1
|
|
|
1
|
|
874
|
use Types::Standard qw( Int ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
11
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has retries => ( |
34
|
|
|
|
|
|
|
is => 'ro', |
35
|
|
|
|
|
|
|
isa => Int, |
36
|
|
|
|
|
|
|
default => 0, |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
with 'Role::REST::Client'; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
foreach my $method (qw( post get head put delete options )) { |
42
|
|
|
|
|
|
|
around $method => sub{ |
43
|
|
|
|
|
|
|
my $orig = shift; |
44
|
|
|
|
|
|
|
my $self = shift; |
45
|
|
|
|
|
|
|
my $path = shift; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $res; |
48
|
|
|
|
|
|
|
my $retry = $self->retries; |
49
|
|
|
|
|
|
|
do { |
50
|
|
|
|
|
|
|
$log->infof( 'Making %s request against %s', uc($method), $path ); |
51
|
|
|
|
|
|
|
$res = $self->$orig( "/$path", @_ ); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
if ($res->code =~ /^5/) { |
54
|
|
|
|
|
|
|
$log->warn('Request failed. Retrying...') if $retry; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
else { |
57
|
|
|
|
|
|
|
$retry = 0; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} while --$retry >= 0; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
return undef if $res->code() eq '404' and $method eq 'get'; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
if ($res->failed()) { |
64
|
|
|
|
|
|
|
local $Carp::Internal{ 'GitLab::API::v3::RESTClient' } = 1; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
confess sprintf( |
67
|
|
|
|
|
|
|
'Error %sing %s from %s (HTTP %s): %s %s', |
68
|
|
|
|
|
|
|
uc($method), $path, $self->server(), $res->code(), $res->error(), |
69
|
|
|
|
|
|
|
_dump_one_line( $res->data() ), |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
return $res->data(); |
74
|
|
|
|
|
|
|
}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Stolen and modified from Log::Any::Adapter::Core. |
78
|
|
|
|
|
|
|
sub _dump_one_line { |
79
|
0
|
|
|
0
|
|
|
my ($value) = @_; |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
return '<undef>' if !defined $value; |
82
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
|
return Data::Dumper->new( [$value] )->Indent(0)->Sortkeys(1)->Quotekeys(0) |
84
|
|
|
|
|
|
|
->Terse(1)->Dump() if ref($value); |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
$value =~ s{\s+}{ }g; |
87
|
0
|
|
|
|
|
|
return $value; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
__END__ |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 AUTHOR |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Aran Clary Deltac <bluefeetE<64>gmail.com> |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 LICENSE |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
100
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
101
|
|
|
|
|
|
|
|