From ee8d38013de70678a56257ffc78dfe6eb2c5c0a4 Mon Sep 17 00:00:00 2001 From: Hemachandar Date: Mon, 26 Jan 2026 15:03:55 +0530 Subject: [PATCH 1/5] Use `installation/repositories` API for searching repos --- src/VCS/Adapter/Git/GitHub.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/VCS/Adapter/Git/GitHub.php b/src/VCS/Adapter/Git/GitHub.php index ad5fb9e..14a7315 100644 --- a/src/VCS/Adapter/Git/GitHub.php +++ b/src/VCS/Adapter/Git/GitHub.php @@ -106,22 +106,22 @@ public function createRepository(string $owner, string $repositoryName, bool $pr */ public function searchRepositories(string $owner, int $page, int $per_page, string $search = ''): array { - $url = '/search/repositories'; + $url = '/installation/repositories'; $response = $this->call(self::METHOD_GET, $url, ['Authorization' => "Bearer $this->accessToken"], [ - 'q' => "{$search} user:{$owner} fork:true", 'page' => $page, 'per_page' => $per_page, - 'sort' => 'updated' ]); - if (!isset($response['body']['items'])) { + if (!isset($response['body']['repositories'])) { throw new Exception("Repositories list missing in the response."); } + $repositories = array_filter($response['body']['repositories'] ?? [], fn ($repo) => str_contains($repo['name'], $search)); + return [ - 'items' => $response['body']['items'], - 'total' => $response['body']['total_count'], + 'items' => $repositories, + 'total' => \count($repositories), ]; } From 0929e6d7cd657ec68e304e94531511e3a489d486 Mon Sep 17 00:00:00 2001 From: Hemachandar Date: Mon, 26 Jan 2026 15:57:50 +0530 Subject: [PATCH 2/5] search pagination --- src/VCS/Adapter/Git/GitHub.php | 36 +++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/src/VCS/Adapter/Git/GitHub.php b/src/VCS/Adapter/Git/GitHub.php index 14a7315..73eabc2 100644 --- a/src/VCS/Adapter/Git/GitHub.php +++ b/src/VCS/Adapter/Git/GitHub.php @@ -106,21 +106,39 @@ public function createRepository(string $owner, string $repositoryName, bool $pr */ public function searchRepositories(string $owner, int $page, int $per_page, string $search = ''): array { - $url = '/installation/repositories'; + $repositories = []; + + $currentPage = 1; + while (true) { + $url = '/installation/repositories'; + $response = $this->call(self::METHOD_GET, $url, ['Authorization' => "Bearer $this->accessToken"], [ + 'page' => $currentPage, + 'per_page' => 100, // Maximum allowed by GitHub API + ]); + + if (!isset($response['body']['repositories'])) { + break; + } - $response = $this->call(self::METHOD_GET, $url, ['Authorization' => "Bearer $this->accessToken"], [ - 'page' => $page, - 'per_page' => $per_page, - ]); + // Filter repositories to only include those that match the search query. + $filteredRepositories = array_filter($response['body']['repositories'], fn ($repo) => empty($search) || stripos($repo['name'], $search) !== false); + + // Merge with result so far. + $repositories = array_merge($repositories, $filteredRepositories); + + // If less than 100 repositories are returned, we have fetched all repositories. + if (\count($filteredRepositories) < 100) { + break; + } - if (!isset($response['body']['repositories'])) { - throw new Exception("Repositories list missing in the response."); + // Increment page number to fetch next page. + $currentPage++; } - $repositories = array_filter($response['body']['repositories'] ?? [], fn ($repo) => str_contains($repo['name'], $search)); + $repositoriesInRequestedPage = \array_slice($repositories, ($page - 1) * $per_page, $per_page); return [ - 'items' => $repositories, + 'items' => $repositoriesInRequestedPage, 'total' => \count($repositories), ]; } From 475c25b16621f7c81782dd857444d177ac978f82 Mon Sep 17 00:00:00 2001 From: Hemachandar Date: Mon, 26 Jan 2026 15:58:37 +0530 Subject: [PATCH 3/5] lint --- src/VCS/Adapter/Git/GitHub.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VCS/Adapter/Git/GitHub.php b/src/VCS/Adapter/Git/GitHub.php index 73eabc2..173d533 100644 --- a/src/VCS/Adapter/Git/GitHub.php +++ b/src/VCS/Adapter/Git/GitHub.php @@ -107,7 +107,7 @@ public function createRepository(string $owner, string $repositoryName, bool $pr public function searchRepositories(string $owner, int $page, int $per_page, string $search = ''): array { $repositories = []; - + $currentPage = 1; while (true) { $url = '/installation/repositories'; From abbd8e25e9804c570528f4e0c27f187e3ba446f6 Mon Sep 17 00:00:00 2001 From: Hemachandar Date: Mon, 26 Jan 2026 16:04:58 +0530 Subject: [PATCH 4/5] throw exception --- src/VCS/Adapter/Git/GitHub.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VCS/Adapter/Git/GitHub.php b/src/VCS/Adapter/Git/GitHub.php index 173d533..4b9ecc0 100644 --- a/src/VCS/Adapter/Git/GitHub.php +++ b/src/VCS/Adapter/Git/GitHub.php @@ -117,7 +117,7 @@ public function searchRepositories(string $owner, int $page, int $per_page, stri ]); if (!isset($response['body']['repositories'])) { - break; + throw new Exception("Repositories list missing in the response."); } // Filter repositories to only include those that match the search query. From d5ef1e33bc2490b51e64ea5ddd849b9bf1724bf1 Mon Sep 17 00:00:00 2001 From: Hemachandar Date: Wed, 28 Jan 2026 12:54:06 +0530 Subject: [PATCH 5/5] fix loop break --- src/VCS/Adapter/Git/GitHub.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VCS/Adapter/Git/GitHub.php b/src/VCS/Adapter/Git/GitHub.php index 4b9ecc0..1c725bf 100644 --- a/src/VCS/Adapter/Git/GitHub.php +++ b/src/VCS/Adapter/Git/GitHub.php @@ -127,7 +127,7 @@ public function searchRepositories(string $owner, int $page, int $per_page, stri $repositories = array_merge($repositories, $filteredRepositories); // If less than 100 repositories are returned, we have fetched all repositories. - if (\count($filteredRepositories) < 100) { + if (\count($response['body']['repositories']) < 100) { break; }