mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-06-22 10:02:15 +00:00
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/<branch_name>`) 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/<pull request number>.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 <mfenniak@noreply.codeberg.org>
This commit is contained in:
parent
c99b35cfa4
commit
b29e21a90c
4 changed files with 8 additions and 6 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue