Skip to content

Fix #1030: truncate resulting Jira instead of markdown source #1031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2024
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
7 changes: 4 additions & 3 deletions jbi/jira/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def markdown_to_jira(markdown: str, max_length: int = 0) -> str:
"""
Convert markdown content into Jira specific markup language.
"""
if max_length > 0 and len(markdown) > max_length:
jira_output = pypandoc.convert_text(markdown, "jira", format="gfm").strip()
if max_length > 0 and len(jira_output) > max_length:
# Truncate on last word.
markdown = markdown[:max_length].rsplit(maxsplit=1)[0]
return pypandoc.convert_text(markdown, "jira", format="gfm").strip() # type: ignore
jira_output = jira_output[:max_length].rsplit(maxsplit=1)[0]
return jira_output # type: ignore
1 change: 1 addition & 0 deletions tests/unit/jira/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def test_markdown_to_jira_with_malformed_input():
("aa\taaa", "aa", 5),
("aaaaaa", "aaaaa", 5),
("aaaaa ", "aaaaa", 5),
("`fo` `fo`", "{{fo}}", 9),
],
)
def test_markdown_to_jira_with_max_chars(markdown, expected, max_length):
Expand Down
Loading