From 52bdcad8eade31414d0e87d0455d8d4ff2649753 Mon Sep 17 00:00:00 2001 From: Sam Coe Date: Tue, 26 Jan 2021 10:19:52 -0800 Subject: [PATCH] Do not display minimized comments --- api/queries_comments.go | 20 ++++++++++++---- api/queries_issue.go | 2 ++ api/queries_pr_review.go | 16 +++++++++---- .../issueView_previewFullComments.json | 14 ++++++++++- .../issueView_previewSingleComment.json | 2 +- pkg/cmd/issue/view/view_test.go | 5 ++-- pkg/cmd/pr/shared/comments.go | 23 +++++++++++++++++-- .../fixtures/prViewPreviewFullComments.json | 14 ++++++++++- .../fixtures/prViewPreviewSingleComment.json | 2 +- pkg/cmd/pr/view/view.go | 2 +- pkg/cmd/pr/view/view_test.go | 3 ++- 11 files changed, 85 insertions(+), 18 deletions(-) diff --git a/api/queries_comments.go b/api/queries_comments.go index 16eba6152..db7482692 100644 --- a/api/queries_comments.go +++ b/api/queries_comments.go @@ -21,6 +21,8 @@ type Comment struct { Body string CreatedAt time.Time IncludesCreatedEdit bool + IsMinimized bool + MinimizedReason string ReactionGroups ReactionGroups } @@ -143,6 +145,8 @@ func commentsFragment() string { body createdAt includesCreatedEdit + isMinimized + minimizedReason ` + reactionGroupsFragment() + ` } totalCount @@ -165,10 +169,22 @@ func (c Comment) Created() time.Time { return c.CreatedAt } +func (c Comment) HiddenReason() string { + return c.MinimizedReason +} + func (c Comment) IsEdited() bool { return c.IncludesCreatedEdit } +func (c Comment) IsHidden() bool { + return c.IsMinimized +} + +func (c Comment) Link() string { + return "" +} + func (c Comment) Reactions() ReactionGroups { return c.ReactionGroups } @@ -176,7 +192,3 @@ func (c Comment) Reactions() ReactionGroups { func (c Comment) Status() string { return "" } - -func (c Comment) Link() string { - return "" -} diff --git a/api/queries_issue.go b/api/queries_issue.go index dca859831..99a628876 100644 --- a/api/queries_issue.go +++ b/api/queries_issue.go @@ -351,6 +351,8 @@ func IssueByNumber(client *Client, repo ghrepo.Interface, number int) (*Issue, e body createdAt includesCreatedEdit + isMinimized + minimizedReason reactionGroups { content users { diff --git a/api/queries_pr_review.go b/api/queries_pr_review.go index 7378db111..27365429e 100644 --- a/api/queries_pr_review.go +++ b/api/queries_pr_review.go @@ -118,10 +118,22 @@ func (prr PullRequestReview) Created() time.Time { return prr.CreatedAt } +func (prr PullRequestReview) HiddenReason() string { + return "" +} + func (prr PullRequestReview) IsEdited() bool { return prr.IncludesCreatedEdit } +func (prr PullRequestReview) IsHidden() bool { + return false +} + +func (prr PullRequestReview) Link() string { + return prr.URL +} + func (prr PullRequestReview) Reactions() ReactionGroups { return prr.ReactionGroups } @@ -129,7 +141,3 @@ func (prr PullRequestReview) Reactions() ReactionGroups { func (prr PullRequestReview) Status() string { return prr.State } - -func (prr PullRequestReview) Link() string { - return prr.URL -} diff --git a/pkg/cmd/issue/view/fixtures/issueView_previewFullComments.json b/pkg/cmd/issue/view/fixtures/issueView_previewFullComments.json index d2cd27f30..9ab620ecd 100644 --- a/pkg/cmd/issue/view/fixtures/issueView_previewFullComments.json +++ b/pkg/cmd/issue/view/fixtures/issueView_previewFullComments.json @@ -240,6 +240,18 @@ } ] }, + { + "author": { + "login": "sam-spam" + }, + "authorAssociation": "NONE", + "body": "Spam comment", + "createdAt": "2020-01-01T12:00:00Z", + "includesCreatedEdit": true, + "isMinimized": true, + "minimizedReason": "spam", + "reactionGroups": [] + }, { "author": { "login": "marseilles" @@ -300,7 +312,7 @@ ] } ], - "totalCount": 5 + "totalCount": 6 } } } diff --git a/pkg/cmd/issue/view/fixtures/issueView_previewSingleComment.json b/pkg/cmd/issue/view/fixtures/issueView_previewSingleComment.json index 87fc7bffc..be099c14b 100644 --- a/pkg/cmd/issue/view/fixtures/issueView_previewSingleComment.json +++ b/pkg/cmd/issue/view/fixtures/issueView_previewSingleComment.json @@ -138,7 +138,7 @@ ] } ], - "totalCount": 5 + "totalCount": 6 }, "url": "https://github.com/OWNER/REPO/issues/123" } diff --git a/pkg/cmd/issue/view/view_test.go b/pkg/cmd/issue/view/view_test.go index 1cfc0db88..97b3189ec 100644 --- a/pkg/cmd/issue/view/view_test.go +++ b/pkg/cmd/issue/view/view_test.go @@ -390,7 +390,7 @@ func TestIssueView_tty_Comments(t *testing.T) { expectedOutputs: []string{ `some title`, `some body`, - `———————— Not showing 4 comments ————————`, + `———————— Not showing 5 comments ————————`, `marseilles \(Collaborator\) • Jan 1, 2020 • Newest comment`, `Comment 5`, `Use --comments to view the full conversation`, @@ -415,6 +415,7 @@ func TestIssueView_tty_Comments(t *testing.T) { `Comment 3`, `loislane \(Owner\) • Jan 1, 2020`, `Comment 4`, + `sam-spam • This comment has been marked as spam`, `marseilles \(Collaborator\) • Jan 1, 2020 • Newest comment`, `Comment 5`, `View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`, @@ -462,7 +463,7 @@ func TestIssueView_nontty_Comments(t *testing.T) { `title:\tsome title`, `state:\tOPEN`, `author:\tmarseilles`, - `comments:\t5`, + `comments:\t6`, `some body`, }, }, diff --git a/pkg/cmd/pr/shared/comments.go b/pkg/cmd/pr/shared/comments.go index 9f27416a2..1b16753f1 100644 --- a/pkg/cmd/pr/shared/comments.go +++ b/pkg/cmd/pr/shared/comments.go @@ -17,7 +17,9 @@ type Comment interface { Association() string Content() string Created() time.Time + HiddenReason() string IsEdited() bool + IsHidden() bool Link() string Reactions() api.ReactionGroups Status() string @@ -33,6 +35,9 @@ func RawCommentList(comments api.Comments, reviews api.PullRequestReviews) strin } func formatRawComment(comment Comment) string { + if comment.IsHidden() { + return "" + } var b strings.Builder fmt.Fprintf(&b, "author:\t%s\n", comment.AuthorLogin()) fmt.Fprintf(&b, "association:\t%s\n", strings.ToLower(comment.Association())) @@ -55,7 +60,7 @@ func CommentList(io *iostreams.IOStreams, comments api.Comments, reviews api.Pul retrievedCount := len(sortedComments) hiddenCount := totalCount - retrievedCount - if hiddenCount > 0 { + if preview && hiddenCount > 0 { fmt.Fprint(&b, cs.Gray(fmt.Sprintf("———————— Not showing %s ————————", utils.Pluralize(hiddenCount, "comment")))) fmt.Fprintf(&b, "\n\n\n") } @@ -72,7 +77,7 @@ func CommentList(io *iostreams.IOStreams, comments api.Comments, reviews api.Pul } } - if hiddenCount > 0 { + if preview && hiddenCount > 0 { fmt.Fprint(&b, cs.Gray("Use --comments to view the full conversation")) fmt.Fprintln(&b) } @@ -84,6 +89,10 @@ func formatComment(io *iostreams.IOStreams, comment Comment, newest bool) (strin var b strings.Builder cs := io.ColorScheme() + if comment.IsHidden() { + return cs.Bold(formatHiddenComment(comment)), nil + } + // Header fmt.Fprint(&b, cs.Bold(comment.AuthorLogin())) if comment.Status() != "" { @@ -182,3 +191,13 @@ func formatRawCommentStatus(status string) string { return "none" } + +func formatHiddenComment(comment Comment) string { + var b strings.Builder + fmt.Fprint(&b, comment.AuthorLogin()) + if comment.Association() != "NONE" { + fmt.Fprintf(&b, " (%s)", strings.Title(strings.ToLower(comment.Association()))) + } + fmt.Fprintf(&b, " • This comment has been marked as %s\n\n", comment.HiddenReason()) + return b.String() +} diff --git a/pkg/cmd/pr/view/fixtures/prViewPreviewFullComments.json b/pkg/cmd/pr/view/fixtures/prViewPreviewFullComments.json index 1ee02364a..35164bd90 100644 --- a/pkg/cmd/pr/view/fixtures/prViewPreviewFullComments.json +++ b/pkg/cmd/pr/view/fixtures/prViewPreviewFullComments.json @@ -240,6 +240,18 @@ } ] }, + { + "author": { + "login": "sam-spam" + }, + "authorAssociation": "NONE", + "body": "Spam comment", + "createdAt": "2020-01-09T12:00:00Z", + "includesCreatedEdit": true, + "isMinimized": true, + "minimizedReason": "spam", + "reactionGroups": [] + }, { "author": { "login": "marseilles" @@ -300,7 +312,7 @@ ] } ], - "totalCount": 5 + "totalCount": 6 } } } diff --git a/pkg/cmd/pr/view/fixtures/prViewPreviewSingleComment.json b/pkg/cmd/pr/view/fixtures/prViewPreviewSingleComment.json index 71d58fe83..c0ab1afbd 100644 --- a/pkg/cmd/pr/view/fixtures/prViewPreviewSingleComment.json +++ b/pkg/cmd/pr/view/fixtures/prViewPreviewSingleComment.json @@ -147,7 +147,7 @@ ] } ], - "totalCount": 5 + "totalCount": 6 } } } diff --git a/pkg/cmd/pr/view/view.go b/pkg/cmd/pr/view/view.go index b2f84ff78..e78a192df 100644 --- a/pkg/cmd/pr/view/view.go +++ b/pkg/cmd/pr/view/view.go @@ -111,7 +111,7 @@ func viewRun(opts *ViewOptions) error { } if opts.Comments { - fmt.Fprint(opts.IO.Out, shared.RawCommentList(pr.Comments, pr.Reviews)) + fmt.Fprint(opts.IO.Out, shared.RawCommentList(pr.Comments, pr.DisplayableReviews())) return nil } diff --git a/pkg/cmd/pr/view/view_test.go b/pkg/cmd/pr/view/view_test.go index c71618cd1..6480adcf0 100644 --- a/pkg/cmd/pr/view/view_test.go +++ b/pkg/cmd/pr/view/view_test.go @@ -816,7 +816,7 @@ func TestPRView_tty_Comments(t *testing.T) { `some title`, `1 \x{1f615} • 2 \x{1f440} • 3 \x{2764}\x{fe0f}`, `some body`, - `———————— Not showing 8 comments ————————`, + `———————— Not showing 9 comments ————————`, `marseilles \(Collaborator\) • Jan 9, 2020 • Newest comment`, `4 \x{1f389} • 5 \x{1f604} • 6 \x{1f680}`, `Comment 5`, @@ -858,6 +858,7 @@ func TestPRView_tty_Comments(t *testing.T) { `louise dismissed • Jan 8, 2020`, `Review 4`, `View the full review: https://github.com/OWNER/REPO/pull/12#pullrequestreview-4`, + `sam-spam • This comment has been marked as spam`, `marseilles \(Collaborator\) • Jan 9, 2020 • Newest comment`, `Comment 5`, `View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12`,