(opts *DeleteOptions, client *api.Client, repo ghrepo.Interface, toDelete []string)
| 157 | } |
| 158 | |
| 159 | func deleteCaches(opts *DeleteOptions, client *api.Client, repo ghrepo.Interface, toDelete []string) error { |
| 160 | cs := opts.IO.ColorScheme() |
| 161 | repoName := ghrepo.FullName(repo) |
| 162 | opts.IO.StartProgressIndicator() |
| 163 | |
| 164 | totalDeleted := 0 |
| 165 | for _, cache := range toDelete { |
| 166 | var count int |
| 167 | var err error |
| 168 | if id, ok := parseCacheID(cache); ok { |
| 169 | err = deleteCacheByID(client, repo, id) |
| 170 | count = 1 |
| 171 | } else { |
| 172 | count, err = deleteCacheByKey(client, repo, cache, opts.Ref) |
| 173 | } |
| 174 | |
| 175 | if err != nil { |
| 176 | var httpErr api.HTTPError |
| 177 | if errors.As(err, &httpErr) { |
| 178 | if httpErr.StatusCode == http.StatusNotFound { |
| 179 | if opts.Ref == "" { |
| 180 | err = fmt.Errorf("%s Could not find a cache matching %s in %s", cs.FailureIcon(), cache, repoName) |
| 181 | } else { |
| 182 | err = fmt.Errorf("%s Could not find a cache matching %s (with ref %s) in %s", cs.FailureIcon(), cache, opts.Ref, repoName) |
| 183 | } |
| 184 | } else { |
| 185 | err = fmt.Errorf("%s Failed to delete cache: %w", cs.FailureIcon(), err) |
| 186 | } |
| 187 | } |
| 188 | opts.IO.StopProgressIndicator() |
| 189 | return err |
| 190 | } |
| 191 | |
| 192 | totalDeleted += count |
| 193 | } |
| 194 | |
| 195 | opts.IO.StopProgressIndicator() |
| 196 | |
| 197 | if opts.IO.IsStdoutTTY() { |
| 198 | fmt.Fprintf(opts.IO.Out, "%s Deleted %s from %s\n", cs.SuccessIcon(), text.Pluralize(totalDeleted, "cache"), repoName) |
| 199 | } |
| 200 | |
| 201 | return nil |
| 202 | } |
| 203 | |
| 204 | func deleteCacheByID(client *api.Client, repo ghrepo.Interface, id int64) error { |
| 205 | // returns HTTP 204 (NO CONTENT) on success |
no test coverage detected