refactor: remove returned resp from api.EndpointNeedsScopes
The returned response from `api.EndpointNeedsScopes` causes `bodyclose` linter to raise a false positive error, assuming it's a new response that its body needs to be closed. Signed-off-by: Babak K. Shandiz <babakks@github.com>
This commit is contained in:
parent
dde7fce602
commit
d129b94fc5
3 changed files with 7 additions and 4 deletions
|
|
@ -152,6 +152,8 @@ func (c Client) RESTWithNext(hostname string, method string, p string, body io.R
|
|||
}
|
||||
|
||||
// HandleHTTPError parses a http.Response into a HTTPError.
|
||||
//
|
||||
// The caller is responsible to close the response body stream.
|
||||
func HandleHTTPError(resp *http.Response) error {
|
||||
return handleResponse(ghAPI.HandleHTTPError(resp))
|
||||
}
|
||||
|
|
@ -196,12 +198,11 @@ func ScopesSuggestion(resp *http.Response) string {
|
|||
// EndpointNeedsScopes adds additional OAuth scopes to an HTTP response as if they were returned from the
|
||||
// server endpoint. This improves HTTP 4xx error messaging for endpoints that don't explicitly list the
|
||||
// OAuth scopes they need.
|
||||
func EndpointNeedsScopes(resp *http.Response, s string) *http.Response {
|
||||
func EndpointNeedsScopes(resp *http.Response, s string) {
|
||||
if resp.StatusCode >= 400 && resp.StatusCode < 500 {
|
||||
oldScopes := resp.Header.Get("X-Accepted-Oauth-Scopes")
|
||||
resp.Header.Set("X-Accepted-Oauth-Scopes", fmt.Sprintf("%s, %s", oldScopes, s))
|
||||
}
|
||||
return resp
|
||||
}
|
||||
|
||||
func generateScopesSuggestion(statusCode int, endpointNeedsScopes, tokenHasScopes, hostname string) string {
|
||||
|
|
|
|||
|
|
@ -286,7 +286,8 @@ func createGist(client *http.Client, hostname, description string, public bool,
|
|||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode > 299 {
|
||||
return nil, api.HandleHTTPError(api.EndpointNeedsScopes(resp, "gist"))
|
||||
api.EndpointNeedsScopes(resp, "gist")
|
||||
return nil, api.HandleHTTPError(resp)
|
||||
}
|
||||
|
||||
result := &shared.Gist{}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,8 @@ func deleteRepo(client *http.Client, repo ghrepo.Interface) error {
|
|||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode > 299 {
|
||||
return api.HandleHTTPError(api.EndpointNeedsScopes(resp, "delete_repo"))
|
||||
api.EndpointNeedsScopes(resp, "delete_repo")
|
||||
return api.HandleHTTPError(resp)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue