Add more webhook fields

This commit is contained in:
Christopher Homberger 2025-02-24 15:03:42 +01:00
parent bdf0c1d476
commit f3fc2f3ddc
2 changed files with 15 additions and 5 deletions

View File

@ -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"`

View File

@ -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(),