forked from elmas3/pull-request-practice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge.sh
61 lines (49 loc) · 1.59 KB
/
merge.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#! /bin/bash
# Merge pushes to development branch to stable branch
if [ ! -n $2 ] ; then
echo "Usage: merge.sh <username> <password>"
exit 1;
fi
GIT_USER="$1"
GIT_PASS="$2"
# Label
OWNER=elmas3
REPO=pull-request-practice
# CI で設定される NUMBER を環境変数からとる
NUMBER=1
LABEL=MergeCat
# GITHUB_TOKEN に token をセットしてあるものとする
curl -XPOST \
-d "[\"$LABEL\"]" \
-H 'Accept: application/vnd.github.v3+json' \
-H "Authorization: token $GITHUB_TOKEN" \
https://api.github.com/repos/$OWNER/$REPO/pulls/$NUMBER/labels
# Specify the development branch and stable branch names
FROM_BRANCH="dev"
TO_BRANCH="stable"
# Get the current branch
export PAGER=cat
CURRENT_BRANCH=$(git log -n 1 --pretty=%d HEAD | cut -d"," -f3 | cut -d" " -f2 | cut -d")" -f1)
echo "current branch is '$CURRENT_BRANCH'"
# Create the URL to push merge to
URL=$(git remote -v | head -n1 | cut -f2 | cut -d" " -f1)
echo "Repo url is $URL"
PUSH_URL="https://$GIT_USER:$GIT_PASS@${URL:6}"
if [ "$CURRENT_BRANCH" = "$FROM_BRANCH" ] ; then
# Checkout the dev branch
#git checkout $FROM_BRANCH && \
#echo "Checking out $TO_BRANCH..." && \
# Checkout the latest stable
git fetch origin $TO_BRANCH:$TO_BRANCH && \
git checkout $TO_BRANCH && \
# Merge the dev into latest stable
echo "Merging changes..." && \
git merge $FROM_BRANCH && \
# Push changes back to remote vcs
echo "Pushing changes..." && \
git push $PUSH_URL && \
echo "Merge complete!" || \
echo "Error Occurred. Merge failed"
else
echo "Not on $FROM_BRANCH. Skipping merge"
fi