feat(api): add q parameter to list branches API for server-side filtering (#37982)

The GET /repos/{owner}/{repo}/branches endpoint currently has no way to
filter branches by name server-side, forcing API consumers to paginate
through all branches and filter client-side.

The UI already supports branch search (added in
[#27055](https://github.com/go-gitea/gitea/pull/27055)). The underlying
DB layer has a Keyword field on FindBranchOptions in
models/git/branch_list.go that does a LIKE %keyword% SQL filter, it just
wasn't wired up to the API handler.

This PR exposes a ?q= query parameter on the endpoint that maps to
FindBranchOptions.Keyword.

Example:

```GET /repos/owner/repo/branches?q=feature ```
Closes #37981

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Harsh Mahajan
2026-06-04 04:51:48 +05:30
committed by GitHub
parent b2748d7654
commit 792fa5eeba
5 changed files with 41 additions and 0 deletions
+6
View File
@@ -7158,6 +7158,12 @@
"description": "page size of results",
"name": "limit",
"in": "query"
},
{
"type": "string",
"description": "branch name substring to filter by",
"name": "q",
"in": "query"
}
],
"responses": {
+8
View File
@@ -18224,6 +18224,14 @@
"schema": {
"type": "integer"
}
},
{
"description": "branch name substring to filter by",
"in": "query",
"name": "q",
"schema": {
"type": "string"
}
}
],
"responses": {