From 0c8c5faad0f4f7879f8137dae079207495b4e3ab Mon Sep 17 00:00:00 2001 From: Alex Kelly Date: Wed, 1 Dec 2021 23:36:57 -0500 Subject: [PATCH] feat(buildbot): add buildbot formatter --- matrix_webhook/formatters/buildbot.py | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 matrix_webhook/formatters/buildbot.py diff --git a/matrix_webhook/formatters/buildbot.py b/matrix_webhook/formatters/buildbot.py new file mode 100644 index 0000000..95f3ded --- /dev/null +++ b/matrix_webhook/formatters/buildbot.py @@ -0,0 +1,32 @@ +from datetime import datetime + + +def formatter(data, headers): + """Pretty-print a buildbot notification.""" + buildid = data["buildid"] + buildstate = data["state_string"] + buildlink = data["url"] + reason = data["buildset"]["reason"] + project = data["properties"]["project"][0] + submittime = datetime.fromtimestamp(data["buildset"]["submitted_at"]) + if buildstate == "starting": + try: + data["body"] = ( + f"###Buildbot job #{buildid} for {project} - {buildstate}\n\n" + f"{reason}\n\n" + f"**started at** {submittime}\n\n" + f"[view details]({buildlink})" + ) + except Exception as error: + print(error) + elif buildstate == "build successful": + try: + data["body"] = ( + f"###Buildbot job #{buildid} for {project} - {buildstate}\n\n" + f"**completed at** {datetime.fromtimestamp(data['complete_at'])}\n\n" + f"[view details]({buildlink})" + ) + except Exception as error: + print(error) + + return data