feat(test): add option to send to slack thread (#5673)

This commit is contained in:
Aseem Bansal 2022-08-18 21:34:32 +05:30 committed by GitHub
parent 9da6f12c18
commit 2ba80f0418
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,5 @@
from slack_sdk import WebClient
import os
import asyncio
from datahub.upgrade.upgrade import retrieve_version_stats
datahub_stats = {}
@ -14,6 +12,7 @@ def add_datahub_stats(stat_name, stat_val):
def send_to_slack(passed: str):
slack_api_token = os.getenv('SLACK_API_TOKEN')
slack_channel = os.getenv('SLACK_CHANNEL')
slack_thread_ts = os.getenv('SLACK_THREAD_TS')
test_identifier = os.getenv('TEST_IDENTIFIER', 'LOCAL_TEST')
if slack_api_token is None or slack_channel is None:
return
@ -26,7 +25,10 @@ def send_to_slack(passed: str):
entity_type = key.replace("num-", "")
message += f"Num {entity_type} is {val}\n"
client.chat_postMessage(channel=slack_channel, text=f'{test_identifier} Status - {passed}\n{message}')
if slack_thread_ts is None:
client.chat_postMessage(channel=slack_channel, text=f'{test_identifier} Status - {passed}\n{message}')
else:
client.chat_postMessage(channel=slack_channel, text=f'{test_identifier} Status - {passed}\n{message}', thread_ts=slack_thread_ts)
def send_message(exitstatus):