Skip to content

Commit

Permalink
Update go-gh to v2 (cli#7299)
Browse files Browse the repository at this point in the history
* Update go-gh

* Update code for go-gh v2
  • Loading branch information
samcoe authored Apr 16, 2023
1 parent c0855a3 commit dbc2f05
Show file tree
Hide file tree
Showing 23 changed files with 55 additions and 57 deletions.
27 changes: 13 additions & 14 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import (
"strings"

"github.com/cli/cli/v2/internal/ghinstance"
"github.com/cli/go-gh"
ghAPI "github.com/cli/go-gh/pkg/api"
ghAPI "github.com/cli/go-gh/v2/pkg/api"
)

const (
Expand Down Expand Up @@ -40,11 +39,11 @@ func (c *Client) HTTP() *http.Client {
}

type GraphQLError struct {
ghAPI.GQLError
*ghAPI.GraphQLError
}

type HTTPError struct {
ghAPI.HTTPError
*ghAPI.HTTPError
scopesSuggestion string
}

Expand All @@ -57,7 +56,7 @@ func (err HTTPError) ScopesSuggestion() string {
func (c Client) GraphQL(hostname string, query string, variables map[string]interface{}, data interface{}) error {
opts := clientOptions(hostname, c.http.Transport)
opts.Headers[graphqlFeatures] = features
gqlClient, err := gh.GQLClient(&opts)
gqlClient, err := ghAPI.NewGraphQLClient(opts)
if err != nil {
return err
}
Expand All @@ -69,7 +68,7 @@ func (c Client) GraphQL(hostname string, query string, variables map[string]inte
func (c Client) Mutate(hostname, name string, mutation interface{}, variables map[string]interface{}) error {
opts := clientOptions(hostname, c.http.Transport)
opts.Headers[graphqlFeatures] = features
gqlClient, err := gh.GQLClient(&opts)
gqlClient, err := ghAPI.NewGraphQLClient(opts)
if err != nil {
return err
}
Expand All @@ -81,7 +80,7 @@ func (c Client) Mutate(hostname, name string, mutation interface{}, variables ma
func (c Client) Query(hostname, name string, query interface{}, variables map[string]interface{}) error {
opts := clientOptions(hostname, c.http.Transport)
opts.Headers[graphqlFeatures] = features
gqlClient, err := gh.GQLClient(&opts)
gqlClient, err := ghAPI.NewGraphQLClient(opts)
if err != nil {
return err
}
Expand All @@ -93,7 +92,7 @@ func (c Client) Query(hostname, name string, query interface{}, variables map[st
func (c Client) QueryWithContext(ctx context.Context, hostname, name string, query interface{}, variables map[string]interface{}) error {
opts := clientOptions(hostname, c.http.Transport)
opts.Headers[graphqlFeatures] = features
gqlClient, err := gh.GQLClient(&opts)
gqlClient, err := ghAPI.NewGraphQLClient(opts)
if err != nil {
return err
}
Expand All @@ -103,7 +102,7 @@ func (c Client) QueryWithContext(ctx context.Context, hostname, name string, que
// REST performs a REST request and parses the response.
func (c Client) REST(hostname string, method string, p string, body io.Reader, data interface{}) error {
opts := clientOptions(hostname, c.http.Transport)
restClient, err := gh.RESTClient(&opts)
restClient, err := ghAPI.NewRESTClient(opts)
if err != nil {
return err
}
Expand All @@ -112,7 +111,7 @@ func (c Client) REST(hostname string, method string, p string, body io.Reader, d

func (c Client) RESTWithNext(hostname string, method string, p string, body io.Reader, data interface{}) (string, error) {
opts := clientOptions(hostname, c.http.Transport)
restClient, err := gh.RESTClient(&opts)
restClient, err := ghAPI.NewRESTClient(opts)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -157,14 +156,14 @@ func HandleHTTPError(resp *http.Response) error {
return handleResponse(ghAPI.HandleHTTPError(resp))
}

// handleResponse takes a ghAPI.HTTPError or ghAPI.GQLError and converts it into an
// handleResponse takes a ghAPI.HTTPError or ghAPI.GraphQLError and converts it into an
// HTTPError or GraphQLError respectively.
func handleResponse(err error) error {
if err == nil {
return nil
}

var restErr ghAPI.HTTPError
var restErr *ghAPI.HTTPError
if errors.As(err, &restErr) {
return HTTPError{
HTTPError: restErr,
Expand All @@ -175,10 +174,10 @@ func handleResponse(err error) error {
}
}

var gqlErr ghAPI.GQLError
var gqlErr *ghAPI.GraphQLError
if errors.As(err, &gqlErr) {
return GraphQLError{
GQLError: gqlErr,
GraphQLError: gqlErr,
}
}

Expand Down
5 changes: 2 additions & 3 deletions api/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import (

"github.com/cli/cli/v2/internal/ghinstance"
"github.com/cli/cli/v2/utils"
"github.com/cli/go-gh"
ghAPI "github.com/cli/go-gh/pkg/api"
ghAPI "github.com/cli/go-gh/v2/pkg/api"
)

type tokenGetter interface {
Expand Down Expand Up @@ -55,7 +54,7 @@ func NewHTTPClient(opts HTTPClientOptions) (*http.Client, error) {
clientOpts.CacheTTL = opts.CacheTTL
}

client, err := gh.HTTPClient(&clientOpts)
client, err := ghAPI.NewHTTPClient(clientOpts)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion api/queries_projects_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func CurrentUserProjectsV2(client *Client, hostname string) ([]ProjectV2, error)
// When querying ProjectsV2 fields we generally dont want to show the user
// scope errors and field does not exist errors. ProjectsV2IgnorableError
// checks against known error strings to see if an error can be safely ignored.
// Due to the fact that the GQLClient can return multiple types of errors
// Due to the fact that the GraphQLClient can return multiple types of errors
// this uses brittle string comparison to check against the known error strings.
func ProjectsV2IgnorableError(err error) bool {
msg := err.Error()
Expand Down
10 changes: 5 additions & 5 deletions api/queries_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"golang.org/x/sync/errgroup"

"github.com/cli/cli/v2/internal/ghrepo"
ghAPI "github.com/cli/go-gh/pkg/api"
ghAPI "github.com/cli/go-gh/v2/pkg/api"
"github.com/shurcooL/githubv4"
)

Expand Down Expand Up @@ -263,8 +263,8 @@ func FetchRepository(client *Client, repo ghrepo.Interface, fields []string) (*R
// guaranteed to happen when an authentication token with insufficient permissions is being used.
if result.Repository == nil {
return nil, GraphQLError{
GQLError: ghAPI.GQLError{
Errors: []ghAPI.GQLErrorItem{{
GraphQLError: &ghAPI.GraphQLError{
Errors: []ghAPI.GraphQLErrorItem{{
Type: "NOT_FOUND",
Message: fmt.Sprintf("Could not resolve to a Repository with the name '%s/%s'.", repo.RepoOwner(), repo.RepoName()),
}},
Expand Down Expand Up @@ -316,8 +316,8 @@ func GitHubRepo(client *Client, repo ghrepo.Interface) (*Repository, error) {
// guaranteed to happen when an authentication token with insufficient permissions is being used.
if result.Repository == nil {
return nil, GraphQLError{
GQLError: ghAPI.GQLError{
Errors: []ghAPI.GQLErrorItem{{
GraphQLError: &ghAPI.GraphQLError{
Errors: []ghAPI.GraphQLErrorItem{{
Type: "NOT_FOUND",
Message: fmt.Sprintf("Could not resolve to a Repository with the name '%s/%s'.", repo.RepoOwner(), repo.RepoName()),
}},
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/cenkalti/backoff/v4 v4.2.0
github.com/charmbracelet/glamour v0.5.1-0.20220727184942-e70ff2d969da
github.com/charmbracelet/lipgloss v0.5.0
github.com/cli/go-gh v1.2.1
github.com/cli/go-gh/v2 v2.0.0
github.com/cli/oauth v1.0.1
github.com/cli/safeexec v1.0.1
github.com/cpuguy83/go-md2man/v2 v2.0.2
Expand Down Expand Up @@ -50,7 +50,7 @@ require (
github.com/alessio/shellescape v1.4.1 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/cli/browser v1.1.0 // indirect
github.com/cli/shurcooL-graphql v0.0.2 // indirect
github.com/cli/shurcooL-graphql v0.0.3 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dlclark/regexp2 v1.4.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ github.com/cli/browser v1.1.0 h1:xOZBfkfY9L9vMBgqb1YwRirGu6QFaQ5dP/vXt5ENSOY=
github.com/cli/browser v1.1.0/go.mod h1:HKMQAt9t12kov91Mn7RfZxyJQQgWgyS/3SZswlZ5iTI=
github.com/cli/crypto v0.0.0-20210929142629-6be313f59b03 h1:3f4uHLfWx4/WlnMPXGai03eoWAI+oGHJwr+5OXfxCr8=
github.com/cli/crypto v0.0.0-20210929142629-6be313f59b03/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
github.com/cli/go-gh v1.2.1 h1:xFrjejSsgPiwXFP6VYynKWwxLQcNJy3Twbu82ZDlR/o=
github.com/cli/go-gh v1.2.1/go.mod h1:Jxk8X+TCO4Ui/GarwY9tByWm/8zp4jJktzVZNlTW5VM=
github.com/cli/go-gh/v2 v2.0.0 h1:JAgQY7VNHletsO0Eqr+/PzF7fF5QEjhY2t2+Tev3vmk=
github.com/cli/go-gh/v2 v2.0.0/go.mod h1:2/ox3Dnc8wDBT5bnTAH1aKGy6Qt1ztlFBe10EufnvoA=
github.com/cli/oauth v1.0.1 h1:pXnTFl/qUegXHK531Dv0LNjW4mLx626eS42gnzfXJPA=
github.com/cli/oauth v1.0.1/go.mod h1:qd/FX8ZBD6n1sVNQO3aIdRxeu5LGw9WhKnYhIIoC2A4=
github.com/cli/safeexec v1.0.0/go.mod h1:Z/D4tTN8Vs5gXYHDCbaM1S/anmEDnJb1iW0+EJ5zx3Q=
github.com/cli/safeexec v1.0.1 h1:e/C79PbXF4yYTN/wauC4tviMxEV13BwljGj0N9j+N00=
github.com/cli/safeexec v1.0.1/go.mod h1:Z/D4tTN8Vs5gXYHDCbaM1S/anmEDnJb1iW0+EJ5zx3Q=
github.com/cli/shurcooL-graphql v0.0.2 h1:rwP5/qQQ2fM0TzkUTwtt6E2LbIYf6R+39cUXTa04NYk=
github.com/cli/shurcooL-graphql v0.0.2/go.mod h1:tlrLmw/n5Q/+4qSvosT+9/W5zc8ZMjnJeYBxSdb4nWA=
github.com/cli/shurcooL-graphql v0.0.3 h1:CtpPxyGDs136/+ZeyAfUKYmcQBjDlq5aqnrDCW5Ghh8=
github.com/cli/shurcooL-graphql v0.0.3/go.mod h1:tlrLmw/n5Q/+4qSvosT+9/W5zc8ZMjnJeYBxSdb4nWA=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
Expand Down
4 changes: 2 additions & 2 deletions internal/browser/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package browser
import (
"io"

ghBrowser "github.com/cli/go-gh/pkg/browser"
ghBrowser "github.com/cli/go-gh/v2/pkg/browser"
)

type Browser interface {
Expand All @@ -12,5 +12,5 @@ type Browser interface {

func New(launcher string, stdout, stderr io.Writer) Browser {
b := ghBrowser.New(launcher, stdout, stderr)
return &b
return b
}
4 changes: 2 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"os"
"path/filepath"

ghAuth "github.com/cli/go-gh/pkg/auth"
ghConfig "github.com/cli/go-gh/pkg/config"
ghAuth "github.com/cli/go-gh/v2/pkg/auth"
ghConfig "github.com/cli/go-gh/v2/pkg/config"
"github.com/zalando/go-keyring"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/config/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"path/filepath"
"testing"

ghConfig "github.com/cli/go-gh/pkg/config"
ghConfig "github.com/cli/go-gh/v2/pkg/config"
)

func NewBlankConfig() *ConfigMock {
Expand Down
6 changes: 3 additions & 3 deletions internal/ghrepo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"strings"

"github.com/cli/cli/v2/internal/ghinstance"
ghAuth "github.com/cli/go-gh/pkg/auth"
"github.com/cli/go-gh/pkg/repository"
ghAuth "github.com/cli/go-gh/v2/pkg/auth"
"github.com/cli/go-gh/v2/pkg/repository"
)

// Interface describes an object that represents a GitHub repository
Expand Down Expand Up @@ -54,7 +54,7 @@ func FromFullNameWithHost(nwo, fallbackHost string) (Interface, error) {
if err != nil {
return nil, err
}
return NewWithHost(repo.Owner(), repo.Name(), repo.Host()), nil
return NewWithHost(repo.Owner, repo.Name, repo.Host), nil
}

// FromURL extracts the GitHub repository information from a git remote URL
Expand Down
2 changes: 1 addition & 1 deletion internal/tableprinter/table_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/cli/cli/v2/internal/text"
"github.com/cli/cli/v2/pkg/iostreams"
"github.com/cli/go-gh/pkg/tableprinter"
"github.com/cli/go-gh/v2/pkg/tableprinter"
)

type TablePrinter struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/text/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"time"

"github.com/cli/go-gh/pkg/text"
"github.com/cli/go-gh/v2/pkg/text"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"github.com/cli/cli/v2/pkg/cmdutil"
"github.com/cli/cli/v2/pkg/iostreams"
"github.com/cli/cli/v2/pkg/jsoncolor"
"github.com/cli/go-gh/pkg/jq"
"github.com/cli/go-gh/pkg/template"
"github.com/cli/go-gh/v2/pkg/jq"
"github.com/cli/go-gh/v2/pkg/template"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -328,7 +328,7 @@ func apiRun(opts *ApiOptions) error {
return err
}

endCursor, err := processResponse(resp, opts, bodyWriter, headersWriter, &tmpl)
endCursor, err := processResponse(resp, opts, bodyWriter, headersWriter, tmpl)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/cli/cli/v2/internal/ghrepo"
"github.com/cli/cli/v2/pkg/cmdutil"
"github.com/cli/cli/v2/pkg/iostreams"
"github.com/cli/go-gh/pkg/template"
"github.com/cli/go-gh/v2/pkg/template"
"github.com/google/shlex"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -1206,7 +1206,7 @@ func Test_processResponse_template(t *testing.T) {
tmpl := template.New(ios.Out, ios.TerminalWidth(), ios.ColorEnabled())
err := tmpl.Parse(opts.Template)
require.NoError(t, err)
_, err = processResponse(&resp, &opts, ios.Out, io.Discard, &tmpl)
_, err = processResponse(&resp, &opts, ios.Out, io.Discard, tmpl)
require.NoError(t, err)
err = tmpl.Flush()
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/auth/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/cli/cli/v2/pkg/cmd/auth/shared"
"github.com/cli/cli/v2/pkg/cmdutil"
"github.com/cli/cli/v2/pkg/iostreams"
ghAuth "github.com/cli/go-gh/pkg/auth"
ghAuth "github.com/cli/go-gh/v2/pkg/auth"
"github.com/spf13/cobra"
)

Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/extension/ext_tmpls/goBinMain.go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package main
import (
"fmt"

"github.com/cli/go-gh"
"github.com/cli/go-gh/v2/pkg/api"
)

func main() {
fmt.Println("hi world, this is the %s extension!")
client, err := gh.RESTClient(nil)
client, err := api.DefaultRESTClient()
if err != nil {
fmt.Println(err)
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/factory/remote_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/cli/cli/v2/internal/config"
"github.com/cli/cli/v2/internal/ghinstance"
"github.com/cli/cli/v2/pkg/set"
"github.com/cli/go-gh/pkg/ssh"
"github.com/cli/go-gh/v2/pkg/ssh"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/repo/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/cli/cli/v2/internal/ghrepo"
"github.com/cli/cli/v2/pkg/cmdutil"
"github.com/cli/cli/v2/pkg/iostreams"
ghAuth "github.com/cli/go-gh/pkg/auth"
ghAuth "github.com/cli/go-gh/v2/pkg/auth"
"github.com/spf13/cobra"
)

Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/cli/cli/v2/pkg/iostreams"
"github.com/cli/cli/v2/pkg/set"
"github.com/cli/cli/v2/utils"
ghAPI "github.com/cli/go-gh/pkg/api"
ghAPI "github.com/cli/go-gh/v2/pkg/api"
"github.com/spf13/cobra"
"golang.org/x/sync/errgroup"
)
Expand Down Expand Up @@ -429,7 +429,7 @@ func (s *StatusGetter) LoadSearchResults() error {
if err != nil {
var gqlErrResponse api.GraphQLError
if errors.As(err, &gqlErrResponse) {
gqlErrors := make([]ghAPI.GQLErrorItem, 0, len(gqlErrResponse.Errors))
gqlErrors := make([]ghAPI.GraphQLErrorItem, 0, len(gqlErrResponse.Errors))
// Exclude any FORBIDDEN errors and show status for what we can.
for _, gqlErr := range gqlErrResponse.Errors {
if gqlErr.Type == "FORBIDDEN" {
Expand All @@ -442,7 +442,7 @@ func (s *StatusGetter) LoadSearchResults() error {
err = nil
} else {
err = api.GraphQLError{
GQLError: ghAPI.GQLError{
GraphQLError: &ghAPI.GraphQLError{
Errors: gqlErrors,
},
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmdutil/json_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/cli/cli/v2/pkg/iostreams"
"github.com/cli/cli/v2/pkg/jsoncolor"
"github.com/cli/cli/v2/pkg/set"
"github.com/cli/go-gh/pkg/jq"
"github.com/cli/go-gh/pkg/template"
"github.com/cli/go-gh/v2/pkg/jq"
"github.com/cli/go-gh/v2/pkg/template"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
Expand Down
Loading

0 comments on commit dbc2f05

Please sign in to comment.