1
0
Fork 0

Merge pull request #2053 from Salamandar/autoupdate_message

Always send a message to Matrix
This commit is contained in:
Alexandre Aubin 2024-02-24 22:26:07 +01:00 committed by GitHub
commit 8e1b1c62ab
2 changed files with 29 additions and 25 deletions

View file

@ -6,18 +6,21 @@ import logging
import logging.handlers import logging.handlers
def send_to_matrix(message: str) -> None:
if which("sendxmpppy") is None:
logging.warning("Could not send error via xmpp.")
return
subprocess.call(["sendxmpppy", message], stdout=subprocess.DEVNULL)
class LogSenderHandler(logging.Handler): class LogSenderHandler(logging.Handler):
def __init__(self): def __init__(self):
logging.Handler.__init__(self) logging.Handler.__init__(self)
self.is_logging = False self.is_logging = False
def emit(self, record): def emit(self, record):
if which("sendxmpppy") is None: msg = f"[Apps tools error] {record.msg}"
logging.warning("Could not send error via xmpp.") send_to_matrix(msg)
return
msg = f"[Applist builder error] {record.msg}"
subprocess.call(["sendxmpppy", msg], stdout=subprocess.DEVNULL)
@classmethod @classmethod
def add(cls, level=logging.ERROR): def add(cls, level=logging.ERROR):

View file

@ -585,37 +585,38 @@ def main() -> None:
if state == State.failure: if state == State.failure:
apps_failed[app] = current_version, main_version # actually stores logs apps_failed[app] = current_version, main_version # actually stores logs
result_message = "" paste_message = ""
matrix_message = "Autoupdater just ran, here are the results:"
if apps_already: if apps_already:
result_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"
for app, info in apps_already.items(): for app, info in apps_already.items():
result_message += f"\n- {app}" paste_message += f"\n- {app}"
result_message += f" ({info[0]} -> {info[1]})" if info[1] else " (app version did not change)" paste_message += f" ({info[0]} -> {info[1]})" if info[1] else " (app version did not change)"
if info[2]: if info[2]:
result_message += f" see {info[2]}" paste_message += f" see {info[2]}"
if apps_updated: if apps_updated:
result_message += f"\n{'=' * 80}\nApps updated:" paste_message += f"\n{'=' * 80}\nApps updated:"
matrix_message += f"\n- {len(apps_updated)} new apps PRs"
for app, info in apps_updated.items(): for app, info in apps_updated.items():
result_message += f"\n- {app}" paste_message += f"\n- {app}"
result_message += f" ({info[0]} -> {info[1]})" if info[1] else " (app version did not change)" paste_message += f" ({info[0]} -> {info[1]})" if info[1] else " (app version did not change)"
if info[2]: if info[2]:
result_message += f" see {info[2]}" paste_message += f" see {info[2]}"
if apps_failed: if apps_failed:
result_message += f"\n{'=' * 80}\nApps failed:" paste_message += f"\n{'=' * 80}\nApps failed:"
matrix_message += f"\n- {len(apps_failed)} failed apps updates: {', '.join(str(app) for app in apps_failed.keys())}"
for app, logs in apps_failed.items(): for app, logs in apps_failed.items():
result_message += f"\n{'='*40}\n{app}\n{'-'*40}\n{logs[0]}\n{logs[1]}\n\n" paste_message += f"\n{'='*40}\n{app}\n{'-'*40}\n{logs[0]}\n{logs[1]}\n\n"
if apps_failed and args.paste: if args.paste:
paste_url = paste_on_haste(result_message) paste_url = paste_on_haste(paste_message)
logging.error(textwrap.dedent(f""" matrix_message += f"\nSee the full log here: {paste_url}"
Failed to run the source auto-update for: {', '.join(apps_failed.keys())}
Please run manually the `autoupdate_app_sources.py` script on these apps to debug what is happening!
See the debug log here: {paste_url}
"""))
print(result_message) appslib.logging_sender.send_to_matrix(matrix_message)
print(paste_message)
if __name__ == "__main__": if __name__ == "__main__":