File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22set -eo pipefail
33
44# Fetch release metadata from GitHub API
5- API_RESPONSE=" $( curl -sf https://api.github.com/repos/brevdev/brev-cli/releases/latest 2>&1 ) " || {
5+ API_RESPONSE=" $( curl -sf ${GITHUB_TOKEN : +-H " Authorization: token ${GITHUB_TOKEN} " } https://api.github.com/repos/brevdev/brev-cli/releases/latest) " || {
66 echo " Error: Failed to fetch release info from GitHub API." >&2
7- echo " This may be caused by rate limiting. Try again later or set a GITHUB_TOKEN." >&2
7+ echo " This is often caused by rate limiting when many requests come from the same IP." >&2
8+ echo " If you are using a VPN, try turning it off and running this script again." >&2
9+ echo " You can also set GITHUB_TOKEN to avoid rate limits." >&2
10+ echo " For more details, see: https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting" >&2
811 exit 1
912}
1013
1114# Extract the download URL for linux/amd64
1215DOWNLOAD_URL=" $( echo " ${API_RESPONSE} " | grep " browser_download_url.*linux.*amd64" | cut -d ' "' -f 4) "
1316if [ -z " ${DOWNLOAD_URL} " ]; then
1417 echo " Error: Could not find release for linux amd64" >&2
18+ echo " GitHub API response (truncated): ${API_RESPONSE: 0: 200} " >&2
1519 exit 1
1620fi
1721
Original file line number Diff line number Diff line change @@ -10,16 +10,20 @@ case "${ARCH}" in
1010esac
1111
1212# Fetch release metadata from GitHub API
13- API_RESPONSE=" $( curl -sf https://api.github.com/repos/brevdev/brev-cli/releases/latest 2>&1 ) " || {
13+ API_RESPONSE=" $( curl -sf ${GITHUB_TOKEN : +-H " Authorization: token ${GITHUB_TOKEN} " } https://api.github.com/repos/brevdev/brev-cli/releases/latest) " || {
1414 echo " Error: Failed to fetch release info from GitHub API." >&2
15- echo " This may be caused by rate limiting. Try again later or set a GITHUB_TOKEN." >&2
15+ echo " This is often caused by rate limiting when many requests come from the same IP." >&2
16+ echo " If you are using a VPN, try turning it off and running this script again." >&2
17+ echo " You can also set GITHUB_TOKEN to avoid rate limits." >&2
18+ echo " For more details, see: https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting" >&2
1619 exit 1
1720}
1821
1922# Extract the download URL for this platform
2023DOWNLOAD_URL=" $( echo " ${API_RESPONSE} " | grep " browser_download_url.*${OS} .*${ARCH} " | cut -d ' "' -f 4) "
2124if [ -z " ${DOWNLOAD_URL} " ]; then
2225 echo " Error: Could not find release for ${OS} ${ARCH} " >&2
26+ echo " GitHub API response (truncated): ${API_RESPONSE: 0: 200} " >&2
2327 exit 1
2428fi
2529
Original file line number Diff line number Diff line change @@ -116,12 +116,21 @@ done
116116rm -rf " $TMPDIR "
117117
118118# Resolve commit SHA and write .version file
119- COMMIT_SHA=$( curl -fsSL " https://api.github.com/repos/$REPO /commits/$BRANCH " 2> /dev/null | grep ' "sha"' | head -1 | sed ' s/.*"sha": *"\([^"]*\)".*/\1/' )
120- if [[ -n " $COMMIT_SHA " ]]; then
121- for dir in " ${INSTALL_DIRS[@]} " ; do
122- printf ' branch=%s\ncommit=%s\n' " $BRANCH " " $COMMIT_SHA " > " $dir /.version"
123- done
124- echo -e " ${GREEN} ✓${NC} .version (${COMMIT_SHA: 0: 12} )"
119+ VERSION_RESPONSE=$( curl -fsSL " https://api.github.com/repos/$REPO /commits/$BRANCH " 2>&1 ) || true
120+ if echo " $VERSION_RESPONSE " | grep -q " API rate limit exceeded" ; then
121+ echo -e " ${YELLOW} ⚠${NC} .version (skipped — GitHub API rate limit exceeded)"
122+ echo -e " ${YELLOW} If you are using a VPN, try turning it off and running this script again.${NC} "
123+ echo -e " ${YELLOW} See: https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting${NC} "
124+ else
125+ COMMIT_SHA=$( echo " $VERSION_RESPONSE " | grep ' "sha"' | head -1 | sed ' s/.*"sha": *"\([^"]*\)".*/\1/' )
126+ if [[ -n " $COMMIT_SHA " ]]; then
127+ for dir in " ${INSTALL_DIRS[@]} " ; do
128+ printf ' branch=%s\ncommit=%s\n' " $BRANCH " " $COMMIT_SHA " > " $dir /.version"
129+ done
130+ echo -e " ${GREEN} ✓${NC} .version (${COMMIT_SHA: 0: 12} )"
131+ else
132+ echo -e " ${YELLOW} ⚠${NC} .version (could not resolve commit SHA)"
133+ fi
125134fi
126135
127136echo " "
You can’t perform that action at this time.
0 commit comments