MCPcopy
hub / github.com/cli/cli / CommentList

Function CommentList

pkg/cmd/pr/shared/comments.go:53–87  ·  view source on GitHub ↗
(io *iostreams.IOStreams, comments api.Comments, reviews api.PullRequestReviews, preview bool)

Source from the content-addressed store, hash-verified

51}
52
53func CommentList(io *iostreams.IOStreams, comments api.Comments, reviews api.PullRequestReviews, preview bool) (string, error) {
54 sortedComments := sortComments(comments, reviews)
55 if preview && len(sortedComments) > 0 {
56 sortedComments = sortedComments[len(sortedComments)-1:]
57 }
58 var b strings.Builder
59 cs := io.ColorScheme()
60 totalCount := comments.TotalCount + reviews.TotalCount
61 retrievedCount := len(sortedComments)
62 hiddenCount := totalCount - retrievedCount
63
64 if preview && hiddenCount > 0 {
65 fmt.Fprint(&b, cs.Muted(fmt.Sprintf("———————— Not showing %s ————————", text.Pluralize(hiddenCount, "comment"))))
66 fmt.Fprintf(&b, "\n\n\n")
67 }
68
69 for i, comment := range sortedComments {
70 last := i+1 == retrievedCount
71 cmt, err := formatComment(io, comment, last)
72 if err != nil {
73 return "", err
74 }
75 fmt.Fprint(&b, cmt)
76 if last {
77 fmt.Fprintln(&b)
78 }
79 }
80
81 if preview && hiddenCount > 0 {
82 fmt.Fprint(&b, cs.Muted("Use --comments to view the full conversation"))
83 fmt.Fprintln(&b)
84 }
85
86 return b.String(), nil
87}
88
89func formatComment(io *iostreams.IOStreams, comment Comment, newest bool) (string, error) {
90 var b strings.Builder

Callers 1

printHumanPrPreviewFunction · 0.92

Calls 6

PluralizeFunction · 0.92
sortCommentsFunction · 0.85
formatCommentFunction · 0.85
ColorSchemeMethod · 0.80
MutedMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected