MCPcopy
hub / github.com/cli/cli / displayIssueResults

Function displayIssueResults

pkg/cmd/search/shared/shared.go:99–157  ·  view source on GitHub ↗
(io *iostreams.IOStreams, now time.Time, et EntityType, results search.IssuesResult)

Source from the content-addressed store, hash-verified

97}
98
99func 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()

Callers 1

SearchIssuesFunction · 0.85

Calls 14

NewFunction · 0.92
WithHeaderFunction · 0.92
colorForPRStateFunction · 0.85
colorForIssueStateFunction · 0.85
listIssueLabelsFunction · 0.85
ColorSchemeMethod · 0.80
JoinMethod · 0.80
IsTTYMethod · 0.80
ColorFromStringMethod · 0.80
StateMethod · 0.80
AddTimeFieldMethod · 0.80

Tested by

no test coverage detected