| 56 | } |
| 57 | |
| 58 | func SearchIssues(opts *IssuesOptions) error { |
| 59 | io := opts.IO |
| 60 | if opts.WebMode { |
| 61 | url := opts.Searcher.URL(opts.Query) |
| 62 | if io.IsStdoutTTY() { |
| 63 | fmt.Fprintf(io.ErrOut, "Opening %s in your browser.\n", text.DisplayURL(url)) |
| 64 | } |
| 65 | return opts.Browser.Browse(url) |
| 66 | } |
| 67 | io.StartProgressIndicator() |
| 68 | result, err := opts.Searcher.Issues(opts.Query) |
| 69 | io.StopProgressIndicator() |
| 70 | if err != nil { |
| 71 | return err |
| 72 | } |
| 73 | if len(result.Items) == 0 && opts.Exporter == nil { |
| 74 | var msg string |
| 75 | switch opts.Entity { |
| 76 | case Both: |
| 77 | msg = "no issues or pull requests matched your search" |
| 78 | case Issues: |
| 79 | msg = "no issues matched your search" |
| 80 | case PullRequests: |
| 81 | msg = "no pull requests matched your search" |
| 82 | } |
| 83 | return cmdutil.NewNoResultsError(msg) |
| 84 | } |
| 85 | |
| 86 | if err := io.StartPager(); err == nil { |
| 87 | defer io.StopPager() |
| 88 | } else { |
| 89 | fmt.Fprintf(io.ErrOut, "failed to start pager: %v\n", err) |
| 90 | } |
| 91 | |
| 92 | if opts.Exporter != nil { |
| 93 | return opts.Exporter.Write(io, result.Items) |
| 94 | } |
| 95 | |
| 96 | return displayIssueResults(io, opts.Now, opts.Entity, result) |
| 97 | } |
| 98 | |
| 99 | func displayIssueResults(io *iostreams.IOStreams, now time.Time, et EntityType, results search.IssuesResult) error { |
| 100 | if now.IsZero() { |