Skip to content

Commit

Permalink
Merge pull request #203 from garethjevans/count-comment
Browse files Browse the repository at this point in the history
feat: show the number of comments against an issue/pr
  • Loading branch information
garethjevans authored Jan 29, 2022
2 parents 5e925e7 + dc3d373 commit 9ac1b2c
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 55 deletions.
12 changes: 12 additions & 0 deletions pkg/cmd/common_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ func TestCommonCmd_Filter_AllData(t *testing.T) {
"login": "author1"
},
"closed": false,
"comments": {
"totalCount": 0
},
"commits": {
"nodes": null
},
Expand All @@ -45,6 +48,9 @@ func TestCommonCmd_Filter_AllData(t *testing.T) {
"login": "author2"
},
"closed": false,
"comments": {
"totalCount": 0
},
"commits": {
"nodes": null
},
Expand All @@ -66,6 +72,9 @@ func TestCommonCmd_Filter_AllData(t *testing.T) {
"login": "author3"
},
"closed": false,
"comments": {
"totalCount": 0
},
"commits": {
"nodes": null
},
Expand Down Expand Up @@ -102,6 +111,9 @@ func TestCommonCmd_Filter_FilterOnAuthor(t *testing.T) {
"login": "author1"
},
"closed": false,
"comments": {
"totalCount": 0
},
"commits": {
"nodes": null
},
Expand Down
20 changes: 11 additions & 9 deletions pkg/cmd/getcmd/get_issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,22 @@ func (c *GetIssuesCmd) Run() error {
"Title",
"Age",
"Labels",
"Comments",
)
}

for _, pr := range d.Issues {
if pullURL != pr.IssueString() {
table.AddRow(fmt.Sprintf("# %s", util.ColorAnswer(pr.IssueString())))
pullURL = pr.IssueString()
for _, issue := range d.Issues {
if pullURL != issue.IssueString() {
table.AddRow(fmt.Sprintf("# %s", util.ColorAnswer(issue.IssueString())))
pullURL = issue.IssueString()
}
table.AddRow(
util.ColorInfo(fmt.Sprintf("#%d", pr.Number)),
pr.Author.Login,
pr.ColoredTitle(),
util.SafeTime(&pr.CreatedAt),
pr.LabelsString(),
util.ColorInfo(fmt.Sprintf("#%d", issue.Number)),
issue.Author.Login,
issue.ColoredTitle(),
util.SafeTime(&issue.CreatedAt),
issue.LabelsString(),
util.SafeIfAboveZero(issue.Comments.TotalCount),
)
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/getcmd/get_prs.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func (c *GetPrsCmd) Run() error {
"Review",
"Labels",
"Mergeable",
"Comments",
)
}

Expand All @@ -133,6 +134,7 @@ func (c *GetPrsCmd) Run() error {
pr.ColoredReviewDecision(),
pr.LabelsString(),
pr.MergeableString(),
util.SafeIfAboveZero(pr.Comments.TotalCount),
)
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/domain/get_issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ var (
repository {
nameWithOwner
}
comments {
totalCount
}
labels(first: 10) {
nodes {
name
Expand Down
3 changes: 3 additions & 0 deletions pkg/domain/get_prs.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ var (
}
}
reviewDecision
comments {
totalCount
}
commits(last: 1){
nodes{
commit{
Expand Down
51 changes: 51 additions & 0 deletions pkg/pr/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package pr

type Comments struct {
TotalCount int `json:"totalCount"`
}

type Repository struct {
NameWithOwner string `json:"nameWithOwner"`
}

type Author struct {
Login string `json:"login"`
}

type Labels struct {
Nodes []Label `json:"nodes"`
}

type Label struct {
Name string `json:"name"`
}

type Commits struct {
Nodes []CommitEntry `json:"nodes"`
}

type CommitEntry struct {
Commit Commit `json:"commit"`
}

type Commit struct {
StatusCheckRollup StatusCheckRollup `json:"statusCheckRollup"`
}

type StatusCheckRollup struct {
State string `json:"state"`
Contexts StatusContext `json:"contexts"`
}

type StatusContext struct {
Nodes []Context `json:"nodes"`
}

type Context struct {
State string `json:"state"`
Description string `json:"description"`
Context string `json:"context"`
Conclusion string `json:"conclusion"`
Name string `json:"name"`
Title string `json:"title"`
}
1 change: 1 addition & 0 deletions pkg/pr/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Issue struct {
Labels Labels `json:"labels"`
Closed bool `json:"closed"`
Repository Repository `json:"repository"`
Comments Comments `json:"comments"`
}

func (p *Issue) Display() bool {
Expand Down
47 changes: 1 addition & 46 deletions pkg/pr/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type PullRequest struct {
Commits Commits `json:"commits"`
Closed bool `json:"closed"`
Repository Repository `json:"repository"`
Comments Comments `json:"comments"`
ReviewDecision string `json:"reviewDecision"`
}

Expand Down Expand Up @@ -154,52 +155,6 @@ func (p *PullRequest) HasContext(name string) bool {
return false
}

type Repository struct {
NameWithOwner string `json:"nameWithOwner"`
}

type Author struct {
Login string `json:"login"`
}

type Labels struct {
Nodes []Label `json:"nodes"`
}

type Label struct {
Name string `json:"name"`
}

type Commits struct {
Nodes []CommitEntry `json:"nodes"`
}

type CommitEntry struct {
Commit Commit `json:"commit"`
}

type Commit struct {
StatusCheckRollup StatusCheckRollup `json:"statusCheckRollup"`
}

type StatusCheckRollup struct {
State string `json:"state"`
Contexts StatusContext `json:"contexts"`
}

type StatusContext struct {
Nodes []Context `json:"nodes"`
}

type Context struct {
State string `json:"state"`
Description string `json:"description"`
Context string `json:"context"`
Conclusion string `json:"conclusion"`
Name string `json:"name"`
Title string `json:"title"`
}

func unique(stringSlice []string) []string {
keys := make(map[string]bool)
list := []string{}
Expand Down
7 changes: 7 additions & 0 deletions pkg/util/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ func SafeTime(in *time.Time) string {
func TrimTemplate(instanceTemplate string, instanceType string) string {
return strings.ReplaceAll(instanceTemplate, fmt.Sprintf("%s-instance-template-", instanceType), "")
}

func SafeIfAboveZero(number int) string {
if number > 0 {
return fmt.Sprintf("%d", number)
}
return ""
}
5 changes: 5 additions & 0 deletions pkg/util/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ import (
func TestTrimTemplate(t *testing.T) {
assert.Equal(t, TrimTemplate("my-instance-template-1.2.3", "my"), "1.2.3")
}

func TestSafeIfAboveZero(t *testing.T) {
assert.Equal(t, SafeIfAboveZero(0), "")
assert.Equal(t, SafeIfAboveZero(1), "1")
}

0 comments on commit 9ac1b2c

Please sign in to comment.