(io *iostreams.IOStreams, now time.Time, et EntityType, results search.IssuesResult)
| 97 | } |
| 98 | |
| 99 | func displayIssueResults(io *iostreams.IOStreams, now time.Time, et EntityType, results search.IssuesResult) error { |
| 100 | if now.IsZero() { |
| 101 | now = time.Now() |
| 102 | } |
| 103 | |
| 104 | var headers []string |
| 105 | if et == Both { |
| 106 | headers = []string{"Kind", "Repo", "ID", "Title", "Labels", "Updated"} |
| 107 | } else { |
| 108 | headers = []string{"Repo", "ID", "Title", "Labels", "Updated"} |
| 109 | } |
| 110 | |
| 111 | cs := io.ColorScheme() |
| 112 | tp := tableprinter.New(io, tableprinter.WithHeader(headers...)) |
| 113 | for _, issue := range results.Items { |
| 114 | if et == Both { |
| 115 | kind := "issue" |
| 116 | if issue.IsPullRequest() { |
| 117 | kind = "pr" |
| 118 | } |
| 119 | tp.AddField(kind) |
| 120 | } |
| 121 | comp := strings.Split(issue.RepositoryURL, "/") |
| 122 | name := comp[len(comp)-2:] |
| 123 | tp.AddField(strings.Join(name, "/")) |
| 124 | issueNum := strconv.Itoa(issue.Number) |
| 125 | if tp.IsTTY() { |
| 126 | issueNum = "#" + issueNum |
| 127 | } |
| 128 | if issue.IsPullRequest() { |
| 129 | color := tableprinter.WithColor(cs.ColorFromString(colorForPRState(issue.State()))) |
| 130 | tp.AddField(issueNum, color) |
| 131 | } else { |
| 132 | color := tableprinter.WithColor(cs.ColorFromString(colorForIssueState(issue.State(), issue.StateReason))) |
| 133 | tp.AddField(issueNum, color) |
| 134 | } |
| 135 | if !tp.IsTTY() { |
| 136 | tp.AddField(issue.State()) |
| 137 | } |
| 138 | tp.AddField(text.RemoveExcessiveWhitespace(issue.Title)) |
| 139 | tp.AddField(listIssueLabels(&issue, cs, tp.IsTTY())) |
| 140 | tp.AddTimeField(now, issue.UpdatedAt, cs.Muted) |
| 141 | tp.EndRow() |
| 142 | } |
| 143 | |
| 144 | if tp.IsTTY() { |
| 145 | var header string |
| 146 | switch et { |
| 147 | case Both: |
| 148 | header = fmt.Sprintf("Showing %d of %d issues and pull requests\n\n", len(results.Items), results.Total) |
| 149 | case Issues: |
| 150 | header = fmt.Sprintf("Showing %d of %d issues\n\n", len(results.Items), results.Total) |
| 151 | case PullRequests: |
| 152 | header = fmt.Sprintf("Showing %d of %d pull requests\n\n", len(results.Items), results.Total) |
| 153 | } |
| 154 | fmt.Fprintf(io.Out, "\n%s", header) |
| 155 | } |
| 156 | return tp.Render() |
no test coverage detected