bin/pr-list
#!/usr/bin/env bash
#
# Select a PR with fzf
#
# Copyright 2021, Joe Block <jpb@unixorn.net>
set -o pipefail
if [[ -n "$DEBUG" ]]; then
set -x
fi
function debug() {
if [[ -n "$DEBUG" ]]; then
echo "$@"
fi
}
function fail() {
printf '%s\n' "$1" >&2 ## Send message to stderr. Exclude >&2 if you don't want it that way.
exit "${2-1}" ## Return a code specified by $2 or 1 by default.
}
function has() {
# Check if a command is in $PATH
which "$@" > /dev/null 2>&1
}
if ! has gh; then
fail "Cannot find 'gh' in your PATH"
fi
if ! has jq; then
fail "Cannot find 'jq' in your PATH"
fi
if ! has fzf; then
fail "Cannot find 'fzf' in your PATH"
fi
gh api --paginate 'repos/:owner/:repo/pulls?state=open' | jq -r '.[] | [.number, .user.login, .title] | @tsv' | fzf