Skip to content

Improve GitHub branch listing pagination#102

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

Improve GitHub branch listing pagination#102
HarshMN2345 wants to merge 4 commits into
mainfrom
feature/github-branch-search-pagination

Conversation

@HarshMN2345
Copy link
Copy Markdown
Member

No description provided.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 14, 2026

Greptile Summary

This PR overhauls listBranches across all four VCS adapters, adding $perPage, $page (integer or cursor string), and $search parameters to the abstract base and each concrete implementation.

  • GitHub migrates from the REST paginated endpoint to a GraphQL query with cursor-based pagination and server-side prefix search via refPrefix, returning a structured {items, hasNext, nextCursor} shape instead of the previous flat array — but reaching an integer page N still requires N sequential GraphQL calls, and the abstract base's return type now covers two incompatible shapes.
  • GitLab / Gitea / Gogs fetch all branches with their existing looping API calls and apply search filtering and pagination client-side, remaining return-type-incompatible with the GitHub adapter; the Gogs adapter makes a single unpaginated API call with no page or limit query parameters.

Confidence Score: 3/5

Not ready to merge: GitHub returns a different shape from the other three adapters, integer-page access issues N sequential GraphQL calls, and Gogs performs client-side pagination over a potentially server-capped response.

Multiple concrete defects across changed files: GitHub structured return breaks polymorphic callers treating the result as a flat array, N sequential calls make large integer page numbers impractical and rate-limit-prone, and Gogs single unpaginated API call means array_slice pagination can silently return wrong data.

GitHub.php for sequential-call and dead-code issues, Gogs.php for missing API pagination parameters, and Adapter.php for the diverged return-type contract.

Important Files Changed

Filename Overview
src/VCS/Adapter.php Abstract listBranches signature updated with new params, but the return type PHPDoc now covers both the old flat array<string> (GitLab/Gitea/Gogs) and the new structured array{items, hasNext, nextCursor} (GitHub), leaving polymorphic callers unable to rely on either form.
src/VCS/Adapter/Git/GitHub.php Migrated to GraphQL with cursor pagination and server-side prefix search; returns {items, hasNext, nextCursor}. Integer-page access still requires N sequential calls, and the return $result after the loop is unreachable dead code.
src/VCS/Adapter/Git/GitLab.php Now accepts perPage/page/search params but applies search client-side after fetching all branches; GitLab's API supports a native ?search= parameter that could eliminate unnecessary data transfer. Still returns a flat array, inconsistent with GitHub's structured return.
src/VCS/Adapter/Git/Gitea.php Now accepts perPage/page/search params but filters client-side; Gitea's branch API supports ?q= for server-side search. Returns a flat array inconsistent with GitHub's structured return.
src/VCS/Adapter/Git/Gogs.php Accepts all new params but makes a single unpaginated API call with no page/limit query params; if Gogs server applies a default result cap, client-side array_slice pagination silently operates on a truncated dataset.
tests/VCS/Adapter/GitHubTest.php Tests updated to validate the new structured return shape, cursor-based pagination, and prefix search; assertions are well-structured and cover the main scenarios.
tests/VCS/Adapter/GitLabTest.php Pagination test assertions compare $result[0] / $result[1] from an unordered full-fetch against deterministic page slices; order is consistent only if GitLab API always returns branches in alphabetical order, which is the default but not guaranteed.
tests/VCS/Adapter/GiteaTest.php Same ordering-assumption fragility as GitLabTest — $branches[0] and $branches[1] from a full fetch are compared against paginated slices without asserting or controlling sort order.

Reviews (4): Last reviewed commit: "Preserve default branch listing behavior" | Re-trigger Greptile

Comment thread src/VCS/Adapter/Git/GitHub.php
Comment thread src/VCS/Adapter/Git/GitHub.php
Comment thread src/VCS/Adapter.php Outdated
@HarshMN2345 HarshMN2345 force-pushed the feature/github-branch-search-pagination branch from 43e2053 to e71e384 Compare May 14, 2026 11:32
Comment thread src/VCS/Adapter/Git/GitLab.php
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.

1 participant