From b29e21a90c22daade085fee002fe5d6463eea61a Mon Sep 17 00:00:00 2001 From: Andreas Ahlenstorf Date: Mon, 15 Jun 2026 04:15:07 +0200 Subject: [PATCH] fix: use proper `${{ forgejo.ref }}` in scheduled workflows (#13081) Forgejo uses the plain branch name instead of a so-called fully-formed ref name (`refs/heads/`) when setting the `Ref` property of scheduled workflows, which is wrong. Resolves https://codeberg.org/forgejo/forgejo/issues/13060. ## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. All work and communication must conform to Forgejo's [AI Agreement](https://codeberg.org/forgejo/governance/src/branch/main/AIAgreement.md). There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org). ### Tests for Go changes (can be removed for JavaScript changes) - I added test coverage for Go changes... - [ ] in their respective `*_test.go` for unit tests. - [x] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I ran... - [x] `make pr-go` before pushing ### Tests for JavaScript changes (can be removed for Go changes) - I added test coverage for JavaScript changes... - [ ] in `web_src/js/*.test.js` if it can be unit tested. - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)). ### Documentation - [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [ ] I did not document these changes and I do not expect someone else to do it. ### Release notes - [x] This change will be noticed by a Forgejo user or admin (feature, bug fix, performance, etc.). I suggest to include a release note for this change. - [ ] This change is not visible to a Forgejo user or admin (refactor, dependency upgrade, etc.). I think there is no need to add a release note for this change. *The decision if the pull request will be shown in the release notes is up to the mergers / release team.* The content of the `release-notes/.md` file will serve as the basis for the release notes. If the file does not exist, the title of the pull request will be used instead. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/13081 Reviewed-by: Mathieu Fenniak --- models/actions/schedule_test.go | 4 ++-- services/actions/notifier_helper.go | 5 +++-- tests/integration/actions_trigger_test.go | 1 + tests/integration/change_default_branch_test.go | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/models/actions/schedule_test.go b/models/actions/schedule_test.go index 016185cb42..41a61e45eb 100644 --- a/models/actions/schedule_test.go +++ b/models/actions/schedule_test.go @@ -56,7 +56,7 @@ jobs: WorkflowID: "test.yaml", WorkflowDirectory: ".forgejo/workflows", TriggerUserID: -2, - Ref: "main", + Ref: "refs/heads/main", CommitSHA: "6af834a5bc97c1a337eb3a21d26903c5cdceca0c", Event: webhook.HookEventPush, EventPayload: "{\"action\":\"schedule\"}", @@ -75,7 +75,7 @@ jobs: assert.Equal(t, "test.yaml", schedules[0].WorkflowID) assert.Equal(t, ".forgejo/workflows", schedules[0].WorkflowDirectory) assert.Equal(t, int64(-2), schedules[0].TriggerUserID) - assert.Equal(t, "main", schedules[0].Ref) + assert.Equal(t, "refs/heads/main", schedules[0].Ref) assert.Equal(t, "6af834a5bc97c1a337eb3a21d26903c5cdceca0c", schedules[0].CommitSHA) assert.Equal(t, webhook.HookEventPush, schedules[0].Event) assert.JSONEq(t, "{\"action\":\"schedule\"}", schedules[0].EventPayload) diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go index 5e048a83ad..5e1cf261ab 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -598,7 +598,7 @@ func handleSchedules( WorkflowID: dwf.EntryName, WorkflowDirectory: dwf.EntryDirectory, TriggerUserID: user_model.ActionsUserID, - Ref: input.Repo.DefaultBranch, + Ref: input.Ref.String(), CommitSHA: commit.ID.String(), Event: input.Event, EventPayload: string(p), @@ -639,7 +639,8 @@ func DetectAndHandleSchedules(ctx context.Context, repo *repo_model.Repository) // We need a notifyInput to call handleSchedules // if repo is a mirror, commit author maybe an external user, // so we use action user as the Doer of the notifyInput - notifyInput := newNotifyInputForSchedules(repo) + notifyInput := newNotifyInputForSchedules(repo). + WithRef(git.RefNameFromBranch(repo.DefaultBranch).String()) return handleSchedules(ctx, scheduleWorkflows, commit, notifyInput, repo.DefaultBranch) } diff --git a/tests/integration/actions_trigger_test.go b/tests/integration/actions_trigger_test.go index 5bd0397498..2556a9eb2f 100644 --- a/tests/integration/actions_trigger_test.go +++ b/tests/integration/actions_trigger_test.go @@ -1289,6 +1289,7 @@ jobs: assert.Equal(t, repo.OwnerID, schedules[0].OwnerID) assert.Equal(t, testCase.workflowID, schedules[0].WorkflowID) assert.Equal(t, testCase.workflowDirectory, schedules[0].WorkflowDirectory) + assert.Equal(t, "refs/heads/main", schedules[0].Ref) assert.Equal(t, int64(-2), schedules[0].TriggerUserID) assert.Equal(t, sha, schedules[0].CommitSHA) assert.Equal(t, webhook_module.HookEventPush, schedules[0].Event) diff --git a/tests/integration/change_default_branch_test.go b/tests/integration/change_default_branch_test.go index 610e3d07c1..f0aa53cb7d 100644 --- a/tests/integration/change_default_branch_test.go +++ b/tests/integration/change_default_branch_test.go @@ -167,12 +167,12 @@ jobs: err = repo_service.SetRepoDefaultBranch(t.Context(), repo, gitRepo, "test") require.NoError(t, err) - assertSchedule(t, "test", testWorkflow.updatedWorkflowContent, expectedTestSpec) + assertSchedule(t, "refs/heads/test", testWorkflow.updatedWorkflowContent, expectedTestSpec) // change default branch to main err = repo_service.SetRepoDefaultBranch(t.Context(), repo, gitRepo, "main") require.NoError(t, err) - assertSchedule(t, "main", testWorkflow.workflowContent, expectedMainSpec) + assertSchedule(t, "refs/heads/main", testWorkflow.workflowContent, expectedMainSpec) }) }