watch: show packages updated but not published yet

parent 7a9e8d8b
from telegrinder.tools.formatting import HTMLFormatter
from config import tg_api
from config import TASK_URL
from altrepo import altrepo
......@@ -15,27 +16,25 @@ async def watch(
maintainer: str | None = None, acl: str | 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:
maintainer = maintainer.lower()
_maintainer = DB.maintainer.get(maintainer)
if not _maintainer:
await tg_api.send_message(
chat_id=chat_id,
text=f"Сопровождающий не найден."
)
if not DB.maintainer.get(maintainer):
await tg_api.send_message(chat_id, "Сопровождающий не найден.")
return
elif user:
maintainer = user.maintainer.nickname
else:
if user:
maintainer = user.maintainer.nickname
else:
return
return
acl = acl or "by-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(
chat_id=chat_id,
text=f"Нет устаревших пакетов."
......@@ -51,15 +50,33 @@ async def watch(
packages[name] = package
packages = list(packages.values())
for i, package in enumerate(packages):
if i == 30:
break
watch_message += (
for package in packages[:30]:
crossed = False
updated_in_task_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} -> "
+ HTMLFormatter(
f"<a href='{package.url.replace(".git/", "/")}'>{package.new_version}</a>"
)
+ "\n"
f"<a href='{package.url.replace(".git/", "/")}'>{package.new_version}</a>"
f"{suffix}"
f"{updated_in_task_message}\n"
)
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