def test_send_potential_action(): """ This sends a message with a potential action """ myTeamsMessage = pymsteams.connectorcard(os.getenv("MS_TEAMS_WEBHOOK")) myTeamsMessage.text("This message should have three potential actions.") myTeamsMessage.title("Action Message Title") myTeamsPotentialAction1 = pymsteams.potentialaction(_name="Add a comment") myTeamsPotentialAction1.addInput("TextInput", "comment", "Add a comment", False) myTeamsPotentialAction1.addAction( "HttpPost", "Add Comment", "https://jsonplaceholder.typicode.com/posts") myTeamsPotentialAction2 = pymsteams.potentialaction(_name="Get Users") myTeamsPotentialAction2.addInput("DateInput", "dueDate", "Enter due date") myTeamsPotentialAction2.addAction( "HttpPost", "save", "https://jsonplaceholder.typicode.com/posts") myTeamsPotentialAction3 = pymsteams.potentialaction(_name="Change Status") myTeamsPotentialAction3.choices.addChoices("In progress", "0") myTeamsPotentialAction3.choices.addChoices("Active", "1") myTeamsPotentialAction3.addInput("MultichoiceInput", "list", "Select a status", False) myTeamsPotentialAction3.addAction( "HttpPost", "Save", "https://jsonplaceholder.typicode.com/posts") myTeamsMessage.addPotentialAction(myTeamsPotentialAction1) myTeamsMessage.addPotentialAction(myTeamsPotentialAction2) myTeamsMessage.addPotentialAction(myTeamsPotentialAction3) myTeamsMessage.summary("Message Summary") myTeamsMessage.send()
def send_teams_webhook_finish_failed(self, text: str, config, reset_links=False): if self.config.args.simulate: print( f"SIM: send Teams webhook for Round Finished Failed with text: {text}" ) return True if self.endpoint: message_card = msteams.connectorcard(self.endpoint) message_card.text(text) if reset_links: reset_section = msteams.cardsection() reset = msteams.potentialaction(f"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}) 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}) msteams.connectorcard.addPotentialAction(reset_section, retry) message_card.addSection(reset_section) failed_section = msteams.cardsection() failed_modules_text = "\n".join([ r.id for r in config.state_data.values() if r.progress == PROGRESS.DONE_FAILED_BLOCKING ]) failed_section.text( f"```\nFailed Modules on {config.args.branch}:\n{failed_modules_text}" ) message_card.addSection(failed_section) 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 test_send_potential_action(): """ This sends a message with a potential action """ myTeamsMessage = pymsteams.connectorcard(os.getenv("MS_TEAMS_WEBHOOK")) myTeamsMessage.text("This message should have four potential actions.") myTeamsMessage.title("Action Message Title") myTeamsPotentialAction1 = pymsteams.potentialaction(_name="Add a comment") myTeamsPotentialAction1.addInput("TextInput", "comment", "Add a comment", False) myTeamsPotentialAction1.addAction( "HttpPost", "Add Comment", "https://jsonplaceholder.typicode.com/posts") myTeamsPotentialAction2 = pymsteams.potentialaction(_name="Get Users") myTeamsPotentialAction2.addInput("DateInput", "dueDate", "Enter due date") myTeamsPotentialAction2.addAction( "HttpPost", "save", "https://jsonplaceholder.typicode.com/posts") myTeamsPotentialAction3 = pymsteams.potentialaction(_name="Change Status") myTeamsPotentialAction3.choices.addChoices("In progress", "0") myTeamsPotentialAction3.choices.addChoices("Active", "1") myTeamsPotentialAction3.addInput("MultichoiceInput", "list", "Select a status", False) myTeamsPotentialAction3.addAction( "HttpPost", "Save", "https://jsonplaceholder.typicode.com/posts") myTeamsPotentialAction4 = pymsteams.potentialaction( _name="Download pymsteams") myTeamsPotentialAction4.addOpenURI("Links", [ { "os": "default", "uri": "https://pypi.org/project/pymsteams/", }, ]) myTeamsMessage.addPotentialAction(myTeamsPotentialAction1) myTeamsMessage.addPotentialAction(myTeamsPotentialAction2) myTeamsMessage.addPotentialAction(myTeamsPotentialAction3) myTeamsMessage.summary("Message Summary") myTeamsMessage.send() assert isinstance(myTeamsMessage.last_http_status.status_code, int)
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: print(f"SIM: send Teams webhook for {repo.id} with text:" + ( text_override or f"Dependency update on *{repo.id}* failed in **{repo.branch}**" ) + '\n' + test_failures) return 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))) 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}) 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}) 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