diff --git a/routers/api/v1/repo/action.go b/routers/api/v1/repo/action.go index 6463ae50d0..621f337a72 100644 --- a/routers/api/v1/repo/action.go +++ b/routers/api/v1/repo/action.go @@ -1000,9 +1000,9 @@ func GetWorkflowRun(ctx *context.APIContext) { // "$ref": "#/responses/notFound" runID := ctx.PathParamInt64("run") - job, _, _ := db.GetByID[actions_model.ActionRun](ctx, runID) + job, _, err := db.GetByID[actions_model.ActionRun](ctx, runID) - if job.RepoID != ctx.Repo.Repository.ID { + if err != nil || job.RepoID != ctx.Repo.Repository.ID { ctx.APIError(http.StatusNotFound, util.ErrNotExist) } @@ -1070,7 +1070,7 @@ func GetWorkflowJobs(ctx *context.APIContext) { res.Entries = make([]*api.ActionWorkflowJob, len(artifacts)) for i := range artifacts { - convertedWorkflowJob, err := convert.ToActionWorkflowJob(ctx, ctx.Repo.Repository, artifacts[i]) + convertedWorkflowJob, err := convert.ToActionWorkflowJob(ctx, ctx.Repo.Repository, nil, artifacts[i]) if err != nil { ctx.APIErrorInternal(err) return @@ -1113,13 +1113,13 @@ func GetWorkflowJob(ctx *context.APIContext) { // "$ref": "#/responses/notFound" jobID := ctx.PathParamInt64("job_id") - job, _, _ := db.GetByID[actions_model.ActionRunJob](ctx, jobID) + job, _, err := db.GetByID[actions_model.ActionRunJob](ctx, jobID) - if job.RepoID != ctx.Repo.Repository.ID { + if err != nil || job.RepoID != ctx.Repo.Repository.ID { ctx.APIError(http.StatusNotFound, util.ErrNotExist) } - convertedWorkflowJob, err := convert.ToActionWorkflowJob(ctx, ctx.Repo.Repository, job) + convertedWorkflowJob, err := convert.ToActionWorkflowJob(ctx, ctx.Repo.Repository, nil, job) if err != nil { ctx.APIErrorInternal(err) return diff --git a/services/convert/convert.go b/services/convert/convert.go index 0a8fa3a477..de1d445749 100644 --- a/services/convert/convert.go +++ b/services/convert/convert.go @@ -276,7 +276,9 @@ func ToActionsStatus(status actions_model.Status) (string, string) { return action, conclusion } -func ToActionWorkflowJob(ctx context.Context, repo *repo_model.Repository, job *actions_model.ActionRunJob) (*api.ActionWorkflowJob, error) { +// ToActionWorkflowJob convert a actions_model.ActionRunJob to an api.ActionWorkflowJob +// task is optional and can be nil +func ToActionWorkflowJob(ctx context.Context, repo *repo_model.Repository, task *actions_model.ActionTask, job *actions_model.ActionRunJob) (*api.ActionWorkflowJob, error) { err := job.LoadAttributes(ctx) if err != nil { return nil, err @@ -300,7 +302,12 @@ func ToActionWorkflowJob(ctx context.Context, repo *repo_model.Repository, job * var steps []*api.ActionWorkflowStep if job.TaskID != 0 { - task, _, _ := db.GetByID[actions_model.ActionTask](ctx, job.TaskID) + if task == nil { + task, _, err = db.GetByID[actions_model.ActionTask](ctx, job.TaskID) + if err != nil { + return nil, err + } + } runnerID = task.RunnerID if runner, ok, _ := db.GetByID[actions_model.ActionRunner](ctx, runnerID); ok { diff --git a/services/webhook/notifier.go b/services/webhook/notifier.go index 95ef0d672e..5c47224b4a 100644 --- a/services/webhook/notifier.go +++ b/services/webhook/notifier.go @@ -956,7 +956,7 @@ func (*webhookNotifier) WorkflowJobStatusUpdate(ctx context.Context, repo *repo_ status, _ := convert.ToActionsStatus(job.Status) - convertedJob, err := convert.ToActionWorkflowJob(ctx, repo, job) + convertedJob, err := convert.ToActionWorkflowJob(ctx, repo, task, job) if err != nil { log.Error("ToActionWorkflowJob: %v", err) return