Commit 3434f6d4 authored by Roman Lacko's avatar Roman Lacko
Browse files

fixed infinite loop for empty response in GitLab::API::Iterator

parent 0da27679
......@@ -148,28 +148,28 @@ sub next_block {
return 0;
}
if (!defined $self->{pages_total}) {
$self->{pages_total} = $response->header("X-Total-Pages");
}
croak "Response for " . $self->name . " did not contain an array"
unless ref $data eq "ARRAY";
# if there was no X-Total-Pages, the response is not paginated, blame the user
# get total number of pages from the header
if (!defined $self->{pages_total}) {
# some requests are not paginated if additional parameters are provided
# carp "Iterating over non-paginated request for " . $self->name;
$self->{pages_total} = 1;
# use 1 if there are data, 0 otherwise
my $default = @$data ? 1 : 0;
$self->{pages_total} = $response->header("X-Total-Pages") // $default;
$self->idebug("total pages $self->{pages_total}");
}
croak "Response for " . $self->name . " did not contain an array"
unless ref $data eq "ARRAY";
push @{$self->{data}}, @$data;
push @{$self->{responses}}, $response;
$self->api->{last} = $response;
$self->{count} += scalar @$data;
++$self->{pages_read};
$self->api->{last} = $response;
$self->{count} += scalar @$data;
# only increase read pages if there are pages to read
++$self->{pages_read} if $self->{pages_total};
$self->{finished} = $self->{pages_read} == $self->{pages_total};
$self->{finished} = !$self->{pages_total} || $self->{pages_read} == $self->{pages_total};
$self->idebug("block read successful");
$self->idebug("all blocks were read") if $self->{finished};
return 1;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment