Skip to content

Add Bash and PowerShell scripts for monitoring GitHub API rate limits#25

Merged
segraef merged 1 commit intomainfrom
gh-ratelimit
Apr 30, 2026
Merged

Add Bash and PowerShell scripts for monitoring GitHub API rate limits#25
segraef merged 1 commit intomainfrom
gh-ratelimit

Conversation

@segraef
Copy link
Copy Markdown
Owner

@segraef segraef commented Apr 30, 2026

Change

Feel free to remove this sample text

Thank you for your contribution !
Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context.
List any dependencies that are required for this change.

Type of Change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update (Wiki)

Checklist

  • I'm sure there are no other open Pull Requests for the same update/change
  • My corresponding pipelines / checks run clean and green without any errors or warnings
  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (readme)
  • I did format my code

Copilot AI review requested due to automatic review settings April 30, 2026 05:30
@segraef segraef merged commit 7009901 into main Apr 30, 2026
3 of 4 checks passed
@segraef segraef deleted the gh-ratelimit branch April 30, 2026 05:31
Copy link
Copy Markdown

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

Adds command-line utilities to query and display GitHub API rate-limit buckets (via gh api rate_limit) in both Bash and PowerShell, with optional watch/JSON/quiet modes.

Changes:

  • Add a Bash script to render /rate_limit buckets as a pressure-sorted table (or JSON) with watch mode.
  • Add a PowerShell equivalent that uses native JSON parsing (no jq) and supports watch/JSON/quiet modes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
_in progress/gh-ratelimit New Bash implementation of a GitHub rate-limit monitor (table/JSON/watch).
_in progress/gh-ratelimit.ps1 New PowerShell implementation of the same monitor (table/JSON/watch).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread _in progress/gh-ratelimit
Comment on lines +1 to +3
#!/usr/bin/env bash
# gh-ratelimit - GitHub API rate-limit monitor for Bash and POSIX-style shells.
#
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

The header comment claims this script works with "Bash and POSIX-style shells", but the implementation uses Bash-specific features (#!/usr/bin/env bash, [[ ... ]], local, and process substitution < <(...)). Either update the description to state it requires Bash, or refactor to be POSIX-sh compatible.

Copilot uses AI. Check for mistakes.
Comment thread _in progress/gh-ratelimit
Comment on lines +1 to +8
#!/usr/bin/env bash
# gh-ratelimit - GitHub API rate-limit monitor for Bash and POSIX-style shells.
#
# What it does:
# Queries GitHub's /rate_limit endpoint through GitHub CLI and renders the
# current API buckets sorted by pressure so the tightest buckets appear first.
#
# Requirements:
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

These scripts are being added under _in progress/ (which also contains a space). That makes invocation and discoverability harder (paths need quoting) and is inconsistent with the existing top-level Bash/ and PowerShell/ script organization. Consider moving this Bash script into Bash/ (and the PowerShell one into PowerShell/) as part of this PR if they’re intended for general use.

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +16
#!/usr/bin/env pwsh

<#
.SYNOPSIS
Displays GitHub API rate-limit buckets using GitHub CLI.

.DESCRIPTION
Queries GitHub's /rate_limit endpoint through GitHub CLI and renders the
response as either formatted JSON or a terminal-friendly table sorted by the
most constrained buckets first.

This PowerShell version only requires GitHub CLI. Unlike the Bash version, it
does not require jq because JSON parsing is handled natively by PowerShell.

.REQUIREMENTS
- GitHub CLI: gh
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

This script is being added under _in progress/ (which contains a space in the directory name). That makes running it more cumbersome (paths need quoting) and is inconsistent with the existing PowerShell/ directory used for PowerShell tooling in this repo. If this is meant to be a supported utility, consider relocating it into PowerShell/ and/or adding a stable entrypoint.

Copilot uses AI. Check for mistakes.
Comment thread _in progress/gh-ratelimit
while [[ $# -gt 0 ]]; do
case "$1" in
-w|--watch) WATCH=1 ;;
-i|--interval) INTERVAL="${2:-10}"; shift ;;
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

-i|--interval parsing shifts an extra time even when no interval value is provided (e.g., gh-ratelimit -i), which will trigger shift: shift count out of range under set -e and exit unexpectedly. Add an explicit check for a missing/invalid $2 before shifting, and print a clear usage error when the interval argument is absent.

Suggested change
-i|--interval) INTERVAL="${2:-10}"; shift ;;
-i|--interval)
if [[ -z "${2:-}" || "${2:-}" == -* ]]; then
echo "error: -i|--interval requires a positive integer argument" >&2
show_usage >&2
exit 2
fi
if ! [[ "$2" =~ ^[1-9][0-9]*$ ]]; then
echo "error: invalid interval '$2'; expected a positive integer" >&2
show_usage >&2
exit 2
fi
INTERVAL="$2"
shift
;;

Copilot uses AI. Check for mistakes.
Comment thread _in progress/gh-ratelimit
# Header
local user host now
user=$(gh api user --jq .login 2>/dev/null || echo '?')
host=$(gh auth status 2>&1 | awk -F'[ ()]+' '/Logged in to/{print $5; exit}' || echo 'github.com')
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

Host parsing from gh auth status is using awk ... {print $5}, which (with the common output Logged in to github.com as <user> (...)) will print as instead of the hostname. Adjust the parsing to reliably extract the hostname (e.g., the token after to), or use a less brittle approach than fixed field numbers.

Suggested change
host=$(gh auth status 2>&1 | awk -F'[ ()]+' '/Logged in to/{print $5; exit}' || echo 'github.com')
host=$(gh auth status 2>&1 | awk -F'[ ()]+' '/Logged in to/ { for (i = 1; i < NF; i++) if ($i == "to") { print $(i + 1); exit } }' || echo 'github.com')

Copilot uses AI. Check for mistakes.
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.

2 participants