mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-04 04:40:38 +08:00
insert_br_after_x_chars
This commit is contained in:
@ -325,7 +325,7 @@ class PRCodeSuggestions:
|
|||||||
|
|
||||||
pr_body += "<table>"
|
pr_body += "<table>"
|
||||||
header = f"Suggestions"
|
header = f"Suggestions"
|
||||||
delta = 77
|
delta = 75
|
||||||
header += " " * delta
|
header += " " * delta
|
||||||
pr_body += f"""<thead><tr><th></th><th>{header}</th></tr></thead>"""
|
pr_body += f"""<thead><tr><th></th><th>{header}</th></tr></thead>"""
|
||||||
pr_body += """<tbody>"""
|
pr_body += """<tbody>"""
|
||||||
|
@ -363,7 +363,7 @@ class PRDescription:
|
|||||||
try:
|
try:
|
||||||
pr_body += "<table>"
|
pr_body += "<table>"
|
||||||
header = f"Relevant files"
|
header = f"Relevant files"
|
||||||
delta = 77
|
delta = 75
|
||||||
# header += " " * delta
|
# header += " " * delta
|
||||||
pr_body += f"""<thead><tr><th></th><th align="left">{header}</th></tr></thead>"""
|
pr_body += f"""<thead><tr><th></th><th align="left">{header}</th></tr></thead>"""
|
||||||
pr_body += """<tbody>"""
|
pr_body += """<tbody>"""
|
||||||
@ -454,6 +454,10 @@ def insert_br_after_x_chars(text, x=70):
|
|||||||
if i < len(lines) - 1:
|
if i < len(lines) - 1:
|
||||||
words[-1] += "<br>"
|
words[-1] += "<br>"
|
||||||
|
|
||||||
|
def count_chars_without_html(string):
|
||||||
|
no_html_string = re.sub('<[^>]+>', '', string)
|
||||||
|
return len(no_html_string)
|
||||||
|
|
||||||
new_text = []
|
new_text = []
|
||||||
is_inside_code = False
|
is_inside_code = False
|
||||||
current_length = 0
|
current_length = 0
|
||||||
@ -461,12 +465,13 @@ def insert_br_after_x_chars(text, x=70):
|
|||||||
is_saved_word = False
|
is_saved_word = False
|
||||||
if word == "<code>" or word == "</code>" or word == "<li>" or word == "<br>":
|
if word == "<code>" or word == "</code>" or word == "<li>" or word == "<br>":
|
||||||
is_saved_word = True
|
is_saved_word = True
|
||||||
if word == "<code>":
|
if "<code>" in word:
|
||||||
is_inside_code = True
|
is_inside_code = True
|
||||||
elif word == "</code>":
|
if "</code>" in word:
|
||||||
is_inside_code = False
|
is_inside_code = False
|
||||||
|
|
||||||
if not is_saved_word and (current_length + len(word) > x):
|
len_word = count_chars_without_html(word)
|
||||||
|
if not is_saved_word and (current_length + len_word > x):
|
||||||
if is_inside_code:
|
if is_inside_code:
|
||||||
new_text.append("</code><br><code>")
|
new_text.append("</code><br><code>")
|
||||||
else:
|
else:
|
||||||
@ -475,7 +480,7 @@ def insert_br_after_x_chars(text, x=70):
|
|||||||
new_text.append(word + " ")
|
new_text.append(word + " ")
|
||||||
|
|
||||||
if not is_saved_word:
|
if not is_saved_word:
|
||||||
current_length += len(word) + 1 # Add 1 for the space
|
current_length += len_word + 1 # Add 1 for the space
|
||||||
|
|
||||||
if word == "<li>" or word == "<br>":
|
if word == "<li>" or word == "<br>":
|
||||||
current_length = 0
|
current_length = 0
|
||||||
|
@ -98,13 +98,11 @@ class TestConvertToMarkdown:
|
|||||||
|
|
||||||
class TestBR:
|
class TestBR:
|
||||||
def test_br1(self):
|
def test_br1(self):
|
||||||
file_change_description = '- Created a new class `ColorPaletteResourcesCollection` in the namespace `Avalonia.Themes.Fluent`.\n- The class extends `AvaloniaDictionary<ThemeVariant, ColorPaletteResources>` and implements `IResourceProvider`.\n- The class includes methods for handling theme variants, resource retrieval, owner management, and property change events.'
|
file_change_description = '- Imported `FilePatchInfo` and `EDIT_TYPE` from `pr_agent.algo.types` instead of `pr_agent.git_providers.git_provider`.'
|
||||||
file_change_description_br = insert_br_after_x_chars(file_change_description)
|
file_change_description_br = insert_br_after_x_chars(file_change_description)
|
||||||
expected_output=('<li>Created a new class <code>ColorPaletteResourcesCollection</code> <br>in the namespace '
|
expected_output = ('<li>Imported <code>FilePatchInfo</code> and <code>EDIT_TYPE</code> from '
|
||||||
'<code>Avalonia.Themes.Fluent</code>.<br> <li> The class extends <code>AvaloniaDictionary'
|
'<code>pr_agent.algo.types</code> instead <br>of '
|
||||||
'<ThemeVariant, <br>ColorPaletteResources></code> and implements <br><code>IResourceProvider'
|
'<code>pr_agent.git_providers.git_provider</code>.')
|
||||||
'</code>.<br> <li> The class includes methods for handling theme variants, resource <br>'
|
|
||||||
'retrieval, owner management, and property change events.')
|
|
||||||
assert file_change_description_br == expected_output
|
assert file_change_description_br == expected_output
|
||||||
# print("-----")
|
# print("-----")
|
||||||
# print(file_change_description_br)
|
# print(file_change_description_br)
|
||||||
@ -113,9 +111,10 @@ class TestBR:
|
|||||||
file_change_description = ('- Created a - new -class `ColorPaletteResourcesCollection ColorPaletteResourcesCollection '
|
file_change_description = ('- Created a - new -class `ColorPaletteResourcesCollection ColorPaletteResourcesCollection '
|
||||||
'ColorPaletteResourcesCollection ColorPaletteResourcesCollection`')
|
'ColorPaletteResourcesCollection ColorPaletteResourcesCollection`')
|
||||||
file_change_description_br = insert_br_after_x_chars(file_change_description)
|
file_change_description_br = insert_br_after_x_chars(file_change_description)
|
||||||
expected_output = ('<li>Created a - new -class <code>ColorPaletteResourcesCollection '
|
expected_output = ('<li>Created a - new -class <code>ColorPaletteResourcesCollection </code><br><code>'
|
||||||
'<br>ColorPaletteResourcesCollection ColorPaletteResourcesCollection '
|
'ColorPaletteResourcesCollection ColorPaletteResourcesCollection <br>'
|
||||||
'<br>ColorPaletteResourcesCollection</code>')
|
'ColorPaletteResourcesCollection</code>')
|
||||||
assert file_change_description_br == expected_output
|
assert file_change_description_br == expected_output
|
||||||
# print("-----")
|
# print("-----")
|
||||||
# print(file_change_description_br)
|
# print(file_change_description_br)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user