@@ -154,6 +154,7 @@ type options struct {
154154 Repositories []string
155155 Last time.Duration
156156 Selector string
157+ Status string
157158}
158159
159160func workflowHealth (w workflow ) string {
@@ -267,7 +268,7 @@ func _main(opts *options) error {
267268 totalBillableMs := 0
268269
269270 for _ , r := range repos {
270- workflows , err := getWorkflows (* r , last )
271+ workflows , err := getWorkflows (* r , last , opts )
271272 if err != nil {
272273 return err
273274 }
@@ -352,7 +353,7 @@ func getAllRepos(path string) ([]*repositoryData, error) {
352353 return repoData , nil
353354}
354355
355- func getWorkflows (repoData repositoryData , last time.Duration ) ([]* workflow , error ) {
356+ func getWorkflows (repoData repositoryData , last time.Duration , opts * options ) ([]* workflow , error ) {
356357 workflowsPath := fmt .Sprintf ("repos/%s/actions/workflows" , repoData .Name )
357358
358359 stdout , _ , err := gh .Exec ("api" , "--cache" , defaultApiCacheTime , workflowsPath , "--jq" , ".workflows" )
@@ -403,7 +404,13 @@ func getWorkflows(repoData repositoryData, last time.Duration) ([]*workflow, err
403404 continue
404405 }
405406
406- runsPath := fmt .Sprintf ("%s/runs" , w .URL )
407+ var runsPath string
408+ if opts .Status != "" {
409+ runsPath = fmt .Sprintf ("%s/runs?status=%s" , w .URL , opts .Status )
410+ } else {
411+ runsPath = fmt .Sprintf ("%s/runs" , w .URL )
412+ }
413+
407414 stdout , _ , err = gh .Exec ("api" , "--cache" , defaultApiCacheTime , runsPath , "--jq" , ".workflow_runs" )
408415 if err != nil {
409416 return nil , fmt .Errorf ("could not call gh: %w" , err )
@@ -462,6 +469,7 @@ func parseArgs() (*options, error) {
462469
463470 repositories := flag .StringSliceP ("repos" , "r" , []string {}, "One or more repository names from the provided org or user" )
464471 last := flag .StringP ("last" , "l" , "30d" , "What period of time to cover in hours (eg 1h) or days (eg 30d). Default: 30d" )
472+ runStatus := flag .StringP ("status" , "s" , "" , "What workflow run status (eg completed, cancelled, failure, success) to query for" )
465473
466474 flag .Parse ()
467475
@@ -522,6 +530,7 @@ func parseArgs() (*options, error) {
522530 Repositories : * repositories ,
523531 Last : duration ,
524532 Selector : selector ,
533+ Status : * runStatus ,
525534 }, nil
526535}
527536
0 commit comments