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:
Lucas 2025-08-27 19:37:39 +02:00
parent 047326fcb4
commit 5c292286cf
No known key found for this signature in database

View file

@ -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
}