Skip to content

Commit dd7992e

Browse files
committed
Adding features to code-search rate limit demo
1 parent 241bb01 commit dd7992e

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

code-search-rate-limit-demo.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
# https://docs.github.com/en/enterprise-cloud@latest/rest/search?apiVersion=2022-11-28#rate-limit
55
# https://api.github.com/search/repositories?q=Q
66

7-
# WORKS ON A MAC
8-
default_start_date="$(date -v -7d +'%Y-%m-%d')"
97

108
# Pass query as an argument, otherwise list all repos with commits in the last seven days
119
if [ -z "$1" ]
@@ -15,13 +13,23 @@ if [ -z "$1" ]
1513
query="$1"
1614
fi
1715

16+
17+
curl_custom_flags="--write-out %output{tmp/headers.json}%{header_json} --fail-with-body --silent "
18+
19+
1820
# Rate limit for code search is 10 (2024-09)
21+
sleep_period=7
1922
for n in {1..11}
2023
do
21-
echo "position in loop ${n}"
2224
# verbose curl but no output from the curl, since it is not interesting for rate limit demo purposes
23-
curl -v ${curl_custom_flags} \
25+
curl ${curl_custom_flags} \
2426
-H "Accept: application/vnd.github+json" \
2527
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
2628
${GITHUB_API_BASE_URL}/search/code?q=${query} > /dev/null
29+
30+
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])"')
31+
echo " " ${results}
32+
33+
sleep ${sleep_period}
2734
done
35+

0 commit comments

Comments
 (0)