From c29d318d23beb838ac95694faec28e63c9d76a2e Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Thu, 6 Apr 2023 14:51:27 +0800 Subject: [PATCH 1/2] set `ref` to fully-formed ref of the tag --- routers/api/actions/runner/utils.go | 3 ++- services/actions/notifier_helper.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/routers/api/actions/runner/utils.go b/routers/api/actions/runner/utils.go index a022445ff38a..cbfcd79a9d99 100644 --- a/routers/api/actions/runner/utils.go +++ b/routers/api/actions/runner/utils.go @@ -9,6 +9,7 @@ import ( actions_model "code.gitea.io/gitea/models/actions" secret_model "code.gitea.io/gitea/models/secret" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" secret_module "code.gitea.io/gitea/modules/secret" @@ -98,7 +99,7 @@ func generateTaskContext(t *actions_model.ActionTask) *structpb.Struct { "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. "job": fmt.Sprint(t.JobID), // string, The job_id of the current job. "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/, for pull requests it is refs/pull//merge, and for tags it is refs/tags/. For example, refs/heads/feature-branch-1. - "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. + "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. "ref_protected": false, // boolean, true if branch protections are configured for the ref that triggered the workflow run. "ref_type": "", // string, The type of ref that triggered the workflow run. Valid values are branch or tag. "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." diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go index b0e199fc6bd4..e5c4b7696acb 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -205,7 +205,7 @@ func notifyRelease(ctx context.Context, doer *user_model.User, rel *repo_model.R mode, _ := access_model.AccessLevel(ctx, doer, rel.Repo) newNotifyInput(rel.Repo, doer, webhook_module.HookEventRelease). - WithRef(ref). + WithRef(git.TagPrefix + rel.TagName). WithPayload(&api.ReleasePayload{ Action: action, Release: convert.ToRelease(ctx, rel), From 15de1af15703bdf225e268f3d5ecae26abffdcfc Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Thu, 6 Apr 2023 15:00:27 +0800 Subject: [PATCH 2/2] delete useless function arg --- services/actions/notifier.go | 6 +++--- services/actions/notifier_helper.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/services/actions/notifier.go b/services/actions/notifier.go index 90eed83eff5e..6956c25cee2f 100644 --- a/services/actions/notifier.go +++ b/services/actions/notifier.go @@ -443,17 +443,17 @@ func (n *actionsNotifier) NotifySyncDeleteRef(ctx context.Context, pusher *user_ func (n *actionsNotifier) NotifyNewRelease(ctx context.Context, rel *repo_model.Release) { ctx = withMethod(ctx, "NotifyNewRelease") - notifyRelease(ctx, rel.Publisher, rel, rel.Sha1, api.HookReleasePublished) + notifyRelease(ctx, rel.Publisher, rel, api.HookReleasePublished) } func (n *actionsNotifier) NotifyUpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) { ctx = withMethod(ctx, "NotifyUpdateRelease") - notifyRelease(ctx, doer, rel, rel.Sha1, api.HookReleaseUpdated) + notifyRelease(ctx, doer, rel, api.HookReleaseUpdated) } func (n *actionsNotifier) NotifyDeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) { ctx = withMethod(ctx, "NotifyDeleteRelease") - notifyRelease(ctx, doer, rel, rel.Sha1, api.HookReleaseDeleted) + notifyRelease(ctx, doer, rel, api.HookReleaseDeleted) } func (n *actionsNotifier) NotifyPackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) { diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go index e5c4b7696acb..cdb411c78d00 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -196,7 +196,7 @@ func newNotifyInputFromIssue(issue *issues_model.Issue, event webhook_module.Hoo return newNotifyInput(issue.Repo, issue.Poster, event) } -func notifyRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release, ref string, action api.HookReleaseAction) { +func notifyRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release, action api.HookReleaseAction) { if err := rel.LoadAttributes(ctx); err != nil { log.Error("LoadAttributes: %v", err) return