Created
February 13, 2026 19:36
-
-
Save peetzweg/0195895bb747d960165f95d66ffd4c08 to your computer and use it in GitHub Desktop.
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
| #!/bin/bash | |
| # GitHub CLI Rate Limiting Function | |
| # | |
| # Purpose: Prevent GitHub spam detection by adding delays to gh commands | |
| # | |
| # Background: GitHub's abuse detection system flags accounts that perform | |
| # rapid automated actions (e.g., creating multiple issues in a short time). | |
| # This function adds appropriate delays based on operation risk level. | |
| # | |
| # Usage: Add this function to your ~/.bashrc or ~/.zshrc | |
| # | |
| # Delay Tiers: | |
| # - High-risk (10-30s): Create/edit/delete operations that modify data | |
| # - Normal (3-5s): Standard CLI operations (list, status, etc.) | |
| # - Low-risk (1-2s): Read-only view operations | |
| # | |
| # Author: Generated for preventing GitHub spam detection | |
| # License: Public Domain / Unlicense | |
| gh() { | |
| local delay | |
| # High-risk operations: creates, edits, deletes (10-30 seconds) | |
| if [[ "$1" == "issue" && "$2" =~ ^(create|edit|delete|close|reopen)$ ]] || \ | |
| [[ "$1" == "pr" && "$2" =~ ^(create|edit|close|merge|ready|draft)$ ]] || \ | |
| [[ "$1" == "label" && "$2" =~ ^(create|edit|delete)$ ]] || \ | |
| [[ "$1" == "project" && "$2" == "item-create" ]] || \ | |
| [[ "$1" == "release" && "$2" == "create" ]]; then | |
| delay=$((10 + RANDOM % 21)) # Random 10-30 seconds | |
| echo "⚠️ High-risk operation detected: ${delay}s delay to avoid spam detection..." >&2 | |
| # Low-risk operations: viewing (read-only) (1-2 seconds) | |
| elif [[ "$1" == "issue" && "$2" == "view" ]] || \ | |
| [[ "$1" == "pr" && "$2" == "view" ]] || \ | |
| [[ "$1" == "repo" && "$2" == "view" ]] || \ | |
| [[ "$1" == "release" && "$2" == "view" ]]; then | |
| delay=$((1 + RANDOM % 2)) # Random 1-2 seconds | |
| # Normal operations: everything else (3-5 seconds) | |
| else | |
| delay=$((3 + RANDOM % 3)) # Random 3-5 seconds | |
| fi | |
| sleep $delay | |
| command gh "$@" | |
| } | |
| # To use: source this file or add it to your shell rc file | |
| # Example: echo "source ~/gh-rate-limit.sh" >> ~/.bashrc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment