Unverified Commit 3bb44662 authored by Lysandre Debut's avatar Lysandre Debut Committed by GitHub
Browse files

Better notification service (#13267)

parent 225de5cc
...@@ -355,6 +355,7 @@ jobs: ...@@ -355,6 +355,7 @@ jobs:
env: env:
CI_SLACK_BOT_TOKEN: ${{ secrets.CI_SLACK_BOT_TOKEN }} CI_SLACK_BOT_TOKEN: ${{ secrets.CI_SLACK_BOT_TOKEN }}
CI_SLACK_CHANNEL_ID: ${{ secrets.CI_SLACK_CHANNEL_ID }} CI_SLACK_CHANNEL_ID: ${{ secrets.CI_SLACK_CHANNEL_ID }}
CI_SLACK_CHANNEL_ID_DAILY: ${{ secrets.CI_SLACK_CHANNEL_ID_DAILY }}
run: | run: |
......
...@@ -39,7 +39,7 @@ def handle_test_results(test_results): ...@@ -39,7 +39,7 @@ def handle_test_results(test_results):
def format_for_slack(total_results, results, scheduled: bool): def format_for_slack(total_results, results, scheduled: bool):
print(results) print(total_results, results)
header = { header = {
"type": "header", "type": "header",
"text": { "text": {
...@@ -49,20 +49,21 @@ def format_for_slack(total_results, results, scheduled: bool): ...@@ -49,20 +49,21 @@ def format_for_slack(total_results, results, scheduled: bool):
}, },
} }
total = ( if total_results["failed"] > 0:
{ total = {
"type": "section", "type": "section",
"fields": [ "fields": [
{"type": "mrkdwn", "text": f"*Failures:*\n{total_results['failed']} failures."}, {"type": "mrkdwn", "text": f"*Failures:*\n{total_results['failed']} failures."},
{"type": "mrkdwn", "text": f"*Passed:*\n{total_results['success']} tests passed."}, {"type": "mrkdwn", "text": f"*Passed:*\n{total_results['success']} tests passed."},
], ],
} }
if total_results["failed"] > 0 else:
else { total = {
"type": "section", "type": "section",
"fields": [{"type": "mrkdwn", "text": f"*Congrats!*\nAll {total_results['success']} tests pass."}], "fields": [
{"type": "mrkdwn", "text": "\n🌞 All tests passed."},
],
} }
)
blocks = [header, total] blocks = [header, total]
...@@ -82,7 +83,7 @@ def format_for_slack(total_results, results, scheduled: bool): ...@@ -82,7 +83,7 @@ def format_for_slack(total_results, results, scheduled: bool):
], ],
} }
) )
else: elif not scheduled:
for key, result in results.items(): for key, result in results.items():
blocks.append( blocks.append(
{"type": "section", "fields": [{"type": "mrkdwn", "text": f"*{key}*\n{result['time_spent']}."}]} {"type": "section", "fields": [{"type": "mrkdwn", "text": f"*{key}*\n{result['time_spent']}."}]}
...@@ -148,7 +149,7 @@ if __name__ == "__main__": ...@@ -148,7 +149,7 @@ if __name__ == "__main__":
} }
client = WebClient(token=os.environ["CI_SLACK_BOT_TOKEN"]) client = WebClient(token=os.environ["CI_SLACK_BOT_TOKEN"])
channel_id = os.environ["CI_SLACK_CHANNEL_ID"] channel_id = os.environ["CI_SLACK_CHANNEL_ID_DAILY"] if scheduled else os.environ["CI_SLACK_CHANNEL_ID"]
try: try:
results = {} results = {}
...@@ -180,6 +181,7 @@ if __name__ == "__main__": ...@@ -180,6 +181,7 @@ if __name__ == "__main__":
for result_key in test_results_keys: for result_key in test_results_keys:
total[result_key] += job_result[result_key] total[result_key] += job_result[result_key]
if total["failed"] != 0 or scheduled:
to_be_sent_to_slack = format_for_slack(total, results, scheduled) to_be_sent_to_slack = format_for_slack(total, results, scheduled)
result = client.chat_postMessage( result = client.chat_postMessage(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment