Merge pull request #2859 from cli/hidden-comments
Do not display minimized comments
This commit is contained in:
commit
11d3972bac
11 changed files with 85 additions and 18 deletions
|
|
@ -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 ""
|
||||
}
|
||||
|
|
|
|||
|
|
@ -351,6 +351,8 @@ func IssueByNumber(client *Client, repo ghrepo.Interface, number int) (*Issue, e
|
|||
body
|
||||
createdAt
|
||||
includesCreatedEdit
|
||||
isMinimized
|
||||
minimizedReason
|
||||
reactionGroups {
|
||||
content
|
||||
users {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@
|
|||
]
|
||||
}
|
||||
],
|
||||
"totalCount": 5
|
||||
"totalCount": 6
|
||||
},
|
||||
"url": "https://github.com/OWNER/REPO/issues/123"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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`,
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@
|
|||
]
|
||||
}
|
||||
],
|
||||
"totalCount": 5
|
||||
"totalCount": 6
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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`,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue