Skip to content

Instantly share code, notes, and snippets.

@KyMidd

KyMidd/asdf.sh Secret

Created July 27, 2024 03:08
Show Gist options
  • Save KyMidd/c1a83f4f806641716ab261c642f39232 to your computer and use it in GitHub Desktop.
Save KyMidd/c1a83f4f806641716ab261c642f39232 to your computer and use it in GitHub Desktop.
hold_until_rate_limit_success() {
# Loop forever
while true; do
# Any call to AWS returns rate limits in the response headers
API_RATE_LIMIT_UNITS_REMAINING=$(curl -sv \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/$GH_ORG/$GH_REPO/autolinks 2>&1 1>/dev/null \
| grep -E '< x-ratelimit-remaining' \
| cut -d ' ' -f 3 \
| xargs \
| tr -d '\r')
# If API rate-limiting is hit, sleep for 1 minute
if [[ "$API_RATE_LIMIT_UNITS_REMAINING" < 100 ]]; then
echo "ℹ️ We have less than 100 GitHub API rate-limit tokens left, sleeping for 1 minute"
sleep 60
# If API rate-limiting shows remaining units, break out of loop and exit function
else
echo ℹ️ Rate limit checked, we have "$API_RATE_LIMIT_UNITS_REMAINING" core tokens remaining so we are continuing
break
fi
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment