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
|
|
10
|
use Carp qw( confess ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
81
|
|
23
|
1
|
|
|
1
|
|
8
|
use Data::Dumper qw(); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
24
|
1
|
|
|
1
|
|
553
|
use Role::REST::Client::Response; |
|
1
|
|
|
|
|
60604
|
|
|
1
|
|
|
|
|
42
|
|
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
1
|
|
9
|
use Moo; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
27
|
1
|
|
|
1
|
|
362
|
use Try::Tiny; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
85
|
|
28
|
1
|
|
|
1
|
|
7
|
use strictures 1; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
47
|
|
29
|
1
|
|
|
1
|
|
791
|
use namespace::clean; |
|
1
|
|
|
|
|
10874
|
|
|
1
|
|
|
|
|
10
|
|
30
|
1
|
|
|
1
|
|
384
|
use Log::Any qw( $log ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
12
|
|
31
|
1
|
|
|
1
|
|
1025
|
use Types::Standard qw( Int ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
14
|
|
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 SUPPORT |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
See L<GitLab::API::v3/SUPPORT>. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 AUTHORS |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
See L<GitLab::API::v3/AUTHORS>. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 LICENSE |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
See L<GitLab::API::v3/LICENSE>. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |
106
|
|
|
|
|
|
|
|