-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerger.sh
executable file
·137 lines (127 loc) · 2.86 KB
/
merger.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
set -e
## Colours
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;93m'
NC='\033[0m'
function waiting()
{
case $toggle
in
1)
echo -n $1" . "
echo -ne "\r"
toggle="2"
;;
2)
echo -n $1" .. "
echo -ne "\r"
toggle="3"
;;
3)
echo -n $1" ... "
echo -ne "\r"
toggle="4"
;;
*)
echo -ne $1" \r"
toggle="1"
;;
esac
}
if [ -z "$1" ]
then
echo -e "${RED}Please submit a comment...${NC}"
exit 1
fi
COMMENT=$1
BRANCH=develop
while :
do
git status
echo -e "${RED}Would you like to merge the file(s) above?${NC}"
read -p "[Y]es | [N]o | [D]iff: " choice
case "$choice" in
y|Y ) echo -e "${GREEN}Adding and commiting the files...${NC}"
break;;
n|N ) echo -e "${RED}Exiting without changes...${NC}"
exit 0;;
d|D ) echo -e "${GREEN}Showing diff...${NC}"
git diff-index -p HEAD;;
* ) echo -e "${RED}invalid...${NC}";;
esac
done
git add *
git commit -m "${COMMENT}"
git pull --rebase upstream ${BRANCH}
git push origin ${BRANCH}
PULL=$(hub pull-request -m "${COMMENT}" upstream ${BRANCH} | rev | cut -d '/' -f1 | rev)
echo -e "${GREEN}Pull request: ${PULL}${NC}"
ghi show ${PULL}
end=$((SECONDS+60))
echo -e ${YELLOW}
while [ $SECONDS -lt $end ]; do
waiting "Waiting for jenkins"
sleep 0.3
done
echo -e "${NC}"
while :
do
ghi show ${PULL}
echo -e "${RED}What would you like to do?${NC}"
read -p "[M]erge | [R]etest | [F]ix | [C]lose | [O]pen in browser: " choice
case "$choice" in
m|M )
echo -e "${GREEN}Merging...${NC}"
ghi comment -m 'ok to merge' ${PULL}
break
;;
r|R )
echo -e "${GREEN}Retesting...${NC}"
ghi comment -m 'retest this please' ${PULL}
ghi show ${PULL}
end=$((SECONDS+45))
echo -e ${YELLOW}
while [ $SECONDS -lt $end ]; do
waiting "Waiting for jenkins"
sleep 0.3
done
echo -e "${NC}"
;;
c|C )
echo -e "${GREEN}Closing...${NC}"
ghi close ${PULL}
break
;;
f|F )
CHANAGES=$(git diff-index --name-only HEAD)
if [[ -n $CHANAGES ]]; then
echo -e "${GREEN}Applying changes to...${NC}"
git diff-index --name-only HEAD
git add *
git commit -m "${COMMENT}"
git pull --rebase upstream ${BRANCH}
git push origin ${BRANCH}
fi
echo -e "${RED}No changes to apply...${NC}"
;;
o|O )
echo -e "${GREEN}Opening pull request in browser...${NC}"
ghi show -w ${PULL}
echo -e "${GREEN}Exiting...${NC}"
exit 0
;;
* ) echo -e "${RED}invalid...${NC}";;
esac
done
ghi show ${PULL}
end=$((SECONDS+45))
echo -e ${YELLOW}
while [ $SECONDS -lt $end ]; do
waiting "Waiting for jenkins"
sleep 0.3
done
echo -e "${NC}"
ghi show ${PULL}
echo -e "${GREEN}done ${YELLOW}:D ${GREEN}have a lovely day!!${NC}"