feat(api): add sort and order query parameters to job list endpoints#37672
Conversation
Adds `sort` and `order` query parameters to all action job list API
endpoints (`/user/actions/jobs`, `/repos/{owner}/{repo}/actions/jobs`,
`/repos/{owner}/{repo}/actions/runs/{run}/jobs`, `/admin/actions/jobs`).
Follows the existing OrderByMap pattern used by repo/user search.
Only `id` is supported as a sort field initially. Default is `id` ASC
for backwards compatibility. Internal callers (webhook dispatch,
concurrency checks) are unaffected — they never set OrderBy so
ToOrders() returns empty string and DB uses natural insertion order.
Fixes go-gitea#37666
Closes go-gitea#37667
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8399660dd3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The unqualified `id` in ORDER BY was ambiguous when the query joins `repository` (user/org job endpoints), causing 500 errors on MySQL/MSSQL/PostgreSQL. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The previous fix only qualified the column in JobOrderByMap (used when sort/order params are provided). The default OrderBy still used the unqualified db.SearchOrderByID, which also fails on MySQL/MSSQL/PgSQL when the user/org endpoints join with repository. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Declare 422 response on all four job-list swagger blocks; the code
already returns it for invalid sort/order but the spec only listed
400 and 404.
- Drop the unreachable empty-OrderBy branch in FindRunJobOptions.ToOrders;
string("") is "", so the conditional was a no-op.
- Add integration tests asserting 422 for sort=bogus and order=bogus on
/api/v1/user/actions/jobs.
- Regenerate swagger templates.
Co-Authored-By: silverwind <me@silverwind.io>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…epos The sort/order validation block was copy-pasted across three handlers (shared/action.go, admin/user.go, repo/repo.go) with identical control flow — each ~17 lines of nested if/else writing the same 422 responses. Hoist it into routers/api/v1/utils.ResolveSortOrder: takes the OrderByMap and a default, returns the resolved SearchOrderBy or writes 422 and signals failure via ok=false. Each call site drops from ~17 to 4 lines with identical behavior. Co-Authored-By: silverwind <me@silverwind.io> Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The two JobsInvalidSort/JobsInvalidOrder integration tests exercised generic ResolveSortOrder validation through a full HTTP round-trip on one of three call sites. Drop them and add a small unit test directly on the helper — one location covers the behavior for all callers. Co-Authored-By: silverwind <me@silverwind.io> Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR adds API-level sorting support (sort + order query parameters) to Actions job list endpoints by introducing a shared sort-resolution helper and plumbing an explicit ORDER BY into the job query options. It also updates Swagger specs and adds integration coverage for default/descending job ordering.
Changes:
- Add
ResolveSortOrderhelper to consistently parse/validatesortandorderquery params and return 422 on invalid values. - Introduce
FindRunJobOptions.OrderBy+ToOrders()and aJobOrderByMapto enable explicit ordering for Action job listings. - Update Swagger (v1 + OpenAPI3) and add integration tests validating default (ASC) and
sort=id&order=descbehavior.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/integration/api_actions_run_test.go | Adds integration tests for default ASC ordering and explicit DESC ordering on /user/actions/jobs. |
| templates/swagger/v1_openapi3_json.tmpl | Documents sort/order query params and 422 response for job list endpoints (OpenAPI3). |
| templates/swagger/v1_json.tmpl | Documents sort/order query params and 422 response for job list endpoints (Swagger v1). |
| routers/api/v1/utils/sort.go | Adds shared ResolveSortOrder helper for API query sorting validation. |
| routers/api/v1/utils/sort_test.go | Adds a unit test for invalid sort/order inputs (error path). |
| routers/api/v1/user/action.go | Updates endpoint docs to include sort/order and 422 response. |
| routers/api/v1/shared/action.go | Applies resolved OrderBy to job list queries via FindRunJobOptions. |
| routers/api/v1/repo/repo.go | Refactors repo search sort/order parsing to use ResolveSortOrder. |
| routers/api/v1/repo/action.go | Updates repo job endpoints docs to include sort/order and 422 response. |
| routers/api/v1/admin/user.go | Refactors admin user search sort/order parsing to use ResolveSortOrder. |
| routers/api/v1/admin/action.go | Updates admin job endpoint docs to include sort/order and 422 response. |
| models/actions/run_job_list.go | Adds OrderBy + ToOrders() and defines JobOrderByMap for action job queries. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address review feedback: previously only the error paths were exercised. Add assertions for default-when-absent, valid sort with default order, and valid sort with explicit desc — with distinct asc/desc values so a swapped lookup would be caught. Co-Authored-By: silverwind <me@silverwind.io> Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* origin/main: chore: clean up "contrib" dir (go-gitea#37690) feat(api): add sort and order query parameters to job list endpoints (go-gitea#37672) fix: Sort action run jobs by JobID and Name with matrix examples (go-gitea#37046) fix: catch and fix more lint problems (go-gitea#37674) docs(agents): update AGENTS.md (go-gitea#37684) fix(actions): run `TransferLogs` on `UpdateLog{Rows:[], NoMore:true}` (go-gitea#37631) # Conflicts: # build/test-env-check.sh # contrib/update_dependencies.sh
…thor * origin/main: [skip ci] Updated translations via Crowdin fix: snap build (main branch) (go-gitea#37685) chore: introduce HTMLBuilder (go-gitea#37688) chore: clean up "contrib" dir (go-gitea#37690) feat(api): add sort and order query parameters to job list endpoints (go-gitea#37672) fix: Sort action run jobs by JobID and Name with matrix examples (go-gitea#37046) fix: catch and fix more lint problems (go-gitea#37674) docs(agents): update AGENTS.md (go-gitea#37684) fix(actions): run `TransferLogs` on `UpdateLog{Rows:[], NoMore:true}` (go-gitea#37631)
Summary
Adds
sortandorderquery parameters to all action job list API endpoints (/admin/actions/jobs,/repos/{owner}/{repo}/actions/jobs,/repos/{owner}/{repo}/actions/runs/{run}/jobs,/user/actions/jobs), following the existingOrderByMappattern used by repo/user search endpoints.id/asc(backwards compatible — matches previous DB natural order)idsort field for now; the map is extensible for future fieldsToOrders()returns empty string whenOrderByis unset, so internal callers (webhook dispatch, concurrency checks) are unaffectedCloses #37666. Supersedes #37667, which was closed because hardcoding
DESCordering broke webhook dispatch by changing the order for all internal callers.Test plan
JobsDefaultOrderAscintegration test — verifies default ordering is ascending by IDJobsOrderedByIDDescintegration test — verifiessort=id&order=descreturns descending orderTestAPIDownloadArchive— pre-existing, unrelated)Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com