Skip to content

Commit e0b7938

Browse files
GiteaBotlunny
andauthored
Fix possible ui 500 if workflow's job is nil (#31092) (#31098)
Backport #31092 by @lunny Fix #31087 Co-authored-by: Lunny Xiao <[email protected]>
1 parent 02b947a commit e0b7938

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3637,6 +3637,7 @@ runs.pushed_by = pushed by
36373637
runs.invalid_workflow_helper = Workflow config file is invalid. Please check your config file: %s
36383638
runs.no_matching_online_runner_helper = No matching online runner with label: %s
36393639
runs.no_job_without_needs = The workflow must contain at least one job without dependencies.
3640+
runs.no_job = The workflow must contain at least one job
36403641
runs.actor = Actor
36413642
runs.status = Status
36423643
runs.actors_no_select = All actors

routers/web/repo/actions/actions.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,12 @@ func List(ctx *context.Context) {
107107
// The workflow must contain at least one job without "needs". Otherwise, a deadlock will occur and no jobs will be able to run.
108108
hasJobWithoutNeeds := false
109109
// Check whether have matching runner and a job without "needs"
110+
emptyJobsNumber := 0
110111
for _, j := range wf.Jobs {
112+
if j == nil {
113+
emptyJobsNumber++
114+
continue
115+
}
111116
if !hasJobWithoutNeeds && len(j.Needs()) == 0 {
112117
hasJobWithoutNeeds = true
113118
}
@@ -131,6 +136,9 @@ func List(ctx *context.Context) {
131136
if !hasJobWithoutNeeds {
132137
workflow.ErrMsg = ctx.Locale.TrString("actions.runs.no_job_without_needs")
133138
}
139+
if emptyJobsNumber == len(wf.Jobs) {
140+
workflow.ErrMsg = ctx.Locale.TrString("actions.runs.no_job")
141+
}
134142
workflows = append(workflows, workflow)
135143
}
136144
}

0 commit comments

Comments
 (0)