Skip to content

Commit

Permalink
Merge pull request #512 from Codium-ai/trlabeling_files_extended
Browse files Browse the repository at this point in the history
Refactoring and Enhancement of PR Description Formatting in 'pr_description.py'
  • Loading branch information
mrT23 authored Dec 7, 2023
2 parents 73eafa2 + 1b22e59 commit a7a0de7
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 28 deletions.
18 changes: 18 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -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
- codiumai/pr-agent:0.10
- codiumai/pr-agent:0.10-github_app
Expand Down
7 changes: 6 additions & 1 deletion docs/DESCRIBE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 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:
```
/describe
Expand All @@ -26,9 +26,14 @@ 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.

- `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)

- `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.

- `enable_semantic_files_types`: if set to true, "PR changes walkthrough" section will be generated. Default is true.

### Markers template

Expand Down
62 changes: 35 additions & 27 deletions pr_agent/tools/pr_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def _prepare_pr_answer(self) -> Tuple[str, str]:
for idx, (key, value) in enumerate(self.data.items()):
if key == 'pr_files':
value = self.file_label_dict
key_publish = "PR changes summary"
key_publish = "PR changes walkthrough"
else:
key_publish = key.rstrip(':').replace("_", " ").capitalize()
pr_body += f"## {key_publish}\n"
Expand Down Expand Up @@ -317,58 +317,66 @@ def process_pr_files_prediction(self, pr_body, value):
return pr_body

try:
pr_body += """\n| | Relevant Files """
pr_body += "  " * 70
pr_body += """|\n|-----------|-------------|\n"""
pr_body += "<table>"
header = f"Relevant files"
delta = 65
header += "&nbsp; " * delta
pr_body += f"""<thead><tr><th></th><th>{header}</th></tr></thead>"""
pr_body += """<tbody>"""
for semantic_label in value.keys():
s_label = semantic_label.strip("'").strip('"')
if self.git_provider.is_supported("gfm_markdown"):
# pr_body += f"<details> <summary>{semantic_label['label']}</summary>\n\n"
pr_body += f"| **{s_label}** | <details><summary>files:</summary><ul>"

pr_body += f"""<tr><td><strong>{s_label.capitalize()}</strong></td>"""
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:
filename = filename.replace("'", "`")
filename_publish = filename.split("/")[-1]
filename_publish = f"**{filename_publish}**"
filename_publish = f"{filename_publish}"
if len(filename_publish) < (delta - 5):
filename_publish += "&nbsp; " * ((delta - 5) - len(filename_publish))
diff_plus_minus = ""
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} )"
diff_plus_minus += f"+{num_plus_lines}/-{num_minus_lines}"
break

# try to add line numbers link to code suggestions
link = ""
if hasattr(self.git_provider, 'get_line_link'):
filename = filename.strip()
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:
filename_publish += diff_plus_minus
if self.git_provider.is_supported("gfm_markdown"):
pr_body += f"<details><summary>{filename_publish}</summary>"
file_change_description = self._insert_br_after_x_chars(file_change_description)
if diff_plus_minus:
pr_body += f"<ul>Changes summary:<br>**{file_change_description}**</ul></details>"
else:
pr_body += f"<ul>Changes summary:<br>**{file_change_description}**</ul></details>"
if self.git_provider.is_supported("gfm_markdown"):
pr_body += "</ul></details>|\n"

file_change_description = self._insert_br_after_x_chars(file_change_description, x=(delta - 5))
pr_body += f"""
<tr>
<td>
<details>
<summary><strong>{filename_publish}</strong></summary>
<ul>
{filename}<br><br>
<strong>{file_change_description}</strong>
</ul>
</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:
get_logger().error(f"Error processing pr files to markdown {self.pr_id}: {e}")
pass
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.
"""
x = 70
if len(text) < x:
return text

Expand Down

0 comments on commit a7a0de7

Please sign in to comment.