77 "github.com/cli/cli/api"
88 "github.com/cli/cli/internal/ghrepo"
99 "github.com/cli/cli/pkg/cmd/run/shared"
10+ workflowShared "github.com/cli/cli/pkg/cmd/workflow/shared"
1011 "github.com/cli/cli/pkg/cmdutil"
1112 "github.com/cli/cli/pkg/iostreams"
1213 "github.com/cli/cli/utils"
@@ -24,7 +25,8 @@ type ListOptions struct {
2425
2526 PlainOutput bool
2627
27- Limit int
28+ Limit int
29+ WorkflowSelector string
2830}
2931
3032func NewCmdList (f * cmdutil.Factory , runF func (* ListOptions ) error ) * cobra.Command {
@@ -58,6 +60,7 @@ func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Comman
5860 }
5961
6062 cmd .Flags ().IntVarP (& opts .Limit , "limit" , "L" , defaultLimit , "Maximum number of runs to fetch" )
63+ cmd .Flags ().StringVarP (& opts .WorkflowSelector , "workflow" , "w" , "" , "Filter runs by workflow" )
6164
6265 return cmd
6366}
@@ -74,8 +77,20 @@ func listRun(opts *ListOptions) error {
7477 }
7578 client := api .NewClientFromHTTP (c )
7679
80+ var runs []shared.Run
81+ var workflow * workflowShared.Workflow
82+
7783 opts .IO .StartProgressIndicator ()
78- runs , err := shared .GetRuns (client , baseRepo , opts .Limit )
84+ if opts .WorkflowSelector != "" {
85+ states := []workflowShared.WorkflowState {workflowShared .Active }
86+ workflow , err = workflowShared .ResolveWorkflow (
87+ opts .IO , client , baseRepo , false , opts .WorkflowSelector , states )
88+ if err == nil {
89+ runs , err = shared .GetRunsByWorkflow (client , baseRepo , opts .Limit , workflow .ID )
90+ }
91+ } else {
92+ runs , err = shared .GetRuns (client , baseRepo , opts .Limit )
93+ }
7994 opts .IO .StopProgressIndicator ()
8095 if err != nil {
8196 return fmt .Errorf ("failed to get runs: %w" , err )
0 commit comments