| 21 | } |
| 22 | |
| 23 | func ListArtifacts(httpClient *http.Client, repo ghrepo.Interface, runID string) ([]Artifact, error) { |
| 24 | var results []Artifact |
| 25 | |
| 26 | perPage := 100 |
| 27 | u, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "actions", "artifacts") |
| 28 | if err != nil { |
| 29 | return nil, err |
| 30 | } |
| 31 | if runID != "" { |
| 32 | u, err = safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "actions", "runs", runID, "artifacts") |
| 33 | if err != nil { |
| 34 | return nil, err |
| 35 | } |
| 36 | } |
| 37 | u.SetQuery("per_page", strconv.Itoa(perPage)) |
| 38 | var pageURL safeurl.SafeURL = u |
| 39 | |
| 40 | // TODO(api-client-rollout) |
| 41 | // This line of code is part of a mechanical roll out of the api client. |
| 42 | // As a follow up, consider whether the api client can be injected to this call site, rather than constructed |
| 43 | client := api.NewClientFromHTTP(httpClient) |
| 44 | |
| 45 | for { |
| 46 | var payload artifactsPayload |
| 47 | nextURL, err := client.RESTWithNext(repo.RepoHost(), http.MethodGet, pageURL.String(), nil, &payload) |
| 48 | if err != nil { |
| 49 | return nil, err |
| 50 | } |
| 51 | results = append(results, payload.Artifacts...) |
| 52 | |
| 53 | if nextURL == "" { |
| 54 | break |
| 55 | } |
| 56 | pageURL = safeurl.NewImmutableSafeURL(nextURL) |
| 57 | } |
| 58 | |
| 59 | return results, nil |
| 60 | } |