| 85 | } |
| 86 | |
| 87 | func listRun(opts *ListOptions) error { |
| 88 | repo, err := opts.BaseRepo() |
| 89 | if err != nil { |
| 90 | return err |
| 91 | } |
| 92 | if err := shared.CheckHost(repo.RepoHost()); err != nil { |
| 93 | return err |
| 94 | } |
| 95 | |
| 96 | c, err := opts.Client() |
| 97 | if err != nil { |
| 98 | return err |
| 99 | } |
| 100 | if err := shared.CheckIssue(c, repo, opts.IssueNumber); err != nil { |
| 101 | return err |
| 102 | } |
| 103 | |
| 104 | artifacts, err := listArtifacts(c, repo, opts.IssueNumber, opts.Type, opts.Limit) |
| 105 | if err != nil { |
| 106 | return err |
| 107 | } |
| 108 | |
| 109 | if opts.Exporter != nil { |
| 110 | return opts.Exporter.Write(opts.IO, artifacts) |
| 111 | } |
| 112 | |
| 113 | issueRef := fmt.Sprintf("%s#%d", ghrepo.FullName(repo), opts.IssueNumber) |
| 114 | if len(artifacts) == 0 { |
| 115 | if opts.Type != "" { |
| 116 | return cmdutil.NewNoResultsError(fmt.Sprintf("no artifacts match your search on %s", issueRef)) |
| 117 | } |
| 118 | return cmdutil.NewNoResultsError(fmt.Sprintf("no artifacts found on %s", issueRef)) |
| 119 | } |
| 120 | |
| 121 | if err := opts.IO.StartPager(); err == nil { |
| 122 | defer opts.IO.StopPager() |
| 123 | } else { |
| 124 | fmt.Fprintf(opts.IO.ErrOut, "failed to start pager: %v\n", err) |
| 125 | } |
| 126 | |
| 127 | if opts.IO.IsStdoutTTY() { |
| 128 | fmt.Fprintf(opts.IO.Out, "\n%s\n\n", listHeader(issueRef, len(artifacts), opts.Type != "")) |
| 129 | } |
| 130 | return printArtifacts(opts.IO, opts.Now(), artifacts) |
| 131 | } |
| 132 | |
| 133 | // listArtifacts lists the artifacts of one type, or of every type when |
| 134 | // artifactType is empty. gh treats generic and plan artifacts alike as |