mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-03 04:10:49 +08:00
Add changes title of files and improve table style and alignments
This commit is contained in:
@ -39,7 +39,8 @@ class PRType(str, Enum):
|
|||||||
|
|
||||||
Class FileDescription(BaseModel):
|
Class FileDescription(BaseModel):
|
||||||
filename: str = Field(description="the relevant file full path")
|
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', ...")
|
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 %}
|
{%- endif %}
|
||||||
|
|
||||||
@ -68,6 +69,8 @@ pr_files:
|
|||||||
...
|
...
|
||||||
changes_summary: |
|
changes_summary: |
|
||||||
...
|
...
|
||||||
|
changes_title: |
|
||||||
|
...
|
||||||
label: |
|
label: |
|
||||||
...
|
...
|
||||||
...
|
...
|
||||||
|
@ -333,10 +333,11 @@ class PRDescription:
|
|||||||
try:
|
try:
|
||||||
filename = file['filename'].replace("'", "`").replace('"', '`')
|
filename = file['filename'].replace("'", "`").replace('"', '`')
|
||||||
changes_summary = file['changes_summary']
|
changes_summary = file['changes_summary']
|
||||||
|
changes_title = file['changes_title'].strip()
|
||||||
label = file.get('label')
|
label = file.get('label')
|
||||||
if label not in self.file_label_dict:
|
if label not in self.file_label_dict:
|
||||||
self.file_label_dict[label] = []
|
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:
|
except Exception as e:
|
||||||
get_logger().error(f"Error preparing file label dict {self.pr_id}: {e}")
|
get_logger().error(f"Error preparing file label dict {self.pr_id}: {e}")
|
||||||
pass
|
pass
|
||||||
@ -357,9 +358,9 @@ class PRDescription:
|
|||||||
try:
|
try:
|
||||||
pr_body += "<table>"
|
pr_body += "<table>"
|
||||||
header = f"Relevant files"
|
header = f"Relevant files"
|
||||||
delta = 65
|
delta = 77
|
||||||
header += " " * delta
|
# header += " " * delta
|
||||||
pr_body += f"""<thead><tr><th></th><th>{header}</th></tr></thead>"""
|
pr_body += f"""<thead><tr><th></th><th align="left">{header}</th></tr></thead>"""
|
||||||
pr_body += """<tbody>"""
|
pr_body += """<tbody>"""
|
||||||
for semantic_label in value.keys():
|
for semantic_label in value.keys():
|
||||||
s_label = semantic_label.strip("'").strip('"')
|
s_label = semantic_label.strip("'").strip('"')
|
||||||
@ -370,19 +371,24 @@ class PRDescription:
|
|||||||
pr_body += f"""<td><details><summary>{len(list_tuples)} files</summary><table>"""
|
pr_body += f"""<td><details><summary>{len(list_tuples)} files</summary><table>"""
|
||||||
else:
|
else:
|
||||||
pr_body += f"""<td><table>"""
|
pr_body += f"""<td><table>"""
|
||||||
for filename, file_change_description in list_tuples:
|
for filename, file_changes_title, file_change_description in list_tuples:
|
||||||
filename = filename.replace("'", "`")
|
filename = filename.replace("'", "`")
|
||||||
filename_publish = filename.split("/")[-1]
|
filename_publish = filename.split("/")[-1]
|
||||||
filename_publish = f"{filename_publish}"
|
file_changes_title_br = insert_br_after_x_chars(file_changes_title, x=(delta - 5),
|
||||||
if len(filename_publish) < (delta - 5):
|
new_line_char="\n\n")
|
||||||
filename_publish += " " * ((delta - 5) - len(filename_publish))
|
file_changes_title_extended = file_changes_title_br.strip() + "</code>"
|
||||||
|
if len(file_changes_title_extended) < (delta - 5):
|
||||||
|
file_changes_title_extended += " " * ((delta - 5) - len(file_changes_title_extended))
|
||||||
|
filename_publish = f"<strong>{filename_publish}</strong><dd><code>{file_changes_title_extended}</dd>"
|
||||||
diff_plus_minus = ""
|
diff_plus_minus = ""
|
||||||
|
delta_nbsp = ""
|
||||||
diff_files = self.git_provider.diff_files
|
diff_files = self.git_provider.diff_files
|
||||||
for f in diff_files:
|
for f in diff_files:
|
||||||
if f.filename.lower() == filename.lower():
|
if f.filename.lower() == filename.lower():
|
||||||
num_plus_lines = f.num_plus_lines
|
num_plus_lines = f.num_plus_lines
|
||||||
num_minus_lines = f.num_minus_lines
|
num_minus_lines = f.num_minus_lines
|
||||||
diff_plus_minus += f"+{num_plus_lines}/-{num_minus_lines}"
|
diff_plus_minus += f"+{num_plus_lines}/-{num_minus_lines}"
|
||||||
|
delta_nbsp = " " * max(0, (8 - len(diff_plus_minus)))
|
||||||
break
|
break
|
||||||
|
|
||||||
# try to add line numbers link to code suggestions
|
# try to add line numbers link to code suggestions
|
||||||
@ -391,21 +397,19 @@ class PRDescription:
|
|||||||
filename = filename.strip()
|
filename = filename.strip()
|
||||||
link = self.git_provider.get_line_link(filename, relevant_line_start=-1)
|
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"""
|
pr_body += f"""
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<details>
|
<details>
|
||||||
<summary><strong>{filename_publish}</strong></summary>
|
<summary>{filename_publish}</summary>
|
||||||
<ul>
|
<hr>
|
||||||
{filename}<br><br>
|
|
||||||
|
|
||||||
**{file_change_description}**
|
{filename}
|
||||||
</ul>
|
{file_change_description_br}
|
||||||
</details>
|
</details>
|
||||||
</td>
|
</td>
|
||||||
<td><a href="{link}"> {diff_plus_minus}</a></td>
|
<td><a href="{link}">{diff_plus_minus}</a>{delta_nbsp}</td>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
"""
|
"""
|
||||||
if use_collapsible_file_list:
|
if use_collapsible_file_list:
|
||||||
@ -419,25 +423,48 @@ class PRDescription:
|
|||||||
pass
|
pass
|
||||||
return pr_body
|
return pr_body
|
||||||
|
|
||||||
def insert_br_after_x_chars(text, x=70):
|
def insert_br_after_x_chars(text, x=70, new_line_char="<br> "):
|
||||||
"""
|
"""
|
||||||
Insert <br> into a string after a word that increases its length above x characters.
|
Insert <br> into a string after a word that increases its length above x characters.
|
||||||
"""
|
"""
|
||||||
if len(text) < x:
|
if len(text) < x:
|
||||||
return text
|
return text
|
||||||
|
|
||||||
words = text.split(' ')
|
lines = text.splitlines()
|
||||||
|
words = []
|
||||||
|
for i,line in enumerate(lines):
|
||||||
|
words += line.split(' ')
|
||||||
|
if i<len(lines)-1:
|
||||||
|
words[-1] += "\n"
|
||||||
|
|
||||||
|
|
||||||
|
# words = text.split(' ')
|
||||||
|
|
||||||
new_text = ""
|
new_text = ""
|
||||||
current_length = 0
|
current_length = 0
|
||||||
|
is_inside_code = False
|
||||||
for word in words:
|
for word in words:
|
||||||
# Check if adding this word exceeds x characters
|
# Check if adding this word exceeds x characters
|
||||||
if current_length + len(word) > x:
|
if current_length + len(word) > x:
|
||||||
new_text += "<br>" # Insert line break
|
if not is_inside_code:
|
||||||
current_length = 0 # Reset counter
|
new_text += f"{new_line_char} " # Insert line break
|
||||||
|
current_length = 0 # Reset counter
|
||||||
|
else:
|
||||||
|
new_text += f"`{new_line_char} `"
|
||||||
|
# check if inside <code> 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
|
# 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
|
current_length += len(word) + 1 # Add 1 for the space
|
||||||
|
|
||||||
|
|
||||||
|
if word.endswith("\n"):
|
||||||
|
current_length = 0
|
||||||
return new_text.strip() # Remove trailing space
|
return new_text.strip() # Remove trailing space
|
||||||
|
Reference in New Issue
Block a user