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 | path := fmt.Sprintf("repos/%s/actions/caches", ghrepo.FullName(repo)) |
| 50 | |
| 51 | perPage := 100 |
| 52 | if opts.Limit > 0 && opts.Limit < 100 { |
| 53 | perPage = opts.Limit |
| 54 | } |
| 55 | path += fmt.Sprintf("?per_page=%d", perPage) |
| 56 | |
| 57 | if opts.Sort != "" { |
| 58 | path += fmt.Sprintf("&sort=%s", opts.Sort) |
| 59 | } |
| 60 | if opts.Order != "" { |
| 61 | path += fmt.Sprintf("&direction=%s", opts.Order) |
| 62 | } |
| 63 | if opts.Key != "" { |
| 64 | path += fmt.Sprintf("&key=%s", url.QueryEscape(opts.Key)) |
| 65 | } |
| 66 | if opts.Ref != "" { |
| 67 | path += fmt.Sprintf("&ref=%s", url.QueryEscape(opts.Ref)) |
| 68 | } |
| 69 | |
| 70 | var result *CachePayload |
| 71 | pagination: |
| 72 | for path != "" { |
| 73 | var response CachePayload |
| 74 | var err error |
| 75 | path, err = client.RESTWithNext(repo.RepoHost(), "GET", path, nil, &response) |
| 76 | if err != nil { |
| 77 | return nil, err |
| 78 | } |
| 79 | |
| 80 | if result == nil { |
| 81 | result = &response |
| 82 | } else { |
| 83 | result.ActionsCaches = append(result.ActionsCaches, response.ActionsCaches...) |
| 84 | } |
| 85 | |
| 86 | if opts.Limit > 0 && len(result.ActionsCaches) >= opts.Limit { |
| 87 | result.ActionsCaches = result.ActionsCaches[:opts.Limit] |
| 88 | break pagination |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | return result, nil |
| 93 | } |
| 94 | |
| 95 | func (c *Cache) ExportData(fields []string) map[string]interface{} { |
| 96 | return cmdutil.StructExportData(c, fields) |