From 221b8632e54aaf4c4cbf55157ec2f8ba58f65cb7 Mon Sep 17 00:00:00 2001 From: Valeriy Svydenko Date: Tue, 12 Sep 2023 13:52:00 +0300 Subject: [PATCH] use one method to get info from openVSX Signed-off-by: Valeriy Svydenko --- build/dockerfiles/import-vsix.sh | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/build/dockerfiles/import-vsix.sh b/build/dockerfiles/import-vsix.sh index 5134b47fa0..c255f72473 100755 --- a/build/dockerfiles/import-vsix.sh +++ b/build/dockerfiles/import-vsix.sh @@ -26,24 +26,32 @@ export OVSX_PAT=eclipse_che_token containsElement () { for e in "${@:2}"; do [[ "$e" = "$1" ]] && return 0; done; return 1; } -vsixMetadata="" #now global so it can be set/checked via function -getMetadata(){ +function getOpenVSXData(){ vsixName=$1 key=$2 + parameters=$3 + + # build the request url + if [[ -n "$parameters" ]]; then + url="https://open-vsx.org/api/${vsixName}/${key}?${parameters}" + else + url="https://open-vsx.org/api/${vsixName}/${key}" + fi # check there is no error field in the metadata and retry if there is for j in 1 2 3 4 5 do - vsixMetadata=$(curl -sLS "https://open-vsx.org/api/${vsixName}/${key}") - if [[ $(echo "${vsixMetadata}" | jq -r ".error") != null ]]; then - echo "Attempt $j/5: Error while getting metadata for ${vsixName} version ${key}" + result=$(curl -sLS "${url}") + if [[ $(echo "${result}" | jq -r ".error") != null ]]; then + echo "Attempt $j/5: Error while getting metadata for ${vsixFullName} version ${key}" if [[ $j -eq 5 ]]; then - echo "[ERROR] Maximum of 5 attempts reached - must exit!" + echo "[ERROR] Maximum of 5 attempts reached - must exit with failure!" exit 1 fi continue else + echo "$result" break fi done @@ -90,18 +98,22 @@ for i in $(seq 0 "$((numberOfExtensions - 1))"); do # grab metadata for the vsix file # if version wasn't set, use latest if [[ $vsixVersion == null ]]; then - getMetadata "${vsixName}" "latest" - versionsPage=$(curl -sLS "https://open-vsx.org/api/${vsixName}/versions?size=500") + vsixMetadata=$(getOpenVSXData "${vsixName}" "latest") + versionsPage=$(getOpenVSXData "${vsixName}" "versions" "size=200") # if version wasn't set in json, grab it from metadata and add it into the file # get all versions of the extension allVersions=$(echo "${versionsPage}" | jq -r '.versions') + if [[ "$allVersions" == "{}" ]]; then + echo "No versions found for ${vsixName}" + exit 1 + fi key_value_pairs=$(echo "$allVersions" | jq -r 'to_entries[] | [ .key, .value ] | @tsv') # go through all versions of the extension to find the latest stable version that is compatible with the VS Code version resultedVersion=null while IFS=$'\t' read -r key value; do # get metadata for the version - getMetadata "${vsixName}" "${key}" + vsixMetadata=$(getOpenVSXData "${vsixName}" "${key}") # check if the version is pre-release preRelease=$(echo "${vsixMetadata}" | jq -r '.preRelease') @@ -137,7 +149,7 @@ for i in $(seq 0 "$((numberOfExtensions - 1))"); do vsixVersion=$resultedVersion fi else - getMetadata "${vsixName}" "${vsixVersion}" + vsixMetadata=$(getOpenVSXData "${vsixName}" "${vsixVersion}") fi # extract the download link from the json metadata