Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion .github/workflows/python-passed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ 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
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
1 change: 1 addition & 0 deletions ci/src/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
github_url = "https://github.com"
release_date = "LatestReleaseDate"
date_added = "DateAdded"
website = "Website"

# typing
PluginType = Dict[str, str]
Expand Down
41 changes: 39 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,43 @@ 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) -> None:
embed = {
"content": None,
"embeds": [
{
"title": info[plugin_name],
"description": f"New Plugin!\nReleased at v{info[version]}.",
"url": info[website],
"color": 5763719, # green
"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"

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 Down
32 changes: 19 additions & 13 deletions ci/src/update-tested.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
import sys
import json
import os
import zipfile
import io
from datetime import datetime
import asyncio
from datetime import datetime, UTC
from sys import argv
from _utils import plugin_reader, plugin_writer, date_added
from discord import release_hook

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

if __name__ == "__main__":
async def update_tested():
webhook_url = None
if len(argv) > 1:
webhook_url = argv[1]

plugin_infos = plugin_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_writer(plugin_infos)



plugin_infos[idx][date_added] = datetime.now(UTC).strftime(
"%Y-%m-%dT%H:%M:%SZ"
)

if webhook_url:
await release_hook(webhook_url, plugin)

plugin_writer(plugin_infos)


if __name__ == "__main__":
asyncio.run(update_tested())
20 changes: 11 additions & 9 deletions ci/src/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
from _utils import *
from discord import update_hook


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
) -> 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
)
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 @@ -90,16 +90,18 @@ def remove_unused_etags(plugin_infos: Ps, etags: ETagsType) -> ETagsType:


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

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