@@ -284,9 +284,36 @@ TRIGGER_ADHOC="false"
284284if [[ -n " ${KOKORO_GITHUB_PULL_REQUEST_NUMBER} " ]]; then
285285 echo " Checking for adhoc test label on PR #${KOKORO_GITHUB_PULL_REQUEST_NUMBER} ..."
286286 # Simple, unauthenticated call to check labels
287- if ! LABELS_JSON=$( curl -s -H " User-Agent: Kokoro-AdHoc-Checker" " https://api.github.com/repos/googleapis/google-cloud-python/issues/${KOKORO_GITHUB_PULL_REQUEST_NUMBER} /labels" ) ; then
287+ # Simple, unauthenticated call to check labels (capturing headers for rate limit debugging)
288+ CURL_OUTPUT=$( curl -s -i -H " User-Agent: Kokoro-AdHoc-Checker" " https://api.github.com/repos/googleapis/google-cloud-python/issues/${KOKORO_GITHUB_PULL_REQUEST_NUMBER} /labels" )
289+
290+ # Separate headers and body
291+ # Using awk to find the blank line separating headers from body
292+ HEADERS=$( echo " $CURL_OUTPUT " | awk ' BEGIN{RS="\r\n\r\n"} NR==1' )
293+ LABELS_JSON=$( echo " $CURL_OUTPUT " | awk ' BEGIN{RS="\r\n\r\n"} NR==2' )
294+
295+ # --- DEBUGGING: Extract and print Rate Limit Headers ---
296+ echo " ---------------------------------------------------------------"
297+ echo " DEBUG: GitHub API Rate Limit Status:"
298+ echo " $HEADERS " | grep -i " ^x-ratelimit-limit:" | tr -d ' \r'
299+ echo " $HEADERS " | grep -i " ^x-ratelimit-remaining:" | tr -d ' \r'
300+ echo " $HEADERS " | grep -i " ^x-ratelimit-used:" | tr -d ' \r'
301+
302+ # Convert reset time to human-readable if date is available, otherwise show raw
303+ RESET_EPOCH=$( echo " $HEADERS " | grep -i " ^x-ratelimit-reset:" | awk ' {print $2}' | tr -d ' \r' )
304+ if [[ -n " $RESET_EPOCH " ]]; then
305+ if date -d " @$RESET_EPOCH " > /dev/null 2>&1 ; then
306+ RESET_HUMAN=$( date -d " @$RESET_EPOCH " " +%Y-%m-%d %H:%M:%S UTC" )
307+ echo " DEBUG: X-RateLimit-Reset: $RESET_HUMAN ($RESET_EPOCH )"
308+ else
309+ echo " DEBUG: X-RateLimit-Reset: $RESET_EPOCH "
310+ fi
311+ fi
312+ echo " ---------------------------------------------------------------"
313+
314+ if [[ -z " $LABELS_JSON " ]] || [[ " $HEADERS " == * " HTTP/1.1 4" * ]] || [[ " $HEADERS " == * " HTTP/1.1 5" * ]]; then
288315 echo " ==============================================================="
289- echo " WARNING: Failed to connect to GitHub API!"
316+ echo " WARNING: Failed to fetch labels or received error from GitHub API!"
290317 echo " Ad-hoc tests will NOT be triggered."
291318 echo " ==============================================================="
292319 else
0 commit comments