Last active
July 16, 2024 20:50
-
-
Save alessbell/f614f350db0cc4b4c7566ffd3d4f75ef to your computer and use it in GitHub Desktop.
list review requests and checkout PRs via gh cli + fzf
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
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inspired by https://gist.github.com/david-crespo/a4833bf5afcae717fc76e8baa4db2bed!