Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/python-passed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r ./ci/envs/requirements-update-tested.txt
- name: Run script
run: python ./ci/src/update-tested.py
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: python ./ci/src/update-tested.py ${{ secrets.DISCORD_WEBHOOK }}
- name: Update plugin manifest
if: success()
uses: stefanzweifel/git-auto-commit-action@v4
Expand Down
2 changes: 2 additions & 0 deletions ci/envs/requirements-update-tested.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
aiohttp
tqdm
57 changes: 55 additions & 2 deletions ci/src/discord.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import aiohttp

from tqdm.asyncio import tqdm
from _utils import *

MAX_BODY_LEN = 1024


async def update_hook(webhook_url: str, info: dict, latest_ver: str, release: dict) -> None:
async def update_hook(webhook_url: str, info: PluginType, latest_ver: str, release: dict) -> None:
embed = {
"content": None,
"embeds": [
Expand Down Expand Up @@ -43,6 +43,45 @@ async def update_hook(webhook_url: str, info: dict, latest_ver: str, release: di
embed['embeds'][0]['fields'].append({"name": "Release Notes", "value": truncate_release_notes(release['html_url'], release.get('body', ""))})
async with aiohttp.ClientSession() as session:
await session.post(webhook_url, json=embed)

async def release_hook(webhook_url: str, info: PluginType, latest_ver: str, release: dict) -> None:
embed = {
"content": None,
"embeds": [
{
"title": info[plugin_name],
"description": f"New Plugin!\nReleased at v{latest_ver}.",
"url": release['html_url'],
"color": 5763719,
"fields": [
{
"name": "Plugin Description",
"value": info[description]
},
{
"name": "Plugin Language",
"value": info[language_name]
}
],
"author": {
"name": info[author]
},
"thumbnail": {
"url": info[icon_path]
}
}
]
}
if 'github.com' in info[url_sourcecode].lower():
github_username = info[url_sourcecode].split('/')[3]
embed['embeds'][0]['author']['name'] = github_username
embed['embeds'][0]['author']['url'] = f"{github_url}/{github_username}"
embed['embeds'][0]["author"]["icon_url"] = f"{github_url}/{github_username}.png?size=40"
release_notes = release.get('body')
if release_notes and release_notes.strip():
embed['embeds'][0]['fields'].append({"name": "Release Notes", "value": truncate_release_notes(release['html_url'], release.get('body', ""))})
async with aiohttp.ClientSession() as session:
await session.post(webhook_url, json=embed)

def truncate_release_notes(url: str, release_notes: str, length: int = MAX_BODY_LEN) -> str:
if len(release_notes) <= length:
Expand All @@ -59,3 +98,17 @@ def truncate_release_notes(url: str, release_notes: str, length: int = MAX_BODY_
graceful_truncation_index = last_included_newline if last_included_newline != -1 else rough_truncation_index

return release_notes[:graceful_truncation_index] + TRUNCATION_MESSAGE

async def send_notification(
info: PluginType, latest_ver, release, webhook_url: str | None = None, is_release: bool = False
) -> None:
if not webhook_url:
return

if is_release or version_tuple(info[version]) != version_tuple(latest_ver):
tqdm.write(f"Update detected: {info[plugin_name]} {latest_ver}")
hook = release_hook if is_release else update_hook
try:
await hook(webhook_url, info, latest_ver, release)
except Exception as e:
tqdm.write(str(e))
27 changes: 21 additions & 6 deletions ci/src/update-tested.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,38 @@
import json
import os
import zipfile
import io
from datetime import datetime
import io, asyncio, aiohttp
from datetime import datetime, UTC
from sys import argv
from os import getenv
from _utils import clean, id_name, language_list, version, plugin_reader, plugin_writer, release_date, date_added, etag_reader, PluginType, ETagsType
from updater import batch_github_plugin_info
from discord import release_hook

def update_tested():
webhook_url = None
if len(argv) > 1:
webhook_url = argv[1]
github_token = getenv("GITHUB_TOKEN")

from _utils import clean, id_name, language_list, language_name, plugin_reader, plugin_writer, release_date, date_added

if __name__ == "__main__":
plugin_infos = plugin_reader()
etags = etag_reader()

for idx, plugin in enumerate(plugin_infos):
if plugin["Language"] == "python" and "Tested" not in plugin.keys():
plugin_infos[idx]["Tested"] = True
# Add date added if field is not present
if plugin.get(date_added) is None:
plugin_infos[idx][date_added] = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
plugin_infos[idx][date_added] = datetime.now(UTC).strftime("%Y-%m-%dT%H:%M:%SZ")
yield batch_github_plugin_info(plugin, etags, github_token, webhook_url, True)

plugin_writer(plugin_infos)

async def main():
await asyncio.gather(*update_tested())

if __name__ == '__main__':
asyncio.run(main())



Expand Down
28 changes: 8 additions & 20 deletions ci/src/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
from tqdm.asyncio import tqdm

from _utils import *
from discord import update_hook

from discord import send_notification

async def batch_github_plugin_info(
info: P, tags: ETagsType, github_token=None, webhook_url: str = None
info: P, tags: ETagsType, github_token=None, webhook_url: str | None = None, is_release_noti: bool = False
) -> P:
try:
headers = {"authorization": f"token {github_token}"}
Expand Down Expand Up @@ -47,9 +46,10 @@ async def batch_github_plugin_info(
info[release_date] = latest_rel.get("published_at")
if assets:
info[url_download] = assets[0]["browser_download_url"]
await send_notification(
info, clean(latest_rel["tag_name"], "v"), latest_rel, webhook_url
)
if webhook_url:
await send_notification(
info, clean(latest_rel["tag_name"], "v"), latest_rel, webhook_url, is_release_noti
)
info[version] = clean(latest_rel["tag_name"], "v")

tags[info[id_name]] = res.headers.get(etag, "")
Expand All @@ -62,7 +62,7 @@ async def batch_github_plugin_info(


async def batch_plugin_infos(
plugin_infos: Ps, tags: ETagsType, github_token, webhook_url: str = None
plugin_infos: Ps, tags: ETagsType, github_token, webhook_url: str | None = None
) -> Ps:
return await tqdm.gather(
*[
Expand All @@ -72,7 +72,7 @@ async def batch_plugin_infos(
)


def remove_unused_etags(plugin_infos: Ps, etags: ETagsType) -> ETagsType:
def remove_unused_etags(plugin_infos: PluginsType, etags: ETagsType) -> ETagsType:
etags_updated = {}
plugin_ids = [info.get("ID") for info in plugin_infos]

Expand All @@ -88,18 +88,6 @@ def remove_unused_etags(plugin_infos: Ps, etags: ETagsType) -> ETagsType:

return etags_updated


async def send_notification(
info: P, latest_ver, release, webhook_url: str = None
) -> None:
if version_tuple(info[version]) != version_tuple(latest_ver):
tqdm.write(f"Update detected: {info[plugin_name]} {latest_ver}")
try:
await update_hook(webhook_url, info, latest_ver, release)
except Exception as e:
tqdm.write(str(e))


async def main():
webhook_url = None
if len(argv) > 1:
Expand Down