-
Notifications
You must be signed in to change notification settings - Fork 1
/
c4pr.sh
executable file
·61 lines (54 loc) · 1.96 KB
/
c4pr.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/sh
if [ "$#" -ne 2 ] || [ "$1" == "help" ]
then
echo "Checkout upstream pull request onto new local fork and push to remote"
echo
echo "usage: $0 PR# new-branch-name";
echo
echo "e.g."
echo
echo "$ $0 123 fix-foo"
exit 1
fi
if [ ! -f ".c4.yml" ]; then
echo "fatal: not at the root of a c4 repository (.c4.yml not found)"
exit 1
fi
function parse_yaml {
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\):|\1|" \
-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
if (length($3) > 0) {
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
}
}'
}
eval $(parse_yaml .c4.yml)
git pull upstream pull/$1/head:$2
git checkout $2
git fetch upstream
git merge upstream/$upstream_branch
if [ $? -ne 0 ]; then
git merge --abort
echo "Merge failed and aborted."
echo "*********************************************************************************"
echo "* Here's a link to the source PR:"
echo "* $forge/$upstream_owner/$upstream_repository/pull/$1"
echo "*********************************************************************************"
exit 1
fi
git push origin $2
echo "*********************************************************************************"
echo "* Here's a better link to create a PR:"
echo "* $forge/$c4_owner/$c4_repository/compare/$c4_branch...$forge_user:$2"
echo "*********************************************************************************"
echo "* And a link to the source PR ( UpstreamPR$1 ):"
echo "* $forge/$upstream_owner/$upstream_repository/pull/$1"
echo "*********************************************************************************"