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 { type ActionWorkflowStep struct {
Name string `json:"name"` Name string `json:"name"`
Number int64 `json:"number"` Number int64 `json:"number"`
Status string `json:"status"`
Conclusion string `json:"conclusion,omitempty"` Conclusion string `json:"conclusion,omitempty"`
// swagger:strfmt date-time // swagger:strfmt date-time
StartedAt time.Time `json:"started_at,omitempty"` StartedAt time.Time `json:"started_at,omitempty"`
@ -118,9 +119,10 @@ type ActionWorkflowJob struct {
RunAttempt int64 `json:"run_attempt"` RunAttempt int64 `json:"run_attempt"`
HeadSha string `json:"head_sha"` HeadSha string `json:"head_sha"`
HeadBranch string `json:"head_branch,omitempty"` HeadBranch string `json:"head_branch,omitempty"`
Status string `json:"status"`
Conclusion string `json:"conclusion,omitempty"` Conclusion string `json:"conclusion,omitempty"`
RunnerID int64 `json:"runner_id"` RunnerID int64 `json:"runner_id,omitempty"`
RunnerName string `json:"runner_name"` RunnerName string `json:"runner_name,omitempty"`
Steps []*ActionWorkflowStep `json:"steps"` Steps []*ActionWorkflowStep `json:"steps"`
// swagger:strfmt date-time // swagger:strfmt date-time
CreatedAt time.Time `json:"created_at"` CreatedAt time.Time `json:"created_at"`

View File

@ -7,6 +7,7 @@ import (
"context" "context"
actions_model "code.gitea.io/gitea/models/actions" actions_model "code.gitea.io/gitea/models/actions"
"code.gitea.io/gitea/models/db"
git_model "code.gitea.io/gitea/models/git" git_model "code.gitea.io/gitea/models/git"
issues_model "code.gitea.io/gitea/models/issues" issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/organization" "code.gitea.io/gitea/models/organization"
@ -960,17 +961,22 @@ func (*webhookNotifier) CreateWorkflowJob(ctx context.Context, repo *repo_model.
return return
} }
action, conclusion := toActionStatus(job.Status) status, conclusion := toActionStatus(job.Status)
var runnerID int64 var runnerID int64
var runnerName string
var steps []*api.ActionWorkflowStep var steps []*api.ActionWorkflowStep
if task != nil { if task != nil {
runnerID = task.RunnerID runnerID = task.RunnerID
if runner, ok, _ := db.GetByID[actions_model.ActionRunner](ctx, runnerID); ok {
runnerName = runner.Name
}
for i, step := range task.Steps { for i, step := range task.Steps {
_, stepConclusion := toActionStatus(job.Status) stepStatus, stepConclusion := toActionStatus(job.Status)
steps = append(steps, &api.ActionWorkflowStep{ steps = append(steps, &api.ActionWorkflowStep{
Name: step.Name, Name: step.Name,
Number: int64(i), Number: int64(i),
Status: stepStatus,
Conclusion: stepConclusion, Conclusion: stepConclusion,
StartedAt: step.Started.AsTime().UTC(), StartedAt: step.Started.AsTime().UTC(),
CompletedAt: step.Stopped.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{ if err := PrepareWebhooks(ctx, source, webhook_module.HookEventWorkflowJob, &api.WorkflowJobPayload{
Action: action, Action: status,
WorkflowJob: &api.ActionWorkflowJob{ WorkflowJob: &api.ActionWorkflowJob{
ID: job.ID, ID: job.ID,
RunID: job.RunID, RunID: job.RunID,
@ -989,8 +995,10 @@ func (*webhookNotifier) CreateWorkflowJob(ctx context.Context, repo *repo_model.
RunAttempt: job.Attempt, RunAttempt: job.Attempt,
HeadSha: job.Run.CommitSHA, HeadSha: job.Run.CommitSHA,
HeadBranch: git.RefName(job.Run.Ref).BranchName(), HeadBranch: git.RefName(job.Run.Ref).BranchName(),
Status: status,
Conclusion: conclusion, Conclusion: conclusion,
RunnerID: runnerID, RunnerID: runnerID,
RunnerName: runnerName,
Steps: steps, Steps: steps,
CreatedAt: job.Created.AsTime().UTC(), CreatedAt: job.Created.AsTime().UTC(),
StartedAt: job.Started.AsTime().UTC(), StartedAt: job.Started.AsTime().UTC(),