Skip to content

Instantly share code, notes, and snippets.

@nateberkopec
Created August 6, 2025 22:37
Show Gist options
  • Save nateberkopec/900ce988d8c6b2d25d500377e61399bc to your computer and use it in GitHub Desktop.
Save nateberkopec/900ce988d8c6b2d25d500377e61399bc to your computer and use it in GitHub Desktop.
Watch GitHub PR status with audio notifications
#!/bin/bash
set -e
if [ $# -eq 0 ]; then
echo "Usage: gh_watch <github-pr-url>"
echo "Example: gh_watch https://github.com/hyfn/xpo/pull/4974"
exit 1
fi
url="$1"
if [[ ! "$url" =~ github\.com/.+/pull/[0-9]+ ]]; then
echo "Error: Invalid GitHub PR URL format"
echo "Expected format: https://github.com/owner/repo/pull/number"
exit 1
fi
repo_path=$(echo "$url" | sed -n 's|.*github\.com/\([^/]*/[^/]*\)/pull/.*|\1|p')
pr_number=$(echo "$url" | sed -n 's|.*/pull/\([0-9]*\).*|\1|p')
if [ -z "$repo_path" ] || [ -z "$pr_number" ]; then
echo "Error: Could not parse repository and PR number from URL"
exit 1
fi
silent_exit=false
cleanup() {
silent_exit=true
exit 0
}
trap cleanup SIGINT SIGTERM
echo "Watching PR #$pr_number in $repo_path..."
gh pr checks "$pr_number" --repo "$repo_path" --watch
exit_code=$?
if [ "$silent_exit" = false ]; then
if [ $exit_code -eq 0 ]; then
say "Build succeeded for PR $pr_number"
else
say "Build failed for PR $pr_number"
fi
fi
exit $exit_code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment