mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-04 04:40:38 +08:00
feat: Enhance PR description formatting in pr_description.py
Improve the table structure for relevant files in PR description by adjusting the header and filename display. Add padding for filename and change summary, and move diff_plus_minus to a separate column. Refactor _insert_br_after_x_chars function to accept a variable length parameter.
This commit is contained in:
@ -317,9 +317,11 @@ class PRDescription:
|
|||||||
return pr_body
|
return pr_body
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pr_body = ""
|
|
||||||
pr_body += "<table>"
|
pr_body += "<table>"
|
||||||
pr_body += """<thead><tr><th></th><th>Relevant Files</th></tr></thead>"""
|
header = f"Relevant Files"
|
||||||
|
delta = 65
|
||||||
|
header +=" " * delta
|
||||||
|
pr_body += f"""<thead><tr><th></th><th>{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('"')
|
||||||
@ -330,6 +332,8 @@ class PRDescription:
|
|||||||
filename = filename.replace("'", "`")
|
filename = filename.replace("'", "`")
|
||||||
filename_publish = filename.split("/")[-1]
|
filename_publish = filename.split("/")[-1]
|
||||||
filename_publish = f"{filename_publish}"
|
filename_publish = f"{filename_publish}"
|
||||||
|
if len(filename_publish)< (delta-5):
|
||||||
|
filename_publish += " " * ((delta-5) - len(filename_publish))
|
||||||
diff_plus_minus = ""
|
diff_plus_minus = ""
|
||||||
diff_files = self.git_provider.diff_files
|
diff_files = self.git_provider.diff_files
|
||||||
for f in diff_files:
|
for f in diff_files:
|
||||||
@ -345,24 +349,24 @@ 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 = self._insert_br_after_x_chars(file_change_description)
|
file_change_description = self._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> <sup><a href="{link}"> {diff_plus_minus}</a></sup></summary>
|
<summary><strong>{filename_publish}</strong></summary>
|
||||||
<ul>
|
<ul>
|
||||||
Changes summary:<br>
|
({filename})<br><br>
|
||||||
<strong>{file_change_description}</strong>
|
<strong>{file_change_description}</strong>
|
||||||
</ul>
|
</ul>
|
||||||
</details>
|
</details>
|
||||||
</td>
|
</td>
|
||||||
|
<td><a href="{link}"> {diff_plus_minus}</a></td>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
"""
|
"""
|
||||||
pr_body += """</table></details></td></tr>"""
|
pr_body += """</table></details></td></tr>"""
|
||||||
pr_body += """</tr></tbody></table>"""
|
pr_body += """</tr></tbody></table>"""
|
||||||
print(pr_body)
|
|
||||||
|
|
||||||
|
|
||||||
# pr_body += """\n| | Relevant Files """
|
# pr_body += """\n| | Relevant Files """
|
||||||
# pr_body += " " * 70
|
# pr_body += " " * 70
|
||||||
@ -411,11 +415,10 @@ class PRDescription:
|
|||||||
pass
|
pass
|
||||||
return pr_body
|
return pr_body
|
||||||
|
|
||||||
def _insert_br_after_x_chars(self, text):
|
def _insert_br_after_x_chars(self, text, x=70):
|
||||||
"""
|
"""
|
||||||
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.
|
||||||
"""
|
"""
|
||||||
x = 70
|
|
||||||
if len(text) < x:
|
if len(text) < x:
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user