File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change 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
119if [ -z " $1 " ]
@@ -15,13 +13,23 @@ if [ -z "$1" ]
1513 query=" $1 "
1614fi
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
1922for n in {1..11}
2023do
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}
2734done
35+
You can’t perform that action at this time.
0 commit comments