Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c9482b4
Add server-side branch prefix search and cursor pagination for GitHub
HarshMN2345 Jun 2, 2026
bbbb5f9
Restore accidentally removed check run tests
HarshMN2345 Jun 2, 2026
4a5f432
Restore accidentally removed createCheckRun, getCheckRun, updateCheckRun
HarshMN2345 Jun 2, 2026
fc4fd54
Simplify listBranches — single GraphQL call, remove do-while loop
HarshMN2345 Jun 2, 2026
846f123
Fix listBranches: use pageInfo.hasNextPage instead of probe item to a…
HarshMN2345 Jun 2, 2026
f46e4fd
Fix listBranches: enforce prefix search client-side, fix null-repo wa…
HarshMN2345 Jun 2, 2026
c2a8fc1
Remove client-side prefix filter — trust GitHub refs(query:) substrin…
HarshMN2345 Jun 2, 2026
7f68ce6
Revert listBranches return to flat array, keep GraphQL for search
HarshMN2345 Jun 4, 2026
51d9e1c
Add search parameter to listBranches
HarshMN2345 Jun 4, 2026
182d6a3
Add page 3 and substring search assertions to listBranches test
HarshMN2345 Jun 4, 2026
848cad9
Add pagination and search tests for listBranches
HarshMN2345 Jun 4, 2026
866aacb
clean up comments
HarshMN2345 Jun 4, 2026
531067a
restore ranch comment
HarshMN2345 Jun 4, 2026
f6dc0a3
simplify listBranches — single GraphQL call, no loop, no helper
HarshMN2345 Jun 5, 2026
7478997
remove comments
HarshMN2345 Jun 5, 2026
b91d73e
add offset pagination support
HarshMN2345 Jun 5, 2026
5e2c6d8
revert pagination
HarshMN2345 Jun 5, 2026
6b33859
feat: add getCheckRunByName
HarshMN2345 Jun 8, 2026
59e181f
add cursor-based pagination to support page offsets
HarshMN2345 Jun 10, 2026
9d1f688
sync with main, keep only search changes
HarshMN2345 Jun 10, 2026
62451e9
remove unrelated getCheckRunByName
HarshMN2345 Jun 10, 2026
12421a8
cap perPage at 50 to avoid GraphQL 100-item limit on cursor skip
HarshMN2345 Jun 10, 2026
fbd2126
use matching-refs for search, REST for pagination
HarshMN2345 Jun 10, 2026
acb18e0
pass per_page=100 to matching-refs to avoid 30-item default cap
HarshMN2345 Jun 10, 2026
9b3ab4c
sort branches by latest updated
HarshMN2345 Jun 10, 2026
d9bd7f7
update docblock
HarshMN2345 Jun 10, 2026
a529fb0
remove unsupported sort params
HarshMN2345 Jun 10, 2026
e54cf58
fix slash encoding in matching-refs URL
HarshMN2345 Jun 10, 2026
7f6aade
clarify 100-branch limit in docblock
HarshMN2345 Jun 10, 2026
5a93859
remove per_page cap — matching-refs returns all results in one call
HarshMN2345 Jun 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 33 additions & 12 deletions src/VCS/Adapter/Git/GitHub.php
Original file line number Diff line number Diff line change
Expand Up @@ -742,19 +742,42 @@ public function getPullRequestFromBranch(string $owner, string $repositoryName,
}

/**
* Lists branches for a given repository
* Lists branches for a given repository, optionally filtered by a search prefix.
*
* @param string $owner Owner name of the repository
* @param string $repositoryName Name of the GitHub repository
* @param int $perPage Number of branches to fetch per page
* @param int $page Page number to start fetching from
* @return array<string> List of branch names as array
* When $search is provided, uses GET /repos/{owner}/{repo}/git/matching-refs/heads/{prefix}
* to perform server-side prefix filtering. This endpoint ignores per_page/page params and
* always returns all matching refs in one call; results are then paginated client-side.
* When $search is empty, uses GET /repos/{owner}/{repo}/branches with GitHub's native pagination.
*
* @param string $owner
* @param string $repositoryName
* @param int $perPage Clamped to [1, 100]
* @param int $page Page number (1-based)
* @param string $search Prefix filter; empty returns all branches
* @return array<string> List of branch names
*/
public function listBranches(string $owner, string $repositoryName, int $perPage = 100, int $page = 1): array
public function listBranches(string $owner, string $repositoryName, int $perPage = 100, int $page = 1, string $search = ''): array
{
$url = "/repos/$owner/$repositoryName/branches";
$perPage = min(max($perPage, 1), 100);

if ($search !== '') {
$url = "/repos/$owner/$repositoryName/git/matching-refs/heads/" . \str_replace('%2F', '/', \rawurlencode($search));
$response = $this->call(self::METHOD_GET, $url, ['Authorization' => "Bearer $this->accessToken"]);

$statusCode = $response['headers']['status-code'] ?? 0;
$responseBody = $response['body'] ?? [];

if ($statusCode < 200 || $statusCode >= 300 || !is_array($responseBody)) {
return [];
}

$branches = array_map(fn ($ref) => str_replace('refs/heads/', '', $ref['ref'] ?? ''), $responseBody);
$offset = ($page - 1) * $perPage;

return array_values(array_slice($branches, $offset, $perPage));
}

$url = "/repos/$owner/$repositoryName/branches";
$response = $this->call(self::METHOD_GET, $url, ['Authorization' => "Bearer $this->accessToken"], [
'page' => $page,
'per_page' => $perPage,
Expand Down Expand Up @@ -831,15 +854,13 @@ public function getLatestCommit(string $owner, string $repositoryName, string $b
$responseBody = $response['body'] ?? [];
$responseBodyCommit = $responseBody['commit'] ?? [];
$responseBodyCommitAuthor = $responseBodyCommit['author'] ?? [];
$responseBodyAuthor = $responseBody['author'] ?? [];
$responseBodyAuthor = is_array($responseBody['author'] ?? null) ? $responseBody['author'] : [];

if (
!array_key_exists('name', $responseBodyCommitAuthor) ||
!array_key_exists('message', $responseBodyCommit) ||
!array_key_exists('sha', $responseBody) ||
!array_key_exists('html_url', $responseBody) ||
!array_key_exists('avatar_url', $responseBodyAuthor) ||
!array_key_exists('html_url', $responseBodyAuthor)
!array_key_exists('html_url', $responseBody)
) {
throw new Exception("Latest commit response is missing required information.");
}
Expand Down
6 changes: 6 additions & 0 deletions tests/VCS/Adapter/GitHubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,12 @@ public function testListBranchesPagination(): void

$all = $adapter->listBranches(static::$owner, $repositoryName, 100, 1);
$this->assertEqualsCanonicalizing([static::$defaultBranch, 'branch-a', 'branch-b'], $all);

$searchResults = $adapter->listBranches(static::$owner, $repositoryName, 100, 1, 'branch');
$this->assertEqualsCanonicalizing(['branch-a', 'branch-b'], $searchResults);

$noMatch = $adapter->listBranches(static::$owner, $repositoryName, 100, 1, 'xyz');
$this->assertEmpty($noMatch);
} finally {
$this->vcsAdapter->deleteRepository(static::$owner, $repositoryName);
}
Expand Down
Loading