Skip to content

feat: add branch_count to repository API (#35351)#36743

Merged
silverwind merged 3 commits intogo-gitea:mainfrom
robinson-j16:feat-branch-count
Feb 27, 2026
Merged

feat: add branch_count to repository API (#35351)#36743
silverwind merged 3 commits intogo-gitea:mainfrom
robinson-j16:feat-branch-count

Conversation

@robinson-j16
Copy link
Copy Markdown
Contributor

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
Screenshot 2026-02-24 at 21 41 07

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).

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 24, 2026
@github-actions github-actions bot added the modifies/go Pull requests that update Go code label Feb 24, 2026
@lunny
Copy link
Copy Markdown
Member

lunny commented Feb 24, 2026

Please run make generate-swagger to update swagger file.

@lunny lunny added the topic/api Concerns mainly the API label Feb 24, 2026
@lunny lunny added this to the 1.26.0 milestone Feb 24, 2026
@github-actions github-actions bot added the modifies/api This PR adds API routes or modifies them label Feb 25, 2026
@robinson-j16
Copy link
Copy Markdown
Contributor Author

@lunny Thanks, I've updated swagger.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Feb 25, 2026
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Feb 27, 2026
@silverwind silverwind added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 27, 2026
@silverwind silverwind enabled auto-merge (squash) February 27, 2026 13:40
@silverwind silverwind merged commit fde7f7d into go-gitea:main Feb 27, 2026
26 checks passed
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 27, 2026
silverwind added a commit to silverwind/gitea that referenced this pull request Feb 27, 2026
* origin/main:
  feat: add branch_count to repository API (go-gitea#35351) (go-gitea#36743)
silverwind added a commit to silverwind/gitea that referenced this pull request Feb 27, 2026
* origin/main:
  Move Fomantic dropdown CSS to custom module (go-gitea#36530)
  Use "Enable Gravatar" but not "Disable" (go-gitea#36771)
  feat: add branch_count to repository API (go-gitea#35351) (go-gitea#36743)
  Deprecate RenderWithErr (go-gitea#36769)
  Lazy-load some Vue components, fix heatmap chunk loading on every page (go-gitea#36719)
  Filter out untracked files from spellchecking (go-gitea#36756)
  Fix CSS stacking context issue in actions log (go-gitea#36749)
  Fix milestone/project text overflow in issue sidebar (go-gitea#36741)
  Update tool dependencies and fix new lint issues (go-gitea#36702)
  Instance-wide (global) info banner and maintenance mode (go-gitea#36571)
  Add created_by filter to SearchIssues (go-gitea#36670)
  Inline and lazy-load EasyMDE CSS, fix border colors (go-gitea#36714)

# Conflicts:
#	templates/repo/issue/view_content/pull_merge_box.tmpl
#	web_src/js/features/repo-issue-pull.ts
zjjhot added a commit to zjjhot/gitea that referenced this pull request Mar 2, 2026
* giteaofficial/main: (21 commits)
  Enable docker layer caching for `dry-run` and `nightly` container builds (go-gitea#36738)
  Add admin badge to navbar avatar (go-gitea#36790)
  WorkflowDispatch api optionally return runid (go-gitea#36706)
  upgrade minimatch (go-gitea#36760)
  Add `never` option to `PUBLIC_URL_DETECTION` configuration (go-gitea#36785)
  Refactor avatar package, support default avatar fallback (go-gitea#36788)
  Mark unused&immature activitypub as "not implemented" (go-gitea#36789)
  Add “Copy Source” to markup comment menu (go-gitea#36726)
  Update Nix flake (go-gitea#36787)
  Implements OIDC RP-Initiated Logout (go-gitea#36724)
  Fix README symlink resolution in subdirectories like .github (go-gitea#36775)
  [skip ci] Updated translations via Crowdin
  Correct spelling (go-gitea#36783)
  refactor: replace legacy tw-flex utility classes with flex-text-block/inline (go-gitea#36778)
  Fix `no-content` message not rendering after comment edit (go-gitea#36733)
  Fix typos and grammar in English locale (go-gitea#36751)
  Move Fomantic dropdown CSS to custom module (go-gitea#36530)
  Use "Enable Gravatar" but not "Disable" (go-gitea#36771)
  feat: add branch_count to repository API (go-gitea#35351) (go-gitea#36743)
  Deprecate RenderWithErr (go-gitea#36769)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code topic/api Concerns mainly the API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/repos/${username}/${repo} to return branch count

5 participants