refactor(cache): extract cache ID parsing logic
* Replaced direct conversion of cache ID string to int with a dedicated `parseCacheID` function. * Improved readability and maintainability of the `deleteCaches` function.
This commit is contained in:
parent
047326fcb4
commit
5c292286cf
1 changed files with 6 additions and 1 deletions
7
pkg/cmd/cache/delete/delete.go
vendored
7
pkg/cmd/cache/delete/delete.go
vendored
|
|
@ -162,7 +162,7 @@ func deleteCaches(opts *DeleteOptions, client *api.Client, repo ghrepo.Interface
|
|||
|
||||
for _, cache := range toDelete {
|
||||
path := ""
|
||||
if id, err := strconv.Atoi(cache); err == nil {
|
||||
if id, ok := parseCacheID(cache); ok {
|
||||
path = fmt.Sprintf("%s/%d", base, id)
|
||||
} else {
|
||||
path = fmt.Sprintf("%s?key=%s", base, url.QueryEscape(cache))
|
||||
|
|
@ -195,3 +195,8 @@ func deleteCaches(opts *DeleteOptions, client *api.Client, repo ghrepo.Interface
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseCacheID(arg string) (int, bool) {
|
||||
id, err := strconv.Atoi(arg)
|
||||
return id, err == nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue