Skip to content

Commit

Permalink
Address code review comments from @zzak
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomorain committed Jun 18, 2018
1 parent 06c8db4 commit 1d9506a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
6 changes: 3 additions & 3 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ func NewClient(endpoint string, logger *logger.Logger) *graphql.Client {

}

// NewAuthorizedRequest returns a ne GraphQL request with the
// newAuthorizedRequest returns a new GraphQL request with the
// authorization headers set for CircleCI auth.
func NewAuthorizedRequest(token, query string) *graphql.Request {
func newAuthorizedRequest(token, query string) *graphql.Request {
req := graphql.NewRequest(query)
req.Header.Set("Authorization", token)
return req
Expand All @@ -34,7 +34,7 @@ func NewAuthorizedRequest(token, query string) *graphql.Request {
// Then it will execute the given query using graphql.Client.Run.
// This function will return the unmarshalled response as JSON.
func Run(client *graphql.Client, token, query string) (map[string]interface{}, error) {
req := NewAuthorizedRequest(token, query)
req := newAuthorizedRequest(token, query)
ctx := context.Background()
var resp map[string]interface{}
err := client.Run(ctx, req, &resp)
Expand Down
2 changes: 1 addition & 1 deletion cmd/diagnostic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ token:
Expect(err).ShouldNot(HaveOccurred())
Eventually(session.Err).Should(gbytes.Say("Error: please set a token"))
Eventually(session.Out).Should(gbytes.Say("GraphQL API endpoint: https://example.com/graphql"))
Eventually(session).Should(gexec.Exit(1))
Eventually(session).Should(gexec.Exit(255))
})
})
})
Expand Down
11 changes: 7 additions & 4 deletions cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,31 @@ import (
"os"

"github.com/circleci/circleci-cli/client"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var queryCmd = &cobra.Command{
Use: "query",
Short: "Query the CircleCI GraphQL API.",
Run: query,
RunE: query,
}

func query(cmd *cobra.Command, args []string) {
func query(cmd *cobra.Command, args []string) error {
c := client.NewClient(viper.GetString("endpoint"), Logger)

query, err := ioutil.ReadAll(os.Stdin)
if err != nil {
Logger.FatalOnError("Unable to read query", err)
return errors.Wrap(err, "Unable to read query from stdin")
}

resp, err := client.Run(c, viper.GetString("token"), string(query))
if err != nil {
Logger.FatalOnError("Error occurred when running query", err)
return errors.Wrap(err, "Error occurred when running query")
}

Logger.Prettyify(resp)

return nil
}

0 comments on commit 1d9506a

Please sign in to comment.