From db343550cc7300689bd91e8a5320773c942fbd6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Sun, 24 Mar 2024 17:52:14 +0100 Subject: [PATCH] Allow markdown messages to be sent if requested --- appslib/logging_sender.py | 32 +++++++++---------- .../autoupdate_app_sources.py | 4 +-- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/appslib/logging_sender.py b/appslib/logging_sender.py index ae9fce9..d65c257 100644 --- a/appslib/logging_sender.py +++ b/appslib/logging_sender.py @@ -5,7 +5,7 @@ import logging import logging.handlers -def notify(message: str, channel: str) -> None: +def notify(message: str, channel: str, markdown: bool = False) -> None: print(f"{channel} -> {message}") chan_list = ["dev", "apps", "doc"] @@ -18,22 +18,22 @@ def notify(message: str, channel: str) -> None: for char in ["'", "`", "!", ";", "$"]: message = message.replace(char, "") + command = [ + "/var/www/webhooks/matrix-commander", + "--message", + message, + "--credentials", + "/var/www/webhooks/credentials.json", + "--store", + "/var/www/webhooks/store", + "--room", + f"yunohost-{channel}", + ] + if markdown: + command.append("--markdown") + try: - subprocess.call( - [ - "/var/www/webhooks/matrix-commander", - "--markdown", - "-m", - message, - "-c", - "/var/www/webhooks/credentials.json", - "--store", - "/var/www/webhooks/store", - "--room", - f"yunohost-{channel}", - ], - stdout=subprocess.DEVNULL, - ) + subprocess.call(command, stdout=subprocess.DEVNULL) except subprocess.CalledProcessError as e: logging.warning( f"""Could not send a notification on {channel}. diff --git a/autoupdate_app_sources/autoupdate_app_sources.py b/autoupdate_app_sources/autoupdate_app_sources.py index b6e6741..ded21e8 100755 --- a/autoupdate_app_sources/autoupdate_app_sources.py +++ b/autoupdate_app_sources/autoupdate_app_sources.py @@ -693,7 +693,7 @@ def main() -> None: apps_failed[app] = current_version, main_version # actually stores logs paste_message = "" - matrix_message = "Autoupdater just ran, here are the results:" + matrix_message = "Autoupdater just ran, here are the results:\n" if apps_already: paste_message += f"\n{'=' * 80}\nApps already with an update PR:" matrix_message += f"\n- {len(apps_already)} pending update PRs" @@ -726,7 +726,7 @@ def main() -> None: paste_url = paste_on_haste(paste_message) matrix_message += f"\nSee the full log here: {paste_url}" - appslib.logging_sender.notify(matrix_message, "apps") + appslib.logging_sender.notify(matrix_message, "apps", markdown=True) print(paste_message)