From 4e386153ea373e5ed60b346ccf11591cec9084a5 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 11 Feb 2024 11:32:16 +0200 Subject: [PATCH 1/2] insert_br_after_x_chars can already handle code --- pr_agent/tools/pr_description.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index 0cdbbd855..3c9854c1a 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -379,11 +379,11 @@ def process_pr_files_prediction(self, pr_body, value): for filename, file_changes_title, file_change_description in list_tuples: filename = filename.replace("'", "`").rstrip() filename_publish = filename.split("/")[-1] - file_changes_title_br = insert_br_after_x_chars(file_changes_title, x=(delta - 5)) - file_changes_title_extended = file_changes_title_br.strip() + "" - if len(file_changes_title_extended) < (delta - 5): - file_changes_title_extended += "  " * ((delta - 5) - len(file_changes_title_extended)) - filename_publish = f"{filename_publish}
{file_changes_title_extended}
" + file_changes_title_code = f"{file_changes_title}" + file_changes_title_code_br = insert_br_after_x_chars(file_changes_title_code, x=(delta - 5)).strip() + if len(file_changes_title_code_br) < (delta - 5): + file_changes_title_code_br += "  " * ((delta - 5) - len(file_changes_title_code_br)) + filename_publish = f"{filename_publish}
{file_changes_title_code_br}
" diff_plus_minus = "" delta_nbsp = "" diff_files = self.git_provider.diff_files From c75413fac5f89e95fcf3e70031c18e60b260644f Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 11 Feb 2024 11:37:11 +0200 Subject: [PATCH 2/2] count_chars_without_html --- pr_agent/tools/pr_description.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index 3c9854c1a..95a691952 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -431,12 +431,20 @@ def process_pr_files_prediction(self, pr_body, value): pass return pr_body + +def count_chars_without_html(string): + if '<' not in string: + return len(string) + no_html_string = re.sub('<[^>]+>', '', string) + return len(no_html_string) + + def insert_br_after_x_chars(text, x=70): """ Insert
into a string after a word that increases its length above x characters. Use proper HTML tags for code and new lines. """ - if len(text) < x: + if count_chars_without_html(text) < x: return text # replace odd instances of ` with and even instances of ` with @@ -458,12 +466,6 @@ def insert_br_after_x_chars(text, x=70): if i < len(lines) - 1: words[-1] += "
" - def count_chars_without_html(string): - if '<' not in string: - return len(string) - no_html_string = re.sub('<[^>]+>', '', string) - return len(no_html_string) - new_text = [] is_inside_code = False current_length = 0