Skip to content

Commit 61eacf1

Browse files
authored
Use git tags when GitHub API returns an empty list of releases (#681)
1 parent f18841c commit 61eacf1

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

.evergreen/mongosh_dl.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,25 @@ def _get_latest_version():
4545
req = urllib.request.Request(url, headers=headers)
4646
try:
4747
resp = urllib.request.urlopen(req, context=SSL_CONTEXT, timeout=30)
48+
raw = resp.read().decode("utf-8")
49+
data = json.loads(raw)
50+
if not data:
51+
LOGGER.debug("Releases (raw): %s", raw)
52+
raise RuntimeError("List of releases is empty")
53+
for item in data:
54+
if item["prerelease"]:
55+
continue
56+
if item.get("draft"):
57+
continue
58+
return item["tag_name"].replace("v", "").strip()
59+
raise RuntimeError(f"Could not find tag name in releases: {data}")
4860
except Exception as e:
4961
LOGGER.warning(
5062
"Error fetching the latest version, falling back to using git tags"
5163
)
5264
LOGGER.warning(str(e))
5365
return _get_latest_version_git()
5466

55-
data = json.loads(resp.read().decode("utf-8"))
56-
for item in data:
57-
if item["prerelease"]:
58-
continue
59-
if item.get("draft"):
60-
continue
61-
return item["tag_name"].replace("v", "").strip()
62-
6367

6468
def _get_latest_version_git():
6569
with tempfile.TemporaryDirectory() as td:

0 commit comments

Comments
 (0)