]> source.dussan.org Git - gitea.git/commitdiff
Fix possible ui 500 if workflow's job is nil (#31092) (#31098)
authorGiteabot <teabot@gitea.io>
Mon, 27 May 2024 06:13:15 +0000 (14:13 +0800)
committerGitHub <noreply@github.com>
Mon, 27 May 2024 06:13:15 +0000 (14:13 +0800)
Backport #31092 by @lunny

Fix #31087

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
options/locale/locale_en-US.ini
routers/web/repo/actions/actions.go

index da45eee92abc2ab5bddc1f900055bc69bfb4d3b4..afb860cfc07d8ff6f945ac3e2fcaed67961e1a11 100644 (file)
@@ -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
index 6059ad1414b761d88daa4e86f99bc943a0baaaa7..a0f03ec7e90044653e607c0d79bafe3361ea32d9 100644 (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)
                }
        }