From 295bf45d5cbe6de809260b3bf6908ad95618c6d8 Mon Sep 17 00:00:00 2001 From: Christopher Homberger Date: Mon, 17 Mar 2025 20:17:42 +0100 Subject: [PATCH] cleanup and fix webhook type bug --- services/actions/notifier.go | 23 ++++++++++++++++++++--- services/webhook/notifier.go | 2 +- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/services/actions/notifier.go b/services/actions/notifier.go index 1040607a56..f708bb8043 100644 --- a/services/actions/notifier.go +++ b/services/actions/notifier.go @@ -8,7 +8,9 @@ import ( actions_model "code.gitea.io/gitea/models/actions" issues_model "code.gitea.io/gitea/models/issues" + "code.gitea.io/gitea/models/organization" packages_model "code.gitea.io/gitea/models/packages" + "code.gitea.io/gitea/models/perm" perm_model "code.gitea.io/gitea/models/perm" access_model "code.gitea.io/gitea/models/perm/access" repo_model "code.gitea.io/gitea/models/repo" @@ -765,11 +767,26 @@ func (n *actionsNotifier) MigrateRepository(ctx context.Context, doer, u *user_m } func (n *actionsNotifier) WorkflowRunStatusUpdate(ctx context.Context, repo *repo_model.Repository, sender *user_model.User, run *actions_model.ActionRun) { + var org *api.Organization + if repo.Owner.IsOrganization() { + org = convert.ToOrganization(ctx, organization.OrgFromUser(repo.Owner)) + } + + status, _ := convert.ToActionsStatus(run.Status) + + convertedRun, err := convert.ToActionWorkflowRun(repo, run) + if err != nil { + log.Error("ToActionWorkflowRun: %v", err) + return + } + run.Status.IsBlocked() newNotifyInput(repo, sender, webhook_module.HookEventWorkflowRun).WithPayload(&api.WorkflowRunPayload{ - Action: "queued", - Repo: convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm_model.AccessModeOwner}), - Organization: nil, + Action: status, + Workflow: nil, + WorkflowRun: convertedRun, + Organization: org, + Repo: convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner}), Sender: convert.ToUser(ctx, sender, nil), }).Notify(ctx) } diff --git a/services/webhook/notifier.go b/services/webhook/notifier.go index 5c47224b4a..c0348243ab 100644 --- a/services/webhook/notifier.go +++ b/services/webhook/notifier.go @@ -992,7 +992,7 @@ func (*webhookNotifier) WorkflowRunStatusUpdate(ctx context.Context, repo *repo_ return } - if err := PrepareWebhooks(ctx, source, webhook_module.HookEventWorkflowJob, &api.WorkflowRunPayload{ + if err := PrepareWebhooks(ctx, source, webhook_module.HookEventWorkflowRun, &api.WorkflowRunPayload{ Action: status, Workflow: nil, WorkflowRun: convertedRun,