Skip to content

Add server-side branch prefix search#110

Open
HarshMN2345 wants to merge 18 commits into
mainfrom
feature/github-branch-search
Open

Add server-side branch prefix search#110
HarshMN2345 wants to merge 18 commits into
mainfrom
feature/github-branch-search

Conversation

@HarshMN2345

Copy link
Copy Markdown
Member

Uses GraphQL refs query with query variable for prefix filtering and cursor-based pagination instead of fetching all branches client-side.

Uses GraphQL refs query with query variable for prefix filtering and
cursor-based pagination instead of fetching all branches client-side.
@greptile-apps

greptile-apps Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR migrates listBranches from the REST API to GraphQL with a new $search parameter for server-side prefix filtering, adds a getCheckRunByName method to both the base adapter and GitHub adapter, and fixes a null-author guard in getLatestCommit.

  • listBranches now uses a GraphQL refs query with an optional query variable, returning a flat array<string> consistent with the base adapter contract.
  • getCheckRunByName is added to Adapter.php as a throwing stub and implemented in GitHub.php using the REST check-runs endpoint with filter=latest.
  • The pre-existing testListBranchesPagination test still asserts page-2 results (assertSame(['branch-b'], $page2)), but the $page parameter is no longer used in the GraphQL query, so that assertion will fail.

Confidence Score: 3/5

The test suite will fail as-is: the pre-existing page-2 pagination assertion was not updated to match the new cursor-less GraphQL implementation.

The new listBranches implementation accepts $page in its signature but never forwards it to the GraphQL query. The testListBranchesPagination test still contains assertSame(['branch-b'], $page2) for a page-2 call, which will now return the first alphabetical branch instead of the second, causing a definite test failure on merge.

tests/VCS/Adapter/GitHubTest.php lines 546-547 and the $page handling in src/VCS/Adapter/Git/GitHub.php

Important Files Changed

Filename Overview
src/VCS/Adapter/Git/GitHub.php Replaces REST list-branches with GraphQL; adds getCheckRunByName; fixes null-author guard in getLatestCommit. The $page parameter is accepted but not forwarded to the GraphQL query, breaking the pre-existing page-2 pagination test.
tests/VCS/Adapter/GitHubTest.php Adds search and getCheckRunByName tests, but the existing assertSame(['branch-b'], $page2) assertion on line 547 will now fail since $page is no longer used in the GraphQL implementation.
src/VCS/Adapter.php Adds getCheckRunByName() stub that throws; no interface contract changes to listBranches.

Comments Outside Diff (1)

  1. tests/VCS/Adapter/GitHubTest.php, line 546-547 (link)

    P1 Pre-existing page-2 test will fail with new implementation

    The $page parameter is accepted by the new listBranches signature but never forwarded to the GraphQL query — there is no after cursor variable and no pageInfo in the query. This means listBranches(..., 1, 2) silently returns the same first alphabetical branch (branch-a) as a $page = 1 call, so assertSame(['branch-b'], $page2) will fail at runtime. The test was not removed in this PR, so the test suite will catch the regression.

Reviews (10): Last reviewed commit: "feat: add getCheckRunByName" | Re-trigger Greptile

Comment thread src/VCS/Adapter/Git/GitHub.php Outdated
Comment thread src/VCS/Adapter/Git/GitHub.php Outdated
Comment thread src/VCS/Adapter/Git/GitHub.php Outdated
Comment thread src/VCS/Adapter/Git/GitHub.php Outdated
Comment thread src/VCS/Adapter/Git/GitHub.php Outdated
Comment thread src/VCS/Adapter/Git/GitHub.php Outdated
Comment thread src/VCS/Adapter/Git/GitHub.php Outdated
Comment thread tests/VCS/Adapter/GitHubTest.php Outdated
Comment thread src/VCS/Adapter/Git/GitHub.php Outdated
Comment on lines +770 to +819
return array_values(array_map(fn ($branch) => $branch['name'] ?? '', $responseBody));
$edges = $refs['edges'] ?? [];
$pageInfo = $refs['pageInfo'] ?? [];
$hasNext = (bool) ($pageInfo['hasNextPage'] ?? false);

return [
'items' => array_map(fn ($edge) => $edge['node']['name'] ?? '', $edges),
'hasNext' => $hasNext,
'nextCursor' => $hasNext ? ($pageInfo['endCursor'] ?? null) : null,
];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep old response structure - no hasNext, no cursor

Comment thread src/VCS/Adapter/Git/GitHub.php Outdated
Comment on lines +762 to +763
if ($page > 1) {
for ($i = 1; $i < $page; $i++) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets not loop

Comment thread src/VCS/Adapter/Git/GitHub.php Outdated
/**
* @return array{names: array<string>, endCursor: string|null}
*/
private function fetchBranchPage(string $owner, string $repositoryName, int $perPage, ?string $after, string $search): array

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets avoid helper method

Comment thread src/VCS/Adapter/Git/GitHub.php
@HarshMN2345 HarshMN2345 changed the title Add server-side branch prefix search and cursor pagination for GitHub Add server-side branch prefix search Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants