Skip to content

Commit 3876f56

Browse files
authored
Set ref to fully-formed of the tag when trigger event is release (#23944)
Fix #23943 When trigger event is `release`, ref should be like `refs/tags/<tag_name>` instead of `CommitID`
1 parent 518d384 commit 3876f56

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

routers/api/actions/runner/utils.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
actions_model "code.gitea.io/gitea/models/actions"
1111
secret_model "code.gitea.io/gitea/models/secret"
12+
"code.gitea.io/gitea/modules/git"
1213
"code.gitea.io/gitea/modules/json"
1314
"code.gitea.io/gitea/modules/log"
1415
secret_module "code.gitea.io/gitea/modules/secret"
@@ -98,7 +99,7 @@ func generateTaskContext(t *actions_model.ActionTask) *structpb.Struct {
9899
"head_ref": "", // string, The head_ref or source branch of the pull request in a workflow run. This property is only available when the event that triggers a workflow run is either pull_request or pull_request_target.
99100
"job": fmt.Sprint(t.JobID), // string, The job_id of the current job.
100101
"ref": t.Job.Run.Ref, // string, The fully-formed ref of the branch or tag that triggered the workflow run. For workflows triggered by push, this is the branch or tag ref that was pushed. For workflows triggered by pull_request, this is the pull request merge branch. For workflows triggered by release, this is the release tag created. For other triggers, this is the branch or tag ref that triggered the workflow run. This is only set if a branch or tag is available for the event type. The ref given is fully-formed, meaning that for branches the format is refs/heads/<branch_name>, for pull requests it is refs/pull/<pr_number>/merge, and for tags it is refs/tags/<tag_name>. For example, refs/heads/feature-branch-1.
101-
"ref_name": t.Job.Run.Ref, // string, The short ref name of the branch or tag that triggered the workflow run. This value matches the branch or tag name shown on GitHub. For example, feature-branch-1.
102+
"ref_name": git.RefEndName(t.Job.Run.Ref), // string, The short ref name of the branch or tag that triggered the workflow run. This value matches the branch or tag name shown on GitHub. For example, feature-branch-1.
102103
"ref_protected": false, // boolean, true if branch protections are configured for the ref that triggered the workflow run.
103104
"ref_type": "", // string, The type of ref that triggered the workflow run. Valid values are branch or tag.
104105
"path": "", // string, Path on the runner to the file that sets system PATH variables from workflow commands. This file is unique to the current step and is a different file for each step in a job. For more information, see "Workflow commands for GitHub Actions."

services/actions/notifier.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -443,17 +443,17 @@ func (n *actionsNotifier) NotifySyncDeleteRef(ctx context.Context, pusher *user_
443443

444444
func (n *actionsNotifier) NotifyNewRelease(ctx context.Context, rel *repo_model.Release) {
445445
ctx = withMethod(ctx, "NotifyNewRelease")
446-
notifyRelease(ctx, rel.Publisher, rel, rel.Sha1, api.HookReleasePublished)
446+
notifyRelease(ctx, rel.Publisher, rel, api.HookReleasePublished)
447447
}
448448

449449
func (n *actionsNotifier) NotifyUpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
450450
ctx = withMethod(ctx, "NotifyUpdateRelease")
451-
notifyRelease(ctx, doer, rel, rel.Sha1, api.HookReleaseUpdated)
451+
notifyRelease(ctx, doer, rel, api.HookReleaseUpdated)
452452
}
453453

454454
func (n *actionsNotifier) NotifyDeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
455455
ctx = withMethod(ctx, "NotifyDeleteRelease")
456-
notifyRelease(ctx, doer, rel, rel.Sha1, api.HookReleaseDeleted)
456+
notifyRelease(ctx, doer, rel, api.HookReleaseDeleted)
457457
}
458458

459459
func (n *actionsNotifier) NotifyPackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) {

services/actions/notifier_helper.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func newNotifyInputFromIssue(issue *issues_model.Issue, event webhook_module.Hoo
216216
return newNotifyInput(issue.Repo, issue.Poster, event)
217217
}
218218

219-
func notifyRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release, ref string, action api.HookReleaseAction) {
219+
func notifyRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release, action api.HookReleaseAction) {
220220
if err := rel.LoadAttributes(ctx); err != nil {
221221
log.Error("LoadAttributes: %v", err)
222222
return
@@ -225,7 +225,7 @@ func notifyRelease(ctx context.Context, doer *user_model.User, rel *repo_model.R
225225
mode, _ := access_model.AccessLevel(ctx, doer, rel.Repo)
226226

227227
newNotifyInput(rel.Repo, doer, webhook_module.HookEventRelease).
228-
WithRef(ref).
228+
WithRef(git.TagPrefix + rel.TagName).
229229
WithPayload(&api.ReleasePayload{
230230
Action: action,
231231
Release: convert.ToRelease(ctx, rel),

0 commit comments

Comments
 (0)