Repository navigation
fix(repo): make --limit cap total results - #135
Merged
Merged
Conversation
andrew
requested changes
Jul 8, 2026
andrew
left a comment
Contributor
There was a problem hiding this comment.
Thanks for picking this up. As written this doesn't fix #133 and regresses repo search:
- No backend reads
ListRepoOpts.LimitorSearchRepoOpts.Limit(seegithub/github.go:105,402,gitlab/gitlab.go:95,388,gitea/gitea.go:102,365,bitbucket/bitbucket.go:210).FilterReposinforge.godoesn't apply it either. Sorepo list --limit Nstill returns everything. Searchon every backend fetches a single page sized byPerPage. RemovingPerPage: flagLimitmeans--limit 5now returns 30 results instead of 5.
Please apply the two changes below so --limit actually caps output, and update the tests to prove it by returning more repos than the limit and checking the printed count. Stopping backend pagination early can be a follow-up.
Apply the review-requested output cap in the CLI after repo list/search calls so backends that do not honor Limit cannot over-print. Keep search PerPage tied to the user limit because search backends fetch a single page. Constraint: Backends currently ignore ListRepoOpts.Limit and SearchRepoOpts.Limit. Rejected: relying on backend pagination changes | larger follow-up than this review requested. Confidence: high Scope-risk: narrow Directive: Keep CLI output caps until repo backends implement total Limit consistently. Tested: go test ./internal/cli -run 'TestRepo(List|Search)LimitCapsTotalResults' -count=1 Tested: go test ./internal/cli -count=1 Tested: go test ./... -count=1 Tested: git diff --check
andrew
approved these changes
Jul 20, 2026
andrew
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the follow-up — both paths now cap correctly and the tests prove it.
andrew
pushed a commit
that referenced
this pull request
Jul 26, 2026
Backend Repos().List implementations (GitHub, GitLab, Gitea, Bitbucket) previously ignored ListRepoOpts.Limit entirely and always fetched every page of results before returning, even when the caller only asked for a handful of repositories via `forge repo list --limit N`. PR #135 worked around this by capping the CLI's printed output after the fact, but the backends still made all the underlying API requests, wasting rate-limit budget and latency for large orgs/users, exactly as described in #134. This closes the gap called out in #134's "Proposed changes": - Add forge.RepoMatchesFilters, a shared archived/fork predicate reused by both the pagination loops and the existing FilterRepos post-filter. - Add forge.CapRepos to truncate matched results to opts.Limit. - In each backend's Repos().List, count filter-matching repos while paginating and stop requesting further pages once opts.Limit matching repos have been collected. Also shrink the requested page size to the limit when it's smaller, so a single small page is fetched instead of a full default page. - Bitbucket's cursor-based pagination (follows a `next` URL) is handled the same way: stop following `next` once enough repos are collected. No behavior change when Limit is 0 (unlimited); all backends still paginate fully in that case, same as before. Tested: - go build ./... - go vet ./... - go test ./... (all existing tests pass unchanged) - Added TestGitHubListReposStopsPaginatingAtLimit, TestGitLabListReposStopsPaginatingAtLimit, TestGiteaListReposStopsPaginatingAtLimit, TestBitbucketListReposStopsPaginatingAtLimit; each asserts the backend issues exactly one HTTP request when Limit is satisfied by the first page, even though the mock server always advertises a next page. Fixes #134
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
repo list --limitoutput after the repo service returns results.repo search --limitas bothSearchRepoOpts.LimitandPerPage, then cap output after the search call.Why
Fixes #133.
--limitshould cap the total number of repositories printed. Search still uses the limit as the backend page size because the current search backends fetch one page.Validation
go test ./internal/cli -run 'TestRepo(List|Search)LimitCapsTotalResults' -count=1go test ./internal/cli -count=1go test ./... -count=1git diff --check