From 5e88a6277b40a8bbd65b74fe3c40159cb8ca2cb1 Mon Sep 17 00:00:00 2001 From: Yasin Date: Thu, 9 May 2024 00:04:07 +0200 Subject: fix possible translate webhook problem shortens the description to a length of less than 4096 characters --- .github/workflows/webhook_translate.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to '.github/workflows') diff --git a/.github/workflows/webhook_translate.yml b/.github/workflows/webhook_translate.yml index 85ed7c3c..9826110c 100644 --- a/.github/workflows/webhook_translate.yml +++ b/.github/workflows/webhook_translate.yml @@ -34,6 +34,37 @@ jobs: shell: bash run: | OUTPUT=$(go run github.com/josephburnett/jd@latest <(git show HEAD^:src/main/resources/assets/skyblocker/lang/en_us.json) <(git show HEAD:src/main/resources/assets/skyblocker/lang/en_us.json) || true) + + MAX_LENGTH=4070 + + if [ "${#OUTPUT}" -gt "$MAX_LENGTH" ]; then + + OUTPUT="${OUTPUT:0:$MAX_LENGTH}" + + LAST_INDEX=-1 + for (( i=${#OUTPUT}-1; i>=0; i-- )); do + if [[ "${OUTPUT:$i:1}" =~ [-+@] ]]; then + LAST_INDEX=$i + break + fi + done + + if [[ $LAST_INDEX -ne -1 && "${OUTPUT:$LAST_INDEX:1}" =~ [-+] ]]; then + + for (( i=LAST_INDEX-1; i>=0; i-- )); do + if [[ "${OUTPUT:$i:1}" == "@" ]]; then + OUTPUT="${OUTPUT:0:i}" + break + fi + done + else + + OUTPUT="${OUTPUT:0:LAST_INDEX}" + fi + fi + + OUTPUT+="..." + OUTPUT="\`\`\`diff $OUTPUT \`\`\`" -- cgit