Skip to content

Commit bc8deed

Browse files
Make sure per page is always restored
1 parent f17c158 commit bc8deed

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

lib/Github/ResultPager.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,26 +78,28 @@ public function fetchAll(ApiInterface $api, $method, array $parameters = [])
7878
// set parameters per_page to GitHub max to minimize number of requests
7979
$api->setPerPage(100);
8080

81-
$result = $this->callApi($api, $method, $parameters);
82-
$this->postFetch();
81+
try {
82+
$result = $this->callApi($api, $method, $parameters);
83+
$this->postFetch();
8384

84-
if ($isSearch) {
85-
$result = isset($result['items']) ? $result['items'] : $result;
86-
}
85+
if ($isSearch) {
86+
$result = isset($result['items']) ? $result['items'] : $result;
87+
}
8788

88-
while ($this->hasNext()) {
89-
$next = $this->fetchNext();
89+
while ($this->hasNext()) {
90+
$next = $this->fetchNext();
9091

91-
if ($isSearch) {
92-
$result = array_merge($result, $next['items']);
93-
} else {
94-
$result = array_merge($result, $next);
92+
if ($isSearch) {
93+
$result = array_merge($result, $next['items']);
94+
} else {
95+
$result = array_merge($result, $next);
96+
}
9597
}
98+
} finally {
99+
// restore the perPage
100+
$api->setPerPage($perPage);
96101
}
97102

98-
// restore the perPage
99-
$api->setPerPage($perPage);
100-
101103
return $result;
102104
}
103105

0 commit comments

Comments
 (0)