Make it work with PRs

This commit is contained in:
Corey Johnson 2020-01-08 11:44:27 -08:00
parent 30abea1813
commit 4fcf13dac4
2 changed files with 27 additions and 10 deletions

View file

@ -6,11 +6,16 @@ import (
)
type PullRequestsPayload struct {
ViewerCreated []PullRequest
ReviewRequested []PullRequest
ViewerCreated PullRequestAndTotalCount
ReviewRequested PullRequestAndTotalCount
CurrentPR *PullRequest
}
type PullRequestAndTotalCount struct {
TotalCount int
PullRequests []PullRequest
}
type PullRequest struct {
Number int
Title string
@ -123,7 +128,8 @@ type Repo interface {
func PullRequests(client *Client, ghRepo Repo, currentPRNumber int, currentPRHeadRef, currentUsername string) (*PullRequestsPayload, error) {
type edges struct {
Edges []struct {
TotalCount int
Edges []struct {
Node PullRequest
}
}
@ -177,6 +183,7 @@ func PullRequests(client *Client, ghRepo Repo, currentPRNumber int, currentPRHea
query($owner: String!, $repo: String!, $headRefName: String!, $viewerQuery: String!, $reviewerQuery: String!, $per_page: Int = 10) {
repository(owner: $owner, name: $repo) {
pullRequests(headRefName: $headRefName, states: OPEN, first: $per_page) {
totalCount
edges {
node {
...prWithReviews
@ -198,6 +205,7 @@ func PullRequests(client *Client, ghRepo Repo, currentPRNumber int, currentPRHea
query := fragments + queryPrefix + `
viewerCreated: search(query: $viewerQuery, type: ISSUE, first: $per_page) {
totalCount: issueCount
edges {
node {
...prWithReviews
@ -205,6 +213,7 @@ func PullRequests(client *Client, ghRepo Repo, currentPRNumber int, currentPRHea
}
}
reviewRequested: search(query: $reviewerQuery, type: ISSUE, first: $per_page) {
totalCount: issueCount
edges {
node {
...pr
@ -260,9 +269,15 @@ func PullRequests(client *Client, ghRepo Repo, currentPRNumber int, currentPRHea
}
payload := PullRequestsPayload{
viewerCreated,
reviewRequested,
currentPR,
ViewerCreated: PullRequestAndTotalCount{
PullRequests: viewerCreated,
TotalCount: resp.ViewerCreated.TotalCount,
},
ReviewRequested: PullRequestAndTotalCount{
PullRequests: reviewRequested,
TotalCount: resp.ReviewRequested.TotalCount,
},
CurrentPR: currentPR,
}
return &payload, nil

View file

@ -97,6 +97,8 @@ func prStatus(cmd *cobra.Command, args []string) error {
out := colorableOut(cmd)
fmt.Printf("🌭 %+v\n", prPayload)
printHeader(out, "Current branch")
if prPayload.CurrentPR != nil {
printPrs(out, *prPayload.CurrentPR)
@ -107,16 +109,16 @@ func prStatus(cmd *cobra.Command, args []string) error {
fmt.Fprintln(out)
printHeader(out, "Created by you")
if len(prPayload.ViewerCreated) > 0 {
printPrs(out, prPayload.ViewerCreated...)
if prPayload.ViewerCreated.TotalCount > 0 {
printPrs(out, prPayload.ViewerCreated.PullRequests...)
} else {
printMessage(out, " You have no open pull requests")
}
fmt.Fprintln(out)
printHeader(out, "Requesting a code review from you")
if len(prPayload.ReviewRequested) > 0 {
printPrs(out, prPayload.ReviewRequested...)
if prPayload.ReviewRequested.TotalCount > 0 {
printPrs(out, prPayload.ReviewRequested.PullRequests...)
} else {
printMessage(out, " You have no pull requests to review")
}