From f3fc2f3ddc6d455d644f91e9823a441b0cbb6677 Mon Sep 17 00:00:00 2001 From: Christopher Homberger Date: Mon, 24 Feb 2025 15:03:42 +0100 Subject: [PATCH] Add more webhook fields --- modules/structs/repo_actions.go | 6 ++++-- services/webhook/notifier.go | 14 +++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/modules/structs/repo_actions.go b/modules/structs/repo_actions.go index 64d16bee18..6b30a5e76e 100644 --- a/modules/structs/repo_actions.go +++ b/modules/structs/repo_actions.go @@ -101,6 +101,7 @@ type ActionArtifactsResponse struct { type ActionWorkflowStep struct { Name string `json:"name"` Number int64 `json:"number"` + Status string `json:"status"` Conclusion string `json:"conclusion,omitempty"` // swagger:strfmt date-time StartedAt time.Time `json:"started_at,omitempty"` @@ -118,9 +119,10 @@ type ActionWorkflowJob struct { RunAttempt int64 `json:"run_attempt"` HeadSha string `json:"head_sha"` HeadBranch string `json:"head_branch,omitempty"` + Status string `json:"status"` Conclusion string `json:"conclusion,omitempty"` - RunnerID int64 `json:"runner_id"` - RunnerName string `json:"runner_name"` + RunnerID int64 `json:"runner_id,omitempty"` + RunnerName string `json:"runner_name,omitempty"` Steps []*ActionWorkflowStep `json:"steps"` // swagger:strfmt date-time CreatedAt time.Time `json:"created_at"` diff --git a/services/webhook/notifier.go b/services/webhook/notifier.go index 499574cf2d..a8b7f7a28a 100644 --- a/services/webhook/notifier.go +++ b/services/webhook/notifier.go @@ -7,6 +7,7 @@ import ( "context" actions_model "code.gitea.io/gitea/models/actions" + "code.gitea.io/gitea/models/db" git_model "code.gitea.io/gitea/models/git" issues_model "code.gitea.io/gitea/models/issues" "code.gitea.io/gitea/models/organization" @@ -960,17 +961,22 @@ func (*webhookNotifier) CreateWorkflowJob(ctx context.Context, repo *repo_model. return } - action, conclusion := toActionStatus(job.Status) + status, conclusion := toActionStatus(job.Status) var runnerID int64 + var runnerName string var steps []*api.ActionWorkflowStep if task != nil { runnerID = task.RunnerID + if runner, ok, _ := db.GetByID[actions_model.ActionRunner](ctx, runnerID); ok { + runnerName = runner.Name + } for i, step := range task.Steps { - _, stepConclusion := toActionStatus(job.Status) + stepStatus, stepConclusion := toActionStatus(job.Status) steps = append(steps, &api.ActionWorkflowStep{ Name: step.Name, Number: int64(i), + Status: stepStatus, Conclusion: stepConclusion, StartedAt: step.Started.AsTime().UTC(), CompletedAt: step.Stopped.AsTime().UTC(), @@ -979,7 +985,7 @@ func (*webhookNotifier) CreateWorkflowJob(ctx context.Context, repo *repo_model. } if err := PrepareWebhooks(ctx, source, webhook_module.HookEventWorkflowJob, &api.WorkflowJobPayload{ - Action: action, + Action: status, WorkflowJob: &api.ActionWorkflowJob{ ID: job.ID, RunID: job.RunID, @@ -989,8 +995,10 @@ func (*webhookNotifier) CreateWorkflowJob(ctx context.Context, repo *repo_model. RunAttempt: job.Attempt, HeadSha: job.Run.CommitSHA, HeadBranch: git.RefName(job.Run.Ref).BranchName(), + Status: status, Conclusion: conclusion, RunnerID: runnerID, + RunnerName: runnerName, Steps: steps, CreatedAt: job.Created.AsTime().UTC(), StartedAt: job.Started.AsTime().UTC(),