Skip to content

feat: Add Actions API rerun endpoints for runs and jobs#36768

Merged
wxiaoguang merged 14 commits intogo-gitea:mainfrom
bircni:feature/trigger-rerun-via-api
Mar 2, 2026
Merged

feat: Add Actions API rerun endpoints for runs and jobs#36768
wxiaoguang merged 14 commits intogo-gitea:mainfrom
bircni:feature/trigger-rerun-via-api

Conversation

@bircni
Copy link
Copy Markdown
Member

@bircni bircni commented Feb 26, 2026

This PR adds official REST API endpoints to rerun Gitea Actions workflow runs and individual jobs:

POST /api/v1/repos/{owner}/{repo}/actions/runs/{run}/rerun
POST /api/v1/repos/{owner}/{repo}/actions/runs/{run}/jobs/{job_id}/rerun
It reuses the existing rerun behavior from the web UI and exposes it through stable API routes.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 26, 2026
@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 26, 2026
@bircni bircni marked this pull request as ready for review February 26, 2026 18:31
@bircni
Copy link
Copy Markdown
Member Author

bircni commented Feb 26, 2026

@silverwind I think it's ready to review

@silverwind silverwind requested a review from Copilot February 26, 2026 18:39
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 adds REST API endpoints to rerun GitHub Actions-like workflow runs and individual jobs in Gitea. The new endpoints expose existing rerun functionality from the web UI through stable API routes.

Changes:

  • Added POST /api/v1/repos/{owner}/{repo}/actions/runs/{run}/rerun endpoint to rerun entire workflow runs
  • Added POST /api/v1/repos/{owner}/{repo}/actions/runs/{run}/jobs/{job_id}/rerun endpoint to rerun specific jobs
  • Implemented comprehensive test coverage for both endpoints including success, authorization, and error cases

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
routers/api/v1/api.go Registers the two new rerun endpoints with proper authentication and authorization middleware
routers/api/v1/repo/action.go Implements the core rerun logic including handlers, validation, status updates, and concurrency handling
templates/swagger/v1_json.tmpl Adds OpenAPI/Swagger documentation for the new rerun endpoints
tests/integration/api_actions_run_test.go Adds integration tests covering successful reruns, authorization failures, and conflict scenarios

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

@bircni
Copy link
Copy Markdown
Member Author

bircni commented Feb 26, 2026

No requests from Copilot 😄

@bircni bircni force-pushed the feature/trigger-rerun-via-api branch 2 times, most recently from c801816 to 7f27b91 Compare February 27, 2026 18:03
@bircni
Copy link
Copy Markdown
Member Author

bircni commented Feb 27, 2026

Vscode adding new lines :-(

@silverwind
Copy link
Copy Markdown
Member

silverwind commented Feb 27, 2026

PR Review (written by Claude)

Overall this is a solid PR — clean extraction of rerun logic into a service layer with proper API endpoints, good error handling, and decent test coverage.

Code duplication with web handler

The main concern is that the web handler in routers/web/repo/actions/view.go (Rerun() and rerunJob(), lines 406-556) still contains the exact same logic that's been freshly written in services/actions/rerun.go. The new RerunWorkflowRunJobs and rerunWorkflowJob are near-copies of the web handler code. The web handler should be refactored to call RerunWorkflowRunJobs() instead of duplicating everything. Otherwise, any future bug fix or behavior change needs to be applied in two places.

Minor

  • HTTP 200 vs 201 — GitHub's equivalent rerun endpoints return 201 Created. If Gitea aims for API compatibility, consider using http.StatusCreated instead of http.StatusOK. Though if existing Gitea conventions use 200 for similar actions, this is fine.

  • Route shape differs from GitHub — The job rerun is POST .../runs/{run}/jobs/{job_id}/rerun here, while GitHub uses POST .../actions/jobs/{job_id}/rerun (not nested under runs). This is consistent with Gitea's existing routing structure so likely intentional, just noting it.

@bircni
Copy link
Copy Markdown
Member Author

bircni commented Feb 27, 2026

@silverwind fixing it - I also let AI review it and it did not find these - do you use some sort of custom instructions?

@silverwind
Copy link
Copy Markdown
Member

silverwind commented Feb 28, 2026

No, my prompt is just "review #36768", it shows that my Opus 4.6 is just more thorough in reviewing. I think it may also have some memory for Gitea API changes regarding checking for GitHub compat issues. BTW I hear Codex 5.3 is also very good at reviewing, possibly even better than Opus.

@bircni
Copy link
Copy Markdown
Member Author

bircni commented Feb 28, 2026

@silverwind ah ok cool!
Codex is just not generating me such a nice useful comment

@bircni
Copy link
Copy Markdown
Member Author

bircni commented Feb 28, 2026

I think I fixed the rest

@silverwind
Copy link
Copy Markdown
Member

What about the 201 status code? Is it worth changing or is 200 more consistent for gitea?

@bircni bircni force-pushed the feature/trigger-rerun-via-api branch from 4417664 to dd1e187 Compare February 28, 2026 14:08
@bircni
Copy link
Copy Markdown
Member Author

bircni commented Feb 28, 2026

What about the 201 status code? Is it worth changing or is 200 more consistent for gitea?

You are right - 201 is better
fixed that

@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 28, 2026
@bircni bircni requested a review from lunny February 28, 2026 14:40
@GiteaBot GiteaBot removed the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label Mar 1, 2026
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

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.


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

// rerun cancel true scenario

// FIXME: is the jobIndex 0-based or 1-based? From code, it should be 0-based, but here it uses 1, and cause failure
req = NewRequest(t, "POST", fmt.Sprintf("/%s/%s/actions/runs/%d/jobs/%d/rerun", user2.Name, apiRepo.Name, run2.Index, 1))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Zettat123

Now we have new problems. I think the test is wrong, it should use 0-based job index.

The error is caught by the newly refactored code.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

seems actually like the old code did just rerun all jobs in this case as 1 is out of range. While the test case has exactly one job.

Copy link
Copy Markdown
Contributor

@wxiaoguang wxiaoguang Mar 2, 2026

Choose a reason for hiding this comment

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

Yep. Such URL is only constructed by our frontend Vue component.

So I think the changed/corrected behavior (404 for out-of-range job index) should be safe and fine.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So I think the changed/corrected behavior (404 for out-of-bound job index) should be safe and fine.

yes I think so as well.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@wxiaoguang Thank you for pointing out and fixing this issue. The corrected logic looks fine.

@wxiaoguang wxiaoguang marked this pull request as draft March 2, 2026 09:41
@wxiaoguang wxiaoguang force-pushed the feature/trigger-rerun-via-api branch from 627db26 to 52cea03 Compare March 2, 2026 09:45
@wxiaoguang wxiaoguang marked this pull request as ready for review March 2, 2026 17:55
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Mar 2, 2026
@lunny lunny enabled auto-merge (squash) March 2, 2026 19:07
@wxiaoguang wxiaoguang removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Mar 2, 2026
@wxiaoguang wxiaoguang disabled auto-merge March 2, 2026 19:25
Signed-off-by: wxiaoguang <wxiaoguang@gmail.com>
@wxiaoguang wxiaoguang added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Mar 2, 2026
@wxiaoguang wxiaoguang enabled auto-merge (squash) March 2, 2026 19:35
@wxiaoguang wxiaoguang merged commit 054eb6d into go-gitea:main Mar 2, 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 Mar 2, 2026
@bircni bircni deleted the feature/trigger-rerun-via-api branch March 2, 2026 21:38
zjjhot added a commit to zjjhot/gitea that referenced this pull request Mar 4, 2026
* giteaofficial/main:
  [skip ci] Updated translations via Crowdin
  fix: /repos/{owner}/{repo}/actions/{runs,jobs} requiring owner permissions (go-gitea#36818)
  Fix CRAN package version validation to allow more than 4 version components (go-gitea#36813)
  Fix API not persisting pull request unit config when has_pull_requests is not set (go-gitea#36718)
  feat: Add Actions API rerun endpoints for runs and jobs (go-gitea#36768)
  Fix bug when pushing mirror with wiki (go-gitea#36795)
  Pull Request Pusher should be the author of the merge (go-gitea#36581)
  Delete non-exist branch should return 404 (go-gitea#36694)
  Remove API registration-token (go-gitea#36801)
  Add background and run count to actions list page (go-gitea#36707)
silverwind added a commit to silverwind/gitea that referenced this pull request Mar 6, 2026
* origin/main: (27 commits)
  Fix OAuth2 authorization code expiry and reuse handling (go-gitea#36797)
  Fix org permission API visibility checks for hidden members and private orgs (go-gitea#36798)
  Fix non-admins unable to automerge PRs from forks (go-gitea#36833)
  upgrade to github.com/cloudflare/circl 1.6.3, svgo 4.0.1, markdownlint-cli 0.48.0 (go-gitea#36837)
  Fix dump release asset bug (go-gitea#36799)
  build(deps): update material-icon-theme v5.32.0 (go-gitea#36832)
  Fix bug to check whether user can update pull request branch or rebase branch (go-gitea#36465)
  Fix forwarded proto handling for public URL detection (go-gitea#36810)
  Fix artifacts v4 backend upload problems (go-gitea#36805)
  Add a git grep search timeout (go-gitea#36809)
  fix(repo): unify DEFAULT_SHOW_FULL_NAME output in templates and dropdown (go-gitea#36597)
  Harden render iframe open-link handling (go-gitea#36811)
  [skip ci] Updated translations via Crowdin
  fix: /repos/{owner}/{repo}/actions/{runs,jobs} requiring owner permissions (go-gitea#36818)
  Fix CRAN package version validation to allow more than 4 version components (go-gitea#36813)
  Fix API not persisting pull request unit config when has_pull_requests is not set (go-gitea#36718)
  feat: Add Actions API rerun endpoints for runs and jobs (go-gitea#36768)
  Fix bug when pushing mirror with wiki (go-gitea#36795)
  Pull Request Pusher should be the author of the merge (go-gitea#36581)
  Delete non-exist branch should return 404 (go-gitea#36694)
  ...

# Conflicts:
#	routers/web/repo/issue_view.go
@bircni bircni mentioned this pull request Mar 22, 2026
lunny pushed a commit that referenced this pull request Mar 22, 2026
I'd like to apply as a maintainer.

Thanks to @TheFox0x7 for the suggestion.

Merged PRs:
- #36441
- #36571
- #36603
- #36768
- #36776
- #36783
- #36876
- #36883
- #36924

Ongoing work:
- #36514
- #36752
- #36912
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants