Skip to content

Commit b33588a

Browse files
committed
feedback
1 parent cb0f8eb commit b33588a

1 file changed

Lines changed: 24 additions & 10 deletions

File tree

src/VCS/Adapter/Git/GitHub.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,20 +191,34 @@ public function searchRepositories(string $installationId, string $owner, int $p
191191

192192
public function getInstallationRepository(string $repositoryName): array
193193
{
194+
$currentPage = 1;
195+
$perPage = 100;
196+
$totalRepositories = 0;
197+
$maxRepositories = 1000;
194198
$url = '/installation/repositories';
195-
$response = $this->call(self::METHOD_GET, $url, ['Authorization' => "Bearer $this->accessToken"], [
196-
'page' => 1,
197-
'per_page' => 100,
198-
]);
199199

200-
if (!isset($response['body']['repositories'])) {
201-
throw new Exception("Repositories list missing in the response.");
202-
}
200+
while ($totalRepositories < $maxRepositories) {
201+
$response = $this->call(self::METHOD_GET, $url, ['Authorization' => "Bearer $this->accessToken"], [
202+
'page' => $currentPage,
203+
'per_page' => $perPage,
204+
]);
205+
206+
if (!isset($response['body']['repositories'])) {
207+
throw new Exception("Repositories list missing in the response.");
208+
}
209+
210+
foreach ($response['body']['repositories'] as $repo) {
211+
if (\strtolower($repo['name']) === \strtolower($repositoryName)) {
212+
return $repo;
213+
}
214+
}
203215

204-
foreach ($response['body']['repositories'] as $repo) {
205-
if (\strtolower($repo['name']) === \strtolower($repositoryName)) {
206-
return $repo;
216+
if (\count($response['body']['repositories']) < $perPage) {
217+
break;
207218
}
219+
220+
$currentPage++;
221+
$totalRepositories += $perPage;
208222
}
209223

210224
throw new RepositoryNotFound("Repository not found.");

0 commit comments

Comments
 (0)