New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix gh run download <run-id> not getting > 100 artifacts
#5799
base: trunk
Are you sure you want to change the base?
Conversation
| var linkRE = regexp.MustCompile(`<([^>]+)>;\s*rel="([^"]+)"`) | ||
|
|
||
| return response.Artifacts, nil | ||
| func findNextPage(resp *http.Response) string { | ||
| for _, m := range linkRE.FindAllStringSubmatch(resp.Header.Get("Link"), -1) { | ||
| if len(m) > 2 && m[2] == "next" { | ||
| return m[1] | ||
| } | ||
| } | ||
| return "" | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, I copied this code from elsewhere in the repository, and I would like to be able to reuse that instead of copying. I wasn't able to get import/referencing to work; I would try:
import (
...
cmdApi "github.com/cli/cli/v2/pkg/cmd/api"
)
...
cmdApi.findNextPage()but that would fail with findNextPage() is undefined in api package...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's perfectly fine to copy the function over. Lowercase functions in Go (e.g. findNextPage vs. FindNextPage) are private to a package and cannot be used from other packages, like you have found out when trying to invoke cmdApi.findNextPage().
|
would also appreciate advice or PR for testing the change. any pointers welcomed; new to golang |
This is looking good, but the code has inconsistent indentation. You can tell Go to format your code by saying go fmt ./pkg/cmd/run/shared. You can also configure your text editor to always format your Go code on file save (it's what I do).
As for testing, you can create a mock http.Client like this:
cli/pkg/cmd/run/shared/shared_test.go
Lines 40 to 47 in 2e6f202
| reg := &httpmock.Registry{} | |
| defer reg.Verify(t) | |
| reg.Register( | |
| httpmock.REST("GET", "repos/OWNER/REPO/check-runs/123456/annotations"), | |
| httpmock.StatusStringResponse(404, "not found")) | |
| httpClient := &http.Client{Transport: reg} |
You can then pass that client to ListArtifacts and use the registry to stub responses, like so
cli/pkg/search/searcher_test.go
Line 98 in 04ed77d
| firstRes = httpmock.WithHeader(firstRes, "Link", `<https://api.github.com/search/repositories?page=2&per_page=100&q=org%3Agithub>; rel="next"`) |
| var linkRE = regexp.MustCompile(`<([^>]+)>;\s*rel="([^"]+)"`) | ||
|
|
||
| return response.Artifacts, nil | ||
| func findNextPage(resp *http.Response) string { | ||
| for _, m := range linkRE.FindAllStringSubmatch(resp.Header.Get("Link"), -1) { | ||
| if len(m) > 2 && m[2] == "next" { | ||
| return m[1] | ||
| } | ||
| } | ||
| return "" | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's perfectly fine to copy the function over. Lowercase functions in Go (e.g. findNextPage vs. FindNextPage) are private to a package and cannot be used from other packages, like you have found out when trying to invoke cmdApi.findNextPage().
| } | ||
| path := fmt.Sprintf("repos/%s/%s/actions/", repo.RepoOwner(), repo.RepoName()) | ||
| if runID == "" { | ||
| path += "artifacts" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of concatenating path together piece by piece like this, just set the whole path and also set a whole path in an if block for when runID is provided, like in the old code. It will be more readable (at the cost of a tiny bit of duplication)
Fixes #5790
Testing
Used this workflow file to create 201 individual artifact uploads to the run, and was able to reproduce the bug not getting all of them when running
gh run download <run-id>.Compiled change, and then tested which was then able to get all 201 artifacts