| 47 | } |
| 48 | |
| 49 | func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Command { |
| 50 | opts := &ListOptions{ |
| 51 | IO: f.IOStreams, |
| 52 | HttpClient: f.HttpClient, |
| 53 | Prompter: f.Prompter, |
| 54 | now: time.Now(), |
| 55 | } |
| 56 | |
| 57 | cmd := &cobra.Command{ |
| 58 | Use: "list", |
| 59 | Short: "List recent workflow runs", |
| 60 | Long: heredoc.Docf(` |
| 61 | List recent workflow runs. |
| 62 | |
| 63 | Note that providing the %[1]sworkflow_name%[1]s to the %[1]s-w%[1]s flag will not fetch disabled workflows. |
| 64 | Also pass the %[1]s-a%[1]s flag to fetch disabled workflow runs using the %[1]sworkflow_name%[1]s and the %[1]s-w%[1]s flag. |
| 65 | |
| 66 | Runs created by organization and enterprise ruleset workflows will not display a workflow name due to GitHub API limitations. |
| 67 | |
| 68 | To see runs associated with a pull request, users should run %[1]sgh pr checks%[1]s. |
| 69 | `, "`"), |
| 70 | Aliases: []string{"ls"}, |
| 71 | Args: cobra.NoArgs, |
| 72 | RunE: func(cmd *cobra.Command, args []string) error { |
| 73 | // support `-R, --repo` override |
| 74 | opts.BaseRepo = f.BaseRepo |
| 75 | |
| 76 | if opts.Limit < 1 { |
| 77 | return cmdutil.FlagErrorf("invalid limit: %v", opts.Limit) |
| 78 | } |
| 79 | |
| 80 | if runF != nil { |
| 81 | return runF(opts) |
| 82 | } |
| 83 | |
| 84 | return listRun(opts) |
| 85 | }, |
| 86 | } |
| 87 | |
| 88 | cmd.Flags().IntVarP(&opts.Limit, "limit", "L", defaultLimit, "Maximum number of runs to fetch") |
| 89 | cmd.Flags().StringVarP(&opts.WorkflowSelector, "workflow", "w", "", "Filter runs by workflow") |
| 90 | cmd.Flags().StringVarP(&opts.Branch, "branch", "b", "", "Filter runs by branch") |
| 91 | cmd.Flags().StringVarP(&opts.Actor, "user", "u", "", "Filter runs by user who triggered the run") |
| 92 | cmd.Flags().StringVarP(&opts.Event, "event", "e", "", "Filter runs by which `event` triggered the run") |
| 93 | cmd.Flags().StringVarP(&opts.Created, "created", "", "", "Filter runs by the `date` it was created") |
| 94 | cmd.Flags().StringVarP(&opts.Commit, "commit", "c", "", "Filter runs by the `SHA` of the commit") |
| 95 | cmd.Flags().BoolVarP(&opts.All, "all", "a", false, "Include disabled workflows") |
| 96 | cmdutil.StringEnumFlag(cmd, &opts.Status, "status", "s", "", shared.AllStatuses, "Filter runs by status") |
| 97 | cmdutil.AddJSONFlags(cmd, &opts.Exporter, shared.RunFields) |
| 98 | |
| 99 | _ = cmdutil.RegisterBranchCompletionFlags(f.GitClient, cmd, "branch") |
| 100 | |
| 101 | return cmd |
| 102 | } |
| 103 | |
| 104 | func listRun(opts *ListOptions) error { |
| 105 | baseRepo, err := opts.BaseRepo() |