Merge branch 'master' into test
This commit is contained in:
commit
bb2876cf37
5 changed files with 63 additions and 64 deletions
|
|
@ -45,7 +45,7 @@ if err != nil {
|
|||
|
||||
fmt.Printf("%+v\n", resp)
|
||||
*/
|
||||
var GraphQL = func(query string, variables map[string]string, v interface{}) error {
|
||||
var GraphQL = func(query string, variables map[string]string, data interface{}) error {
|
||||
url := "https://api.github.com/graphql"
|
||||
reqBody, err := json.Marshal(map[string]interface{}{"query": query, "variables": variables})
|
||||
if err != nil {
|
||||
|
|
@ -81,29 +81,31 @@ var GraphQL = func(query string, variables map[string]string, v interface{}) err
|
|||
}
|
||||
|
||||
debugResponse(resp, string(body))
|
||||
return handleResponse(resp, body, v)
|
||||
return handleResponse(resp, body, data)
|
||||
}
|
||||
|
||||
func handleResponse(resp *http.Response, body []byte, v interface{}) error {
|
||||
func handleResponse(resp *http.Response, body []byte, data interface{}) error {
|
||||
success := resp.StatusCode >= 200 && resp.StatusCode < 300
|
||||
|
||||
if success {
|
||||
gr := &graphQLResponse{Data: v}
|
||||
err := json.Unmarshal(body, &gr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(gr.Errors) > 0 {
|
||||
errorMessages := gr.Errors[0].Message
|
||||
for _, e := range gr.Errors[1:] {
|
||||
errorMessages += ", " + e.Message
|
||||
}
|
||||
return fmt.Errorf("graphql error: '%s'", errorMessages)
|
||||
}
|
||||
return nil
|
||||
if !success {
|
||||
return handleHTTPError(resp, body)
|
||||
}
|
||||
|
||||
return handleHTTPError(resp, body)
|
||||
gr := &graphQLResponse{Data: data}
|
||||
err := json.Unmarshal(body, &gr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(gr.Errors) > 0 {
|
||||
errorMessages := gr.Errors[0].Message
|
||||
for _, e := range gr.Errors[1:] {
|
||||
errorMessages += ", " + e.Message
|
||||
}
|
||||
return fmt.Errorf("graphql error: '%s'", errorMessages)
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func handleHTTPError(resp *http.Response, body []byte) error {
|
||||
|
|
|
|||
|
|
@ -41,45 +41,45 @@ func PullRequests() (PullRequestsPayload, error) {
|
|||
}
|
||||
|
||||
query := `
|
||||
fragment pr on PullRequest {
|
||||
number
|
||||
title
|
||||
url
|
||||
headRefName
|
||||
}
|
||||
fragment pr on PullRequest {
|
||||
number
|
||||
title
|
||||
url
|
||||
headRefName
|
||||
}
|
||||
|
||||
query($owner: String!, $repo: String!, $headRefName: String!, $viewerQuery: String!, $reviewerQuery: String!, $per_page: Int = 10) {
|
||||
repository(owner: $owner, name: $repo) {
|
||||
pullRequests(headRefName: $headRefName, first: 1) {
|
||||
edges {
|
||||
node {
|
||||
...pr
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
viewerCreated: search(query: $viewerQuery, type: ISSUE, first: $per_page) {
|
||||
edges {
|
||||
node {
|
||||
...pr
|
||||
}
|
||||
}
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
}
|
||||
}
|
||||
reviewRequested: search(query: $reviewerQuery, type: ISSUE, first: $per_page) {
|
||||
edges {
|
||||
node {
|
||||
...pr
|
||||
}
|
||||
}
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
query($owner: String!, $repo: String!, $headRefName: String!, $viewerQuery: String!, $reviewerQuery: String!, $per_page: Int = 10) {
|
||||
repository(owner: $owner, name: $repo) {
|
||||
pullRequests(headRefName: $headRefName, first: 1) {
|
||||
edges {
|
||||
node {
|
||||
...pr
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
viewerCreated: search(query: $viewerQuery, type: ISSUE, first: $per_page) {
|
||||
edges {
|
||||
node {
|
||||
...pr
|
||||
}
|
||||
}
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
}
|
||||
}
|
||||
reviewRequested: search(query: $reviewerQuery, type: ISSUE, first: $per_page) {
|
||||
edges {
|
||||
node {
|
||||
...pr
|
||||
}
|
||||
}
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
project := project()
|
||||
owner := project.Owner
|
||||
|
|
|
|||
|
|
@ -26,11 +26,8 @@ work with pull requests.`,
|
|||
var prListCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List pull requests",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
err := ExecutePr()
|
||||
if err != nil {
|
||||
panic(err) // In the future this should handle the error better, but for now panic seems like a valid reaction
|
||||
}
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return ExecutePr()
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,10 +17,10 @@ import (
|
|||
|
||||
const (
|
||||
GitHubHost string = "github.com"
|
||||
OAuthAppURL string = "https://hub.github.com/"
|
||||
OAuthAppURL string = "https://github.com/github/gh-cli"
|
||||
)
|
||||
|
||||
var UserAgent = "Hub " + version.Version
|
||||
var userAgent = "GitHub CLI " + version.Version
|
||||
|
||||
func NewClient(h string) *Client {
|
||||
return NewClientWithHost(&Host{Host: h})
|
||||
|
|
|
|||
|
|
@ -221,7 +221,7 @@ func (c *simpleClient) performRequestUrl(method string, url *url.URL, body io.Re
|
|||
if c.PrepareRequest != nil {
|
||||
c.PrepareRequest(req)
|
||||
}
|
||||
req.Header.Set("User-Agent", UserAgent)
|
||||
req.Header.Set("User-Agent", userAgent)
|
||||
req.Header.Set("Accept", apiPayloadVersion)
|
||||
|
||||
if configure != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue