Skip to content

Instantly share code, notes, and snippets.

@alessbell
Last active July 16, 2024 20:50
Show Gist options
  • Save alessbell/f614f350db0cc4b4c7566ffd3d4f75ef to your computer and use it in GitHub Desktop.
Save alessbell/f614f350db0cc4b4c7566ffd3d4f75ef to your computer and use it in GitHub Desktop.
list review requests and checkout PRs via gh cli + fzf
function ghrv() {
PR_NUMBER_AND_REPO=`
gh search prs --state=open --review-requested=@me \
--json author,authorAssociation,number,repository,title,updatedAt \
--template '{{range .}}{{tablerow .number .repository.nameWithOwner .title .author.name .authorAssociation (timeago .updatedAt)}}{{end}}' \
-- -author:"svc-secops" -author:"app/renovate" -author:"app/github-actions" -author:"app/dependabot" |
fzf --height 25% --reverse |
cut -d' ' -f1-6 |
sed 's/ */:/g' |
awk '{$1=$1;print}'
`
PR_NUMBER=$(echo $PR_NUMBER_AND_REPO | cut -d : -f 1)
REPOSITORY_WITH_OWNER=$(echo $PR_NUMBER_AND_REPO | cut -d : -f 2)
REPOSITORY="${REPOSITORY_WITH_OWNER#*/}"
# Replace this with a directory containing git repositories
CODE_DIR="$HOME/Documents"
if [ -d $CODE_DIR/$REPOSITORY ]; then
echo "$CODE_DIR/$REPOSITORY exists, checking out branch..."
else
echo "$CODE_DIR/$REPOSITORY does not exist, cloning repo and checking out branch..."
cd $CODE_DIR
echo $REPOSITORY_WITH_OWNER | xargs gh repo clone
fi
cd $CODE_DIR/$REPOSITORY
echo $PR_NUMBER | xargs gh pr checkout
}
@alessbell
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment