Add verbose rate limit handling and improve API error handling#7
Merged
Add verbose rate limit handling and improve API error handling#7
Conversation
When the GitHub API rate limits requests, the agithub library silently sleeps with no user feedback. This adds a monkey-patch to print a message to stderr showing how long the script will sleep and when it will resume. Also adds rate limit detection for API responses, output file support, and better error handling for unexpected API responses. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR adds verbose rate limit handling to provide feedback when the GitHub API rate limits requests, and improves error handling throughout the script. It also adds a --output-file option to write results to a file.
Changes:
- Added
make_verbose_rate_limit_handler()to patch the GitHub client and print rate limit messages to stderr - Added
is_rate_limited()helper function to detect rate limit responses - Added
--output-fileoption andoutput()function to write results to a file - Added error handling checks for rate limiting, non-2xx status codes, and unexpected response formats in
get_workflow_runs() - Added rate limit checks at various API call points throughout the script
Comments suppressed due to low confidence (2)
get-deployment-metrics.py:507
- The file writing at line 507 uses
"\n".join(output_lines)which will not include a trailing newline, and each message inoutput_linesis a complete line without a newline character. This means the output file will be missing the final newline that's typically expected in text files. Consider addingf.write("\n")after the join, or usingf.write("\n".join(output_lines) + "\n")to ensure the file ends with a newline character.
get-deployment-metrics.py:372 - After checking for rate limiting, there's no check for other API errors (non-2xx status codes) or unexpected response format before accessing
workflow_durationsas a dict at line 369. If the API returns an error status,workflow_durationsmight not be a dict, which could cause an exception. Consider adding status code validation and type checking similar to what was added inget_workflow_runs().
"WARNING: GitHub API rate limit exceeded while fetching timing data. Results may be incomplete."
)
break
# Some jobs may not have run at all
if "run_duration_ms" in workflow_durations:
job_duration = workflow_durations["run_duration_ms"]
else:
job_duration = 0
workflow_total_duration += job_duration
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Remove unused original_sleep variable - Add 429 status code check for secondary rate limits - Fix typo: critiera -> criteria Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
stairsj
approved these changes
Feb 4, 2026
kevintylerstark
approved these changes
Feb 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
is_rate_limited()helper to detect rate limit responses from API--output-fileoption to write results to a fileTest plan
Rate limited by GitHub API. Sleeping for X seconds until HH:MM:SS...--output-fileoption writes results correctly🤖 Generated with Claude Code