Skip to content

Commit 4fcf13d

Browse files
committed
Make it work with PRs
1 parent 30abea1 commit 4fcf13d

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

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/pr.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ func prStatus(cmd *cobra.Command, args []string) error {
9797

9898
out := colorableOut(cmd)
9999

100+
fmt.Printf("🌭 %+v\n", prPayload)
101+
100102
printHeader(out, "Current branch")
101103
if prPayload.CurrentPR != nil {
102104
printPrs(out, *prPayload.CurrentPR)
@@ -107,16 +109,16 @@ func prStatus(cmd *cobra.Command, args []string) error {
107109
fmt.Fprintln(out)
108110

109111
printHeader(out, "Created by you")
110-
if len(prPayload.ViewerCreated) > 0 {
111-
printPrs(out, prPayload.ViewerCreated...)
112+
if prPayload.ViewerCreated.TotalCount > 0 {
113+
printPrs(out, prPayload.ViewerCreated.PullRequests...)
112114
} else {
113115
printMessage(out, " You have no open pull requests")
114116
}
115117
fmt.Fprintln(out)
116118

117119
printHeader(out, "Requesting a code review from you")
118-
if len(prPayload.ReviewRequested) > 0 {
119-
printPrs(out, prPayload.ReviewRequested...)
120+
if prPayload.ReviewRequested.TotalCount > 0 {
121+
printPrs(out, prPayload.ReviewRequested.PullRequests...)
120122
} else {
121123
printMessage(out, " You have no pull requests to review")
122124
}

0 commit comments

Comments
 (0)