Skip to content

Commit

Permalink
Migrate ghmerge from using python to jq
Browse files Browse the repository at this point in the history
jq is a nice handy tool to do json parsing, use it instead of python
  • Loading branch information
nhorman committed Apr 15, 2024
1 parent 8a57945 commit 3294119
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions review-tools/ghmerge
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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}"
Expand Down

0 comments on commit 3294119

Please sign in to comment.