Skip to content

Commit 466070b

Browse files
Sander van Harmelengmlewis
authored andcommitted
Make GetArchiveLink behave the same as other calls
All available calls in the `go-github` package close the `resp.Body` before returning. Because the `GetArchiveLink` method doesn’t use the [`Do`](https://github.com/google/go-github/blob/master/github/github.go#L381) method, we have to make sure the body is closed here as well. Closes #485. Change-Id: Iec0d88cf66d4d658fcd6aec374b4bc2358269a09
1 parent 939928b commit 466070b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

github/repos_contents.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,12 @@ func (s *RepositoriesService) GetArchiveLink(owner, repo string, archiveformat a
267267
} else {
268268
resp, err = s.client.client.Transport.RoundTrip(req)
269269
}
270-
if err != nil || resp.StatusCode != http.StatusFound {
271-
return nil, newResponse(resp), err
270+
if err != nil {
271+
return nil, nil, err
272+
}
273+
resp.Body.Close()
274+
if resp.StatusCode != http.StatusFound {
275+
return nil, newResponse(resp), fmt.Errorf("unexpected status code: %s", resp.Status)
272276
}
273277
parsedURL, err := url.Parse(resp.Header.Get("Location"))
274278
return parsedURL, newResponse(resp), err

0 commit comments

Comments
 (0)