@@ -44,22 +44,26 @@ function try_curl_with_rate_limit_handling() {
4444 json_output=" ${curl_output#* $' \r\n\r\n ' } "
4545
4646 if test " ${http_code-} " -eq 403; then
47- local debug_file_headers debug_file_json reset_time
47+ local debug_file_headers debug_file_json reset_time remaining
4848
4949 debug_file_headers=" ${DOCS_DIR} /github_rate_limit_headers.txt"
5050 debug_file_json=" ${DOCS_DIR} /github_rate_limit_response.json"
5151 echo " $headers_output " > " $debug_file_headers "
5252 echo " $json_output " > " $debug_file_json "
5353
54- reset_time=" $( pcregrep -o1 ' ^x\-ratelimit\-reset\: (.*?)$' " $debug_file_headers " ) "
55- if command -v epoch_converter > /dev/null 2>&1 ; then
56- reset_time=" $( epoch_converter --iso " $reset_time " ) "
57- fi
54+ remaining=" $( pcregrep -o1 ' ^x\-ratelimit\-remaining\: (.*?)$' " $debug_file_headers " ) "
55+
56+ if ! test " $remaining " -gt 0; then
57+ reset_time=" $( pcregrep -o1 ' ^x\-ratelimit\-reset\: (.*?)$' " $debug_file_headers " ) "
58+ if command -v epoch_converter > /dev/null 2>&1 ; then
59+ reset_time=" $( epoch_converter --iso " $reset_time " ) "
60+ fi
5861
59- log_stderr " $( TZ=UTC gdate ' +%Y-%m-%dT%H:%M:%S.%3NZ' ) Rate limited, will retry shortly. Output at ${debug_file_headers} and ${debug_file_json} . x-ratelimit-reset: ${reset_time} "
60- sleep 30
61- try_curl_with_rate_limit_handling
62- return $?
62+ log_stderr " $( TZ=UTC gdate ' +%Y-%m-%dT%H:%M:%S.%3NZ' ) Rate limited, will retry shortly. Output at ${debug_file_headers} and ${debug_file_json} . x-ratelimit-reset: ${reset_time} "
63+ sleep 30
64+ try_curl_with_rate_limit_handling
65+ return $?
66+ fi
6367 fi
6468
6569 if test " ${http_code-} " -eq 200; then
0 commit comments