Last active
March 23, 2024 14:39
-
-
Save sixlive/18ca695cf8fdc6426ed7ff0d461eb124 to your computer and use it in GitHub Desktop.
An interactive way to search pull requests and check them out
This file contains 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 -uoe pipefail | |
SCRIPT_NAME="$(basename "$0")" | |
_verify_dependencies() { | |
_p_err() { | |
printf "[$SCRIPT_NAME] \033[31m%s\033[0m\n" "$1" | |
} | |
if ! command -v gh &>/dev/null; then | |
_p_err "Github CLI must be installed!" | |
_p_err "See: https://cli.github.com" | |
exit 1 | |
fi | |
if ! command -v gum &>/dev/null; then | |
_p_err "charmbracelet/gum must be installed!" | |
_p_err "See: https://github.com/charmbracelet/gum" | |
exit 1 | |
fi | |
if ! command -v jq &>/dev/null; then | |
_p_err "jqlang/jq must be installed!" | |
_p_err "See: https://github.com/jqlang/jq" | |
exit 1 | |
fi | |
} | |
main() { | |
_verify_dependencies | |
local appPrs selectedPr prNumber | |
allPrs=$(gh pr list --json number,title,author,headRefName) | |
selectedPr=$(echo $allPrs | jq -r '.[] | "#\(.number) \(.title) | \(.author.login) | \(.headRefName)"' | gum filter) | |
prNumber=$(echo "$selectedPr" | awk '{print $1}') | |
if [ -n "$prNumber" ]; then | |
gh pr checkout $prNumber | |
else | |
echo "No PR selected." | |
fi | |
} | |
main "$@" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment