Add server-side branch prefix search#110
Conversation
Uses GraphQL refs query with query variable for prefix filtering and cursor-based pagination instead of fetching all branches client-side.
Greptile SummaryThis PR replaces the REST-based
Confidence Score: 3/5Two defects in the changed code need fixing before this is safe to merge: the cursor preflight query breaks for pages 4+ and the new substring test will fail against the real API. The cursor query passes ($page - 1) * $perPage as first; with $perPage capped at 50 this exceeds GitHub GraphQL's hard limit of 100 starting at page 4, silently returning empty results. Additionally, the new integration test asserts that refs(query: 'ranch') returns branches containing the string 'ranch', but GitHub's refs(query:) is prefix-only — the test will fail against the real API on every run. Both src/VCS/Adapter/Git/GitHub.php (cursor first limit) and tests/VCS/Adapter/GitHubTest.php (incorrect substring assertion) need attention before merging. Important Files Changed
Reviews (12): Last reviewed commit: "cap perPage at 50 to avoid GraphQL 100-i..." | Re-trigger Greptile |
| 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, | ||
| ]; |
There was a problem hiding this comment.
Keep old response structure - no hasNext, no cursor
| if ($page > 1) { | ||
| for ($i = 1; $i < $page; $i++) { |
| /** | ||
| * @return array{names: array<string>, endCursor: string|null} | ||
| */ | ||
| private function fetchBranchPage(string $owner, string $repositoryName, int $perPage, ?string $after, string $search): array |
| 'variables' => [ | ||
| 'owner' => $owner, | ||
| 'name' => $repositoryName, | ||
| 'first' => ($page - 1) * $perPage, |
There was a problem hiding this comment.
Cursor query
first value exceeds GitHub's GraphQL limit for pages 4+
The cursor query passes ($page - 1) * $perPage as first. With $perPage clamped to a maximum of 50, $page = 4 yields first = 150, which exceeds GitHub GraphQL's hard limit of 100 for any connection field. GitHub returns a validation error; the code at line 783 treats a non-array response as "no next page" and returns [], so every request for page 4 or higher silently returns an empty result instead of the actual data.
Uses GraphQL refs query with query variable for prefix filtering and cursor-based pagination instead of fetching all branches client-side.