Skip to content

fix(actions): use base branch ref for pull_request_target context - #38636

Merged
bircni merged 5 commits into
go-gitea:mainfrom
SudhanshuMatrix:fix/actions-pull-request-target-ref
Jul 27, 2026
Merged

bircni merged 5 commits into
go-gitea:mainfrom
SudhanshuMatrix:fix/actions-pull-request-target-ref

Conversation

@SudhanshuMatrix

Copy link
Copy Markdown
Contributor

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:

ref = git.BranchPrefix + pullPayload.PullRequest.Base.Name

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>
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jul 26, 2026
@github-actions github-actions Bot added topic/gitea-actions related to the actions of Gitea type/bug labels Jul 26, 2026
@SudhanshuMatrix
SudhanshuMatrix marked this pull request as draft July 26, 2026 07:27
@SudhanshuMatrix
SudhanshuMatrix marked this pull request as ready for review July 26, 2026 07:28
@silverwind
silverwind requested a review from Copilot July 26, 2026 11:04

Copilot AI left a comment

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.

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 of PullRequest.Base.Name (label) when computing ref for pull_request_target.
  • Add a regression unit test ensuring ref and ref_name are 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.

@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 Jul 26, 2026
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jul 26, 2026
@lunny lunny added the backport/v1.27 This PR should be backported to Gitea 1.27 label Jul 26, 2026
@wxiaoguang wxiaoguang mentioned this pull request Jul 26, 2026
22 tasks
Signed-off-by: wxiaoguang <wxiaoguang@gmail.com>
@wxiaoguang

wxiaoguang commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

merge conflict is resolved, due to the new test TestGenerateGiteaContext_NilAttempt, maybe need to manually backport.

@bircni
bircni enabled auto-merge (squash) July 27, 2026 05:36
@bircni bircni added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Jul 27, 2026
@bircni
bircni merged commit e15a7e9 into go-gitea:main Jul 27, 2026
23 checks passed
@GiteaBot GiteaBot added this to the 28.0.0 milestone Jul 27, 2026
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Jul 27, 2026
@GiteaBot GiteaBot added the backport/done All backports for this PR have been created label Jul 27, 2026
@SudhanshuMatrix
SudhanshuMatrix deleted the fix/actions-pull-request-target-ref branch July 27, 2026 06:39
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/done All backports for this PR have been created backport/v1.27 This PR should be backported to Gitea 1.27 lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. topic/gitea-actions related to the actions of Gitea type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants