Skip to content

Commit a7a0de7

Browse files
authored
Merge pull request #512 from Codium-ai/trlabeling_files_extended
Refactoring and Enhancement of PR Description Formatting in 'pr_description.py'
2 parents 73eafa2 + 1b22e59 commit a7a0de7

File tree

3 files changed

+59
-28
lines changed

3 files changed

+59
-28
lines changed

RELEASE_NOTES.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
## [Version 0.11] - 2023-12-07
2+
- codiumai/pr-agent:0.11
3+
- codiumai/pr-agent:0.11-github_app
4+
- codiumai/pr-agent:0.11-bitbucket-app
5+
- codiumai/pr-agent:0.11-gitlab_webhook
6+
- codiumai/pr-agent:0.11-github_polling
7+
- codiumai/pr-agent:0.11-github_action
8+
9+
### Added::Algo
10+
- New section in `/describe` tool - [PR changes walkthrough](https://github.com/Codium-ai/pr-agent/pull/509)
11+
- Improving PR Agent [prompts](https://github.com/Codium-ai/pr-agent/pull/501)
12+
- Persistent tools (`/review`, `/describe`) now send an [update message](https://github.com/Codium-ai/pr-agent/pull/499) after finishing
13+
- Add Amazon Bedrock [support](https://github.com/Codium-ai/pr-agent/pull/483)
14+
15+
### Fixed
16+
- Update [dependencies](https://github.com/Codium-ai/pr-agent/pull/503) in requirements.txt for Python 3.12
17+
18+
119
## [Version 0.10] - 2023-11-15
220
- codiumai/pr-agent:0.10
321
- codiumai/pr-agent:0.10-github_app

docs/DESCRIBE.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Describe Tool
22

3-
The `describe` tool scans the PR code changes, and automatically generates PR description - title, type, summary, code walkthrough and labels.
3+
The `describe` tool scans the PR code changes, and automatically generates PR description - title, type, summary, walkthrough and labels.
44
It can be invoked manually by commenting on any PR:
55
```
66
/describe
@@ -26,9 +26,14 @@ Under the section 'pr_description', the [configuration file](./../pr_agent/setti
2626
- `keep_original_user_title`: if set to true, the tool will keep the original PR title, and won't change it. Default is false.
2727

2828
- `extra_instructions`: Optional extra instructions to the tool. For example: "focus on the changes in the file X. Ignore change in ...".
29+
2930
- To enable `custom labels`, apply the configuration changes described [here](./GENERATE_CUSTOM_LABELS.md#configuration-changes)
31+
3032
- `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.
33+
3134
- `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.
35+
36+
- `enable_semantic_files_types`: if set to true, "PR changes walkthrough" section will be generated. Default is true.
3237

3338
### Markers template
3439

pr_agent/tools/pr_description.py

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def _prepare_pr_answer(self) -> Tuple[str, str]:
269269
for idx, (key, value) in enumerate(self.data.items()):
270270
if key == 'pr_files':
271271
value = self.file_label_dict
272-
key_publish = "PR changes summary"
272+
key_publish = "PR changes walkthrough"
273273
else:
274274
key_publish = key.rstrip(':').replace("_", " ").capitalize()
275275
pr_body += f"## {key_publish}\n"
@@ -317,58 +317,66 @@ def process_pr_files_prediction(self, pr_body, value):
317317
return pr_body
318318

319319
try:
320-
pr_body += """\n| | Relevant Files """
321-
pr_body += "  " * 70
322-
pr_body += """|\n|-----------|-------------|\n"""
320+
pr_body += "<table>"
321+
header = f"Relevant files"
322+
delta = 65
323+
header += "&nbsp; " * delta
324+
pr_body += f"""<thead><tr><th></th><th>{header}</th></tr></thead>"""
325+
pr_body += """<tbody>"""
323326
for semantic_label in value.keys():
324327
s_label = semantic_label.strip("'").strip('"')
325-
if self.git_provider.is_supported("gfm_markdown"):
326-
# pr_body += f"<details> <summary>{semantic_label['label']}</summary>\n\n"
327-
pr_body += f"| **{s_label}** | <details><summary>files:</summary><ul>"
328-
328+
pr_body += f"""<tr><td><strong>{s_label.capitalize()}</strong></td>"""
329329
list_tuples = value[semantic_label]
330+
pr_body += f"""<td><details><summary>{len(list_tuples)} files</summary><table>"""
330331
for filename, file_change_description in list_tuples:
331332
filename = filename.replace("'", "`")
332333
filename_publish = filename.split("/")[-1]
333-
filename_publish = f"**{filename_publish}**"
334+
filename_publish = f"{filename_publish}"
335+
if len(filename_publish) < (delta - 5):
336+
filename_publish += "&nbsp; " * ((delta - 5) - len(filename_publish))
334337
diff_plus_minus = ""
335338
diff_files = self.git_provider.diff_files
336339
for f in diff_files:
337340
if f.filename.lower() == filename.lower():
338341
num_plus_lines = f.num_plus_lines
339342
num_minus_lines = f.num_minus_lines
340-
diff_plus_minus += f" ( +{num_plus_lines}/-{num_minus_lines} )"
343+
diff_plus_minus += f"+{num_plus_lines}/-{num_minus_lines}"
341344
break
342345

343346
# try to add line numbers link to code suggestions
347+
link = ""
344348
if hasattr(self.git_provider, 'get_line_link'):
345349
filename = filename.strip()
346350
link = self.git_provider.get_line_link(filename, relevant_line_start=-1)
347-
if link:
348-
diff_plus_minus = f"[{diff_plus_minus}]({link})"
349-
diff_plus_minus = f" <sup>{diff_plus_minus}</sup>"
350-
351-
if diff_plus_minus:
352-
filename_publish += diff_plus_minus
353-
if self.git_provider.is_supported("gfm_markdown"):
354-
pr_body += f"<details><summary>{filename_publish}</summary>"
355-
file_change_description = self._insert_br_after_x_chars(file_change_description)
356-
if diff_plus_minus:
357-
pr_body += f"<ul>Changes summary:<br>**{file_change_description}**</ul></details>"
358-
else:
359-
pr_body += f"<ul>Changes summary:<br>**{file_change_description}**</ul></details>"
360-
if self.git_provider.is_supported("gfm_markdown"):
361-
pr_body += "</ul></details>|\n"
351+
352+
file_change_description = self._insert_br_after_x_chars(file_change_description, x=(delta - 5))
353+
pr_body += f"""
354+
<tr>
355+
<td>
356+
<details>
357+
<summary><strong>{filename_publish}</strong></summary>
358+
<ul>
359+
{filename}<br><br>
360+
<strong>{file_change_description}</strong>
361+
</ul>
362+
</details>
363+
</td>
364+
<td><a href="{link}"> {diff_plus_minus}</a></td>
365+
366+
</tr>
367+
"""
368+
pr_body += """</table></details></td></tr>"""
369+
pr_body += """</tr></tbody></table>"""
370+
362371
except Exception as e:
363372
get_logger().error(f"Error processing pr files to markdown {self.pr_id}: {e}")
364373
pass
365374
return pr_body
366375

367-
def _insert_br_after_x_chars(self, text):
376+
def _insert_br_after_x_chars(self, text, x=70):
368377
"""
369378
Insert <br> into a string after a word that increases its length above x characters.
370379
"""
371-
x = 70
372380
if len(text) < x:
373381
return text
374382

0 commit comments

Comments
 (0)