Skip to content

Commit

Permalink
use one method to get info from openVSX
Browse files Browse the repository at this point in the history
Signed-off-by: Valeriy Svydenko <[email protected]>
  • Loading branch information
svor committed Sep 12, 2023
1 parent d010563 commit 221b863
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions build/dockerfiles/import-vsix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 221b863

Please sign in to comment.