| 23 | } |
| 24 | |
| 25 | func ListArtifacts(httpClient *http.Client, repo ghrepo.Interface, runID string) ([]Artifact, error) { |
| 26 | var results []Artifact |
| 27 | |
| 28 | perPage := 100 |
| 29 | path := fmt.Sprintf("repos/%s/%s/actions/artifacts?per_page=%d", repo.RepoOwner(), repo.RepoName(), perPage) |
| 30 | if runID != "" { |
| 31 | path = fmt.Sprintf("repos/%s/%s/actions/runs/%s/artifacts?per_page=%d", repo.RepoOwner(), repo.RepoName(), runID, perPage) |
| 32 | } |
| 33 | |
| 34 | url := fmt.Sprintf("%s%s", ghinstance.RESTPrefix(repo.RepoHost()), path) |
| 35 | |
| 36 | for { |
| 37 | var payload artifactsPayload |
| 38 | nextURL, err := apiGet(httpClient, url, &payload) |
| 39 | if err != nil { |
| 40 | return nil, err |
| 41 | } |
| 42 | results = append(results, payload.Artifacts...) |
| 43 | |
| 44 | if nextURL == "" { |
| 45 | break |
| 46 | } |
| 47 | url = nextURL |
| 48 | } |
| 49 | |
| 50 | return results, nil |
| 51 | } |
| 52 | |
| 53 | func apiGet(httpClient *http.Client, url string, data interface{}) (string, error) { |
| 54 | req, err := http.NewRequest("GET", url, nil) |