| 117 | } |
| 118 | |
| 119 | func deleteRun(opts *DeleteOptions) error { |
| 120 | httpClient, err := opts.HttpClient() |
| 121 | if err != nil { |
| 122 | return fmt.Errorf("failed to create http client: %w", err) |
| 123 | } |
| 124 | client := api.NewClientFromHTTP(httpClient) |
| 125 | |
| 126 | repo, err := opts.BaseRepo() |
| 127 | if err != nil { |
| 128 | return fmt.Errorf("failed to determine base repo: %w", err) |
| 129 | } |
| 130 | |
| 131 | var toDelete []string |
| 132 | if opts.DeleteAll { |
| 133 | opts.IO.StartProgressIndicator() |
| 134 | caches, err := shared.GetCaches(client, repo, shared.GetCachesOptions{Limit: -1, Ref: opts.Ref}) |
| 135 | opts.IO.StopProgressIndicator() |
| 136 | if err != nil { |
| 137 | return err |
| 138 | } |
| 139 | if len(caches.ActionsCaches) == 0 { |
| 140 | if opts.SucceedOnNoCaches { |
| 141 | if opts.IO.IsStdoutTTY() { |
| 142 | fmt.Fprintf(opts.IO.Out, "%s No caches to delete\n", opts.IO.ColorScheme().SuccessIcon()) |
| 143 | } |
| 144 | return nil |
| 145 | } else { |
| 146 | return fmt.Errorf("%s No caches to delete", opts.IO.ColorScheme().FailureIcon()) |
| 147 | } |
| 148 | } |
| 149 | for _, cache := range caches.ActionsCaches { |
| 150 | toDelete = append(toDelete, strconv.Itoa(cache.Id)) |
| 151 | } |
| 152 | } else { |
| 153 | toDelete = append(toDelete, opts.Identifier) |
| 154 | } |
| 155 | |
| 156 | return deleteCaches(opts, client, repo, toDelete) |
| 157 | } |
| 158 | |
| 159 | func deleteCaches(opts *DeleteOptions, client *api.Client, repo ghrepo.Interface, toDelete []string) error { |
| 160 | cs := opts.IO.ColorScheme() |