diff --git a/pkg/cmd/repo/garden/http.go b/pkg/cmd/repo/garden/http.go index af269fbfa..3ca60d0bd 100644 --- a/pkg/cmd/repo/garden/http.go +++ b/pkg/cmd/repo/garden/http.go @@ -36,7 +36,7 @@ func getCommits(client *http.Client, repo ghrepo.Interface, maxCommits int) ([]* break } result := Result{} - resp, err := getResponse(client, repo.RepoHost(), pathF(page), &result) + links, err := getResponse(client, repo.RepoHost(), pathF(page), &result) if err != nil { return nil, err } @@ -52,8 +52,7 @@ func getCommits(client *http.Client, repo ghrepo.Interface, maxCommits int) ([]* Char: colorFunc(string(handle[0])), }) } - link := resp.Header["Link"] - if len(link) == 0 || !strings.Contains(link[0], "last") { + if len(links) == 0 || !strings.Contains(links[0], "last") { paginating = false } page++ @@ -68,7 +67,8 @@ func getCommits(client *http.Client, repo ghrepo.Interface, maxCommits int) ([]* return commits, nil } -func getResponse(client *http.Client, host, path string, data interface{}) (*http.Response, error) { +// getResponse performs the API call and returns the response's link header. +func getResponse(client *http.Client, host, path string, data interface{}) ([]string, error) { url := ghinstance.RESTPrefix(host) + path req, err := http.NewRequest("GET", url, nil) if err != nil { @@ -87,8 +87,10 @@ func getResponse(client *http.Client, host, path string, data interface{}) (*htt return nil, errors.New("api call failed") } + links := resp.Header["Link"] + if resp.StatusCode == http.StatusNoContent { - return resp, nil + return links, nil } b, err := io.ReadAll(resp.Body) @@ -101,5 +103,5 @@ func getResponse(client *http.Client, host, path string, data interface{}) (*htt return nil, err } - return resp, nil + return links, nil }