X Tutup
Skip to content

Commit 52bdcad

Browse files
committed
Do not display minimized comments
1 parent c71dc87 commit 52bdcad

File tree

11 files changed

+85
-18
lines changed

11 files changed

+85
-18
lines changed

api/queries_comments.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ type Comment struct {
2121
Body string
2222
CreatedAt time.Time
2323
IncludesCreatedEdit bool
24+
IsMinimized bool
25+
MinimizedReason string
2426
ReactionGroups ReactionGroups
2527
}
2628

@@ -143,6 +145,8 @@ func commentsFragment() string {
143145
body
144146
createdAt
145147
includesCreatedEdit
148+
isMinimized
149+
minimizedReason
146150
` + reactionGroupsFragment() + `
147151
}
148152
totalCount
@@ -165,18 +169,26 @@ func (c Comment) Created() time.Time {
165169
return c.CreatedAt
166170
}
167171

172+
func (c Comment) HiddenReason() string {
173+
return c.MinimizedReason
174+
}
175+
168176
func (c Comment) IsEdited() bool {
169177
return c.IncludesCreatedEdit
170178
}
171179

172-
func (c Comment) Reactions() ReactionGroups {
173-
return c.ReactionGroups
180+
func (c Comment) IsHidden() bool {
181+
return c.IsMinimized
174182
}
175183

176-
func (c Comment) Status() string {
184+
func (c Comment) Link() string {
177185
return ""
178186
}
179187

180-
func (c Comment) Link() string {
188+
func (c Comment) Reactions() ReactionGroups {
189+
return c.ReactionGroups
190+
}
191+
192+
func (c Comment) Status() string {
181193
return ""
182194
}

api/queries_issue.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ func IssueByNumber(client *Client, repo ghrepo.Interface, number int) (*Issue, e
351351
body
352352
createdAt
353353
includesCreatedEdit
354+
isMinimized
355+
minimizedReason
354356
reactionGroups {
355357
content
356358
users {

api/queries_pr_review.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,26 @@ func (prr PullRequestReview) Created() time.Time {
118118
return prr.CreatedAt
119119
}
120120

121+
func (prr PullRequestReview) HiddenReason() string {
122+
return ""
123+
}
124+
121125
func (prr PullRequestReview) IsEdited() bool {
122126
return prr.IncludesCreatedEdit
123127
}
124128

129+
func (prr PullRequestReview) IsHidden() bool {
130+
return false
131+
}
132+
133+
func (prr PullRequestReview) Link() string {
134+
return prr.URL
135+
}
136+
125137
func (prr PullRequestReview) Reactions() ReactionGroups {
126138
return prr.ReactionGroups
127139
}
128140

129141
func (prr PullRequestReview) Status() string {
130142
return prr.State
131143
}
132-
133-
func (prr PullRequestReview) Link() string {
134-
return prr.URL
135-
}

pkg/cmd/issue/view/fixtures/issueView_previewFullComments.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,18 @@
240240
}
241241
]
242242
},
243+
{
244+
"author": {
245+
"login": "sam-spam"
246+
},
247+
"authorAssociation": "NONE",
248+
"body": "Spam comment",
249+
"createdAt": "2020-01-01T12:00:00Z",
250+
"includesCreatedEdit": true,
251+
"isMinimized": true,
252+
"minimizedReason": "spam",
253+
"reactionGroups": []
254+
},
243255
{
244256
"author": {
245257
"login": "marseilles"
@@ -300,7 +312,7 @@
300312
]
301313
}
302314
],
303-
"totalCount": 5
315+
"totalCount": 6
304316
}
305317
}
306318
}

pkg/cmd/issue/view/fixtures/issueView_previewSingleComment.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
]
139139
}
140140
],
141-
"totalCount": 5
141+
"totalCount": 6
142142
},
143143
"url": "https://github.com/OWNER/REPO/issues/123"
144144
}

pkg/cmd/issue/view/view_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ func TestIssueView_tty_Comments(t *testing.T) {
390390
expectedOutputs: []string{
391391
`some title`,
392392
`some body`,
393-
`———————— Not showing 4 comments ————————`,
393+
`———————— Not showing 5 comments ————————`,
394394
`marseilles \(Collaborator\) • Jan 1, 2020 • Newest comment`,
395395
`Comment 5`,
396396
`Use --comments to view the full conversation`,
@@ -415,6 +415,7 @@ func TestIssueView_tty_Comments(t *testing.T) {
415415
`Comment 3`,
416416
`loislane \(Owner\) • Jan 1, 2020`,
417417
`Comment 4`,
418+
`sam-spam • This comment has been marked as spam`,
418419
`marseilles \(Collaborator\) • Jan 1, 2020 • Newest comment`,
419420
`Comment 5`,
420421
`View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`,
@@ -462,7 +463,7 @@ func TestIssueView_nontty_Comments(t *testing.T) {
462463
`title:\tsome title`,
463464
`state:\tOPEN`,
464465
`author:\tmarseilles`,
465-
`comments:\t5`,
466+
`comments:\t6`,
466467
`some body`,
467468
},
468469
},

pkg/cmd/pr/shared/comments.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ type Comment interface {
1717
Association() string
1818
Content() string
1919
Created() time.Time
20+
HiddenReason() string
2021
IsEdited() bool
22+
IsHidden() bool
2123
Link() string
2224
Reactions() api.ReactionGroups
2325
Status() string
@@ -33,6 +35,9 @@ func RawCommentList(comments api.Comments, reviews api.PullRequestReviews) strin
3335
}
3436

3537
func formatRawComment(comment Comment) string {
38+
if comment.IsHidden() {
39+
return ""
40+
}
3641
var b strings.Builder
3742
fmt.Fprintf(&b, "author:\t%s\n", comment.AuthorLogin())
3843
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
5560
retrievedCount := len(sortedComments)
5661
hiddenCount := totalCount - retrievedCount
5762

58-
if hiddenCount > 0 {
63+
if preview && hiddenCount > 0 {
5964
fmt.Fprint(&b, cs.Gray(fmt.Sprintf("———————— Not showing %s ————————", utils.Pluralize(hiddenCount, "comment"))))
6065
fmt.Fprintf(&b, "\n\n\n")
6166
}
@@ -72,7 +77,7 @@ func CommentList(io *iostreams.IOStreams, comments api.Comments, reviews api.Pul
7277
}
7378
}
7479

75-
if hiddenCount > 0 {
80+
if preview && hiddenCount > 0 {
7681
fmt.Fprint(&b, cs.Gray("Use --comments to view the full conversation"))
7782
fmt.Fprintln(&b)
7883
}
@@ -84,6 +89,10 @@ func formatComment(io *iostreams.IOStreams, comment Comment, newest bool) (strin
8489
var b strings.Builder
8590
cs := io.ColorScheme()
8691

92+
if comment.IsHidden() {
93+
return cs.Bold(formatHiddenComment(comment)), nil
94+
}
95+
8796
// Header
8897
fmt.Fprint(&b, cs.Bold(comment.AuthorLogin()))
8998
if comment.Status() != "" {
@@ -182,3 +191,13 @@ func formatRawCommentStatus(status string) string {
182191

183192
return "none"
184193
}
194+
195+
func formatHiddenComment(comment Comment) string {
196+
var b strings.Builder
197+
fmt.Fprint(&b, comment.AuthorLogin())
198+
if comment.Association() != "NONE" {
199+
fmt.Fprintf(&b, " (%s)", strings.Title(strings.ToLower(comment.Association())))
200+
}
201+
fmt.Fprintf(&b, " • This comment has been marked as %s\n\n", comment.HiddenReason())
202+
return b.String()
203+
}

pkg/cmd/pr/view/fixtures/prViewPreviewFullComments.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,18 @@
240240
}
241241
]
242242
},
243+
{
244+
"author": {
245+
"login": "sam-spam"
246+
},
247+
"authorAssociation": "NONE",
248+
"body": "Spam comment",
249+
"createdAt": "2020-01-09T12:00:00Z",
250+
"includesCreatedEdit": true,
251+
"isMinimized": true,
252+
"minimizedReason": "spam",
253+
"reactionGroups": []
254+
},
243255
{
244256
"author": {
245257
"login": "marseilles"
@@ -300,7 +312,7 @@
300312
]
301313
}
302314
],
303-
"totalCount": 5
315+
"totalCount": 6
304316
}
305317
}
306318
}

pkg/cmd/pr/view/fixtures/prViewPreviewSingleComment.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
]
148148
}
149149
],
150-
"totalCount": 5
150+
"totalCount": 6
151151
}
152152
}
153153
}

pkg/cmd/pr/view/view.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func viewRun(opts *ViewOptions) error {
111111
}
112112

113113
if opts.Comments {
114-
fmt.Fprint(opts.IO.Out, shared.RawCommentList(pr.Comments, pr.Reviews))
114+
fmt.Fprint(opts.IO.Out, shared.RawCommentList(pr.Comments, pr.DisplayableReviews()))
115115
return nil
116116
}
117117

0 commit comments

Comments
 (0)
X Tutup