From 1fd330fa0ec6e69abf33506848cbae19eb0586e4 Mon Sep 17 00:00:00 2001 From: Vladimir Bryzgalov Date: Wed, 22 Apr 2026 00:08:49 +0500 Subject: [PATCH] refactor(release): use pretty download_url from /releases/{id} API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gitea's POST /releases/{id}/assets endpoint returns an internal /attachments/ URL. GET /releases/{id} returns the pretty ///releases/download// URL for the same asset. Both resolve to the same bytes (verified: 207949 for 1.2.0 zip). Pretty URL is preferred: filename is visible in the URL (better for WP admin «View version details» and manual downloads), consistent across Gitea instances (UUID format is git.netranking.ru-specific Postgres attachment storage). Also: switch `echo "$VAR" | jq` to `jq ... <<< "$VAR"` herestring for CREATE_RESPONSE parsing — macOS /bin/echo can interpret backslash-escapes in multi-line JSON bodies and corrupt jq input. wp-plugin-info.json for 1.2.0 patched in-place to use the pretty URL for consistency with future releases. Both URLs continue to work; domработница.рус's next PUC poll will refresh its local transient to the pretty URL (version comparison stays 1.2.0 == 1.2.0, so no update notice). Closes cf7stg-pmf (T20). --- release.sh | 24 +++++++++++++++++++----- wp-plugin-info.json | 2 +- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/release.sh b/release.sh index 3f263e1..af11119 100755 --- a/release.sh +++ b/release.sh @@ -182,7 +182,7 @@ CREATE_RESPONSE="$(curl -fsSL \ -H "Content-Type: application/json" \ -d "$CREATE_PAYLOAD")" -RELEASE_ID="$(echo "$CREATE_RESPONSE" | jq -r '.id')" +RELEASE_ID="$(jq -r '.id' <<< "$CREATE_RESPONSE")" [[ -n "$RELEASE_ID" && "$RELEASE_ID" != "null" ]] \ || fail "Gitea create-release response missing id: $CREATE_RESPONSE" @@ -192,14 +192,28 @@ log "Created Gitea release id=$RELEASE_ID" log "Uploading asset $ZIP_NAME to release id=$RELEASE_ID" -UPLOAD_RESPONSE="$(curl -fsSL \ +curl -fsSL \ -X POST "${GITEA_API}/repos/${REPO_OWNER}/${REPO_NAME}/releases/${RELEASE_ID}/assets?name=${ZIP_NAME}" \ -H "Authorization: token ${TOKEN}" \ - -F "attachment=@${ZIP_PATH};type=application/zip")" + -F "attachment=@${ZIP_PATH};type=application/zip" \ + -o /dev/null + +# Gitea's asset upload response returns an internal /attachments/ URL, +# but the release detail endpoint returns the pretty /releases/download// +# URL for the same asset. Both resolve to the same bytes; the pretty URL is +# preferred for readability and WP-admin UX. +RELEASE_DETAIL="$(curl -fsSL \ + "${GITEA_API}/repos/${REPO_OWNER}/${REPO_NAME}/releases/${RELEASE_ID}" \ + -H "Authorization: token ${TOKEN}")" + +# Use herestring instead of `echo | jq`: `echo` on macOS may interpret +# backslash-escapes in a multi-line release body, corrupting the JSON. +DOWNLOAD_URL="$(jq -r --arg name "$ZIP_NAME" \ + '.assets[] | select(.name == $name) | .browser_download_url' \ + <<< "$RELEASE_DETAIL" | head -n 1)" -DOWNLOAD_URL="$(echo "$UPLOAD_RESPONSE" | jq -r '.browser_download_url')" [[ -n "$DOWNLOAD_URL" && "$DOWNLOAD_URL" != "null" ]] \ - || fail "Gitea asset upload response missing browser_download_url: $UPLOAD_RESPONSE" + || fail "release $RELEASE_ID has no asset named $ZIP_NAME" log "Asset uploaded: $DOWNLOAD_URL" diff --git a/wp-plugin-info.json b/wp-plugin-info.json index 9e2fdbd..ab5ab78 100644 --- a/wp-plugin-info.json +++ b/wp-plugin-info.json @@ -2,7 +2,7 @@ "name": "CF7 Spam → Telegram", "slug": "cf7-spam-to-telegram", "version": "1.2.0", - "download_url": "https://git.netranking.ru/attachments/a04cdb20-7e80-4703-8c30-1000e5945e8b", + "download_url": "https://git.netranking.ru/bryzgalov/cf7-spam-to-telegram/releases/download/v1.2.0/cf7-spam-to-telegram-1.2.0.zip", "homepage": "https://git.netranking.ru/bryzgalov/cf7-spam-to-telegram", "requires": "6.0", "tested": "6.9",