diff --git a/pr_agent/settings/pr_description_prompts.toml b/pr_agent/settings/pr_description_prompts.toml
index 09d1c6e4..b9c5ce39 100644
--- a/pr_agent/settings/pr_description_prompts.toml
+++ b/pr_agent/settings/pr_description_prompts.toml
@@ -39,7 +39,8 @@ class PRType(str, Enum):
Class FileDescription(BaseModel):
filename: str = Field(description="the relevant file full path")
- changes_summary: str = Field(description="minimal and concise summary of the changes in the relevant file")
+ changes_summary: str = Field(description="concise summary of the changes in the relevant file, in bullet points (1-4 bullet points).")
+ changes_title: str = Field(description="an informative title for the changes in the files, describing its main theme (5-10 words).")
label: str = Field(description="a single semantic label that represents a type of code changes that occurred in the File. Possible values (partial list): 'bug fix', 'tests', 'enhancement', 'documentation', 'error handling', 'configuration changes', 'dependencies', 'formatting', 'miscellaneous', ...")
{%- endif %}
@@ -68,6 +69,8 @@ pr_files:
...
changes_summary: |
...
+ changes_title: |
+ ...
label: |
...
...
diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py
index e3ec92ff..0cc32b7f 100644
--- a/pr_agent/tools/pr_description.py
+++ b/pr_agent/tools/pr_description.py
@@ -333,10 +333,11 @@ class PRDescription:
try:
filename = file['filename'].replace("'", "`").replace('"', '`')
changes_summary = file['changes_summary']
+ changes_title = file['changes_title'].strip()
label = file.get('label')
if label not in self.file_label_dict:
self.file_label_dict[label] = []
- self.file_label_dict[label].append((filename, changes_summary))
+ self.file_label_dict[label].append((filename, changes_title, changes_summary))
except Exception as e:
get_logger().error(f"Error preparing file label dict {self.pr_id}: {e}")
pass
@@ -357,9 +358,9 @@ class PRDescription:
try:
pr_body += "
"
header = f"Relevant files"
- delta = 65
- header += " " * delta
- pr_body += f""" | {header} |
"""
+ delta = 77
+ # header += " " * delta
+ pr_body += f""" | {header} |
"""
pr_body += """"""
for semantic_label in value.keys():
s_label = semantic_label.strip("'").strip('"')
@@ -370,19 +371,24 @@ class PRDescription:
pr_body += f"""{len(list_tuples)} files"""
else:
pr_body += f""""""
- for filename, file_change_description in list_tuples:
+ for filename, file_changes_title, file_change_description in list_tuples:
filename = filename.replace("'", "`")
filename_publish = filename.split("/")[-1]
- filename_publish = f"{filename_publish}"
- if len(filename_publish) < (delta - 5):
- filename_publish += " " * ((delta - 5) - len(filename_publish))
+ file_changes_title_br = insert_br_after_x_chars(file_changes_title, x=(delta - 5),
+ new_line_char="\n\n")
+ 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} "
diff_plus_minus = ""
+ delta_nbsp = ""
diff_files = self.git_provider.diff_files
for f in diff_files:
if f.filename.lower() == filename.lower():
num_plus_lines = f.num_plus_lines
num_minus_lines = f.num_minus_lines
diff_plus_minus += f"+{num_plus_lines}/-{num_minus_lines}"
+ delta_nbsp = " " * max(0, (8 - len(diff_plus_minus)))
break
# try to add line numbers link to code suggestions
@@ -391,21 +397,19 @@ class PRDescription:
filename = filename.strip()
link = self.git_provider.get_line_link(filename, relevant_line_start=-1)
- file_change_description = insert_br_after_x_chars(file_change_description, x=(delta - 5))
+ file_change_description_br = insert_br_after_x_chars(file_change_description, x=(delta - 5))
pr_body += f"""
- {filename_publish}
-
- {filename}
+ {filename_publish}
+
-**{file_change_description}**
-
+{filename}
+{file_change_description_br}
|
- {diff_plus_minus} |
-
+ {diff_plus_minus}{delta_nbsp} |
"""
if use_collapsible_file_list:
@@ -419,25 +423,48 @@ class PRDescription:
pass
return pr_body
-def insert_br_after_x_chars(text, x=70):
+def insert_br_after_x_chars(text, x=70, new_line_char=" "):
"""
Insert into a string after a word that increases its length above x characters.
"""
if len(text) < x:
return text
- words = text.split(' ')
+ lines = text.splitlines()
+ words = []
+ for i,line in enumerate(lines):
+ words += line.split(' ')
+ if i x:
- new_text += " " # Insert line break
- current_length = 0 # Reset counter
+ if not is_inside_code:
+ new_text += f"{new_line_char} " # Insert line break
+ current_length = 0 # Reset counter
+ else:
+ new_text += f"`{new_line_char} `"
+ # check if inside tag
+ if word.startswith("`") and not is_inside_code and not word.endswith("`"):
+ is_inside_code = True
+ if word.endswith("`"):
+ is_inside_code = False
# Add the word to the new text
- new_text += word + " "
+ if word.endswith("\n"):
+ new_text += word
+ else:
+ new_text += word + " "
current_length += len(word) + 1 # Add 1 for the space
+
+ if word.endswith("\n"):
+ current_length = 0
return new_text.strip() # Remove trailing space
| |