From 2722242c69fbb4c75e1efa4958bcd304b2b5fd0a Mon Sep 17 00:00:00 2001 From: Daniel Smith Date: Mon, 30 May 2022 12:57:50 +0200 Subject: Fix Teams Card buttons for current version of the teams python lib A recent update broke the expected format of button payloads. Update it to create properly formatted JSON strings. Change-Id: If07df122c7c8090c18c5fabfcc9480c6dda83b13 Reviewed-by: Daniel Smith --- util/dependency_updater/tools/teams_connector.py | 52 +++++++++--------------- 1 file changed, 19 insertions(+), 33 deletions(-) diff --git a/util/dependency_updater/tools/teams_connector.py b/util/dependency_updater/tools/teams_connector.py index fdb6bfc..08239b8 100644 --- a/util/dependency_updater/tools/teams_connector.py +++ b/util/dependency_updater/tools/teams_connector.py @@ -39,11 +39,10 @@ class TeamsConnector: else: print("MS Teams connector disabled: No webhook URL provided.") - @staticmethod - def _link_creator_failed_stage(card: msteams.connectorcard, + def _link_creator_failed_stage(self, card: msteams.connectorcard, repo) -> msteams.connectorcard: for change_id in repo.to_stage: - card.addLinkButton(*gerrit_link_maker(repo, change_id)) + card.addLinkButton(*gerrit_link_maker(self.config, repo, change_id)) return card def _card_formatter_failed_stage(self, card: msteams.connectorcard, @@ -66,15 +65,10 @@ class TeamsConnector: message_card = msteams.connectorcard(self.endpoint) message_card = self._card_formatter_failed_stage(message_card, repo) message_card.send() - print(message_card.last_http_status.status_code, message_card.last_http_status.reason, - message_card.last_http_status.text) - if message_card.last_http_status.status_code != 200: - print( - f"WARN: Unable to send alert to webhook for {repo.id}") - return False return True - def send_teams_webhook_module_failed(self, repo, text_override: str = None, test_failures: str = None, pause_links: bool = False): + def send_teams_webhook_module_failed(self, repo, text_override: str = None, + test_failures: str = None, pause_links: bool = False): if self.config.args.simulate: _text = text_override or f"Dependency update on *{repo.id}* failed in **{repo.branch}**" print(f"SIM: send Teams webhook for {repo.id} with text:" @@ -83,28 +77,29 @@ class TeamsConnector: if self.endpoint: message_card = msteams.connectorcard(self.endpoint) message_card.color('#FF0000') - message_card.text(text_override or f"Dependency update on *{repo.id}* failed in **{repo.branch}*" - f"*") - message_card.addSection(msteams.cardsection().linkButton(*gerrit_link_maker(self.config, repo))) + message_card.text( + text_override or f"Dependency update on *{repo.id}* failed in **{repo.branch}*" + f"*") + message_card.addSection( + msteams.cardsection().linkButton(*gerrit_link_maker(self.config, repo))) if pause_links: pause_section = msteams.cardsection() - pause = msteams.potentialaction(f"Pause Updates on '{repo.branch}' (This failure can be fixed)", "HttpPOST") - pause.payload["target"] = "https://qt-cherry-pick-bot.herokuapp.com/pause-submodule-updates" - pause.payload["body"] = yaml.dump({"branch": repo.branch}) + pause = msteams.potentialaction( + f"Pause Updates on '{repo.branch}' (This failure can be fixed)", "HttpPOST") + pause.payload[ + "target"] = "https://qt-cherry-pick-bot.herokuapp.com/pause-submodule-updates" + pause.payload["body"] = json.dumps({"branch": repo.branch}) msteams.connectorcard.addPotentialAction(pause_section, pause) resume = msteams.potentialaction(f"Resume Updates on '{repo.branch}'", "HttpPOST") - resume.payload["target"] = "https://qt-cherry-pick-bot.herokuapp.com/resume-submodule-updates" - resume.payload["body"] = yaml.dump({"branch": repo.branch}) + resume.payload[ + "target"] = "https://qt-cherry-pick-bot.herokuapp.com/resume-submodule-updates" + resume.payload["body"] = json.dumps({"branch": repo.branch}) msteams.connectorcard.addPotentialAction(pause_section, resume) message_card.addSection(pause_section) if test_failures: message_card.addSection( msteams.cardsection().text('```\nBuild/Test Log:\n' + test_failures)) message_card.send() - if message_card.last_http_status.status_code != 200: - print( - f"WARN: Unable to send alert to webhook for {repo.id}") - return False return True def send_teams_webhook_finish_failed(self, text: str, config, reset_links=False): @@ -120,13 +115,13 @@ class TeamsConnector: "Reset round (New qtbase)", "HttpPOST") reset.payload[ "target"] = "https://qt-cherry-pick-bot.herokuapp.com/reset-submodule-updates" - reset.payload["body"] = yaml.dump({"branch": config.args.branch}) + reset.payload["body"] = json.dumps({"branch": config.args.branch}) msteams.connectorcard.addPotentialAction(reset_section, reset) retry = msteams.potentialaction( f"Retry current failed modules on '{config.args.branch}'", "HttpPOST") retry.payload[ "target"] = "https://qt-cherry-pick-bot.herokuapp.com/retry-submodule-updates" - retry.payload["body"] = yaml.dump({"branch": config.args.branch}) + retry.payload["body"] = json.dumps({"branch": config.args.branch}) msteams.connectorcard.addPotentialAction(reset_section, retry) message_card.addSection(reset_section) failed_section = msteams.cardsection() @@ -142,12 +137,7 @@ class TeamsConnector: failed_section.text( f"```\nFailed Modules on {config.args.branch}:\n{failed_modules_text}") message_card.addSection(failed_section) - print(message_card.payload) message_card.send() - # if message_card.last_http_status.status_code != 200: - # print( - # f"WARN: Unable to send alert to webhook for Round Failed Finished on {config.args.branch}") - # return False return True def send_teams_webhook_basic(self, text: str, repo: Repo = None, reset_links=False): @@ -160,8 +150,4 @@ class TeamsConnector: if repo and repo.proposal.change_id: message_card.addLinkButton(*gerrit_link_maker(self.config, repo)) message_card.send() - if message_card.last_http_status.status_code != 200: - print( - f"WARN: Unable to send alert to webhook for {repo.id}") - return False return True -- cgit v1.2.1