MCPcopy Create free account
hub / github.com/cli/cli / ListArtifacts

Function ListArtifacts

pkg/cmd/run/shared/artifacts.go:26–59  ·  view source on GitHub ↗
(httpClient *http.Client, repo ghrepo.Interface, runID string)

Source from the content-addressed store, hash-verified

24}
25
26func ListArtifacts(httpClient *http.Client, repo ghrepo.Interface, runID string) ([]Artifact, error) {
27 var results []Artifact
28
29 restPrefix := ghinstance.RESTPrefix(repo.RepoHost())
30 perPage := 100
31 u, err := safeurl.JoinPathWithHostPrefix(restPrefix, "repos", repo.RepoOwner(), repo.RepoName(), "actions", "artifacts")
32 if err != nil {
33 return nil, err
34 }
35 if runID != "" {
36 u, err = safeurl.JoinPathWithHostPrefix(restPrefix, "repos", repo.RepoOwner(), repo.RepoName(), "actions", "runs", runID, "artifacts")
37 if err != nil {
38 return nil, err
39 }
40 }
41 u.SetQuery("per_page", strconv.Itoa(perPage))
42 var pageURL safeurl.SafeURL = u
43
44 for {
45 var payload artifactsPayload
46 nextURL, err := apiGet(httpClient, pageURL, &payload)
47 if err != nil {
48 return nil, err
49 }
50 results = append(results, payload.Artifacts...)
51
52 if nextURL == "" {
53 break
54 }
55 pageURL = safeurl.NewImmutableSafeURL(nextURL)
56 }
57
58 return results, nil
59}
60
61func apiGet(httpClient *http.Client, url safeurl.SafeURL, data interface{}) (string, error) {
62 req, err := http.NewRequest("GET", url.String(), nil)

Callers 3

runViewFunction · 0.92
ListMethod · 0.92

Calls 8

RESTPrefixFunction · 0.92
JoinPathWithHostPrefixFunction · 0.92
NewImmutableSafeURLFunction · 0.92
apiGetFunction · 0.85
SetQueryMethod · 0.80
RepoHostMethod · 0.65
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65

Tested by 1