Format Matrix report by converting it to HTML (#674)
Co-authored-by: Eva Bardou <ebardou@teklia.com>
This commit is contained in:
Родитель
5971f4611e
Коммит
f11cfe6920
|
@ -5,6 +5,7 @@
|
|||
|
||||
import os
|
||||
|
||||
import markdown2
|
||||
import taskcluster
|
||||
import taskcluster_urls as liburls
|
||||
from loguru import logger
|
||||
|
@ -162,9 +163,18 @@ def notify_matrix(body, room):
|
|||
logger.warning("No Matrix room available in configuration")
|
||||
return
|
||||
|
||||
formatted_body = markdown2.markdown(body)
|
||||
|
||||
notify_service = taskcluster.Notify(get_taskcluster_options())
|
||||
try:
|
||||
notify_service.matrix({"roomId": room, "body": body})
|
||||
notify_service.matrix(
|
||||
{
|
||||
"roomId": room,
|
||||
"body": body,
|
||||
"format": "org.matrix.custom.html",
|
||||
"formattedBody": formatted_body,
|
||||
}
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to send the report on the Matrix room {room}: {e}")
|
||||
raise
|
||||
|
|
|
@ -395,6 +395,14 @@ category = "main"
|
|||
optional = false
|
||||
python-versions = "*"
|
||||
|
||||
[[package]]
|
||||
name = "markdown2"
|
||||
version = "2.4.2"
|
||||
description = "A fast and complete Python implementation of Markdown"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.5, <4"
|
||||
|
||||
[[package]]
|
||||
name = "markupsafe"
|
||||
version = "2.1.0"
|
||||
|
@ -1009,7 +1017,7 @@ cache-seeded-file = ["zstandard"]
|
|||
[metadata]
|
||||
lock-version = "1.1"
|
||||
python-versions = ">=3.7,<4"
|
||||
content-hash = "fbbab8cccf1104a0ed311b25bbb4187f41a8ad6aa31179d1fb18bd8aa828e096"
|
||||
content-hash = "7d89ada30078b13498ba8e10e4fd72a91021733ac548e39d172848e32c8c9625"
|
||||
|
||||
[metadata.files]
|
||||
aiohttp = [
|
||||
|
@ -1330,6 +1338,10 @@ loguru = [
|
|||
lru-dict = [
|
||||
{file = "lru-dict-1.1.7.tar.gz", hash = "sha256:45b81f67d75341d4433abade799a47e9c42a9e22a118531dcb5e549864032d7c"},
|
||||
]
|
||||
markdown2 = [
|
||||
{file = "markdown2-2.4.2-py2.py3-none-any.whl", hash = "sha256:8f4ac8d9a124ab408c67361090ed512deda746c04362c36c2ec16190c720c2b0"},
|
||||
{file = "markdown2-2.4.2.tar.gz", hash = "sha256:91113caf23aa662570fe21984f08fe74f814695c0a0ea8e863a8b4c4f63f9f6e"},
|
||||
]
|
||||
markupsafe = [
|
||||
{file = "MarkupSafe-2.1.0-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:3028252424c72b2602a323f70fbf50aa80a5d3aa616ea6add4ba21ae9cc9da4c"},
|
||||
{file = "MarkupSafe-2.1.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:290b02bab3c9e216da57c1d11d2ba73a9f73a614bbdcc027d299a60cdfabb11a"},
|
||||
|
|
|
@ -32,6 +32,7 @@ ValidX = "^0.7"
|
|||
cleo = "^0.8.1"
|
||||
tabulate = "^0.8.9"
|
||||
arrow = "^1.2.2"
|
||||
markdown2 = "^2.4.2"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
pre-commit = "^2.17"
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
import json
|
||||
|
||||
import markdown2
|
||||
import pytest
|
||||
|
||||
from mozci.console.commands.push import ClassifyCommand
|
||||
|
@ -144,6 +145,8 @@ def test_classification_evolution(
|
|||
assert json.loads(matrix_call.request.body) == {
|
||||
"roomId": "!tEsTmAtRIxRooM:mozilla.org",
|
||||
"body": email_content,
|
||||
"formattedBody": markdown2.markdown(email_content),
|
||||
"format": "org.matrix.custom.html",
|
||||
}
|
||||
else:
|
||||
# Check no email was sent
|
||||
|
|
Загрузка…
Ссылка в новой задаче