Last active
July 26, 2023 19:58
-
-
Save jtyr/96aa214ce0719d9e5f1449d11fc1764c to your computer and use it in GitHub Desktop.
GitHub PR waiting
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 | |
# Usage: gh pr create -f && ghwait && gh pr merge -sd | |
function msg() { | |
TYPE="$1" | |
TEXT="$2" | |
EXIT="$3" | |
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $TYPE: $TEXT" | |
if [[ -n $EXIT ]]; then | |
exit "$EXIT" | |
fi | |
} | |
function main() { | |
# Wait for the PR to be created | |
while [[ $(gh pr checks 2>&1 | grep -c 'no pull requests found') -gt 0 ]]; do | |
msg 'I' 'Waiting for PR to be created' | |
sleep 5 | |
done | |
# Wait for the checks to start running | |
while [[ $(gh pr checks 2>&1 | grep -c 'no checks reported') -gt 0 ]]; do | |
msg 'I' 'Waiting for checks to start running' | |
sleep 5 | |
done | |
# Wait for the checks to finish | |
while [[ $(gh pr checks | cut -f2 | grep -c 'pending') -gt 0 ]]; do | |
msg 'I' 'Waiting for checks to finish' | |
sleep 10 | |
done | |
# Check if there is any check that failed | |
if [[ $(gh pr checks | cut -f2 | grep -Pcv '(pass|skipping)') -gt 0 ]]; then | |
msg 'E' 'PR checks failed' 1 | |
fi | |
msg 'I' 'PR can be merged now' | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment