MCPcopy
hub / github.com/cli/cli / formatComment

Function formatComment

pkg/cmd/pr/shared/comments.go:89–142  ·  view source on GitHub ↗
(io *iostreams.IOStreams, comment Comment, newest bool)

Source from the content-addressed store, hash-verified

87}
88
89func formatComment(io *iostreams.IOStreams, comment Comment, newest bool) (string, error) {
90 var b strings.Builder
91 cs := io.ColorScheme()
92
93 if comment.IsHidden() {
94 return cs.Bold(formatHiddenComment(comment)), nil
95 }
96
97 // Header
98 fmt.Fprint(&b, cs.Bold(comment.AuthorLogin()))
99 if comment.Status() != "" {
100 fmt.Fprint(&b, formatCommentStatus(cs, comment.Status()))
101 }
102 if comment.Association() != "NONE" {
103 fmt.Fprint(&b, cs.Boldf(" (%s)", text.Title(comment.Association())))
104 }
105 fmt.Fprint(&b, cs.Boldf(" • %s", text.FuzzyAgoAbbr(time.Now(), comment.Created())))
106 if comment.IsEdited() {
107 fmt.Fprint(&b, cs.Bold(" • Edited"))
108 }
109 if newest {
110 fmt.Fprint(&b, cs.Bold(" • "))
111 fmt.Fprint(&b, cs.CyanBold("Newest comment"))
112 }
113 fmt.Fprintln(&b)
114
115 // Reactions
116 if reactions := ReactionGroupList(comment.Reactions()); reactions != "" {
117 fmt.Fprint(&b, reactions)
118 fmt.Fprintln(&b)
119 }
120
121 // Body
122 var md string
123 var err error
124 if comment.Content() == "" {
125 md = fmt.Sprintf("\n %s\n\n", cs.Muted("No body provided"))
126 } else {
127 md, err = markdown.Render(comment.Content(),
128 markdown.WithTheme(io.TerminalTheme()),
129 markdown.WithWrap(io.TerminalWidth()))
130 if err != nil {
131 return "", err
132 }
133 }
134 fmt.Fprint(&b, md)
135
136 // Footer
137 if comment.Link() != "" {
138 fmt.Fprintf(&b, cs.Muted("View the full review: %s\n\n"), comment.Link())
139 }
140
141 return b.String(), nil
142}
143
144func sortComments(cs api.Comments, rs api.PullRequestReviews) []Comment {
145 comments := cs.Nodes

Callers 1

CommentListFunction · 0.85

Calls 15

TitleFunction · 0.92
FuzzyAgoAbbrFunction · 0.92
RenderFunction · 0.92
WithThemeFunction · 0.92
WithWrapFunction · 0.92
formatHiddenCommentFunction · 0.85
formatCommentStatusFunction · 0.85
ReactionGroupListFunction · 0.85
ColorSchemeMethod · 0.80
BoldMethod · 0.80
BoldfMethod · 0.80
CyanBoldMethod · 0.80

Tested by

no test coverage detected