Skip to content

Add paging headers#36521

Merged
silverwind merged 17 commits intogo-gitea:mainfrom
TheFox0x7:add-paging-headers
Feb 6, 2026
Merged

Add paging headers#36521
silverwind merged 17 commits intogo-gitea:mainfrom
TheFox0x7:add-paging-headers

Conversation

@TheFox0x7
Copy link
Copy Markdown
Contributor

Adds support for paging in admin/hooks api endpoint

fixes: #36516

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 2, 2026
@TheFox0x7
Copy link
Copy Markdown
Contributor Author

Webhooks could probably be unified but I figured it's better to keep this focused. They are also in an awkward spot as they lack paging in webui so I don't think I can just add pagination for functions that are used by web routes without looking at UI.

This reverts commit bd9fb97.

revert date changes
This reverts commit 7052dd6edebe7ceb09a16d351100fd01c04f26be.
@github-actions github-actions bot added modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code labels Feb 3, 2026
@silverwind
Copy link
Copy Markdown
Member

test failure looks related:

--- FAIL: TestGetSystemOrDefaultWebhooks (0.01s)
    webhook_system_test.go:20: 
        	Error Trace:	/home/runner/work/gitea/gitea/models/webhook/webhook_system_test.go:20
        	Error:      	"[0xc0000f1200 0xc0000f12c0 0xc0000f1380 0xc0000f1440 0xc0000f1500 0xc0000f15c0]" should have 2 item(s), but has 6
        	Test:       	TestGetSystemOrDefaultWebhooks

@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 3, 2026
@silverwind silverwind requested a review from Copilot February 4, 2026 10:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR standardizes API pagination behavior across multiple endpoints, adding Link and X-Total-Count headers where appropriate and introducing proper paging for the admin webhooks endpoint, while also refactoring the system/default webhook query model.

Changes:

  • Centralizes pagination through utils.GetListOptions, clamping pages to a minimum of 1 and wiring ctx.SetLinkHeader and SetTotalCountHeader into numerous user, org, repo, shared, and notification endpoints.
  • Refactors system/default webhook listing to a new ListSystemWebhookOptions + GetGlobalWebhooks model and updates the admin /admin/hooks endpoint to be fully paginated and to emit paging headers.
  • Adds or adjusts pagination headers for specific resource listings (teams, org members, wiki pages, actions runs/jobs/tasks, secrets/variables, notifications, issue dependencies, etc.).

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
routers/api/v1/utils/page.go Ensures GetListOptions always uses at least page 1 and a normalized page size for all consumers.
routers/api/v1/utils/hook.go Makes owner hook listing use ListOptions and emit Link/X-Total-Count headers.
routers/api/v1/user/watch.go Uses shared ListOptions and adds Link/X-Total-Count for watched-repos endpoints.
routers/api/v1/user/star.go Adds Link headers for starred-repo listings using the user’s star count and current limit.
routers/api/v1/user/key.go Adds pagination support and headers for user public key listings; introduces a bug when filtering by fingerprint.
routers/api/v1/user/follower.go Wires in ListOptions and Link headers for followers and following lists.
routers/api/v1/user/action.go Paginates user-level actions variables and adds Link/X-Total-Count headers.
routers/api/v1/shared/block.go Uses ListOptions and emits pagination headers for user block listings.
routers/api/v1/shared/action.go Adds paging and Link/X-Total-Count headers to shared actions jobs and runs listings.
routers/api/v1/repo/wiki.go Adds pagination headers for wiki page list; adds a FIXME noting missing SetLinkHeader for revisions.
routers/api/v1/repo/status.go Paginates combined commit status-by-ref and adds corresponding pagination headers.
routers/api/v1/repo/issue_dependency.go Switches dependency listing to ListOptions and adds pagination headers, but currently uses the page size as the reported total.
routers/api/v1/repo/action.go Adds paging + Link headers for repo actions secrets, variables, and tasks.
routers/api/v1/org/team.go Makes org/team and user/team listings use ListOptions and emit Link/X-Total-Count, addressing the linked pagination issue.
routers/api/v1/org/member.go Paginates org member listing and adds Link/X-Total-Count headers.
routers/api/v1/org/action.go Adds pagination headers for org-level actions secrets and variables.
routers/api/v1/notify/user.go Adds Link headers alongside existing total-count logic for notification lists.
routers/api/v1/notify/repo.go Adds Link headers for repo-scoped notifications.
routers/api/v1/admin/hooks.go Refactors admin hooks listing to use GetGlobalWebhooks with ListOptions and emit pagination headers.
models/webhook/webhook_system.go Introduces ListSystemWebhookOptions and GetGlobalWebhooks to support paginated global webhook queries.
models/webhook/webhook_system_test.go Updates tests to cover GetGlobalWebhooks/ListSystemWebhookOptions while retaining an outdated test name.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}
}

ctx.SetLinkHeader(count, listOptions.PageSize)
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the fingerprint query parameter is provided, the query above uses db.Find without ListOptions, so pagination (page/limit) is ignored, but this line still sets the Link header based on listOptions.PageSize. That combination will generate pagination metadata that doesn't match the actual results (for example, clients may see multiple pages while every page returns the full, unpaginated result set); please either apply listOptions and a FindAndCount call in the fingerprint != "" branch as well, or skip SetLinkHeader/SetTotalCountHeader when filtering by fingerprint.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disagree with that. The promise is that it returns list of keys so the this is consistent with other lists (or at least that's what we're aiming for).
Besides from a quick look the function seems smart enough to skip those if there are no more pages

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the review is right. line 70 should also add ListOptions: listOptions,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added though I don't think it's needed - do we expect more than one key with the exact same fingerprint?

@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 4, 2026
@lunny lunny added this to the 1.26.0 milestone Feb 4, 2026
@lunny lunny added the type/enhancement An improvement of existing functionality label Feb 4, 2026
@silverwind silverwind added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 6, 2026
@silverwind silverwind enabled auto-merge (squash) February 6, 2026 12:42
@silverwind silverwind merged commit 403a73d into go-gitea:main Feb 6, 2026
24 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 6, 2026
zjjhot added a commit to zjjhot/gitea that referenced this pull request Feb 9, 2026
* giteaofficial/main:
  Refactor merge conan and container auth preserve actions taskID (go-gitea#36560)
  Fix assignee sidebar links and empty placeholder after go-gitea#32465 refactor (go-gitea#36559)
  Fix various version parsing problems (go-gitea#36553)
  Fix highlight diff result (go-gitea#36539)
  Refactor Nuget Auth to reuse Basic Auth Token Validation (go-gitea#36558)
  Update go dependencies (go-gitea#36548)
  Prevent navigation keys from triggering actions during IME composition (go-gitea#36540)
  Fix various mermaid bugs (go-gitea#36547)
  Add `elk` layout support to mermaid (go-gitea#36486)
  Allow configuring default PR base branch (fixes go-gitea#36412) (go-gitea#36425)
  [skip ci] Updated translations via Crowdin
  Color command/error logs in Actions log (go-gitea#36538)
  Add paging headers (go-gitea#36521)
  Fix issues filter dropdown showing empty label scope section (go-gitea#36535)
  [SECURITY] fix: Adjust the toolchain version (go-gitea#36537)
  Hide `add-matcher` and `remove-matcher` from actions job logs (go-gitea#36520)
  Improve timeline entries for WIP prefix changes in pull requests (go-gitea#36518)
Sirherobrine23 pushed a commit to Sirherobrine23/gitea that referenced this pull request Mar 4, 2026
Adds support for paging in admin/hooks api endpoint

fixes: go-gitea#36516

---------

Co-authored-by: techknowlogick <techknowlogick@gitea.com>
Co-authored-by: techknowlogick <matti@mdranta.net>
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 type/enhancement An improvement of existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API endpoint /org/{org}/teams doesn't provide Link header for pagination

6 participants