Return a list of caches for a repository. Pass a negative limit to request all pages from the API until all caches have been fetched.
(client *api.Client, repo ghrepo.Interface, opts GetCachesOptions)
| 46 | // Return a list of caches for a repository. Pass a negative limit to request |
| 47 | // all pages from the API until all caches have been fetched. |
| 48 | func GetCaches(client *api.Client, repo ghrepo.Interface, opts GetCachesOptions) (*CachePayload, error) { |
| 49 | u, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "actions", "caches") |
| 50 | if err != nil { |
| 51 | return nil, err |
| 52 | } |
| 53 | |
| 54 | perPage := 100 |
| 55 | if opts.Limit > 0 && opts.Limit < 100 { |
| 56 | perPage = opts.Limit |
| 57 | } |
| 58 | u.SetQuery("per_page", strconv.Itoa(perPage)) |
| 59 | |
| 60 | if opts.Sort != "" { |
| 61 | u.SetQuery("sort", opts.Sort) |
| 62 | } |
| 63 | if opts.Order != "" { |
| 64 | u.SetQuery("direction", opts.Order) |
| 65 | } |
| 66 | if opts.Key != "" { |
| 67 | u.SetQuery("key", opts.Key) |
| 68 | } |
| 69 | if opts.Ref != "" { |
| 70 | u.SetQuery("ref", opts.Ref) |
| 71 | } |
| 72 | var pageURL safeurl.SafeURL = u |
| 73 | |
| 74 | var result *CachePayload |
| 75 | pagination: |
| 76 | for pageURL.String() != "" { |
| 77 | var response CachePayload |
| 78 | next, err := client.RESTWithNext(repo.RepoHost(), "GET", pageURL.String(), nil, &response) |
| 79 | if err != nil { |
| 80 | return nil, err |
| 81 | } |
| 82 | pageURL = safeurl.NewImmutableSafeURL(next) |
| 83 | |
| 84 | if result == nil { |
| 85 | result = &response |
| 86 | } else { |
| 87 | result.ActionsCaches = append(result.ActionsCaches, response.ActionsCaches...) |
| 88 | } |
| 89 | |
| 90 | if opts.Limit > 0 && len(result.ActionsCaches) >= opts.Limit { |
| 91 | result.ActionsCaches = result.ActionsCaches[:opts.Limit] |
| 92 | break pagination |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | return result, nil |
| 97 | } |
| 98 | |
| 99 | func (c *Cache) ExportData(fields []string) map[string]any { |
| 100 | return cmdutil.StructExportData(c, fields) |