Skip to content

Commit 2b2229e

Browse files
authored
feat: bump diff size truncate size (#417)
2 parents 68da7da + fc9aa48 commit 2b2229e

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

app/components/github_integration/webhooks/issues.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,16 @@ def issue_footer(issue: IssueLike, /, *, emoji: EmojiName | None = None) -> Foot
5050

5151

5252
def issue_embed_content(
53-
issue: IssueLike, template: str, body: str | None = None, /
53+
issue: IssueLike,
54+
template: str,
55+
body: str | None = None,
56+
/,
57+
*,
58+
description: str | None = None,
5459
) -> EmbedContent:
55-
return EmbedContent(template.format(f"issue #{issue.number}"), issue.html_url, body)
60+
return EmbedContent(
61+
template.format(f"issue #{issue.number}"), issue.html_url, body, description
62+
)
5663

5764

5865
def register_hooks(bot: GhosttyBot, webhook: Monalisten) -> None:

app/components/github_integration/webhooks/prs.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,16 @@ def pr_footer(
4343

4444

4545
def pr_embed_content(
46-
pr: PRLike, template: str, body: str | None = None, /
46+
pr: PRLike,
47+
template: str,
48+
body: str | None = None,
49+
/,
50+
*,
51+
description: str | None = None,
4752
) -> EmbedContent:
48-
return EmbedContent(template.format(f"PR #{pr.number}"), pr.html_url, body)
53+
return EmbedContent(
54+
template.format(f"PR #{pr.number}"), pr.html_url, body, description
55+
)
4956

5057

5158
def register_hooks(bot: GhosttyBot, webhook: Monalisten) -> None: # noqa: PLR0915

app/components/github_integration/webhooks/utils.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,16 @@ class EmbedContent(NamedTuple):
5555
title: str
5656
url: str
5757
body: str | None = None
58+
description: str | None = None
5859

5960
@property
6061
def dict(self) -> EmbedContentArgs:
6162
args: EmbedContentArgs = {"title": self.title, "url": self.url}
62-
if self.body:
63+
if self.description:
64+
# If a description is provided explicitly, don't truncate. However, Discord
65+
# has a description character size limit.
66+
args["description"] = truncate(self.description, 4096)
67+
elif self.body:
6368
args["description"] = truncate(self.body, 500)
6469
return args
6570

@@ -77,7 +82,13 @@ def dict(self, bot: GhosttyBot) -> dict[str, str | None]:
7782

7883
class ContentGenerator(Protocol):
7984
def __call__(
80-
self, event_like: Any, template: str, body: str | None = None, /
85+
self,
86+
event_like: Any,
87+
template: str,
88+
body: str | None = None,
89+
/,
90+
*,
91+
description: str | None = None,
8192
) -> EmbedContent: ...
8293

8394

@@ -119,9 +130,9 @@ async def send_edit_difference(
119130
)
120131
if old_title == new_title:
121132
# If the titles are the same, there's no point in showing them;
122-
# they just take up a lot of the 500 available characters.
133+
# they just take up a lot of the 750 available characters.
123134
diff_lines = islice(diff_lines, 2, None)
124-
diff = truncate("\n".join(diff_lines), 500 - len("```diff\n\n```"))
135+
diff = truncate("\n".join(diff_lines), 750 - len("```diff\n\n```"))
125136
content = f"```diff\n{diff}\n```"
126137
elif changes.title:
127138
content = f'Renamed from "{changes.title.from_}" to "{event_object.title}"'
@@ -132,7 +143,7 @@ async def send_edit_difference(
132143
await send_embed(
133144
bot,
134145
event.sender,
135-
content_generator(event_object, "edited {}", content),
146+
content_generator(event_object, "edited {}", None, description=content),
136147
footer_generator(event_object),
137148
)
138149

0 commit comments

Comments
 (0)