Created
June 4, 2019 02:51
-
-
Save kittinunf/5cbfaaa3137296c7decc2c97f7ea0aea 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
#!/usr/bin/env bash | |
# fail if any commands fails | |
set -eu | |
# Requirements | |
# - Set GITHUB_TOKEN as environment variable. | |
# - This token must have `repo` permission and authorize kouzoh organization. | |
if [[ $# -ne 2 ]]; then | |
echo "Usage: ./script/merge_branch.sh BASE_BRANCH COMPARE_BRANCH" | |
exit 1 | |
fi | |
function pull-request() { | |
local base=$1 | |
local head=$2 | |
local body=$3 | |
local title="[CI] Merge $head into $base" | |
curl -H "Authorization: token $GITHUB_TOKEN" \ | |
-X POST \ | |
-d "{\"title\":\"$title\",\"body\":\"$body\",\"base\":\"$base\",\"head\":\"kouzoh:$head\"}" \ | |
https://api.github.com/repos/kouzoh/merpay-android/pulls | |
} | |
BASE_BRANCH=$1 | |
COMPARE_BRANCH=$2 | |
TMP_BRANCH="ci/${COMPARE_BRANCH}_to_${BASE_BRANCH}" | |
MESSAGE="This pull request is created by ./scripts/merge_branch.sh" | |
git fetch origin | |
git checkout ${COMPARE_BRANCH} | |
git pull --rebase origin ${COMPARE_BRANCH} | |
git checkout ${BASE_BRANCH} | |
git checkout -b ${TMP_BRANCH} | |
git merge --no-ff ${COMPARE_BRANCH} --message "$MESSAGE" | |
git push -u origin ${TMP_BRANCH} | |
pull-request ${BASE_BRANCH} ${TMP_BRANCH} "$MESSAGE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment