Re-run workflow runs and jobs with the API token on Forgejo 17 #305

Merged
stephen merged 1 commit from fj-297-run-rerun into main 2026-11-10 04:15:58 +00:00
Owner

Closes #297 for Forgejo 17: fj run rerun <n> [--failed | -j <job>] now works with the API token on private repositories.

rasterhub's Forgejo 17 has token-accepting POST /api/v1/repos/{owner}/{repo}/actions/runs/{run_id}/rerun and .../actions/jobs/{job_id}/rerun (204 on success, 400, 403, 404), so this uses option 1 from the issue and needs neither the cookie and CSRF path nor #103. The displayed run number is resolved to the internal run id first. -j keeps its zero-based job index. Gitea and older Forgejo behave as before, and the "no API route" message is gone where the route exists. Requests go through Client::request and the existing trusted-URL policy.

--failed picks the failed or cancelled jobs from the run. If every job is selected it sends one run rerun. Otherwise it reruns the selected jobs one at a time, refreshing the run's jobs before each POST and skipping any selected job that is no longer in a terminal state (it was already rescheduled as a dependent of an earlier rerun; no server-side deduplication is assumed). A rejected POST does not stop the rest: the server message is reported, the remaining jobs still run, and the exit status is nonzero. A 400 keeps the server's detail, a 403 is a permission failure, and a 404 names the run URL.

The rerun code moves into workflow_rerun.rs with its own wiremock tests, which also shrinks workflow_run.rs. Help text and the compatibility docs are updated.

Known edge, to follow up: a selected dependent that finishes between two refreshes can be rerun again, since jobs are tracked by id and not by attempt.

Not run live. Clippy fails locally on an unrelated, unchanged line (pr_line_comment.rs:65) under the host's newer Rust; CI pins 1.95.

Closes #297 for Forgejo 17: `fj run rerun <n> [--failed | -j <job>]` now works with the API token on private repositories. rasterhub's Forgejo 17 has token-accepting `POST /api/v1/repos/{owner}/{repo}/actions/runs/{run_id}/rerun` and `.../actions/jobs/{job_id}/rerun` (204 on success, 400, 403, 404), so this uses option 1 from the issue and needs neither the cookie and CSRF path nor #103. The displayed run number is resolved to the internal run id first. `-j` keeps its zero-based job index. Gitea and older Forgejo behave as before, and the "no API route" message is gone where the route exists. Requests go through `Client::request` and the existing trusted-URL policy. `--failed` picks the failed or cancelled jobs from the run. If every job is selected it sends one run rerun. Otherwise it reruns the selected jobs one at a time, refreshing the run's jobs before each POST and skipping any selected job that is no longer in a terminal state (it was already rescheduled as a dependent of an earlier rerun; no server-side deduplication is assumed). A rejected POST does not stop the rest: the server message is reported, the remaining jobs still run, and the exit status is nonzero. A 400 keeps the server's detail, a 403 is a permission failure, and a 404 names the run URL. The rerun code moves into `workflow_rerun.rs` with its own wiremock tests, which also shrinks `workflow_run.rs`. Help text and the compatibility docs are updated. Known edge, to follow up: a selected dependent that finishes between two refreshes can be rerun again, since jobs are tracked by id and not by attempt. Not run live. Clippy fails locally on an unrelated, unchanged line (`pr_line_comment.rs:65`) under the host's newer Rust; CI pins 1.95.
Support token-authenticated workflow reruns on Forgejo 17
All checks were successful
ci / check (pull_request) Successful in 18m35s
ci / coverage (pull_request) Successful in 3m11s
ci / live-e2e (pull_request) Successful in 3m19s
2dd81872ee
gerri approved these changes 2026-11-10 03:53:34 +00:00
gerri left a comment

Automated Codex review (read-only) of head 2dd81872ee.

  • Low (edge case), src/api/workflow_rerun.rs:80,112: Invariant: identity across attempts (standards 6 and 17). As acknowledged in the PR body’s known edge case, a dependent can finish its new attempt before the next refresh. Its reused ID and terminal status then cause another rerun. Track selected jobs by (id, attempt) and skip jobs whose attempt advanced. This affects Forgejo --failed; whole-run, explicit-job, and Gitea paths do not use this loop. Accepted follow-up, nonblocking.

No additional confirmed problems found. Tests were not run in the read-only review.

BLOCKING: 0

Reviewed head 2dd81872ee at 2026-11-10T03:53:33Z by codex exec (read-only sandbox).

Automated Codex review (read-only) of head 2dd81872ee30531becd49b914919be74b4584edb. - **Low** (edge case), `src/api/workflow_rerun.rs:80,112`: **Invariant: identity across attempts** (standards 6 and 17). As acknowledged in the PR body’s known edge case, a dependent can finish its new attempt before the next refresh. Its reused ID and terminal status then cause another rerun. Track selected jobs by `(id, attempt)` and skip jobs whose attempt advanced. This affects Forgejo `--failed`; whole-run, explicit-job, and Gitea paths do not use this loop. Accepted follow-up, nonblocking. No additional confirmed problems found. Tests were not run in the read-only review. BLOCKING: 0 --- Reviewed head 2dd81872ee30531becd49b914919be74b4584edb at 2026-11-10T03:53:33Z by codex exec (read-only sandbox).
Sign in to join this conversation.
No description provided.