From 3294119adcc81a3eed4973279054616cf0e0ae97 Mon Sep 17 00:00:00 2001 From: Neil Horman Date: Mon, 15 Apr 2024 09:48:21 -0400 Subject: [PATCH 1/3] Migrate ghmerge from using python to jq jq is a nice handy tool to do json parsing, use it instead of python --- review-tools/ghmerge | 54 ++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/review-tools/ghmerge b/review-tools/ghmerge index 134e0c2..b9e36c7 100755 --- a/review-tools/ghmerge +++ b/review-tools/ghmerge @@ -29,8 +29,19 @@ Examples: exit 9 } +function check_tools { + which jq >/dev/null 2>&1 + if [ $? -ne 0 ] + then + >&2 echo "You must install the jq utility for ghmerge to work" + exit 1 + fi +} + set -o errexit +check_tools + WHAT="" PICK=no INTERACTIVE=yes @@ -153,12 +164,9 @@ if ! wget --quiet $PR_URL -O $PR_URL_CONTENTS; then echo "Error getting $PR_URL" exit 1 fi -set -- `python3 -c ' -from __future__ import print_function -import json, sys; -input = json.load(sys.stdin) -print(str(input["head"]["label"]).replace(":", " "), - str(input["head"]["repo"]["ssh_url"]))' <$PR_URL_CONTENTS` + +set -- $(jq -r '[.head.user.login, .head.ref, .head.repo.ssh_url] | join(" ")' $PR_URL_CONTENTS) + WHO=$1 BRANCH=$2 REPO=$3 @@ -168,30 +176,22 @@ if [ -z "$WHO" -o -z "$BRANCH" -o -z "$REPO" ]; then exit 1 fi -REPO_CHECK=$(python3 -c ' -from __future__ import print_function -import json, sys -rtm_set=0 -urgent_set=0 -input = json.load(sys.stdin) -# Dont do this check if its not for the openssl repo -if (input["base"]["repo"]["name"] != "openssl"): - sys.exit(0) -for l in input["labels"]: - if (l["name"] == "approval: ready to merge"): - rtm_set=1 - if (l["name"] == "severity: urgent"): - urgent_set=1 -if (rtm_set == 0 and urgent_set == 0): - print("Not ready to merge") -' <$PR_URL_CONTENTS) - -if [ "$REPO_CHECK" == "Not ready to merge" ] +TARGET_REPO=$(jq -r '.base.repo.name' $PR_URL_CONTENTS) +RTM_LABEL=$(jq -r '.labels[] | select(.name == "approval: ready to merge") | .name' $PR_URL_CONTENTS) +URGENT_LABEL=$(jq -r '.labels[] | select(.name == "severity: urgent") | .name' $PR_URL_CONTENTS) + +if [ "$TARGET_REPO" == "openssl" ] then - >&2 echo "This pr has neither the urgent or ready to merge flag set, Won't merge" - exit 1 + if [ -z "$RTM_LABEL" -a -z "$URGENT_LABEL" ] + then + >&2 echo "This PR has neither the ready to merge or urgent label set, can't merge" + exit 1 + fi +else + >&2 echo "Skipping ready to merge check for non-openssl repo" fi + ORIG_REF=`git rev-parse --abbrev-ref HEAD` # usually this will be 'master' STASH_OUT=`git stash` WORK="copy-of-${WHO}-${BRANCH}" From e76812094d856c4b709fe6e69c65095a874b0b62 Mon Sep 17 00:00:00 2001 From: Neil Horman Date: Mon, 15 Apr 2024 11:40:11 -0400 Subject: [PATCH 2/3] fixup! Migrate ghmerge from using python to jq --- review-tools/ghmerge | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/review-tools/ghmerge b/review-tools/ghmerge index b9e36c7..66bd7b5 100755 --- a/review-tools/ghmerge +++ b/review-tools/ghmerge @@ -30,7 +30,7 @@ Examples: } function check_tools { - which jq >/dev/null 2>&1 + command -v jq >/dev/null 2>&1 if [ $? -ne 0 ] then >&2 echo "You must install the jq utility for ghmerge to work" From 91a438b46c6ebfbbed27c4164b3dc55bdfeab71e Mon Sep 17 00:00:00 2001 From: Neil Horman Date: Sat, 18 May 2024 16:59:54 -0400 Subject: [PATCH 3/3] fixup! fixup! Migrate ghmerge from using python to jq --- review-tools/ghmerge | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/review-tools/ghmerge b/review-tools/ghmerge index 66bd7b5..20f9532 100755 --- a/review-tools/ghmerge +++ b/review-tools/ghmerge @@ -180,15 +180,13 @@ TARGET_REPO=$(jq -r '.base.repo.name' $PR_URL_CONTENTS) RTM_LABEL=$(jq -r '.labels[] | select(.name == "approval: ready to merge") | .name' $PR_URL_CONTENTS) URGENT_LABEL=$(jq -r '.labels[] | select(.name == "severity: urgent") | .name' $PR_URL_CONTENTS) -if [ "$TARGET_REPO" == "openssl" ] +if [ "$TARGET_REPO" != "openssl" ] then - if [ -z "$RTM_LABEL" -a -z "$URGENT_LABEL" ] - then - >&2 echo "This PR has neither the ready to merge or urgent label set, can't merge" - exit 1 - fi -else >&2 echo "Skipping ready to merge check for non-openssl repo" +elif [ -z "$RTM_LABEL" -a -z "$URGENT_LABEL" ] +then + >&2 echo "This PR has neither the ready to merge or urgent label set, can't merge" + exit 1 fi