Skip to content

Commit 424fabe

Browse files
committed
Migrate ghmerge from using python to jq
jq is a nice handy tool to do json parsing, use it instead of python Reviewed-by: Saša Nedvědický <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Richard Levitte <[email protected]> Reviewed-by: Paul Dale <[email protected]> (Merged from #192)
1 parent 78d053b commit 424fabe

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

review-tools/ghmerge

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,20 @@ Examples:
3030
ghmerge --nobuild --target openssl-3.0 --cherry-pick 3 16051 paulidale"
3131
exit 9
3232
}
33+
34+
function check_tools {
35+
command -v jq >/dev/null 2>&1
36+
if [ $? -ne 0 ]
37+
then
38+
>&2 echo "You must install the jq utility for ghmerge to work"
39+
exit 1
40+
fi
41+
}
42+
3343
set -o errexit
3444

45+
check_tools
46+
3547
WHAT=""
3648
PICK=no
3749
INTERACTIVE=yes
@@ -160,12 +172,9 @@ if ! wget --quiet $PR_URL -O $PR_URL_CONTENTS; then
160172
echo "Error getting $PR_URL"
161173
exit 1
162174
fi
163-
set -- `python3 -c '
164-
from __future__ import print_function
165-
import json, sys;
166-
input = json.load(sys.stdin)
167-
print(str(input["head"]["label"]).replace(":", " "),
168-
str(input["head"]["repo"]["ssh_url"]))' <$PR_URL_CONTENTS`
175+
176+
set -- $(jq -r '[.head.user.login, .head.ref, .head.repo.ssh_url] | join(" ")' $PR_URL_CONTENTS)
177+
169178
WHO=$1
170179
BRANCH=$2
171180
REPO=$3
@@ -175,30 +184,20 @@ if [ -z "$WHO" -o -z "$BRANCH" -o -z "$REPO" ]; then
175184
exit 1
176185
fi
177186

178-
REPO_CHECK=$(python3 -c '
179-
from __future__ import print_function
180-
import json, sys
181-
rtm_set=0
182-
urgent_set=0
183-
input = json.load(sys.stdin)
184-
# Dont do this check if its not for the openssl repo
185-
if (input["base"]["repo"]["name"] != "openssl"):
186-
sys.exit(0)
187-
for l in input["labels"]:
188-
if (l["name"] == "approval: ready to merge"):
189-
rtm_set=1
190-
if (l["name"] == "severity: urgent"):
191-
urgent_set=1
192-
if (rtm_set == 0 and urgent_set == 0):
193-
print("Not ready to merge")
194-
' <$PR_URL_CONTENTS)
195-
196-
if [ "$REPO_CHECK" == "Not ready to merge" ]
187+
TARGET_REPO=$(jq -r '.base.repo.name' $PR_URL_CONTENTS)
188+
RTM_LABEL=$(jq -r '.labels[] | select(.name == "approval: ready to merge") | .name' $PR_URL_CONTENTS)
189+
URGENT_LABEL=$(jq -r '.labels[] | select(.name == "severity: urgent") | .name' $PR_URL_CONTENTS)
190+
191+
if [ "$TARGET_REPO" != "openssl" ]
197192
then
198-
>&2 echo "This pr has neither the urgent or ready to merge flag set, Won't merge"
193+
>&2 echo "Skipping ready to merge check for non-openssl repo"
194+
elif [ -z "$RTM_LABEL" -a -z "$URGENT_LABEL" ]
195+
then
196+
>&2 echo "This PR has neither the ready to merge or urgent label set, can't merge"
199197
exit 1
200198
fi
201199

200+
202201
ORIG_REF=`git rev-parse --abbrev-ref HEAD` # usually this will be 'master'
203202
STASH_OUT=`git stash`
204203
WORK="copy-of-${WHO}-${BRANCH}"

0 commit comments

Comments
 (0)