Repository navigation
fix: page through branches and tags in resource completions - #4019
Open
chanyang721 wants to merge 2 commits into
Open
chanyang721 wants to merge 2 commits into
chanyang721 wants to merge 2 commits into
Conversation
Branch and tag completion called ListBranches and ListTags once without options, so only the first 30 refs were ever offered. Request 100 per page and follow the next page until more than 100 values match or the list ends. A failed list request now returns its error instead of a partial list that looks complete. The completion handler cut results to 100 but never reported hasMore and set Total to the cut length. Report hasMore=true when values are cut, and leave Total unset then because a resolver may stop reading before it has seen every ref.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Branch and tag completion can fetch every ref page for nonexistent prefixes, risking API quota exhaustion because neither resolver enforces a per-completion request budget.
1 open issue
What changed in this PR
Fixes repository resource completions so branches and tags beyond the first API page can be suggested.
Changes:
- Fetches additional pages until more than 100 matches are found or refs are exhausted.
- Reports
hasMorefor truncated results and propagates list errors. - Adds regression tests for pagination, result limits, and later-page failures.
| File | Description |
|---|---|
pkg/github/repository_resource_completions.go |
Adds branch/tag pagination and updates completion metadata and error handling. |
pkg/github/repository_resource_completions_test.go |
Adds paginated mocks and regression coverage. |
Review effort: Balanced (adaptive)
Contributor
AI Assessment: Missing DetailsThanks for the contribution. Please edit the description to fill in these
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Branch and tag completion for repository resource templates now reads past the first page of refs, and when the completion handler receives more than 100 values it now reports
hasMore: true.Each branch or tag completion reads at most 10 pages (1,000 refs). If refs are left unread at that point, it returns an error asking for a longer prefix rather than a list that may be missing matches, so a prefix that matches nothing cannot walk every page of a large repository.
Why
completeBranchandcompleteTagcallListBranchesandListTagsonce with no options, so they only ever see the API's default first page of 30 refs. In a repository with more refs, a branch or tag past the 30th is never suggested, even when the typed text matches it exactly (for example a release tag such asv2.0.0listed after older tags).RepositoryResourceCompletionHandlercuts values to 100, but never setshasMore(so it is omitted from the response) and setstotalto the cut length, so a client cannot tell that more matches exist.No upstream issue is associated with this fix.
What changed
pkg/github/repository_resource_completions.go:completeBranchandcompleteTagrequest 100 refs per page and follow the next page until more than 100 values match or the list ends. Stopping after the page that holds the 101st match lets the handler know there are more without reading every remaining page. The existing filters are unchanged (prefix for branches, substring for tags).hasMore: trueand leavestotalunset, because a resolver may have stopped reading before it saw every ref and the real count is unknown. For results that are not cut, nonempty responses include the exacttotaland empty responses still omit it, as before. Other resolvers (owner,sha,prNumber,path) still cut to 100 themselves, so the handler cannot detect more for them; that is unchanged.pkg/github/repository_resource_completions_test.go: a paginated mock that behaves like the list endpoints (30 per page by default,per_page/pageparameters, aLinknext header), and tests thattotal: 31for 31 branches, and 100 values withhasMore: truefor 150 branches,total: 100withouthasMore,MaxResultstest also assertshasMore: true.With these tests applied on
main, all of the new tests andMaxResultsfail; with this change they pass.Commit SHA completion (
completeSHA) still reads one page. It lists recent commits, so this may be intended, and it is left out of this PR.MCP impact
Tool definitions and schemas are unchanged. Branch and tag completions can return matches from later pages and now return list errors. When the handler cuts results, it sets
hasMoreand omitstotal.Prompts tested (tool changes only)
Security / limits
Branch and tag completion can now make more than one list request, so the request count is bounded: each completion reads at most 10 pages of 100 refs (1,000 refs), and stops earlier after the page that holds the 101st match or the last page. If refs are still unread after 10 pages, it returns an error asking for a longer prefix instead of a possibly incomplete list, so a prefix that matches nothing cannot walk every page of a large repository or exhaust the API quota. Results are still cut to 100 values. No new permissions, scopes or data sources are used; the same list endpoints are called with the caller's existing token.
Tool renaming
deprecated_tool_aliases.goLint & tests
golangci-lint run ./pkg/github/...(v2.14.0, the versionscript/lintinstalls): ran, passed, 0 issuesgo test ./pkg/github -run 'Complet|RepositoryResource' -count=1: ran, passed (Go 1.27.4, darwin/arm64)repository_resource_completions.gofrommainfails the new tests andMaxResults../script/test(go test -race ./...) and the full./script/lint: not run on the final commit; relying on PR CI for the full suite.Docs
Skills
No tool or toolset instruction changes, so no bundled skill applies.