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

Method List

pkg/cmd/issue/artifact/client/client.go:87–125  ·  view source on GitHub ↗

List requests pages until one comes back short or the limit is reached. Every request asks for the same page size, so the page numbers line up.

(repo ghrepo.Interface, issueNumber int, artifactType string, limit int)

Source from the content-addressed store, hash-verified

85// List requests pages until one comes back short or the limit is reached.
86// Every request asks for the same page size, so the page numbers line up.
87func (c *artifactClient) List(repo ghrepo.Interface, issueNumber int, artifactType string, limit int) ([]Artifact, error) {
88 u, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "issues", strconv.Itoa(issueNumber), "artifacts")
89 if err != nil {
90 return nil, err
91 }
92
93 perPage := maxPageSize
94 if limit > 0 && limit < maxPageSize {
95 perPage = limit
96 }
97 u.SetQuery("per_page", strconv.Itoa(perPage))
98 if artifactType != "" {
99 u.SetQuery("type", artifactType)
100 }
101
102 artifacts := []Artifact{}
103 for page := 1; ; page++ {
104 if page > 1 {
105 u.SetQuery("page", strconv.Itoa(page))
106 }
107
108 var pageArtifacts []Artifact
109 if err := c.apiClient.REST(repo.RepoHost(), "GET", u.String(), nil, &pageArtifacts); err != nil {
110 return nil, err
111 }
112 artifacts = append(artifacts, pageArtifacts...)
113
114 // The API fills every page but the last, so a page with fewer
115 // artifacts than requested is the last one.
116 if len(pageArtifacts) < perPage || (limit > 0 && len(artifacts) >= limit) {
117 break
118 }
119 }
120
121 if limit > 0 && len(artifacts) > limit {
122 artifacts = artifacts[:limit]
123 }
124 return artifacts, nil
125}
126
127func (c *artifactClient) Get(repo ghrepo.Interface, issueNumber int, number int) (*ArtifactWithVersions, error) {
128 u, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "issues", strconv.Itoa(issueNumber), "artifacts", strconv.Itoa(number))

Callers

nothing calls this directly

Calls 7

JoinPathFunction · 0.92
SetQueryMethod · 0.80
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RESTMethod · 0.65
RepoHostMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected