Last active
August 16, 2017 14:20
-
-
Save mriehl/2bd60e744f0b3a563b35d961104b27ae to your computer and use it in GitHub Desktop.
push branch and merge it (almost) automatically when CI is green using github API
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
--- | |
files: | |
"/usr/local/bin/fbpush": | |
src: "fbpush.sh" | |
type: LINK |
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 -e -u -o pipefail | |
BRANCH_NAME=${1:? "no branch name specified, usage: $0 <branch>"} | |
command -v hub >/dev/null 2>&1 || { | |
echo "You need to install hub (https://github.com/github/hub) and it must be in your path." | |
exit 1 | |
} | |
MSG="$(git log -1 --pretty=%B)" | |
git checkout -b $BRANCH_NAME | |
git push origin $BRANCH_NAME:$BRANCH_NAME | |
URL=$(hub pull-request -m "$MSG" | tr -d "\n") | |
echo "Pull request at $URL" | |
while true; do | |
sleep 30 | |
CI_STATUS="$(hub ci-status || :)" | |
echo "CI status: $CI_STATUS" | |
[[ "$CI_STATUS" == "success" ]] && { | |
echo "Ok to merge" | |
break | |
} | |
[[ "$CI_STATUS" == "pending" ]] && { | |
echo "Will retry soon" | |
continue | |
} | |
echo "ERROR: don't know how to deal with $CI_STATUS" | |
exit 1 | |
done | |
xdg-open "$URL" | |
echo "I have opened the pull request page. Please click on merge there and delete the remote branch." | |
echo " See https://github.com/github/hub/issues/1483 for context - this can't be automated with hub yet." | |
git checkout master | |
git remote update | |
git branch -d $BRANCH_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment