fix(actions): use base branch ref for pull_request_target context - #38636
Merged
bircni merged 5 commits intoJul 27, 2026
Merged
Conversation
Fixes an issue where pull_request_target workflows set 'ref' in gitea/github context to 'refs/heads/owner:branch' instead of 'refs/heads/branch'. PRBranchInfo.Name contains the full label string (e.g. 'owner:branch'), whereas PRBranchInfo.Ref contains the git branch reference name (e.g. 'branch'). Signed-off-by: Sudhanshu Singh <sudhanshuwriterblc@gmail.com>
SudhanshuMatrix
marked this pull request as draft
July 26, 2026 07:27
SudhanshuMatrix
marked this pull request as ready for review
July 26, 2026 07:28
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes Actions context generation for pull_request_target runs so that gitea.ref / github.ref correctly points to the base branch ref (refs/heads/<branch>) instead of the display label (<owner>:<branch>), aligning with GitHub’s documented semantics for pull_request_target.
Changes:
- Use
PullRequest.Base.Ref(branch name) instead ofPullRequest.Base.Name(label) when computingrefforpull_request_target. - Add a regression unit test ensuring
refandref_nameare derived from the base branch ref.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| services/actions/context.go | Corrects pull_request_target context ref construction to use the base branch ref. |
| services/actions/context_test.go | Adds regression coverage for pull_request_target ref/ref_name behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
silverwind
approved these changes
Jul 26, 2026
lunny
approved these changes
Jul 26, 2026
Signed-off-by: wxiaoguang <wxiaoguang@gmail.com>
Contributor
|
merge conflict is resolved, due to the new test TestGenerateGiteaContext_NilAttempt, maybe need to manually backport. |
bircni
enabled auto-merge (squash)
July 27, 2026 05:36
zjjhot
added a commit
to zjjhot/gitea
that referenced
this pull request
Jul 27, 2026
* 'main' of https://github.com/go-gitea/gitea: (55 commits) fix(actions): use base branch ref for pull_request_target context (go-gitea#38636) fix(actions): skip already-approved runs in `ApproveRuns` (go-gitea#38653) fix(api): accept fully-qualified refs in contents API (go-gitea#38650) [skip ci] Updated translations via Crowdin chore(build): upload release to Cloudflare R2 (go-gitea#38635) ci: match `# renovate:` markers that trail the value (go-gitea#38640) feat: admin impersonates a user (go-gitea#38614) refactor: git patch apply (go-gitea#38637) fix: orgmode render include path (go-gitea#38642) fix(actions): cancel tasks immediately when the runner stopped reporting (go-gitea#38616) fix(issues): fix label bulk-load key and reduce log noise in LoadLabel (go-gitea#38632) fix(ui): avoid layout shifts in `overflow-menu` and repo filter (go-gitea#37818) chore: generate codemirror languages from `linguist-languages` package (go-gitea#38624) [skip ci] Updated translations via Crowdin fix(actions): improve runner list status sorting, labels and task job links (go-gitea#38586) fix(actions): correctness and hardening fixes (go-gitea#38518) chore: remove goreportcard badge (go-gitea#38630) fix(repo): prevent double-write redirect collisions on dependency errors, fix ui (go-gitea#38627) fix(deps): update module github.com/getkin/kin-openapi to v0.144.0 [security] (go-gitea#38623) chore: update and relax revive naming rules (go-gitea#38615) ...
zjjhot
added a commit
to zjjhot/gitea
that referenced
this pull request
Jul 27, 2026
* main: (55 commits) fix(actions): use base branch ref for pull_request_target context (go-gitea#38636) fix(actions): skip already-approved runs in `ApproveRuns` (go-gitea#38653) fix(api): accept fully-qualified refs in contents API (go-gitea#38650) [skip ci] Updated translations via Crowdin chore(build): upload release to Cloudflare R2 (go-gitea#38635) ci: match `# renovate:` markers that trail the value (go-gitea#38640) feat: admin impersonates a user (go-gitea#38614) refactor: git patch apply (go-gitea#38637) fix: orgmode render include path (go-gitea#38642) fix(actions): cancel tasks immediately when the runner stopped reporting (go-gitea#38616) fix(issues): fix label bulk-load key and reduce log noise in LoadLabel (go-gitea#38632) fix(ui): avoid layout shifts in `overflow-menu` and repo filter (go-gitea#37818) chore: generate codemirror languages from `linguist-languages` package (go-gitea#38624) [skip ci] Updated translations via Crowdin fix(actions): improve runner list status sorting, labels and task job links (go-gitea#38586) fix(actions): correctness and hardening fixes (go-gitea#38518) chore: remove goreportcard badge (go-gitea#38630) fix(repo): prevent double-write redirect collisions on dependency errors, fix ui (go-gitea#38627) fix(deps): update module github.com/getkin/kin-openapi to v0.144.0 [security] (go-gitea#38623) chore: update and relax revive naming rules (go-gitea#38615) ...
silverwind
pushed a commit
that referenced
this pull request
Jul 27, 2026
…8636) (#38657) Backport #38636 by @SudhanshuMatrix Fixes a bug in Actions context generation for `pull_request_target` workflows where `github.ref` / `gitea.ref` was incorrectly populated with `refs/heads/owner:branch` instead of `refs/heads/branch`. ### Problem Statement In `services/actions/context.go`, when constructing the `ref` string for `pull_request_target` events: ```go ref = git.BranchPrefix + pullPayload.PullRequest.Base.Name Signed-off-by: Sudhanshu Singh <sudhanshuwriterblc@gmail.com> Signed-off-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Shudhanshu Singh <sudhanshuwriterblc@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a bug in Actions context generation for
pull_request_targetworkflows wheregithub.ref/gitea.refwas incorrectly populated withrefs/heads/owner:branchinstead ofrefs/heads/branch.Problem Statement
In
services/actions/context.go, when constructing therefstring forpull_request_targetevents: