Created
September 20, 2016 17:12
-
-
Save iilyak/65405673cfbb6ea53b77796a65f0bd48 to your computer and use it in GitHub Desktop.
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
set -e | |
function pr_label { | |
REPO_URL=${1} | |
PR=${2} | |
REPO=${REPO_URL##https://github.com/} | |
echo `curl -s https://api.github.com/repos/${REPO}/pulls/${PR} \ | |
| jq .head.label | tr -d '"'` | |
} | |
if [ $# == 1 ]; then | |
PR=${1##*/} | |
REPO_URL=${1%%/pull/${PR}} | |
elif [ $# == 2 ]; then | |
REPO_URL=$1 | |
PR=$2 | |
else | |
echo "usage: $0 <repo_url> <pr_number>" | |
echo "OR" | |
echo "usage: $0 <pr_url>" | |
exit 1 | |
fi | |
REPO_BASE=${REPO_URL%.git} | |
PROJECT=${REPO_BASE##*/} | |
ASF_REPO_URL=https://git-wip-us.apache.org/repos/asf/${PROJECT}.git | |
WORKING_DIR=`mktemp -d` | |
CUR_DIR=`pwd` | |
USER_NAME=`git config user.name` | |
USER_EMAIL=`git config user.email` | |
ME="${USER_NAME} <${USER_EMAIL}>" | |
echo $PROJECT | |
cd ${WORKING_DIR} | |
git init | |
git remote add github ${REPO_URL} | |
git remote add asf ${ASF_REPO_URL} | |
git fetch github master | |
git fetch github pull/${PR}/head:github/pr/${PR} | |
git checkout master | |
if [ `git merge-base master github/pr/${PR}` != `git rev-parse HEAD` ]; then | |
echo "The master branch is updated. Please rebase before the merge" | |
cd ${CUR_DIR} | |
rm -rf ${WORKING_DIR} | |
exit 1 | |
fi | |
LABEL=$(pr_label $REPO_URL $PR) | |
echo "============== CHANGES ===========================" | |
echo $(git rev-parse github/pr/${PR})$'\t\t'"github/pr/${PR}" | git fmt-merge-msg --log=5 | |
echo "==================================================" | |
git merge --no-ff --no-edit github/pr/${PR} | |
cat <<EOF | git commit --amend --file - | |
Merge remote branch '${LABEL}' | |
This closes #${PR} | |
Signed-off-by: ${ME} | |
EOF | |
git show | |
echo "The merged PR for ${PROJECT} is in ${WORKING_DIR}" | |
cd ${CUR_DIR} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment