(io *iostreams.IOStreams, comments api.Comments, reviews api.PullRequestReviews, preview bool)
| 51 | } |
| 52 | |
| 53 | func 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 | |
| 89 | func formatComment(io *iostreams.IOStreams, comment Comment, newest bool) (string, error) { |
| 90 | var b strings.Builder |
no test coverage detected