Skip to content

Commit 869f50e

Browse files
Merge pull request cli#205 from github/and-four-more
Add "show more" to the issues and PR results in `gh issue status` and `gh pr status`
2 parents 2053809 + 5ed1dbe commit 869f50e

File tree

7 files changed

+180
-116
lines changed

7 files changed

+180
-116
lines changed

api/queries_issue.go

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ import (
55
)
66

77
type IssuesPayload struct {
8-
Assigned []Issue
9-
Mentioned []Issue
10-
Authored []Issue
8+
Assigned IssuesAndTotalCount
9+
Mentioned IssuesAndTotalCount
10+
Authored IssuesAndTotalCount
11+
}
12+
13+
type IssuesAndTotalCount struct {
14+
Issues []Issue
15+
TotalCount int
1116
}
1217

1318
type Issue struct {
@@ -80,13 +85,16 @@ func IssueStatus(client *Client, ghRepo Repo, currentUsername string) (*IssuesPa
8085
type response struct {
8186
Repository struct {
8287
Assigned struct {
83-
Nodes []Issue
88+
TotalCount int
89+
Nodes []Issue
8490
}
8591
Mentioned struct {
86-
Nodes []Issue
92+
TotalCount int
93+
Nodes []Issue
8794
}
8895
Authored struct {
89-
Nodes []Issue
96+
TotalCount int
97+
Nodes []Issue
9098
}
9199
HasIssuesEnabled bool
92100
}
@@ -97,16 +105,19 @@ func IssueStatus(client *Client, ghRepo Repo, currentUsername string) (*IssuesPa
97105
repository(owner: $owner, name: $repo) {
98106
hasIssuesEnabled
99107
assigned: issues(filterBy: {assignee: $viewer, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
108+
totalCount
100109
nodes {
101110
...issue
102111
}
103112
}
104113
mentioned: issues(filterBy: {mentioned: $viewer, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
114+
totalCount
105115
nodes {
106116
...issue
107117
}
108118
}
109119
authored: issues(filterBy: {createdBy: $viewer, states: OPEN}, first: $per_page, orderBy: {field: CREATED_AT, direction: DESC}) {
120+
totalCount
110121
nodes {
111122
...issue
112123
}
@@ -133,9 +144,18 @@ func IssueStatus(client *Client, ghRepo Repo, currentUsername string) (*IssuesPa
133144
}
134145

135146
payload := IssuesPayload{
136-
Assigned: resp.Repository.Assigned.Nodes,
137-
Mentioned: resp.Repository.Mentioned.Nodes,
138-
Authored: resp.Repository.Authored.Nodes,
147+
Assigned: IssuesAndTotalCount{
148+
Issues: resp.Repository.Assigned.Nodes,
149+
TotalCount: resp.Repository.Assigned.TotalCount,
150+
},
151+
Mentioned: IssuesAndTotalCount{
152+
Issues: resp.Repository.Mentioned.Nodes,
153+
TotalCount: resp.Repository.Mentioned.TotalCount,
154+
},
155+
Authored: IssuesAndTotalCount{
156+
Issues: resp.Repository.Authored.Nodes,
157+
TotalCount: resp.Repository.Authored.TotalCount,
158+
},
139159
}
140160

141161
return &payload, nil

api/queries_pr.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ import (
66
)
77

88
type PullRequestsPayload struct {
9-
ViewerCreated []PullRequest
10-
ReviewRequested []PullRequest
9+
ViewerCreated PullRequestAndTotalCount
10+
ReviewRequested PullRequestAndTotalCount
1111
CurrentPR *PullRequest
1212
}
1313

14+
type PullRequestAndTotalCount struct {
15+
TotalCount int
16+
PullRequests []PullRequest
17+
}
18+
1419
type PullRequest struct {
1520
Number int
1621
Title string
@@ -123,7 +128,8 @@ type Repo interface {
123128

124129
func PullRequests(client *Client, ghRepo Repo, currentPRNumber int, currentPRHeadRef, currentUsername string) (*PullRequestsPayload, error) {
125130
type edges struct {
126-
Edges []struct {
131+
TotalCount int
132+
Edges []struct {
127133
Node PullRequest
128134
}
129135
}
@@ -177,6 +183,7 @@ func PullRequests(client *Client, ghRepo Repo, currentPRNumber int, currentPRHea
177183
query($owner: String!, $repo: String!, $headRefName: String!, $viewerQuery: String!, $reviewerQuery: String!, $per_page: Int = 10) {
178184
repository(owner: $owner, name: $repo) {
179185
pullRequests(headRefName: $headRefName, states: OPEN, first: $per_page) {
186+
totalCount
180187
edges {
181188
node {
182189
...prWithReviews
@@ -198,13 +205,15 @@ func PullRequests(client *Client, ghRepo Repo, currentPRNumber int, currentPRHea
198205

199206
query := fragments + queryPrefix + `
200207
viewerCreated: search(query: $viewerQuery, type: ISSUE, first: $per_page) {
208+
totalCount: issueCount
201209
edges {
202210
node {
203211
...prWithReviews
204212
}
205213
}
206214
}
207215
reviewRequested: search(query: $reviewerQuery, type: ISSUE, first: $per_page) {
216+
totalCount: issueCount
208217
edges {
209218
node {
210219
...pr
@@ -260,9 +269,15 @@ func PullRequests(client *Client, ghRepo Repo, currentPRNumber int, currentPRHea
260269
}
261270

262271
payload := PullRequestsPayload{
263-
viewerCreated,
264-
reviewRequested,
265-
currentPR,
272+
ViewerCreated: PullRequestAndTotalCount{
273+
PullRequests: viewerCreated,
274+
TotalCount: resp.ViewerCreated.TotalCount,
275+
},
276+
ReviewRequested: PullRequestAndTotalCount{
277+
PullRequests: reviewRequested,
278+
TotalCount: resp.ReviewRequested.TotalCount,
279+
},
280+
CurrentPR: currentPR,
266281
}
267282

268283
return &payload, nil

command/issue.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,25 +172,25 @@ func issueStatus(cmd *cobra.Command, args []string) error {
172172
out := colorableOut(cmd)
173173

174174
printHeader(out, "Issues assigned to you")
175-
if len(issuePayload.Assigned) > 0 {
176-
printIssues(out, " ", issuePayload.Assigned...)
175+
if issuePayload.Assigned.TotalCount > 0 {
176+
printIssues(out, " ", issuePayload.Assigned.TotalCount, issuePayload.Assigned.Issues)
177177
} else {
178178
message := fmt.Sprintf(" There are no issues assigned to you")
179179
printMessage(out, message)
180180
}
181181
fmt.Fprintln(out)
182182

183183
printHeader(out, "Issues mentioning you")
184-
if len(issuePayload.Mentioned) > 0 {
185-
printIssues(out, " ", issuePayload.Mentioned...)
184+
if issuePayload.Mentioned.TotalCount > 0 {
185+
printIssues(out, " ", issuePayload.Mentioned.TotalCount, issuePayload.Mentioned.Issues)
186186
} else {
187187
printMessage(out, " There are no issues mentioning you")
188188
}
189189
fmt.Fprintln(out)
190190

191191
printHeader(out, "Issues opened by you")
192-
if len(issuePayload.Authored) > 0 {
193-
printIssues(out, " ", issuePayload.Authored...)
192+
if issuePayload.Authored.TotalCount > 0 {
193+
printIssues(out, " ", issuePayload.Authored.TotalCount, issuePayload.Authored.Issues)
194194
} else {
195195
printMessage(out, " There are no issues opened by you")
196196
}
@@ -318,7 +318,7 @@ func issueCreate(cmd *cobra.Command, args []string) error {
318318
return nil
319319
}
320320

321-
func printIssues(w io.Writer, prefix string, issues ...api.Issue) {
321+
func printIssues(w io.Writer, prefix string, totalCount int, issues []api.Issue) {
322322
for _, issue := range issues {
323323
number := utils.Green("#" + strconv.Itoa(issue.Number))
324324
coloredLabels := labelList(issue)
@@ -327,6 +327,10 @@ func printIssues(w io.Writer, prefix string, issues ...api.Issue) {
327327
}
328328
fmt.Fprintf(w, "%s%s %s%s\n", prefix, number, truncate(70, replaceExcessiveWhitespace(issue.Title)), coloredLabels)
329329
}
330+
remaining := totalCount - len(issues)
331+
if remaining > 0 {
332+
fmt.Fprintf(w, utils.Gray("%sAnd %d more\n"), prefix, remaining)
333+
}
330334
}
331335

332336
func labelList(issue api.Issue) string {

command/pr.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,24 +99,24 @@ func prStatus(cmd *cobra.Command, args []string) error {
9999

100100
printHeader(out, "Current branch")
101101
if prPayload.CurrentPR != nil {
102-
printPrs(out, *prPayload.CurrentPR)
102+
printPrs(out, 0, *prPayload.CurrentPR)
103103
} else {
104104
message := fmt.Sprintf(" There is no pull request associated with %s", utils.Cyan("["+currentPRHeadRef+"]"))
105105
printMessage(out, message)
106106
}
107107
fmt.Fprintln(out)
108108

109109
printHeader(out, "Created by you")
110-
if len(prPayload.ViewerCreated) > 0 {
111-
printPrs(out, prPayload.ViewerCreated...)
110+
if prPayload.ViewerCreated.TotalCount > 0 {
111+
printPrs(out, prPayload.ViewerCreated.TotalCount, prPayload.ViewerCreated.PullRequests...)
112112
} else {
113113
printMessage(out, " You have no open pull requests")
114114
}
115115
fmt.Fprintln(out)
116116

117117
printHeader(out, "Requesting a code review from you")
118-
if len(prPayload.ReviewRequested) > 0 {
119-
printPrs(out, prPayload.ReviewRequested...)
118+
if prPayload.ReviewRequested.TotalCount > 0 {
119+
printPrs(out, prPayload.ReviewRequested.TotalCount, prPayload.ReviewRequested.PullRequests...)
120120
} else {
121121
printMessage(out, " You have no pull requests to review")
122122
}
@@ -435,7 +435,7 @@ func prCheckout(cmd *cobra.Command, args []string) error {
435435
return nil
436436
}
437437

438-
func printPrs(w io.Writer, prs ...api.PullRequest) {
438+
func printPrs(w io.Writer, totalCount int, prs ...api.PullRequest) {
439439
for _, pr := range prs {
440440
prNumber := fmt.Sprintf("#%d", pr.Number)
441441
fmt.Fprintf(w, " %s %s %s", utils.Green(prNumber), truncate(50, replaceExcessiveWhitespace(pr.Title)), utils.Cyan("["+pr.HeadLabel()+"]"))
@@ -472,6 +472,10 @@ func printPrs(w io.Writer, prs ...api.PullRequest) {
472472

473473
fmt.Fprint(w, "\n")
474474
}
475+
remaining := totalCount - len(prs)
476+
if remaining > 0 {
477+
fmt.Fprintf(w, utils.Gray(" And %d more\n"), remaining)
478+
}
475479
}
476480

477481
func printHeader(w io.Writer, s string) {

test/fixtures/issueStatus.json

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,33 @@
33
"repository": {
44
"hasIssuesEnabled": true,
55
"assigned": {
6+
"totalCount": 2,
67
"nodes": [
78
{
8-
"number": 9,
9-
"title": "corey thinks squash tastes bad"
9+
"number": 9,
10+
"title": "corey thinks squash tastes bad"
1011
},
1112
{
12-
"number": 10,
13-
"title": "broccoli is a superfood"
13+
"number": 10,
14+
"title": "broccoli is a superfood"
1415
}
1516
]
1617
},
1718
"mentioned": {
19+
"totalCount": 2,
1820
"nodes": [
1921
{
20-
"number": 8,
21-
"title": "rabbits eat carrots"
22+
"number": 8,
23+
"title": "rabbits eat carrots"
2224
},
2325
{
24-
"number": 11,
25-
"title": "swiss chard is neutral"
26+
"number": 11,
27+
"title": "swiss chard is neutral"
2628
}
2729
]
2830
},
2931
"authored": {
32+
"totalCount": 0,
3033
"nodes": []
3134
}
3235
}

test/fixtures/prStatus.json

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,57 @@
1-
{"data":{
2-
"repository": {
3-
"pullRequests": {
1+
{
2+
"data": {
3+
"repository": {
4+
"pullRequests": {
5+
"totalCount": 1,
6+
"edges": [
7+
{
8+
"node": {
9+
"number": 10,
10+
"title": "Blueberries are a good fruit",
11+
"url": "https://github.com/github/gh-cli/pull/10",
12+
"headRefName": "blueberries",
13+
"headRepositoryOwner": {
14+
"login": "OWNER"
15+
},
16+
"isCrossRepository": false
17+
}
18+
}
19+
]
20+
}
21+
},
22+
"viewerCreated": {
23+
"totalCount": 1,
424
"edges": [
525
{
626
"node": {
7-
"number": 10,
8-
"title": "Blueberries are a good fruit",
9-
"url": "https://github.com/github/gh-cli/pull/10",
10-
"headRefName": "blueberries",
11-
"headRepositoryOwner": {
12-
"login": "OWNER"
13-
},
14-
"isCrossRepository": false
27+
"number": 8,
28+
"title": "Strawberries are not actually berries",
29+
"url": "https://github.com/github/gh-cli/pull/8",
30+
"headRefName": "strawberries"
1531
}
1632
}
1733
]
18-
}
19-
},
20-
"viewerCreated": {
21-
"edges": [
22-
{
23-
"node": {
24-
"number": 8,
25-
"title": "Strawberries are not actually berries",
26-
"url": "https://github.com/github/gh-cli/pull/8",
27-
"headRefName": "strawberries"
28-
}
29-
}
30-
]
31-
},
32-
"reviewRequested": {
33-
"edges": [
34-
{
35-
"node": {
36-
"number": 9,
37-
"title": "Apples are tasty",
38-
"url": "https://github.com/github/gh-cli/pull/9",
39-
"headRefName": "apples"
40-
}
41-
},
42-
{
43-
"node": {
44-
"number": 11,
45-
"title": "Figs are my favorite",
46-
"url": "https://github.com/github/gh-cli/pull/1",
47-
"headRefName": "figs"
34+
},
35+
"reviewRequested": {
36+
"totalCount": 2,
37+
"edges": [
38+
{
39+
"node": {
40+
"number": 9,
41+
"title": "Apples are tasty",
42+
"url": "https://github.com/github/gh-cli/pull/9",
43+
"headRefName": "apples"
44+
}
45+
},
46+
{
47+
"node": {
48+
"number": 11,
49+
"title": "Figs are my favorite",
50+
"url": "https://github.com/github/gh-cli/pull/1",
51+
"headRefName": "figs"
52+
}
4853
}
49-
}
50-
]
54+
]
55+
}
5156
}
52-
}}
57+
}

0 commit comments

Comments
 (0)