Skip to content

Commit

Permalink
cmd: use github.Client for release command
Browse files Browse the repository at this point in the history
Also add a note about why `--auth-user` is unnecessary/misleading for
the release command.

Fixes #106.
  • Loading branch information
kevinburke committed May 29, 2020
1 parent c4d67c5 commit fdf470c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -101,6 +101,13 @@ $ github-release delete \
--tag v0.1.0
```

Errata
======

The `release` command does not have an `--auth-user` flag because in practice,
Github ignores the `--auth-user` flag when validating releases. The only thing
that matters is passing a token that has permission to create the release.

GitHub Enterprise Support
=========================
You can point to a different GitHub API endpoint via the environment variable ```GITHUB_API```:
Expand Down
13 changes: 10 additions & 3 deletions cmd.go
Expand Up @@ -354,10 +354,17 @@ func releasecmd(opt Options) error {
}
reader := bytes.NewReader(payload)

URL := nvls(EnvApiEndpoint, github.DefaultBaseURL) + fmt.Sprintf("/repos/%s/%s/releases", user, repo)
resp, err := github.DoAuthRequest("POST", URL, "application/json", token, nil, reader)
// NB: Github appears to ignore the user here - the only thing that seems to
// matter is that the token is valid.
client := github.NewClient(user, token, nil)
client.SetBaseURL(EnvApiEndpoint)
req, err := client.NewRequest("POST", fmt.Sprintf("/repos/%s/%s/releases", user, repo), reader)
if err != nil {
return fmt.Errorf("while submitting %v, %v", string(payload), err)
return fmt.Errorf("while submitting %v: %w", string(payload), err)
}
resp, err := client.Do(req)
if err != nil {
return fmt.Errorf("while submitting %v: %w", string(payload), err)
}
defer resp.Body.Close()

Expand Down
6 changes: 3 additions & 3 deletions github/github.go
Expand Up @@ -158,7 +158,7 @@ func init() {
}

// Caller is responsible for reading and closing the response body.
func (c Client) do(r *http.Request) (*http.Response, error) {
func (c Client) Do(r *http.Request) (*http.Response, error) {
// Pulled this out of client.go:Do because we need to read the response
// headers.
var res *http.Response
Expand Down Expand Up @@ -217,7 +217,7 @@ func (c Client) getPaginated(uri string) (io.ReadCloser, error) {
if err != nil {
return nil, err
}
resp, err := c.do(req)
resp, err := c.Do(req)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -251,7 +251,7 @@ func (c Client) getPaginated(uri string) (io.ReadCloser, error) {
w.CloseWithError(err)
return
}
resp, err := c.do(req)
resp, err := c.Do(req)
if err != nil {
w.CloseWithError(err)
return
Expand Down

0 comments on commit fdf470c

Please sign in to comment.