mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-04 04:40:38 +08:00
Merge pull request #512 from Codium-ai/trlabeling_files_extended
Refactoring and Enhancement of PR Description Formatting in 'pr_description.py'
This commit is contained in:
@ -1,3 +1,21 @@
|
|||||||
|
## [Version 0.11] - 2023-12-07
|
||||||
|
- codiumai/pr-agent:0.11
|
||||||
|
- codiumai/pr-agent:0.11-github_app
|
||||||
|
- codiumai/pr-agent:0.11-bitbucket-app
|
||||||
|
- codiumai/pr-agent:0.11-gitlab_webhook
|
||||||
|
- codiumai/pr-agent:0.11-github_polling
|
||||||
|
- codiumai/pr-agent:0.11-github_action
|
||||||
|
|
||||||
|
### Added::Algo
|
||||||
|
- New section in `/describe` tool - [PR changes walkthrough](https://github.com/Codium-ai/pr-agent/pull/509)
|
||||||
|
- Improving PR Agent [prompts](https://github.com/Codium-ai/pr-agent/pull/501)
|
||||||
|
- Persistent tools (`/review`, `/describe`) now send an [update message](https://github.com/Codium-ai/pr-agent/pull/499) after finishing
|
||||||
|
- Add Amazon Bedrock [support](https://github.com/Codium-ai/pr-agent/pull/483)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Update [dependencies](https://github.com/Codium-ai/pr-agent/pull/503) in requirements.txt for Python 3.12
|
||||||
|
|
||||||
|
|
||||||
## [Version 0.10] - 2023-11-15
|
## [Version 0.10] - 2023-11-15
|
||||||
- codiumai/pr-agent:0.10
|
- codiumai/pr-agent:0.10
|
||||||
- codiumai/pr-agent:0.10-github_app
|
- codiumai/pr-agent:0.10-github_app
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Describe Tool
|
# Describe Tool
|
||||||
|
|
||||||
The `describe` tool scans the PR code changes, and automatically generates PR description - title, type, summary, code walkthrough and labels.
|
The `describe` tool scans the PR code changes, and automatically generates PR description - title, type, summary, walkthrough and labels.
|
||||||
It can be invoked manually by commenting on any PR:
|
It can be invoked manually by commenting on any PR:
|
||||||
```
|
```
|
||||||
/describe
|
/describe
|
||||||
@ -26,10 +26,15 @@ Under the section 'pr_description', the [configuration file](./../pr_agent/setti
|
|||||||
- `keep_original_user_title`: if set to true, the tool will keep the original PR title, and won't change it. Default is false.
|
- `keep_original_user_title`: if set to true, the tool will keep the original PR title, and won't change it. Default is false.
|
||||||
|
|
||||||
- `extra_instructions`: Optional extra instructions to the tool. For example: "focus on the changes in the file X. Ignore change in ...".
|
- `extra_instructions`: Optional extra instructions to the tool. For example: "focus on the changes in the file X. Ignore change in ...".
|
||||||
|
|
||||||
- To enable `custom labels`, apply the configuration changes described [here](./GENERATE_CUSTOM_LABELS.md#configuration-changes)
|
- To enable `custom labels`, apply the configuration changes described [here](./GENERATE_CUSTOM_LABELS.md#configuration-changes)
|
||||||
|
|
||||||
- `enable_pr_type`: if set to false, it will not show the `PR type` as a text value in the description content. Default is true.
|
- `enable_pr_type`: if set to false, it will not show the `PR type` as a text value in the description content. Default is true.
|
||||||
|
|
||||||
- `final_update_message`: if set to true, it will add a comment message [`PR Description updated to latest commit...`](https://github.com/Codium-ai/pr-agent/pull/499#issuecomment-1837412176) after finishing calling `/describe`. Default is true.
|
- `final_update_message`: if set to true, it will add a comment message [`PR Description updated to latest commit...`](https://github.com/Codium-ai/pr-agent/pull/499#issuecomment-1837412176) after finishing calling `/describe`. Default is true.
|
||||||
|
|
||||||
|
- `enable_semantic_files_types`: if set to true, "PR changes walkthrough" section will be generated. Default is true.
|
||||||
|
|
||||||
### Markers template
|
### Markers template
|
||||||
|
|
||||||
markers enable to easily integrate user's content and auto-generated content, with a template-like mechanism.
|
markers enable to easily integrate user's content and auto-generated content, with a template-like mechanism.
|
||||||
|
@ -269,7 +269,7 @@ class PRDescription:
|
|||||||
for idx, (key, value) in enumerate(self.data.items()):
|
for idx, (key, value) in enumerate(self.data.items()):
|
||||||
if key == 'pr_files':
|
if key == 'pr_files':
|
||||||
value = self.file_label_dict
|
value = self.file_label_dict
|
||||||
key_publish = "PR changes summary"
|
key_publish = "PR changes walkthrough"
|
||||||
else:
|
else:
|
||||||
key_publish = key.rstrip(':').replace("_", " ").capitalize()
|
key_publish = key.rstrip(':').replace("_", " ").capitalize()
|
||||||
pr_body += f"## {key_publish}\n"
|
pr_body += f"## {key_publish}\n"
|
||||||
@ -317,58 +317,66 @@ class PRDescription:
|
|||||||
return pr_body
|
return pr_body
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pr_body += """\n| | Relevant Files """
|
pr_body += "<table>"
|
||||||
pr_body += " " * 70
|
header = f"Relevant files"
|
||||||
pr_body += """|\n|-----------|-------------|\n"""
|
delta = 65
|
||||||
|
header += " " * delta
|
||||||
|
pr_body += f"""<thead><tr><th></th><th>{header}</th></tr></thead>"""
|
||||||
|
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('"')
|
||||||
if self.git_provider.is_supported("gfm_markdown"):
|
pr_body += f"""<tr><td><strong>{s_label.capitalize()}</strong></td>"""
|
||||||
# pr_body += f"<details> <summary>{semantic_label['label']}</summary>\n\n"
|
|
||||||
pr_body += f"| **{s_label}** | <details><summary>files:</summary><ul>"
|
|
||||||
|
|
||||||
list_tuples = value[semantic_label]
|
list_tuples = value[semantic_label]
|
||||||
|
pr_body += f"""<td><details><summary>{len(list_tuples)} files</summary><table>"""
|
||||||
for filename, file_change_description in list_tuples:
|
for filename, 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}**"
|
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:
|
||||||
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}"
|
||||||
break
|
break
|
||||||
|
|
||||||
# try to add line numbers link to code suggestions
|
# try to add line numbers link to code suggestions
|
||||||
|
link = ""
|
||||||
if hasattr(self.git_provider, 'get_line_link'):
|
if hasattr(self.git_provider, 'get_line_link'):
|
||||||
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)
|
||||||
if link:
|
|
||||||
diff_plus_minus = f"[{diff_plus_minus}]({link})"
|
|
||||||
diff_plus_minus = f" <sup>{diff_plus_minus}</sup>"
|
|
||||||
|
|
||||||
if diff_plus_minus:
|
file_change_description = self._insert_br_after_x_chars(file_change_description, x=(delta - 5))
|
||||||
filename_publish += diff_plus_minus
|
pr_body += f"""
|
||||||
if self.git_provider.is_supported("gfm_markdown"):
|
<tr>
|
||||||
pr_body += f"<details><summary>{filename_publish}</summary>"
|
<td>
|
||||||
file_change_description = self._insert_br_after_x_chars(file_change_description)
|
<details>
|
||||||
if diff_plus_minus:
|
<summary><strong>{filename_publish}</strong></summary>
|
||||||
pr_body += f"<ul>Changes summary:<br>**{file_change_description}**</ul></details>"
|
<ul>
|
||||||
else:
|
{filename}<br><br>
|
||||||
pr_body += f"<ul>Changes summary:<br>**{file_change_description}**</ul></details>"
|
<strong>{file_change_description}</strong>
|
||||||
if self.git_provider.is_supported("gfm_markdown"):
|
</ul>
|
||||||
pr_body += "</ul></details>|\n"
|
</details>
|
||||||
|
</td>
|
||||||
|
<td><a href="{link}"> {diff_plus_minus}</a></td>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
"""
|
||||||
|
pr_body += """</table></details></td></tr>"""
|
||||||
|
pr_body += """</tr></tbody></table>"""
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
get_logger().error(f"Error processing pr files to markdown {self.pr_id}: {e}")
|
get_logger().error(f"Error processing pr files to markdown {self.pr_id}: {e}")
|
||||||
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