From 32e8ba331a3c2ed8c4bdf77a3c4a32c7cb95f4b3 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Mon, 5 Feb 2024 10:12:47 +0200 Subject: [PATCH] insert_br_after_x_chars --- pr_agent/tools/pr_code_suggestions.py | 2 +- pr_agent/tools/pr_description.py | 15 ++++++++++----- tests/unittest/test_convert_to_markdown.py | 19 +++++++++---------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index fb725848..5fc45619 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -325,7 +325,7 @@ class PRCodeSuggestions: pr_body += "" header = f"Suggestions" - delta = 77 + delta = 75 header += "  " * delta pr_body += f"""""" pr_body += """""" diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index ef64f515..bbe53fca 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -363,7 +363,7 @@ class PRDescription: try: pr_body += "
{header}
" header = f"Relevant files" - delta = 77 + delta = 75 # header += "  " * delta pr_body += f"""""" pr_body += """""" @@ -454,6 +454,10 @@ def insert_br_after_x_chars(text, x=70): if i < len(lines) - 1: words[-1] += "
" + def count_chars_without_html(string): + no_html_string = re.sub('<[^>]+>', '', string) + return len(no_html_string) + new_text = [] is_inside_code = False current_length = 0 @@ -461,12 +465,13 @@ def insert_br_after_x_chars(text, x=70): is_saved_word = False if word == "" or word == "" or word == "
  • " or word == "
    ": is_saved_word = True - if word == "": + if "" in word: is_inside_code = True - elif word == "": + if "" in word: 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: new_text.append("
    ") else: @@ -475,7 +480,7 @@ def insert_br_after_x_chars(text, x=70): new_text.append(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 == "
  • " or word == "
    ": current_length = 0 diff --git a/tests/unittest/test_convert_to_markdown.py b/tests/unittest/test_convert_to_markdown.py index 9e662a76..72d34656 100644 --- a/tests/unittest/test_convert_to_markdown.py +++ b/tests/unittest/test_convert_to_markdown.py @@ -98,13 +98,11 @@ class TestConvertToMarkdown: class TestBR: def test_br1(self): - file_change_description = '- Created a new class `ColorPaletteResourcesCollection` in the namespace `Avalonia.Themes.Fluent`.\n- The class extends `AvaloniaDictionary` 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) - expected_output=('
  • Created a new class ColorPaletteResourcesCollection
    in the namespace ' - 'Avalonia.Themes.Fluent.
  • The class extends AvaloniaDictionary' - 'ColorPaletteResources> and implements
    IResourceProvider' - '.
  • The class includes methods for handling theme variants, resource
    ' - 'retrieval, owner management, and property change events.') + expected_output = ('
  • Imported FilePatchInfo and EDIT_TYPE from ' + 'pr_agent.algo.types instead
    of ' + 'pr_agent.git_providers.git_provider.') assert file_change_description_br == expected_output # print("-----") # print(file_change_description_br) @@ -113,9 +111,10 @@ class TestBR: file_change_description = ('- Created a - new -class `ColorPaletteResourcesCollection ColorPaletteResourcesCollection ' 'ColorPaletteResourcesCollection ColorPaletteResourcesCollection`') file_change_description_br = insert_br_after_x_chars(file_change_description) - expected_output = ('
  • Created a - new -class ColorPaletteResourcesCollection ' - '
    ColorPaletteResourcesCollection ColorPaletteResourcesCollection ' - '
    ColorPaletteResourcesCollection
    ') + expected_output = ('
  • Created a - new -class ColorPaletteResourcesCollection
    ' + 'ColorPaletteResourcesCollection ColorPaletteResourcesCollection
    ' + 'ColorPaletteResourcesCollection
    ') assert file_change_description_br == expected_output # print("-----") - # print(file_change_description_br) \ No newline at end of file + # print(file_change_description_br) +
  • {header}