@@ -5,6 +5,7 @@ package shared
55
66import (
77 "errors"
8+ "fmt"
89 "net/http"
910
1011 actions_model "code.gitea.io/gitea/models/actions"
@@ -132,12 +133,24 @@ func ListJobs(ctx *context.APIContext, ownerID, repoID, runID int64) {
132133 if ownerID != 0 && repoID != 0 {
133134 setting .PanicInDevOrTesting ("ownerID and repoID should not be both set" )
134135 }
135- jobs , total , err := db . FindAndCount [actions_model. ActionRunJob ]( ctx , actions_model.FindRunJobOptions {
136+ opts := actions_model.FindRunJobOptions {
136137 OwnerID : ownerID ,
137138 RepoID : repoID ,
138139 RunID : runID ,
139140 ListOptions : utils .GetListOptions (ctx ),
140- })
141+ }
142+ if statuses , ok := ctx .Req .URL .Query ()["status" ]; ok {
143+ for _ , status := range statuses {
144+ values , err := convertToInternal (status )
145+ if err != nil {
146+ ctx .APIError (http .StatusBadRequest , fmt .Errorf ("Invalid status %s" , status ))
147+ return
148+ }
149+ opts .Statuses = append (opts .Statuses , values ... )
150+ }
151+ }
152+
153+ jobs , total , err := db .FindAndCount [actions_model.ActionRunJob ](ctx , opts )
141154 if err != nil {
142155 ctx .APIErrorInternal (err )
143156 return
@@ -172,22 +185,31 @@ func ListJobs(ctx *context.APIContext, ownerID, repoID, runID int64) {
172185 ctx .JSON (http .StatusOK , & res )
173186}
174187
175- func convertToInternal (s string ) actions_model.Status {
188+ func convertToInternal (s string ) ([] actions_model.Status , error ) {
176189 switch s {
177- case "pending" :
178- return actions_model .StatusBlocked
190+ case "pending" , "waiting" , "requested" , "action_required" :
191+ return [] actions_model.Status { actions_model . StatusBlocked }, nil
179192 case "queued" :
180- return actions_model .StatusWaiting
193+ return [] actions_model.Status { actions_model . StatusWaiting }, nil
181194 case "in_progress" :
182- return actions_model .StatusRunning
195+ return []actions_model.Status {actions_model .StatusRunning }, nil
196+ case "completed" :
197+ return []actions_model.Status {
198+ actions_model .StatusSuccess ,
199+ actions_model .StatusFailure ,
200+ actions_model .StatusSkipped ,
201+ actions_model .StatusCancelled ,
202+ }, nil
183203 case "failure" :
184- return actions_model .StatusFailure
204+ return [] actions_model.Status { actions_model . StatusFailure }, nil
185205 case "success" :
186- return actions_model .StatusSuccess
187- case "skipped" :
188- return actions_model .StatusSkipped
206+ return []actions_model.Status {actions_model .StatusSuccess }, nil
207+ case "skipped" , "neutral" :
208+ return []actions_model.Status {actions_model .StatusSkipped }, nil
209+ case "cancelled" , "timed_out" :
210+ return []actions_model.Status {actions_model .StatusCancelled }, nil
189211 default :
190- return actions_model . StatusUnknown
212+ return nil , fmt . Errorf ( "invalid status %s" , s )
191213 }
192214}
193215
@@ -213,8 +235,15 @@ func ListRuns(ctx *context.APIContext, ownerID, repoID int64) {
213235 if branch := ctx .Req .URL .Query ().Get ("branch" ); branch != "" {
214236 opts .Ref = string (git .RefNameFromBranch (branch ))
215237 }
216- if status := ctx .Req .URL .Query ().Get ("status" ); status != "" {
217- opts .Status = []actions_model.Status {convertToInternal (status )}
238+ if statuses , ok := ctx .Req .URL .Query ()["status" ]; ok {
239+ for _ , status := range statuses {
240+ values , err := convertToInternal (status )
241+ if err != nil {
242+ ctx .APIError (http .StatusBadRequest , fmt .Errorf ("Invalid status %s" , status ))
243+ return
244+ }
245+ opts .Status = append (opts .Status , values ... )
246+ }
218247 }
219248 if actor := ctx .Req .URL .Query ().Get ("actor" ); actor != "" {
220249 user , err := user_model .GetUserByName (ctx , actor )
0 commit comments