gitea/modules
James Robinson fde7f7db28
feat: add branch_count to repository API (#35351) (#36743)
Description
This PR adds a branch_count field to the repository API response.
Currently, clients have to fetch all branches via /branches just to
determine the total number of branches. This addition brings Gitea
closer to parity with GitLab's API and improves efficiency for UI/CLI
clients that need this metric.

Linked Issue
Fixes #35351

Changes
API Structs: Added BranchCount field to Repository struct in
modules/structs/repo.go.

Database Logic: Implemented CountBranches in models/git/branch.go using
XORM for efficient counting.

Service Layer: Updated the ToRepo conversion logic in
services/convert/repository.go to populate the new field during API
serialisation.

Tests: Added a new unit test TestCountBranches in
models/git/branch_test.go to verify counts (including handling of
deleted branches).

Screenshots
<img width="196" height="121" alt="Screenshot 2026-02-24 at 21 41 07"
src="https://github.com/user-attachments/assets/cd023e92-f338-448b-9e49-0a5d54cc96c2"
/>

Testing
Manually verified the output using curl against a local Gitea instance.

Verified that adding a branch increments the count and deleting a branch
(soft-delete) decrements it.

Ran backend linting: make lint-backend (Passed).

Ran specific unit test: go test -v -tags "sqlite sqlite_unlock_notify"
./models/git -run TestCountBranches (Passed).

Co-authored-by: silverwind <me@silverwind.io>
2026-02-27 14:10:01 +00:00
..
actions Move jobparser from act repository to Gitea (#36699) 2026-02-22 19:33:01 +00:00
activitypub
analyze Fix incorrect vendored detections (#36508) 2026-02-01 10:35:51 +00:00
assetfs Refactor template render (#36438) 2026-01-24 05:11:49 +00:00
auth Fix oauth2 session gob register (#36017) 2025-11-26 23:25:34 +08:00
avatar
badge
base Fix incorrect setting loading order (#36735) 2026-02-24 23:46:08 +08:00
cache
cachegroup
charset Fix code highlighting on blame page (#36157) 2025-12-14 12:40:55 +02:00
commitstatus
container
csv
dump
emoji Update emoji data for Unicode 16 (#36596) 2026-02-12 21:39:36 +00:00
eventsource Add more check for stopwatch read or list (#36340) 2026-01-13 13:13:39 +00:00
fileicon Add FOLDER_ICON_THEME configuration option (#36496) 2026-01-30 20:48:56 +00:00
generate
git Update tool dependencies and fix new lint issues (#36702) 2026-02-26 19:13:19 +00:00
gitrepo Clean up Makefile, tests and legacy code (#36638) 2026-02-19 01:23:32 +00:00
glob
globallock
graceful Enable `nilnil` linter for new code (#36591) 2026-02-16 09:57:18 +00:00
gtprof
hcaptcha Clean up Makefile, tests and legacy code (#36638) 2026-02-19 01:23:32 +00:00
highlight Fix chroma lexer mapping (#36629) 2026-02-16 02:11:02 +00:00
hostmatcher
htmlutil Fix markup heading parsing, fix emphasis parsing (#36284) 2026-01-23 20:24:58 +00:00
httpcache
httplib Prevent redirect bypasses via backslash-encoded paths (#36660) 2026-02-22 22:15:03 +00:00
indexer Refactor highlight and diff (#36599) 2026-02-13 00:15:46 +00:00
issue/template
json
label
lfs Refactor git command stdio pipe (#36422) 2026-01-22 06:04:26 +00:00
lfstransfer
log Refactor git command context & pipeline (#36406) 2026-01-21 01:35:14 +00:00
markup Instance-wide (global) info banner and maintenance mode (#36571) 2026-02-26 23:16:11 +08:00
mcaptcha
metrics
migration fix: prevent panic when GitLab release has more links than sources (#36295) 2026-01-05 21:48:12 +08:00
nosql Refactor git command context & pipeline (#36406) 2026-01-21 01:35:14 +00:00
optional Enable `nilnil` linter for new code (#36591) 2026-02-16 09:57:18 +00:00
options
packages Fix various version parsing problems (#36553) 2026-02-08 20:25:30 +00:00
paginator
pprof
private
process Refactor git command context & pipeline (#36406) 2026-01-21 01:35:14 +00:00
proxy
proxyprotocol
public Refactor template render (#36438) 2026-01-24 05:11:49 +00:00
queue Refactor git command context & pipeline (#36406) 2026-01-21 01:35:14 +00:00
recaptcha
references Support closing keywords with URL references (#36221) 2025-12-27 09:05:24 -08:00
regexplru
repository Fix mirror sync parser and fix mirror messages (#36504) 2026-02-11 00:16:05 +00:00
reqctx
secret
session Clean up Makefile, tests and legacy code (#36638) 2026-02-19 01:23:32 +00:00
setting Instance-wide (global) info banner and maintenance mode (#36571) 2026-02-26 23:16:11 +08:00
sitemap
ssh
storage
structs feat: add branch_count to repository API (#35351) (#36743) 2026-02-27 14:10:01 +00:00
svg
system
tailmsg
tempdir
templates Use `relative-time` to render absolute dates (#36238) 2026-02-16 10:58:04 +00:00
test Fix various version parsing problems (#36553) 2026-02-08 20:25:30 +00:00
testlogger Clean up Makefile, tests and legacy code (#36638) 2026-02-19 01:23:32 +00:00
timeutil Clean up Makefile, tests and legacy code (#36638) 2026-02-19 01:23:32 +00:00
translation Use flatten translation keys (#36225) 2025-12-25 12:51:33 -08:00
turnstile
typesniffer Fix incorrect text content detection (#36364) 2026-01-14 23:35:52 +08:00
updatechecker
uri
user
util Fix path resolving (#36734) 2026-02-25 01:21:07 +00:00
validation Update tool dependencies (#36445) 2026-01-24 09:58:28 +01:00
web Instance-wide (global) info banner and maintenance mode (#36571) 2026-02-26 23:16:11 +08:00
webhook actions: report commit status for pull_request_review events (#36589) 2026-02-20 16:12:22 +00:00
zstd