MCPcopy
hub / github.com/cli/cli / printDiscussions

Function printDiscussions

pkg/cmd/discussion/list/list.go:316–380  ·  view source on GitHub ↗
(opts *ListOptions, repoName string, discussions []client.Discussion, totalCount int)

Source from the content-addressed store, hash-verified

314}
315
316func printDiscussions(opts *ListOptions, repoName string, discussions []client.Discussion, totalCount int) {
317 isTerminal := opts.IO.IsStdoutTTY()
318 cs := opts.IO.ColorScheme()
319 now := opts.Now()
320
321 if isTerminal {
322 title := listHeader(repoName, len(discussions), totalCount, opts.State)
323 fmt.Fprintf(opts.IO.Out, "\n%s\n\n", title)
324 }
325
326 headers := []string{"ID", "TITLE", "CATEGORY", "LABELS", "ANSWERED", "UPDATED"}
327 if !isTerminal {
328 headers = []string{"ID", "STATE", "TITLE", "CATEGORY", "LABELS", "ANSWERED", "UPDATED"}
329 }
330 tp := tableprinter.New(opts.IO, tableprinter.WithHeader(headers...))
331
332 for _, d := range discussions {
333 if isTerminal {
334 idColor := cs.Green
335 if d.Closed {
336 idColor = cs.Muted
337 }
338 tp.AddField(fmt.Sprintf("#%d", d.Number), tableprinter.WithColor(idColor))
339 } else {
340 tp.AddField(fmt.Sprintf("%d", d.Number))
341 if d.Closed {
342 tp.AddField("CLOSED")
343 } else {
344 tp.AddField("OPEN")
345 }
346 }
347
348 tp.AddField(text.RemoveExcessiveWhitespace(d.Title))
349 tp.AddField(d.Category.Name)
350
351 labelNames := make([]string, len(d.Labels))
352 for i, l := range d.Labels {
353 if isTerminal {
354 labelNames[i] = cs.Label(l.Color, l.Name)
355 } else {
356 labelNames[i] = l.Name
357 }
358 }
359 tp.AddField(strings.Join(labelNames, ", "), tableprinter.WithTruncate(nil))
360
361 if d.Answered {
362 if isTerminal {
363 tp.AddField(cs.SuccessIcon())
364 } else {
365 tp.AddField("answered")
366 }
367 } else {
368 tp.AddField("")
369 }
370
371 tp.AddTimeField(now, d.UpdatedAt, cs.Muted)
372 tp.EndRow()
373 }

Callers 1

listRunFunction · 0.85

Calls 12

NewFunction · 0.92
WithHeaderFunction · 0.92
IsStdoutTTYMethod · 0.80
ColorSchemeMethod · 0.80
JoinMethod · 0.80
SuccessIconMethod · 0.80
AddTimeFieldMethod · 0.80
MutedMethod · 0.80
listHeaderFunction · 0.70
RenderMethod · 0.65
LabelMethod · 0.45

Tested by

no test coverage detected