Skip to content

Commit

Permalink
Adding features to code-search rate limit demo
Browse files Browse the repository at this point in the history
  • Loading branch information
gm3dmo committed Sep 24, 2024
1 parent 241bb01 commit dd7992e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions code-search-rate-limit-demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand All @@ -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

0 comments on commit dd7992e

Please sign in to comment.