From dd7992e39a1c21c84a743668aed8ca51a6006dd7 Mon Sep 17 00:00:00 2001 From: David Morris Date: Tue, 24 Sep 2024 15:22:18 +0100 Subject: [PATCH] Adding features to code-search rate limit demo --- code-search-rate-limit-demo.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/code-search-rate-limit-demo.sh b/code-search-rate-limit-demo.sh index 0d94284e..f5ceebf7 100755 --- a/code-search-rate-limit-demo.sh +++ b/code-search-rate-limit-demo.sh @@ -4,8 +4,6 @@ # https://docs.github.com/en/enterprise-cloud@latest/rest/search?apiVersion=2022-11-28#rate-limit # https://api.github.com/search/repositories?q=Q -# WORKS ON A MAC -default_start_date="$(date -v -7d +'%Y-%m-%d')" # Pass query as an argument, otherwise list all repos with commits in the last seven days if [ -z "$1" ] @@ -15,13 +13,23 @@ if [ -z "$1" ] query="$1" fi + +curl_custom_flags="--write-out %output{tmp/headers.json}%{header_json} --fail-with-body --silent " + + # Rate limit for code search is 10 (2024-09) +sleep_period=7 for n in {1..11} do -echo "position in loop ${n}" # verbose curl but no output from the curl, since it is not interesting for rate limit demo purposes -curl -v ${curl_custom_flags} \ +curl ${curl_custom_flags} \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ ${GITHUB_API_BASE_URL}/search/code?q=${query} > /dev/null + + results=$(cat tmp/headers.json | jq -r --arg n "$n" '"position in loop: \($n)\ndate: \(.date[0])\nx-ratelimit-limit: \(.["x-ratelimit-limit"][0])\nx-rate-limit-remaining: \(.["x-ratelimit-remaining"][0])\nx-github-request-id: \(.["x-github-request-id"][0])"') + echo " " ${results} + + sleep ${sleep_period} done +