1
0
Fork 0

Allow markdown messages to be sent if requested

This commit is contained in:
Félix Piédallu 2024-03-24 17:52:14 +01:00 committed by OniriCorpe
parent cb36b5a020
commit db343550cc
2 changed files with 18 additions and 18 deletions

View file

@ -5,7 +5,7 @@ import logging
import logging.handlers import logging.handlers
def notify(message: str, channel: str) -> None: def notify(message: str, channel: str, markdown: bool = False) -> None:
print(f"{channel} -> {message}") print(f"{channel} -> {message}")
chan_list = ["dev", "apps", "doc"] chan_list = ["dev", "apps", "doc"]
@ -18,22 +18,22 @@ def notify(message: str, channel: str) -> None:
for char in ["'", "`", "!", ";", "$"]: for char in ["'", "`", "!", ";", "$"]:
message = message.replace(char, "") 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: try:
subprocess.call( subprocess.call(command, stdout=subprocess.DEVNULL)
[
"/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,
)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
logging.warning( logging.warning(
f"""Could not send a notification on {channel}. f"""Could not send a notification on {channel}.

View file

@ -693,7 +693,7 @@ def main() -> None:
apps_failed[app] = current_version, main_version # actually stores logs apps_failed[app] = current_version, main_version # actually stores logs
paste_message = "" paste_message = ""
matrix_message = "Autoupdater just ran, here are the results:" matrix_message = "Autoupdater just ran, here are the results:\n"
if apps_already: if apps_already:
paste_message += f"\n{'=' * 80}\nApps already with an update PR:" paste_message += f"\n{'=' * 80}\nApps already with an update PR:"
matrix_message += f"\n- {len(apps_already)} pending update PRs" matrix_message += f"\n- {len(apps_already)} pending update PRs"
@ -726,7 +726,7 @@ def main() -> None:
paste_url = paste_on_haste(paste_message) paste_url = paste_on_haste(paste_message)
matrix_message += f"\nSee the full log here: {paste_url}" 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) print(paste_message)