Rename package to api
This commit is contained in:
parent
bcf3eb75c8
commit
8b69ca3919
3 changed files with 20 additions and 16 deletions
|
|
@ -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) {
|
||||
|
|
@ -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{
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue