Skip to content

Commit e373195

Browse files
committed
WIP migrate gist create to separate package
1 parent 6a48a60 commit e373195

File tree

8 files changed

+446
-236
lines changed

8 files changed

+446
-236
lines changed

api/client.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ func NewClient(opts ...ClientOption) *Client {
3333
return client
3434
}
3535

36+
// NewClientFromHTTP takes in an http.Client instance
37+
func NewClientFromHTTP(httpClient *http.Client) *Client {
38+
client := &Client{http: httpClient}
39+
return client
40+
}
41+
3642
// AddHeader turns a RoundTripper into one that adds a request header
3743
func AddHeader(name, value string) ClientOption {
3844
return func(tr http.RoundTripper) http.RoundTripper {
@@ -179,9 +185,10 @@ func (gr GraphQLErrorResponse) Error() string {
179185

180186
// HTTPError is an error returned by a failed API call
181187
type HTTPError struct {
182-
StatusCode int
183-
RequestURL *url.URL
184-
Message string
188+
StatusCode int
189+
RequestURL *url.URL
190+
Message string
191+
OAuthScopes string
185192
}
186193

187194
func (err HTTPError) Error() string {
@@ -322,8 +329,9 @@ func handleResponse(resp *http.Response, data interface{}) error {
322329

323330
func handleHTTPError(resp *http.Response) error {
324331
httpError := HTTPError{
325-
StatusCode: resp.StatusCode,
326-
RequestURL: resp.Request.URL,
332+
StatusCode: resp.StatusCode,
333+
RequestURL: resp.Request.URL,
334+
OAuthScopes: resp.Header.Get("X-Oauth-Scopes"),
327335
}
328336

329337
body, err := ioutil.ReadAll(resp.Body)

command/gist.go

Lines changed: 0 additions & 175 deletions
This file was deleted.

command/gist_test.go

Lines changed: 0 additions & 56 deletions
This file was deleted.

command/root.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/cli/cli/internal/ghrepo"
2121
"github.com/cli/cli/internal/run"
2222
apiCmd "github.com/cli/cli/pkg/cmd/api"
23+
gistCreateCmd "github.com/cli/cli/pkg/cmd/gist/create"
2324
"github.com/cli/cli/pkg/cmdutil"
2425
"github.com/cli/cli/pkg/iostreams"
2526
"github.com/cli/cli/utils"
@@ -95,6 +96,14 @@ func init() {
9596
},
9697
}
9798
RootCmd.AddCommand(apiCmd.NewCmdApi(cmdFactory, nil))
99+
100+
gistCmd := &cobra.Command{
101+
Use: "gist",
102+
Short: "Create gists",
103+
Long: `Work with GitHub gists.`,
104+
}
105+
RootCmd.AddCommand(gistCmd)
106+
gistCmd.AddCommand(gistCreateCmd.NewCmdCreate(cmdFactory, nil))
98107
}
99108

100109
// RootCmd is the entry point of command-line execution

0 commit comments

Comments
 (0)