Created
February 27, 2026 15:47
-
-
Save wokoman/5d4fd772eae79fa9522e3bc9a5b48b35 to your computer and use it in GitHub Desktop.
Bash script to bulk approve GitHub pull requests matching a search query using gh CLI
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 | |
| set -e | |
| if [ $# -lt 2 ]; then | |
| echo "Usage: $0 <owner/repo> <search-query>" | |
| echo "Example: $0 keboola/kbc-stacks 'is:pr is:open [prod sync] connection@production-d9e9740dd2fbe3e9e182e0707bedc05be6e68418'" | |
| exit 1 | |
| fi | |
| REPO="$1" | |
| QUERY="$2" | |
| echo "Searching for PRs in $REPO with query: $QUERY" | |
| # Search for PRs using gh CLI | |
| PR_NUMBERS=$(gh pr list --repo "$REPO" --search "$QUERY" --json number --jq '.[].number') | |
| if [ -z "$PR_NUMBERS" ]; then | |
| echo "No PRs found matching the query." | |
| exit 0 | |
| fi | |
| echo "Found PRs:" | |
| echo "$PR_NUMBERS" | |
| echo "" | |
| # Count PRs | |
| PR_COUNT=$(echo "$PR_NUMBERS" | wc -l | tr -d ' ') | |
| echo "Total: $PR_COUNT PR(s)" | |
| echo "" | |
| # Approve each PR | |
| for PR in $PR_NUMBERS; do | |
| echo "Approving PR #$PR..." | |
| if gh pr review "$PR" --repo "$REPO" --approve; then | |
| echo "✓ Approved PR #$PR" | |
| else | |
| echo "✗ Failed to approve PR #$PR" | |
| fi | |
| echo "" | |
| done | |
| echo "Done! Approved $PR_COUNT PR(s)." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment