refactor(repo garden): return pagination link instead of resp

Signed-off-by: Babak K. Shandiz <babakks@github.com>
This commit is contained in:
Babak K. Shandiz 2025-11-03 15:29:51 +00:00
parent 9f65e89760
commit 2709c39179
No known key found for this signature in database
GPG key ID: 9472CAEFF56C742E

View file

@ -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
}