-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgit-push-pr
executable file
·106 lines (87 loc) · 2.32 KB
/
git-push-pr
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
#!/usr/bin/env bash
set -e
if [[ -z "$GHTOKEN" ]]; then
echo "No \$GHTOKEN environment variable defined." >&2
exit 1
fi
DEBUG=0
RESET=1
VERBOSE=0
opt=
while getopts 'hdvr' opt; do
case "$opt" in
h)
echo "Usage:"
echo " $0 (-h | --help)"
echo " $0 [-d] [-r] [<DEST_BRANCH>]"
echo ""
echo "Options:"
echo " -v output executed commands"
echo " -d debug mode. imply -v. Do not actually push."
echo " -r do no reset to upsteam"
exit 0
;;
d)
DEBUG=1
;;
v)
VERBOSE=1
;;
r)
RESET=0
;;
?) exit 1
;;
*);;
esac
done
shift $((OPTIND - 1))
if [[ $DEBUG = 1 || $VERBOSE = 1 ]]; then
set -x
fi
REMOTE=$(git remote get-url origin)
HOST=${REMOTE:0:20}
if [[ "${HOST}" != "git@github.com:odoo/" ]]; then
echo "Invalid remote for 'origin'." >&2
exit 1
fi
REPO=${REMOTE:20}
REPO=${REPO%.git}
BRANCH=$(git symbolic-ref --short HEAD)
EEC=$((DEBUG==1 ? 0 : 1))
# ensure we have something to push
git rev-list --count --left-right "@{upstream}...HEAD" | awk "
/0\\t0/ { print \"In sync with ${BRANCH}.\"; exit $EEC }
/0\\t[0-9]+/ { exit 0 }
// { print \"You diverge from ${BRANCH}.\"; exit $EEC }
" >&2
MSG=$(git log -n1 --format=%s)
DT=$(date -j +%y%m%d)
DYNDEVBRANCH="fp-${BRANCH}-${DT}"
DEVBRANCH=${1:-$DYNDEVBRANCH}
HADCONFLICTS=$(git diff-tree --cc --pretty= HEAD | wc -l)
PRIORITY=$((HADCONFLICTS > 0 ? 0 : 1))
if [[ $DEBUG = 1 ]]; then
exit 1
fi
PUSH_ARGS=
if [[ $RESET = 0 ]]; then
git checkout -B "${DEVBRANCH}"
PUSH_ARGS="--set-upsteam"
fi
git push --quiet --force ${PUSH_ARGS} dev "HEAD:${DEVBRANCH}"
if [[ $RESET = 1 ]]; then
git reset --quiet --hard '@{upstream}'
fi
RESP=$(http --json --body --pretty=none "https://api.github.com/repos/odoo/${REPO}/pulls" \
Accept:application/vnd.github.v3+json \
"Authorization:token ${GHTOKEN}" \
title="${MSG}" head="odoo-dev:${DEVBRANCH}" base="${BRANCH}" \
)
PR=$(echo "${RESP}" | jq -r ".number")
http --json --print= --pretty=none "https://api.github.com/repos/odoo/${REPO}/issues/${PR}/comments" \
Accept:application/vnd.github.v3+json \
"Authorization:token ${GHTOKEN}" \
body="robodoo merge review+ priority=$PRIORITY"
URL=$(echo "${RESP}" | jq -r ".html_url")
echo "${URL}"