Skip to content

Add verbose rate limit handling and improve API error handling#7

Merged
dnorth98 merged 3 commits intomainfrom
add-verbose-rate-limit-handling
Feb 4, 2026
Merged

Add verbose rate limit handling and improve API error handling#7
dnorth98 merged 3 commits intomainfrom
add-verbose-rate-limit-handling

Conversation

@dnorth98
Copy link
Contributor

@dnorth98 dnorth98 commented Feb 4, 2026

Summary

  • Adds visible feedback when the GitHub API rate limits requests (previously the script would silently hang)
  • Prints message to stderr showing sleep duration and resume time when rate limited
  • Adds is_rate_limited() helper to detect rate limit responses from API
  • Adds --output-file option to write results to a file
  • Improves error handling for unexpected API responses throughout the script

Test plan

  • Run script until rate limited and verify message appears: Rate limited by GitHub API. Sleeping for X seconds until HH:MM:SS...
  • Verify script continues normally after rate limit period expires
  • Test --output-file option writes results correctly

🤖 Generated with Claude Code

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>
@dnorth98 dnorth98 requested a review from a team as a code owner February 4, 2026 21:04
@dnorth98 dnorth98 requested review from Copilot, kevintylerstark, phamtriduy and stairsj and removed request for a team February 4, 2026 21:04
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-file option and output() 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 in output_lines is 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 adding f.write("\n") after the join, or using f.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_durations as a dict at line 369. If the API returns an error status, workflow_durations might not be a dict, which could cause an exception. Consider adding status code validation and type checking similar to what was added in get_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>
@dnorth98 dnorth98 merged commit 674de3d into main Feb 4, 2026
4 checks passed
@dnorth98 dnorth98 deleted the add-verbose-rate-limit-handling branch February 4, 2026 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants