Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 6 additions & 22 deletions src/sentry/notifications/platform/discord/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@

if TYPE_CHECKING:
from sentry.integrations.discord.message_builder.base.base import DiscordMessage
from sentry.integrations.discord.message_builder.base.embed.field import (
DiscordMessageEmbedField,
)

# TODO(ecosystem): Proper typing - https://discord.com/developers/docs/resources/message#create-message
type DiscordRenderable = DiscordMessage
Expand Down Expand Up @@ -65,7 +62,7 @@ def render[DataT: NotificationData](
embeds.append(
DiscordMessageEmbed(
title=rendered_template.subject,
fields=body_blocks,
description=body_blocks,
image=(
DiscordMessageEmbedImage(url=rendered_template.chart.url)
if rendered_template.chart
Expand Down Expand Up @@ -94,28 +91,15 @@ def render[DataT: NotificationData](
return builder.build()

@classmethod
def render_body_blocks(
cls, body: list[NotificationBodyFormattingBlock]
) -> list[DiscordMessageEmbedField]:
from sentry.integrations.discord.message_builder.base.embed.field import (
DiscordMessageEmbedField,
)
def render_body_blocks(cls, body: list[NotificationBodyFormattingBlock]) -> str:

fields = []
description = []
for block in body:
if block.type == NotificationBodyFormattingBlockType.PARAGRAPH:
fields.append(
DiscordMessageEmbedField(
name=block.type.value, value=cls.render_text_blocks(block.blocks)
)
)
description.append(f"\n{cls.render_text_blocks(block.blocks)}")
elif block.type == NotificationBodyFormattingBlockType.CODE_BLOCK:
fields.append(
DiscordMessageEmbedField(
name=block.type.value, value=f"```{cls.render_text_blocks(block.blocks)}```"
)
)
return fields
description.append(f"\n```{cls.render_text_blocks(block.blocks)}```")
return "".join(description)

@classmethod
def render_text_blocks(cls, blocks: list[NotificationBodyTextBlock]) -> str:
Expand Down
7 changes: 2 additions & 5 deletions tests/sentry/notifications/platform/discord/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,8 @@ def test_default_renderer(self) -> None:
embeds = renderable["embeds"]
assert len(embeds) == 1
embed = embeds[0]
fields = list(embed["fields"])
assert len(fields) == 1
field = fields[0]
assert field["name"] == "paragraph"
assert field["value"] == "test"
description = embed["description"]
assert description == "\ntest"
assert embed["title"] == "Mock Notification"
assert embed["footer"]["text"] == "This is a mock footer"
assert (
Expand Down
Loading