diff --git a/graphql/client.go b/api/client.go similarity index 96% rename from graphql/client.go rename to api/client.go index 71ee8ce13..ec5f0dbcd 100644 --- a/graphql/client.go +++ b/api/client.go @@ -1,4 +1,4 @@ -package graphql +package api import ( "bytes" @@ -54,7 +54,7 @@ func graphQL(query string, variables map[string]string, v interface{}) error { if err != nil { panic(err) } - debugRequest(req, reqBody) + debugRequest(req, string(reqBody)) req.Header.Set("Authorization", "token "+getToken()) req.Header.Set("Content-Type", "application/json; charset=utf-8") @@ -135,7 +135,7 @@ func debugRequest(req *http.Request, body string) { return } - fmt.Printf("DEBUG: GraphQL query to %s:\n %s\n\n", req.URL, body) + fmt.Printf("DEBUG: GraphQL request to %s:\n %s\n\n", req.URL, body) } func debugResponse(resp *http.Response, body string) { diff --git a/graphql/queries.go b/api/queries.go similarity index 89% rename from graphql/queries.go rename to api/queries.go index a885e5c5a..928b40585 100644 --- a/graphql/queries.go +++ b/api/queries.go @@ -1,4 +1,4 @@ -package graphql +package api import ( "fmt" @@ -23,7 +23,9 @@ type PullRequest struct { func PullRequests() (PullRequestsPayload, error) { type edges struct { - Edges []PullRequest + Edges []struct { + Node PullRequest + } PageInfo struct { HasNextPage bool EndCursor string @@ -43,6 +45,7 @@ func PullRequests() (PullRequestsPayload, error) { number title url + headRefName } query($owner: String!, $repo: String!, $headRefName: String!, $viewerQuery: String!, $reviewerQuery: String!, $per_page: Int = 10) { @@ -101,18 +104,18 @@ func PullRequests() (PullRequestsPayload, error) { } var viewerCreated []PullRequest - for _, pr := range resp.ViewerCreated.Edges { - viewerCreated = append(viewerCreated, pr) + for _, edge := range resp.ViewerCreated.Edges { + viewerCreated = append(viewerCreated, edge.Node) } var reviewRequested []PullRequest - for _, pr := range resp.ReviewRequested.Edges { - reviewRequested = append(reviewRequested, pr) + for _, edge := range resp.ReviewRequested.Edges { + reviewRequested = append(reviewRequested, edge.Node) } var currentPR *PullRequest - for _, pr := range resp.Repository.PullRequests.Edges { - currentPR = &pr + for _, edge := range resp.Repository.PullRequests.Edges { + currentPR = &edge.Node } payload := PullRequestsPayload{ diff --git a/command/pr.go b/command/pr.go index 67cc58468..9522b2a75 100644 --- a/command/pr.go +++ b/command/pr.go @@ -3,6 +3,7 @@ package command import ( "fmt" + "github.com/github/gh-cli/api" "github.com/github/gh-cli/graphql" "github.com/spf13/cobra" @@ -38,20 +39,20 @@ func ExecutePr() { panic(err) } + fmt.Printf("Current Pr\n") if prPayload.CurrentPR != nil { - fmt.Printf("Current Pr\n") printPr(*prPayload.CurrentPR) } + fmt.Printf("Your Prs\n") for _, pr := range prPayload.ViewerCreated { - fmt.Printf("Your Prs\n") printPr(pr) } + fmt.Printf("Prs you need to review\n") for _, pr := range prPayload.ReviewRequested { - fmt.Printf("Prs you need to review\n") printPr(pr) } } -func printPr(pr graphql.PullRequest) { - fmt.Printf("%d %s [%s]\n", pr.Number, pr.Title, pr.HeadRefName) +func printPr(pr api.PullRequest) { + fmt.Printf(" #%d %s [%s]\n", pr.Number, pr.Title, pr.HeadRefName) }