feat(repositories): add type filter to list repos APIs#36891
Open
appleboy wants to merge 12 commits intogo-gitea:mainfrom
Open
feat(repositories): add type filter to list repos APIs#36891appleboy wants to merge 12 commits intogo-gitea:mainfrom
appleboy wants to merge 12 commits intogo-gitea:mainfrom
Conversation
- Add support for filtering repositories by type query parameter with values all, public, or private across user, org, and self repo listing APIs - Introduce an optional IsPrivate filter in repository search logic to explicitly handle public or private queries - Return a 422 validation error for invalid type query values - Update pagination handling to use list options consistently after refactoring search options - Extend Swagger API documentation to describe the new type filter and validation error responses - Add comprehensive integration tests covering public, private, all, no filter, and invalid type scenarios for all relevant endpoints Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a type query filter (all | public | private) to repository listing APIs and wires it through to the repository query layer, with Swagger and integration-test updates to match.
Changes:
- Add
typequery parsing in API handlers and map it toSearchRepoOptions.IsPrivate. - Update
GetUserRepositoriesto honoropts.IsPrivatewhen provided. - Extend Swagger docs and add integration tests for the new filter values and invalid input (
422).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
models/repo/repo_list.go |
Applies IsPrivate as an explicit is_private condition when set. |
routers/api/v1/user/repo.go |
Adds parseRepoTypeFilter helper and applies IsPrivate to list endpoints. |
templates/swagger/v1_json.tmpl |
Documents type query parameter and 422 validation response for the three endpoints. |
tests/integration/api_user_repos_test.go |
Adds integration tests covering public/private/all/no filter/invalid filter for the endpoints. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
wxiaoguang
reviewed
Mar 12, 2026
…ount leaking - Fix GetUserRepositories: Private=false (access gate) now takes precedence over IsPrivate, so unauthenticated callers cannot use type=private to query private repos regardless of the IsPrivate filter - Short-circuit listUserRepos to empty result (total=0) when caller is unauthenticated and requests type=private, preventing X-Total-Count header from leaking private repo existence - Add TypePrivateUnauthenticated test case to verify body is empty and X-Total-Count is 0 for unauthenticated type=private requests Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Per reviewer feedback (wxiaoguang, lunny): remove the dual Private bool / IsPrivate optional.Option[bool] pattern in GetUserRepositories and use only IsPrivate. - GetUserRepositories: drop opts.Private gate, rely solely on opts.IsPrivate (None = no filter, Some(false) = public only, Some(true) = private only) - listUserRepos: encode access-control into IsPrivate before calling the model layer — unauthenticated callers get Some(false); type=private from an unauthenticated caller short-circuits to an empty result with X-Total-Count: 0 so private repo existence is never leaked - All other GetUserRepositories callers use Private: true (= want all repos) which maps cleanly to IsPrivate = None (zero value, no filter) Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
GetUserRepositories no longer uses opts.Private to restrict results to public repos by default. Callers that want public-only results must now set opts.IsPrivate = Some(false) explicitly. Update the test setup call to pass IsPrivate: optional.Some(false) to preserve the original intent of the test. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…ld in SearchRepoOptions Remove the `Private bool` field from `SearchRepoOptions` and use only `IsPrivate optional.Option[bool]` for controlling repository visibility filtering. This eliminates the confusing overlap between the two fields. Semantics: - IsPrivate=None: include both public and private (with access control) - IsPrivate=Some(true): include only private repos (with access control) - IsPrivate=Some(false): include only public repos (no private/limited orgs) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Test cases named "Public*" previously relied on the default Private=false to restrict results to public repos. With the field removed, they need explicit IsPrivate=Some(false). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Member
Author
|
@lunny, please note that this feature must be included in the Enterprise version. Thank you. |
lunny
approved these changes
Mar 14, 2026
Member
Author
|
@wxiaoguang need your approval :) |
Contributor
|
I don't have time to review. Can other maintainers help. |
Zettat123
reviewed
Mar 16, 2026
- Guard `is_private` query parameter so it only applies when the user is signed in and not in PublicOnly mode, preventing unauthenticated users from overriding the public-only visibility restriction Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
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
typequery parameter (all|public|private) to three repo listing endpoints:GET /user/repos— list authenticated user's reposGET /users/{username}/repos— list a user's reposGET /orgs/{org}/repos— list an org's reposIsPrivateoptional filter support inGetUserRepositoriesto handle explicit public/private queries422 Unprocessable Entityfor invalidtypevaluesparseRepoTypeFilterhelper to avoid duplicating the switch logicChanges
models/repo/repo_list.goGetUserRepositories: honouropts.IsPrivatewhen set, falling back to existingopts.Privatebehaviourrouters/api/v1/user/repo.goparseRepoTypeFilterhelper; apply filter inlistUserReposandListMyRepostemplates/swagger/v1_json.tmpltypeparameter and422response for all three endpointstests/integration/api_user_repos_test.gopublic,private,all, no-filter, and invalid-type scenariosTest plan
TestAPIListMyRepos—GET /user/reposTestAPIListUserReposByType—GET /users/{username}/reposTestAPIListOrgReposByType—GET /orgs/{org}/reposAll tests pass with
make test-sqlite.🤖 Generated with Claude Code