1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-22 12:54:53 -05:00

Fix possible ui 500 if workflow's job is nil (#31092)

Fix #31087

(cherry picked from commit e695ba47557ed4c3999c63b28051a449ca4653de)
This commit is contained in:
Lunny Xiao 2024-05-27 13:21:00 +08:00 committed by Earl Warren
parent 9d4f0671f3
commit 9e495f700e
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
2 changed files with 9 additions and 0 deletions

View file

@ -3724,6 +3724,7 @@ runs.workflow = Workflow
runs.invalid_workflow_helper = Workflow config file is invalid. Please check your config file: %s
runs.no_matching_online_runner_helper = No matching online runner with label: %s
runs.no_job_without_needs = The workflow must contain at least one job without dependencies.
runs.no_job = The workflow must contain at least one job
runs.actor = Actor
runs.status = Status
runs.actors_no_select = All actors

View file

@ -107,7 +107,12 @@ func List(ctx *context.Context) {
// The workflow must contain at least one job without "needs". Otherwise, a deadlock will occur and no jobs will be able to run.
hasJobWithoutNeeds := false
// Check whether have matching runner and a job without "needs"
emptyJobsNumber := 0
for _, j := range wf.Jobs {
if j == nil {
emptyJobsNumber++
continue
}
if !hasJobWithoutNeeds && len(j.Needs()) == 0 {
hasJobWithoutNeeds = true
}
@ -131,6 +136,9 @@ func List(ctx *context.Context) {
if !hasJobWithoutNeeds {
workflow.ErrMsg = ctx.Locale.TrString("actions.runs.no_job_without_needs")
}
if emptyJobsNumber == len(wf.Jobs) {
workflow.ErrMsg = ctx.Locale.TrString("actions.runs.no_job")
}
workflows = append(workflows, workflow)
}
}