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

Function GetCaches

pkg/cmd/cache/shared/shared.go:48–97  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
48func 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
75pagination:
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
99func (c *Cache) ExportData(fields []string) map[string]any {
100 return cmdutil.StructExportData(c, fields)

Callers 3

deleteRunFunction · 0.92
listRunFunction · 0.92
TestGetCachesFunction · 0.85

Calls 8

StringMethod · 0.95
JoinPathFunction · 0.92
NewImmutableSafeURLFunction · 0.92
SetQueryMethod · 0.80
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RESTWithNextMethod · 0.65
RepoHostMethod · 0.65

Tested by 1

TestGetCachesFunction · 0.68