bevry/dorothy

Bug: api rate exceeds at `setup-utils`

wasdee opened this issue · 3 comments

Preliminary Diagnostic

GET https://api.github.com/repos/nushell/nushell/releases
{
    "message": "API rate limit exceeded for xx.xx.xx.xx . (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)",
    "documentation_url": "https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting"
}

Propose fix

ask user to voluntary sign in the gh, and

# Fetch the latest release tag
latest_tag=$(gh release list -L 1 -R <repository> | cut -f3)

# Download the latest release
gh release download $latest_tag -R <repository> -D <destination-directory>

Error

curl: (22) The requested URL returned error: 403
Failed to fetch the URL: https://api.github.com/repos/microsoft/ripgrep-prebuilt/releases

ERROR:
No release assets were found for repository microsoft/ripgrep-prebuilt release latest

ERROR:
No download assets were found for repository microsoft/ripgrep-prebuilt
The [ripgrep] utility is already installed. ✅
curl: (22) The requested URL returned error: 403
Failed to fetch the URL: https://api.github.com/repos/koalaman/shellcheck/releases

ERROR:
No release assets were found for repository koalaman/shellcheck release latest

ERROR:
No download assets were found for repository koalaman/shellcheck
The [shellcheck] utility was not found. Installing automatically... ⏲
The [shellcheck] utility was installed via [apt]
The [shellcheck] utility was installed. ✅
curl: (22) The requested URL returned error: 403
Failed to fetch the URL: https://api.github.com/repos/starship/starship/releases

ERROR:
No release assets were found for repository starship/starship release latest

ERROR:
No download assets were found for repository starship/starship
The [Starship] utility is already installed. ✅
If you see unknown icons while using Starship, then you need to run:
    setup-linux-fonts
then set your terminal to use the Fira Code Nerd font, or another monospace nerd font that was installed.
curl: (22) The requested URL returned error: 403
Failed to fetch the URL: https://api.github.com/repos/dbrgn/tealdeer/releases

ERROR:
No release assets were found for repository dbrgn/tealdeer release latest

ERROR:
No download assets were found for repository dbrgn/tealdeer
The [tealdeer] utility is already installed. ✅
< 'tldr' '--update' >
</ 'tldr' '--update' >[0]
curl: (22) The requested URL returned error: 403
Failed to fetch the URL: https://api.github.com/repos/XAMPPRocky/tokei/releases

ERROR:
No release assets were found for repository XAMPPRocky/tokei release latest

ERROR:
No download assets were found for repository XAMPPRocky/tokei

Interesting fix proposal. Makes sense to check if gh is authed (already done in setup-git) and use that if so, and if not, then check use the api and check the response for rate limit failure and if so do the auth flow and use gh.

an alternative would be to check if the auth token is mapped via secret or to even guide the user with how to map it via secret, but that is more involved than the above proposal

Implementing now.

Difficulty is that gh doesn't support fetching via a release ID, which at times has been necessary, such as when locking JQ to a specific release ID.

That said, I believe that release IDs were used as filtering via tag name was fragile when jq was not present on the system. In which case, perhaps instead of just passing a release, we should pass the tag, alias, or id of a release so the fetcher can use the appropriate technique.

I believe I've resolved this locally through a thorough rewrite of get-github-release and a partial rewrite of gihtub-download. Will do cross-platform testing tomorrow.