watch: show packages updated but not published yet

parent 7a9e8d8b
from telegrinder.tools.formatting import HTMLFormatter from telegrinder.tools.formatting import HTMLFormatter
from config import tg_api from config import tg_api
from config import TASK_URL
from altrepo import altrepo from altrepo import altrepo
...@@ -15,27 +16,25 @@ async def watch( ...@@ -15,27 +16,25 @@ async def watch(
maintainer: str | None = None, acl: str | None = None maintainer: str | None = None, acl: str | None = None
) -> None: ) -> None:
chat_id = chat_id or user.user_id if chat_id is None:
if user is None:
return
chat_id = user.user_id
if maintainer: if maintainer:
maintainer = maintainer.lower() maintainer = maintainer.lower()
_maintainer = DB.maintainer.get(maintainer) if not DB.maintainer.get(maintainer):
if not _maintainer: await tg_api.send_message(chat_id, "Сопровождающий не найден.")
await tg_api.send_message(
chat_id=chat_id,
text=f"Сопровождающий не найден."
)
return return
elif user:
maintainer = user.maintainer.nickname
else: else:
if user: return
maintainer = user.maintainer.nickname
else:
return
acl = acl or "by-acl" acl = acl or "by-acl"
watch_data = await altrepo.parser.packages.watch_by_maintainer(maintainer, acl) watch_data = await altrepo.parser.packages.watch_by_maintainer(maintainer, acl)
if not len(watch_data): if not watch_data:
await tg_api.send_message( await tg_api.send_message(
chat_id=chat_id, chat_id=chat_id,
text=f"Нет устаревших пакетов." text=f"Нет устаревших пакетов."
...@@ -51,15 +50,33 @@ async def watch( ...@@ -51,15 +50,33 @@ async def watch(
packages[name] = package packages[name] = package
packages = list(packages.values()) packages = list(packages.values())
for i, package in enumerate(packages): for package in packages[:30]:
if i == 30: crossed = False
break updated_in_task_message = ""
watch_message += ( for status in ["DONE", "EPERM"]:
try:
data = await altrepo.api.task.progress.find_tasks(
input=[package.pkg_name, "sisyphus",
package.new_version, status]
)
task_id = data.tasks[0].task_id
updated_in_task_message = (
f" (<a href='{TASK_URL}{task_id}'>{task_id}/{status}</a>)"
)
crossed = True
break
except:
crossed = False
continue
prefix = "<s>" if crossed else ""
suffix = "</s>" if crossed else ""
watch_message += HTMLFormatter(
f"{prefix}"
f"{package.pkg_name}: {package.old_version} -> " f"{package.pkg_name}: {package.old_version} -> "
+ HTMLFormatter( f"<a href='{package.url.replace(".git/", "/")}'>{package.new_version}</a>"
f"<a href='{package.url.replace(".git/", "/")}'>{package.new_version}</a>" f"{suffix}"
) f"{updated_in_task_message}\n"
+ "\n"
) )
markup = None markup = None
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment