refactor(repo garden): return pagination link instead of resp
Signed-off-by: Babak K. Shandiz <babakks@github.com>
This commit is contained in:
parent
9f65e89760
commit
2709c39179
1 changed files with 8 additions and 6 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue