Why This Matters
Six modules independently define a private _truncate() function with inconsistent implementations, different ellipsis characters, and undocumented magic limits. Adding a new delivery channel or integration means writing yet another truncation function from scratch.
This is the same class of duplication fixed in #869 for the GitLab write-back flow.
Current State
| File |
Limit |
Ellipsis |
Signature |
app/utils/discord_delivery.py:83 |
configurable |
… |
_truncate(text, limit) |
app/utils/telegram_delivery.py:47 |
configurable |
… |
_truncate(text, limit) |
app/integrations/azure_sql.py:177 |
500 (_QUERY_TRUNCATE_LEN) |
... |
_truncate(text, max_len) |
app/integrations/mysql.py:203 |
500 (_QUERY_TRUNCATE_LEN) |
... |
_truncate(text, max_len) |
app/integrations/mariadb.py:154 |
200 (_QUERY_TRUNCATE_LEN) |
... |
_truncate(text, max_len) |
app/nodes/publish_findings/gitlab_writeback.py:14 |
4000 (inline) |
... |
inlined, no function |
discord_delivery.py and telegram_delivery.py use the Unicode ellipsis …; everything else uses "...". mariadb.py also has a second ad-hoc truncation at line 294 using "\n... (truncated)".
Proposed Fix
- Add
app/utils/truncation.py with one shared helper:
def truncate(text: str, limit: int, ellipsis: str = "...") -> str:
if len(text) <= limit:
return text
return text[: limit - len(ellipsis)] + ellipsis
- Migrate all six call sites to use it.
- Keep each module's limit constant where it is — only the function body moves.
Tests / Coverage
- one parametrised test: text under limit → unchanged, text over limit → truncated with correct ellipsis
- one test for Unicode ellipsis variant
- existing tests for all six modules must stay green
Acceptance Criteria
_truncate is defined in exactly one place
- ellipsis character is consistent or explicitly configurable per call site
- no behaviour change for any existing caller
- scope limited to the six files listed above
Why This Matters
Six modules independently define a private
_truncate()function with inconsistent implementations, different ellipsis characters, and undocumented magic limits. Adding a new delivery channel or integration means writing yet another truncation function from scratch.This is the same class of duplication fixed in #869 for the GitLab write-back flow.
Current State
app/utils/discord_delivery.py:83…_truncate(text, limit)app/utils/telegram_delivery.py:47…_truncate(text, limit)app/integrations/azure_sql.py:177_QUERY_TRUNCATE_LEN)..._truncate(text, max_len)app/integrations/mysql.py:203_QUERY_TRUNCATE_LEN)..._truncate(text, max_len)app/integrations/mariadb.py:154_QUERY_TRUNCATE_LEN)..._truncate(text, max_len)app/nodes/publish_findings/gitlab_writeback.py:14...discord_delivery.pyandtelegram_delivery.pyuse the Unicode ellipsis…; everything else uses"...".mariadb.pyalso has a second ad-hoc truncation at line 294 using"\n... (truncated)".Proposed Fix
app/utils/truncation.pywith one shared helper:Tests / Coverage
Acceptance Criteria
_truncateis defined in exactly one place