Skip to content

Commit

Permalink
Fix possible ui 500 if workflow's job is nil (#31092) (#31098)
Browse files Browse the repository at this point in the history
Backport #31092 by @lunny

Fix #31087

Co-authored-by: Lunny Xiao <[email protected]>
  • Loading branch information
GiteaBot and lunny authored May 27, 2024
1 parent 02b947a commit e0b7938
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3637,6 +3637,7 @@ runs.pushed_by = pushed by
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
Expand Down
8 changes: 8 additions & 0 deletions routers/web/repo/actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
}
}
Expand Down

0 comments on commit e0b7938

Please sign in to comment.