Skip to content

Commit 327b3da

Browse files
authored
fix: handle paging when fetching versions for import-vsix.sh (#2102)
Assisted-by: Claude Sonnet 4.5 Signed-off-by: Mykhailo Kuznietsov <mkuznets@redhat.com>
1 parent 2e18b24 commit 327b3da

1 file changed

Lines changed: 39 additions & 6 deletions

File tree

build/dockerfiles/import-vsix.sh

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,21 @@ getMetadata(){
5555
done
5656
}
5757

58-
versionsPage=""
58+
allVersions=""
5959
getVersions(){
6060
vsixName=$1
61-
# check the versions page is empty and retry if it is
61+
local totalSize=-1
62+
local offset=0
63+
local apiResponse=""
64+
65+
# Initialize allVersions for this call
66+
allVersions="{}"
67+
68+
# Fetch first page to get totalSize
6269
for j in 1 2 3 4 5
6370
do
64-
versionsPage=$(curl -sLS "https://open-vsx.org/api/${vsixName}/versions?size=600")
65-
totalSize=$(echo "${versionsPage}" | jq -r ".totalSize")
71+
apiResponse=$(curl -sLS "https://open-vsx.org/api/${vsixName}/versions?size=100&offset=0")
72+
totalSize=$(echo "${apiResponse}" | jq -r ".totalSize")
6673
if [[ "$totalSize" != "null" && "$totalSize" -eq 0 ]]; then
6774
echo "Attempt $j/5: Error while getting versions for ${vsixName}"
6875

@@ -75,6 +82,33 @@ getVersions(){
7582
break
7683
fi
7784
done
85+
86+
# Merge first page versions
87+
allVersions=$(echo "$allVersions $(echo "${apiResponse}" | jq -r '.versions')" | jq -s '.[0] * .[1]')
88+
offset=100
89+
90+
# Fetch remaining pages if needed
91+
while [[ $offset -lt $totalSize ]]; do
92+
for j in 1 2 3 4 5
93+
do
94+
local versions
95+
apiResponse=$(curl -sLS "https://open-vsx.org/api/${vsixName}/versions?size=100&offset=${offset}")
96+
versions=$(echo "${apiResponse}" | jq -r ".versions")
97+
if [[ "$versions" != "null" ]]; then
98+
# Merge current page versions
99+
allVersions=$(echo "$allVersions $versions" | jq -s '.[0] * .[1]')
100+
break
101+
else
102+
echo "Attempt $j/5: Error while getting versions for ${vsixName} at offset ${offset}"
103+
if [[ $j -eq 5 ]]; then
104+
echo "[ERROR] Maximum of 5 attempts reached - must exit!"
105+
exit 1
106+
fi
107+
continue
108+
fi
109+
done
110+
offset=$((offset + 100))
111+
done
78112
}
79113

80114
# pull vsix from OpenVSX
@@ -121,8 +155,7 @@ for i in $(seq 0 "$((numberOfExtensions - 1))"); do
121155
getMetadata "${vsixName}" "latest"
122156
getVersions "${vsixName}"
123157
# if version wasn't set in json, grab it from metadata and add it into the file
124-
# get all versions of the extension
125-
allVersions=$(echo "${versionsPage}" | jq -r '.versions')
158+
# get all versions of the extension (allVersions is set by getVersions)
126159
if [[ "$allVersions" == "{}" ]]; then
127160
echo "No versions found for ${vsixName}"
128161
exit 1

0 commit comments

Comments
 (0)