Skip to content

Instantly share code, notes, and snippets.

@jtyr
Last active July 26, 2023 19:58
Show Gist options
  • Save jtyr/96aa214ce0719d9e5f1449d11fc1764c to your computer and use it in GitHub Desktop.
Save jtyr/96aa214ce0719d9e5f1449d11fc1764c to your computer and use it in GitHub Desktop.
GitHub PR waiting
#!/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 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