@@ -123,7 +123,8 @@ func viewRun(opts *ViewOptions) error {
123123 }
124124
125125 if opts .Comments {
126- return printRawIssueComments (opts .IO .Out , issue )
126+ fmt .Fprint (opts .IO .Out , prShared .RawCommentList (issue .Comments ))
127+ return nil
127128 }
128129
129130 return printRawIssuePreview (opts .IO .Out , issue )
@@ -149,26 +150,6 @@ func printRawIssuePreview(out io.Writer, issue *api.Issue) error {
149150 return nil
150151}
151152
152- func printRawIssueComments (out io.Writer , issue * api.Issue ) error {
153- var b strings.Builder
154- for _ , comment := range issue .Comments .Nodes {
155- fmt .Fprint (& b , formatRawIssueComment (comment ))
156- }
157- fmt .Fprint (out , b .String ())
158- return nil
159- }
160-
161- func formatRawIssueComment (comment api.Comment ) string {
162- var b strings.Builder
163- fmt .Fprintf (& b , "author:\t %s\n " , comment .Author .Login )
164- fmt .Fprintf (& b , "association:\t %s\n " , strings .ToLower (comment .AuthorAssociation ))
165- fmt .Fprintf (& b , "edited:\t %t\n " , comment .IncludesCreatedEdit )
166- fmt .Fprintln (& b , "--" )
167- fmt .Fprintln (& b , comment .Body )
168- fmt .Fprintln (& b , "--" )
169- return b .String ()
170- }
171-
172153func printHumanIssuePreview (io * iostreams.IOStreams , issue * api.Issue ) error {
173154 out := io .Out
174155 now := time .Now ()
@@ -186,7 +167,7 @@ func printHumanIssuePreview(io *iostreams.IOStreams, issue *api.Issue) error {
186167 )
187168
188169 // Reactions
189- if reactions := reactionGroupList (issue .ReactionGroups ); reactions != "" {
170+ if reactions := prShared . ReactionGroupList (issue .ReactionGroups ); reactions != "" {
190171 fmt .Fprint (out , reactions )
191172 fmt .Fprintln (out )
192173 }
@@ -224,7 +205,7 @@ func printHumanIssuePreview(io *iostreams.IOStreams, issue *api.Issue) error {
224205
225206 // Comments
226207 if issue .Comments .TotalCount > 0 {
227- comments , err := issueCommentList (io , issue .Comments )
208+ comments , err := prShared . CommentList (io , issue .Comments )
228209 if err != nil {
229210 return err
230211 }
@@ -237,75 +218,6 @@ func printHumanIssuePreview(io *iostreams.IOStreams, issue *api.Issue) error {
237218 return nil
238219}
239220
240- func issueCommentList (io * iostreams.IOStreams , comments api.Comments ) (string , error ) {
241- var b strings.Builder
242- cs := io .ColorScheme ()
243- retrievedCount := len (comments .Nodes )
244- hiddenCount := comments .TotalCount - retrievedCount
245-
246- if hiddenCount > 0 {
247- fmt .Fprint (& b , cs .Gray (fmt .Sprintf ("———————— Not showing %s ————————" , utils .Pluralize (hiddenCount , "comment" ))))
248- fmt .Fprintf (& b , "\n \n \n " )
249- }
250-
251- for i , comment := range comments .Nodes {
252- last := i + 1 == retrievedCount
253- cmt , err := formatIssueComment (io , comment , last )
254- if err != nil {
255- return "" , err
256- }
257- fmt .Fprint (& b , cmt )
258- if last {
259- fmt .Fprintln (& b )
260- }
261- }
262-
263- if hiddenCount > 0 {
264- fmt .Fprint (& b , cs .Gray ("Use --comments to view the full conversation" ))
265- fmt .Fprintln (& b )
266- }
267-
268- return b .String (), nil
269- }
270-
271- func formatIssueComment (io * iostreams.IOStreams , comment api.Comment , newest bool ) (string , error ) {
272- var b strings.Builder
273- cs := io .ColorScheme ()
274-
275- // Header
276- fmt .Fprint (& b , cs .Bold (comment .Author .Login ))
277- if comment .AuthorAssociation != "NONE" {
278- fmt .Fprint (& b , cs .Bold (fmt .Sprintf (" (%s)" , strings .ToLower (comment .AuthorAssociation ))))
279- }
280- fmt .Fprint (& b , cs .Bold (fmt .Sprintf (" • %s" , utils .FuzzyAgoAbbr (time .Now (), comment .CreatedAt ))))
281- if comment .IncludesCreatedEdit {
282- fmt .Fprint (& b , cs .Bold (" • edited" ))
283- }
284- if newest {
285- fmt .Fprint (& b , cs .Bold (" • " ))
286- fmt .Fprint (& b , cs .CyanBold ("Newest comment" ))
287- }
288- fmt .Fprintln (& b )
289-
290- // Reactions
291- if reactions := reactionGroupList (comment .ReactionGroups ); reactions != "" {
292- fmt .Fprint (& b , reactions )
293- fmt .Fprintln (& b )
294- }
295-
296- // Body
297- if comment .Body != "" {
298- style := markdown .GetStyle (io .TerminalTheme ())
299- md , err := markdown .Render (comment .Body , style , "" )
300- if err != nil {
301- return "" , err
302- }
303- fmt .Fprint (& b , md )
304- }
305-
306- return b .String (), nil
307- }
308-
309221func issueStateTitleWithColor (cs * iostreams.ColorScheme , state string ) string {
310222 colorFunc := cs .ColorFromString (prShared .ColorForState (state ))
311223 return colorFunc (strings .Title (strings .ToLower (state )))
@@ -348,27 +260,3 @@ func issueProjectList(issue api.Issue) string {
348260 }
349261 return list
350262}
351-
352- func reactionGroupList (rgs api.ReactionGroups ) string {
353- var rs []string
354-
355- for _ , rg := range rgs {
356- if r := formatReactionGroup (rg ); r != "" {
357- rs = append (rs , r )
358- }
359- }
360-
361- return strings .Join (rs , " • " )
362- }
363-
364- func formatReactionGroup (rg api.ReactionGroup ) string {
365- c := rg .Count ()
366- if c == 0 {
367- return ""
368- }
369- e := rg .Emoji ()
370- if e == "" {
371- return ""
372- }
373- return fmt .Sprintf ("%v %s" , c , e )
374- }
0 commit comments