From 8c18c2054e0ee8394f82c9b801c481cf01ca4a6d Mon Sep 17 00:00:00 2001 From: Alex Kelly Date: Tue, 11 Jan 2022 22:22:20 -0500 Subject: [PATCH] refactor(formatter/buildbot): cleanup redundancy in logic --- matrix_webhook/formatters/buildbot.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/matrix_webhook/formatters/buildbot.py b/matrix_webhook/formatters/buildbot.py index 9a07f4c..16a06d6 100644 --- a/matrix_webhook/formatters/buildbot.py +++ b/matrix_webhook/formatters/buildbot.py @@ -9,33 +9,26 @@ def formatter(data, headers): reason = data["buildset"]["reason"] project = data["properties"]["project"][0] submittime = datetime.fromtimestamp(data["buildset"]["submitted_at"]) - # This could use some optimization, but it works for now. - if buildstate == "starting": - try: + try: + if buildstate == "starting": 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: + elif buildstate == "build successful": 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) - else: - try: + else: data["body"] = ( f"###Buildbot job #{buildid} for {project} - {buildstate}\n\n" f"[view details]({buildlink})" ) - except Exception as error: - print(error) + except Exception as error: + print(error) return data