Skip to content

fix(api): add default sort order for action job queries#37667

Closed
mtschoen wants to merge 3 commits into
go-gitea:mainfrom
mtschoen:fix/action-jobs-default-sort-order
Closed

fix(api): add default sort order for action job queries#37667
mtschoen wants to merge 3 commits into
go-gitea:mainfrom
mtschoen:fix/action-jobs-default-sort-order

Conversation

@mtschoen
Copy link
Copy Markdown
Contributor

FindRunJobOptions does not implement ToOrders(), so action job API endpoints return results in ascending primary-key order (oldest first). Paginated queries like ?status=success&limit=20 return the 20 oldest jobs rather than the 20 most recent.

Add ToOrders() returning `action_run_job`.`id` DESC and a compile-time interface assertion, matching the existing FindRunOptions.ToOrders() from #28084 and the artifact ordering fix pattern from #33569.

Fixes #37666


Built with Claude Code.

FindRunJobOptions does not implement ToOrders(), so action job API
endpoints return results in ascending primary-key order (oldest first).
Paginated queries like ?status=success&limit=20 return the 20 oldest
jobs rather than the 20 most recent.

The sibling FindRunOptions already has ToOrders() returning DESC
(added in go-gitea#28084 to preserve the pre-refactor .Desc("id") call),
but FindRunJobOptions never had ordering — the original hand-written
FindRunJobs() also lacked it.

Add ToOrders() returning `action_run_job.id DESC` and a compile-time
interface assertion, following the pattern from go-gitea#33569 (artifact
ordering fix).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label May 12, 2026
mtschoen and others added 2 commits May 11, 2026 19:37
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Internal callers (webhook dispatch, concurrency checks) pass
FindRunJobOptions with zero-value ListOptions, so they should not get
DESC ordering imposed — it changed the webhook payload order and broke
Test_WebhookWorkflowJob which expects jobs in creation order.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mtschoen
Copy link
Copy Markdown
Contributor Author

Closing in favor of a better approach: adding explicit sort/direction query parameters to the job list endpoints instead of hardcoding DESC ordering. The blanket ToOrders() override broke internal callers (webhook dispatch) that depend on creation order. Will open a new PR with the parameter-based approach and proper test coverage.

— Matt (with help from Claude Code)

@mtschoen mtschoen closed this May 12, 2026
silverwind added a commit that referenced this pull request May 13, 2026
…37672)

Adds `sort` and `order` query 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 existing `OrderByMap` pattern used by repo/user search
endpoints.

- Default is `id` / `asc` (backwards compatible — matches previous DB
natural order)
- Only `id` sort field for now; the map is extensible for future fields
- Returns 422 for invalid sort/order values
- `ToOrders()` returns empty string when `OrderBy` is unset, so internal
callers (webhook dispatch, concurrency checks) are unaffected

Closes: #37666
Supersedes: #37667
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: silverwind <me@silverwind.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Action job API endpoints return oldest jobs first with no sort option

2 participants