From a6596762701e0b1299675d9071c8b8f06af8d523 Mon Sep 17 00:00:00 2001 From: vilmibm Date: Fri, 22 Jul 2022 11:53:05 -0500 Subject: [PATCH 1/4] ext alias --- pkg/cmd/extension/command.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cmd/extension/command.go b/pkg/cmd/extension/command.go index cefda803b..a79b99ad1 100644 --- a/pkg/cmd/extension/command.go +++ b/pkg/cmd/extension/command.go @@ -36,7 +36,7 @@ func NewCmdExtension(f *cmdutil.Factory) *cobra.Command { See the list of available extensions at . `, "`"), - Aliases: []string{"extensions"}, + Aliases: []string{"extensions", "ext"}, } extCmd.AddCommand( From f34fc61a9a579c6a6fc634838361e073dbe9ee54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 25 Jul 2022 13:10:44 +0200 Subject: [PATCH 2/4] api: avoid HTML-escaping JSON output json.Marshal does HTML-escaping by default, which is what we don't want since we're printing to the terminal instead of embedding this JSON into a HTML document. --- pkg/jsoncolor/jsoncolor.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pkg/jsoncolor/jsoncolor.go b/pkg/jsoncolor/jsoncolor.go index d7c808a14..dbe3d9a4b 100644 --- a/pkg/jsoncolor/jsoncolor.go +++ b/pkg/jsoncolor/jsoncolor.go @@ -1,6 +1,7 @@ package jsoncolor import ( + "bytes" "encoding/json" "fmt" "io" @@ -49,7 +50,7 @@ func Write(w io.Writer, r io.Reader, indent string) error { fmt.Fprintf(w, "\x1b[%sm%s\x1b[m", colorDelim, tt) } default: - b, err := json.Marshal(tt) + b, err := marshalJSON(tt) if err != nil { return err } @@ -94,3 +95,19 @@ func Write(w io.Writer, r io.Reader, indent string) error { return nil } + +// marshalJSON works like json.Marshal but with HTML-escaping disabled +func marshalJSON(v interface{}) ([]byte, error) { + buf := bytes.Buffer{} + enc := json.NewEncoder(&buf) + enc.SetEscapeHTML(false) + if err := enc.Encode(v); err != nil { + return nil, err + } + bb := buf.Bytes() + // omit trailing newline added by json.Encoder + if len(bb) > 0 && bb[len(bb)-1] == '\n' { + return bb[:len(bb)-1], nil + } + return bb, nil +} From e7029616cb95058d240022b64979ba1e31466dee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 25 Jul 2022 20:17:32 +0200 Subject: [PATCH 3/4] Fix parsing base repo out of outdated git remotes If any of the repositories named by git remotes could not be found via API lookup, a "could not resolve to a Repository" error would be thrown, but the goal of the base repo logic was to ignore NOT_FOUND errors. --- api/queries_repo.go | 5 +++-- pkg/cmd/status/status.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/api/queries_repo.go b/api/queries_repo.go index d63888cef..1b0f00ade 100644 --- a/api/queries_repo.go +++ b/api/queries_repo.go @@ -3,6 +3,7 @@ package api import ( "bytes" "encoding/json" + "errors" "fmt" "io" "net/http" @@ -422,8 +423,8 @@ func RepoNetwork(client *Client, repos []ghrepo.Interface) (RepoNetworkResult, e %s } `, strings.Join(queries, "")), nil, &graphqlResult) - graphqlError, isGraphQLError := err.(*GraphQLError) - if isGraphQLError { + var graphqlError GraphQLError + if errors.As(err, &graphqlError) { // If the only errors are that certain repositories are not found, // continue processing this response instead of returning an error tolerated := true diff --git a/pkg/cmd/status/status.go b/pkg/cmd/status/status.go index 7a19d07dd..69a53686e 100644 --- a/pkg/cmd/status/status.go +++ b/pkg/cmd/status/status.go @@ -441,7 +441,7 @@ func (s *StatusGetter) LoadSearchResults() error { if len(gqlErrors) == 0 { err = nil } else { - err = &api.GraphQLError{ + err = api.GraphQLError{ GQLError: ghAPI.GQLError{ Errors: gqlErrors, }, From 2cdb9d34d43031de5511633d3637e45ae06dd5eb Mon Sep 17 00:00:00 2001 From: Sam Coe Date: Tue, 26 Jul 2022 07:15:50 +0200 Subject: [PATCH 4/4] Use SkipDefaultHeaders option (#5996) --- api/client.go | 12 +++--------- go.mod | 3 ++- go.sum | 7 +++++-- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/api/client.go b/api/client.go index 54c25c0ff..6c24e54ee 100644 --- a/api/client.go +++ b/api/client.go @@ -18,10 +18,8 @@ const ( accept = "Accept" authorization = "Authorization" cacheTTL = "X-GH-CACHE-TTL" - contentType = "Content-Type" graphqlFeatures = "GraphQL-Features" mergeQueue = "merge_queue" - timeZone = "Time-Zone" userAgent = "User-Agent" ) @@ -249,16 +247,12 @@ func clientOptions(hostname string, transport http.RoundTripper) ghAPI.ClientOpt // so let go-gh know that it does not need to resolve them. opts := ghAPI.ClientOptions{ AuthToken: "none", - // Blank values for Accept, Authorization, Content-Type, Time-Zone, and User-Agent headers. Headers: map[string]string{ - accept: "", authorization: "", - contentType: "", - timeZone: "", - userAgent: "", }, - Host: hostname, - Transport: transport, + Host: hostname, + SkipDefaultHeaders: true, + Transport: transport, } return opts } diff --git a/go.mod b/go.mod index d7134eea1..17ae86c3e 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/charmbracelet/glamour v0.4.0 github.com/charmbracelet/lipgloss v0.5.0 github.com/cli/browser v1.1.0 - github.com/cli/go-gh v0.0.4-0.20220623035622-91ca4ef447d4 + github.com/cli/go-gh v0.0.4-0.20220725193052-79f89db738dc github.com/cli/oauth v0.9.0 github.com/cli/safeexec v1.0.0 github.com/cli/shurcooL-graphql v0.0.1 @@ -65,6 +65,7 @@ require ( github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/shurcooL/graphql v0.0.0-20200928012149-18c5c3165e3a // indirect github.com/stretchr/objx v0.4.0 // indirect + github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e // indirect github.com/yuin/goldmark v1.4.4 // indirect github.com/yuin/goldmark-emoji v1.0.1 // indirect golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e // indirect diff --git a/go.sum b/go.sum index 76342fbec..601d286dd 100644 --- a/go.sum +++ b/go.sum @@ -58,8 +58,8 @@ 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 v0.0.4-0.20220623035622-91ca4ef447d4 h1:6WrekNBE2Y+Xl9OCl7vsg49SSN68hwaVryfEawQevaQ= -github.com/cli/go-gh v0.0.4-0.20220623035622-91ca4ef447d4/go.mod h1:Y/QFb/VxnXQH0W4VlP+507HVxMzQ430x8kdjUuVcono= +github.com/cli/go-gh v0.0.4-0.20220725193052-79f89db738dc h1:qHm0KQPwmr2gsov+Vqsb0bm5jwWykf8zfUS0Q0/xeR4= +github.com/cli/go-gh v0.0.4-0.20220725193052-79f89db738dc/go.mod h1:YDzUlo0eCH9G0jY2CONIPYSuIMiQiSDnWaTB/YW6yfk= github.com/cli/oauth v0.9.0 h1:nxBC0Df4tUzMkqffAB+uZvisOwT3/N9FpkfdTDtafxc= github.com/cli/oauth v0.9.0/go.mod h1:qd/FX8ZBD6n1sVNQO3aIdRxeu5LGw9WhKnYhIIoC2A4= github.com/cli/safeexec v1.0.0 h1:0VngyaIyqACHdcMNWfo6+KdUYnqEr2Sg+bSP1pdF+dI= @@ -242,6 +242,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.5 h1:s5PTfem8p8EbKQOctVV53k6jCJt3UX4IEJzwh+C324Q= github.com/stretchr/testify v1.7.5/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e h1:BuzhfgfWQbX0dWzYzT1zsORLnHRv3bcRcsaUk0VmXA8= +github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e/go.mod h1:/Tnicc6m/lsJE0irFMA0LfIwTBo4QP7A8IfyIv4zZKI= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -365,6 +367,7 @@ golang.org/x/sys v0.0.0-20210319071255-635bc2c9138d/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=