Skip to content

Instantly share code, notes, and snippets.

@ErikDeBruijn
Last active September 7, 2020 14:31
Show Gist options
  • Save ErikDeBruijn/a3767e448d82349cbf41561625289cf1 to your computer and use it in GitHub Desktop.
Save ErikDeBruijn/a3767e448d82349cbf41561625289cf1 to your computer and use it in GitHub Desktop.
# ZSH functions to quickly make and merge a PR on Github
# Use it from a repository, but set up gh first (`brew install gh && gh`)
# https://gist.github.com/ErikDeBruijn/a3767e448d82349cbf41561625289cf1/
qmerge () {
if [[ "$1" != "NESTED" ]]
then
echo -n Seeing if we can merge it...
fi
SLEEP_SECONDS=5
LAST_OPEN_PR=$(gh pr list --label automerge --state open --limit 1 1>/dev/null |grep OPEN|cut -f1)
if [ -z "$LAST_OPEN_PR" ]
then
echo No open PR labeled \'automerge\' to merge. Retring in $SLEEP_SECONDS seconds...
sleep $SLEEP_SECONDS
$0 NESTED
else
PR_STATUS=$(gh pr status|grep --color=never -A1 $LAST_OPEN_PR)
CHECKS_PASSING=0
echo $PR_STATUS | grep "Checks passing" >/dev/null && CHECKS_PASSING=1
echo $PR_STATUS | grep " failing" && echo Checks failing... && rubocop --auto-correct && rspec && exit 1
if [[ "$CHECKS_PASSING" == "1" ]]
then
echo Tests GREEN\!
gh pr merge -m
git pull
else
echo -n .
sleep $SLEEP_SECONDS
$0 NESTED
fi
fi
}
qpr () {
rubocop --auto-correct 2>&1 > /tmp/rubocop.txt &
if [ -z "$1" ]
then
echo -n "Name your branch (e.g. fixes-this-thing): "
read BRANCH
else
BRANCH=$1
fi
cat /tmp/rubocop.txt
echo "Continue?"
read
stash && git checkout master && git pull && git checkout -b $BRANCH && unstash && \
git add . && git commit && git push && gh pr create -l automerge && \
echo Next up: merging... && sleep 2 && qmerge
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment