Skip to content

Commit 5996da6

Browse files
committed
fix bug with the first release asset always being fetched
1 parent c09a5a9 commit 5996da6

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

ci/src/updater.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# -*-coding: utf-8 -*-
22
import asyncio
33
import aiohttp
4+
import re
45
from typing import List
5-
from unicodedata import name
66
from os import getenv
77
from sys import argv
88
import traceback
@@ -12,6 +12,11 @@
1212
from _utils import *
1313
from discord import update_hook
1414

15+
github_download_url_regex = re.compile(
16+
r"https://github\.com/(?P<author>[a-zA-Z0-9-]+)/(?P<repo>[a-zA-Z0-9\.\-\_]*)/releases/download/(?P<version>[a-zA-Z\.0-9]+)/(?P<filename>.*)\.zip"
17+
)
18+
19+
1520
async def batch_github_plugin_info(
1621
info: P, tags: ETagsType, github_token=None, webhook_url: str | None = None
1722
) -> P:
@@ -44,11 +49,31 @@ async def batch_github_plugin_info(
4449

4550
if info.get(release_date, "") != latest_rel.get("published_at"):
4651
info[release_date] = latest_rel.get("published_at")
52+
4753
if assets:
48-
info[url_download] = assets[0]["browser_download_url"]
54+
browser_download_url = None
55+
56+
if len(assets) > 1:
57+
match = github_download_url_regex.match(info[url_download])
58+
if not match:
59+
raise ValueError(
60+
f"Download URL did not mach regex: {info[url_download]!r}"
61+
)
62+
filename = f"{match['filename']}.zip"
63+
for asset in assets:
64+
if asset["browser_download_url"].endswith(filename):
65+
browser_download_url = asset["browser_download_url"]
66+
67+
info[url_download] = (
68+
browser_download_url or assets[0]["browser_download_url"]
69+
)
70+
4971
if webhook_url:
5072
await send_notification(
51-
info, clean(latest_rel["tag_name"], "v"), latest_rel, webhook_url
73+
info,
74+
clean(latest_rel["tag_name"], "v"),
75+
latest_rel,
76+
webhook_url,
5277
)
5378
info[version] = clean(latest_rel["tag_name"], "v")
5479

@@ -77,7 +102,6 @@ def remove_unused_etags(plugin_infos: PluginsType, etags: ETagsType) -> ETagsTyp
77102
plugin_ids = [info.get("ID") for info in plugin_infos]
78103

79104
for id, tag in etags.items():
80-
81105
if id not in plugin_ids:
82106
print(
83107
f"Plugin with ID {id} has been removed. The associated ETag will be also removed now."
@@ -94,14 +118,15 @@ async def send_notification(
94118
) -> None:
95119
if not webhook_url:
96120
return
97-
121+
98122
if version_tuple(info[version]) != version_tuple(latest_ver):
99123
tqdm.write(f"Update detected: {info[plugin_name]} {latest_ver}")
100124
try:
101125
await update_hook(webhook_url, info, latest_ver, release)
102126
except Exception as e:
103127
tqdm.write(str(e))
104128

129+
105130
async def main():
106131
webhook_url = None
107132
if len(argv) > 1:

0 commit comments

Comments
 (0)