From e62acef6d2deb4e2177d865c28ce91396a8f7687 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Thu, 7 Dec 2023 09:50:36 +0200 Subject: [PATCH 1/6] s1 --- pr_agent/tools/pr_description.py | 93 ++++++++++++++++++++++++-------- 1 file changed, 70 insertions(+), 23 deletions(-) diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index 88baaac57..2f0466c67 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -317,20 +317,19 @@ 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 = "" + pr_body += "" + pr_body += """""" + pr_body += """""" for semantic_label in value.keys(): s_label = semantic_label.strip("'").strip('"') - if self.git_provider.is_supported("gfm_markdown"): - # pr_body += f"
{semantic_label['label']}\n\n" - pr_body += f"| **{s_label}** |
files:
    " - + pr_body += f"""
""" list_tuples = value[semantic_label] + pr_body += f"""""" + pr_body += """
Relevant Files
{s_label}
{len(list_tuples)} files""" 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}" diff_plus_minus = "" diff_files = self.git_provider.diff_files for f in diff_files: @@ -341,24 +340,72 @@ def process_pr_files_prediction(self, pr_body, value): 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" {diff_plus_minus}" - - if diff_plus_minus: - filename_publish += diff_plus_minus - if self.git_provider.is_supported("gfm_markdown"): - pr_body += f"
{filename_publish}" - file_change_description = self._insert_br_after_x_chars(file_change_description) - if diff_plus_minus: - pr_body += f"
    Changes summary:
    **{file_change_description}**
" - else: - pr_body += f"
    Changes summary:
    **{file_change_description}**
" - if self.git_provider.is_supported("gfm_markdown"): - pr_body += "|\n" + + file_change_description = self._insert_br_after_x_chars(file_change_description) + pr_body += f""" + + + +""" + pr_body += """
+
+ {filename_publish} {diff_plus_minus} +
    + Changes summary:
    + {file_change_description} +
+
+
""" + print(pr_body) + + + # pr_body += """\n| | Relevant Files """ + # pr_body += "  " * 70 + # pr_body += """|\n|-----------|-------------|\n""" + # for semantic_label in value.keys(): + # s_label = semantic_label.strip("'").strip('"') + # if self.git_provider.is_supported("gfm_markdown"): + # # pr_body += f"
{semantic_label['label']}\n\n" + # pr_body += f"| **{s_label}** |
files:
    " + # + # list_tuples = value[semantic_label] + # for filename, file_change_description in list_tuples: + # filename = filename.replace("'", "`") + # filename_publish = filename.split("/")[-1] + # filename_publish = f"**{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} )" + # break + # + # # try to add line numbers link to code suggestions + # 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" {diff_plus_minus}" + # + # if diff_plus_minus: + # filename_publish += diff_plus_minus + # if self.git_provider.is_supported("gfm_markdown"): + # pr_body += f"
    {filename_publish}" + # file_change_description = self._insert_br_after_x_chars(file_change_description) + # if diff_plus_minus: + # pr_body += f"
      Changes summary:
      **{file_change_description}**
    " + # else: + # pr_body += f"
      Changes summary:
      **{file_change_description}**
" + # if self.git_provider.is_supported("gfm_markdown"): + # pr_body += "
|\n" except Exception as e: get_logger().error(f"Error processing pr files to markdown {self.pr_id}: {e}") pass From 4cd6649a44c7d7861f6b4dccfd7a2bcf84afba1b Mon Sep 17 00:00:00 2001 From: mrT23 Date: Thu, 7 Dec 2023 10:14:18 +0200 Subject: [PATCH 2/6] 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. --- pr_agent/tools/pr_description.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index 2f0466c67..88f5b69c1 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -317,9 +317,11 @@ def process_pr_files_prediction(self, pr_body, value): return pr_body try: - pr_body = "" pr_body += "" - pr_body += """""" + header = f"Relevant Files" + delta = 65 + header +="  " * delta + pr_body += f"""""" pr_body += """""" for semantic_label in value.keys(): s_label = semantic_label.strip("'").strip('"') @@ -330,13 +332,15 @@ def process_pr_files_prediction(self, pr_body, value): filename = filename.replace("'", "`") filename_publish = filename.split("/")[-1] filename_publish = f"{filename_publish}" + if len(filename_publish)< (delta-5): + filename_publish += "  " * ((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 @@ -345,24 +349,24 @@ def process_pr_files_prediction(self, pr_body, value): filename = filename.strip() 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 += """
Relevant Files
{header}
- {filename_publish} {diff_plus_minus} + {filename_publish}
    - Changes summary:
    + ({filename})

    {file_change_description}
{diff_plus_minus}
""" pr_body += """""" - print(pr_body) - # pr_body += """\n| | Relevant Files """ # pr_body += "  " * 70 @@ -411,11 +415,10 @@ def process_pr_files_prediction(self, pr_body, value): pass return pr_body - def _insert_br_after_x_chars(self, text): + def _insert_br_after_x_chars(self, text, x=70): """ Insert
into a string after a word that increases its length above x characters. """ - x = 70 if len(text) < x: return text From e351428848aeea107d766d9e61ae692d74506627 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Thu, 7 Dec 2023 10:24:36 +0200 Subject: [PATCH 3/6] s --- pr_agent/tools/pr_description.py | 56 ++++---------------------------- 1 file changed, 7 insertions(+), 49 deletions(-) diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index 88f5b69c1..924eedbe3 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -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" @@ -318,9 +318,9 @@ def process_pr_files_prediction(self, pr_body, value): try: pr_body += "" - header = f"Relevant Files" + header = f"Relevant files" delta = 65 - header +="  " * delta + header += "  " * delta pr_body += f"""""" pr_body += """""" for semantic_label in value.keys(): @@ -332,15 +332,15 @@ def process_pr_files_prediction(self, pr_body, value): filename = filename.replace("'", "`") filename_publish = filename.split("/")[-1] filename_publish = f"{filename_publish}" - if len(filename_publish)< (delta-5): - filename_publish += "  " * ((delta-5) - len(filename_publish)) + if len(filename_publish) < (delta - 5): + filename_publish += "  " * ((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 @@ -349,7 +349,7 @@ def process_pr_files_prediction(self, pr_body, value): filename = filename.strip() link = self.git_provider.get_line_link(filename, relevant_line_start=-1) - file_change_description = self._insert_br_after_x_chars(file_change_description, x=(delta-5)) + file_change_description = self._insert_br_after_x_chars(file_change_description, x=(delta - 5)) pr_body += f"""
{header}
@@ -368,48 +368,6 @@ def process_pr_files_prediction(self, pr_body, value): pr_body += """
""" pr_body += """""" - # pr_body += """\n| | Relevant Files """ - # pr_body += "  " * 70 - # pr_body += """|\n|-----------|-------------|\n""" - # for semantic_label in value.keys(): - # s_label = semantic_label.strip("'").strip('"') - # if self.git_provider.is_supported("gfm_markdown"): - # # pr_body += f"
{semantic_label['label']}\n\n" - # pr_body += f"| **{s_label}** |
files:
    " - # - # list_tuples = value[semantic_label] - # for filename, file_change_description in list_tuples: - # filename = filename.replace("'", "`") - # filename_publish = filename.split("/")[-1] - # filename_publish = f"**{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} )" - # break - # - # # try to add line numbers link to code suggestions - # 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" {diff_plus_minus}" - # - # if diff_plus_minus: - # filename_publish += diff_plus_minus - # if self.git_provider.is_supported("gfm_markdown"): - # pr_body += f"
    {filename_publish}" - # file_change_description = self._insert_br_after_x_chars(file_change_description) - # if diff_plus_minus: - # pr_body += f"
      Changes summary:
      **{file_change_description}**
    " - # else: - # pr_body += f"
      Changes summary:
      **{file_change_description}**
" - # if self.git_provider.is_supported("gfm_markdown"): - # pr_body += "
|\n" except Exception as e: get_logger().error(f"Error processing pr files to markdown {self.pr_id}: {e}") pass From 7d2a35e32c71cefa673364f3890871df1c8b367b Mon Sep 17 00:00:00 2001 From: mrT23 Date: Thu, 7 Dec 2023 10:27:19 +0200 Subject: [PATCH 4/6] final commit --- pr_agent/tools/pr_description.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index 924eedbe3..e97abafad 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -325,7 +325,7 @@ def process_pr_files_prediction(self, pr_body, value): pr_body += """""" for semantic_label in value.keys(): s_label = semantic_label.strip("'").strip('"') - pr_body += f"""{s_label}""" + pr_body += f"""{s_label.capitalize()}""" list_tuples = value[semantic_label] pr_body += f"""
{len(list_tuples)} files""" for filename, file_change_description in list_tuples: From f908d02ab4524bb43a664777220a70133b954113 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Thu, 7 Dec 2023 15:26:36 +0200 Subject: [PATCH 5/6] readme --- docs/DESCRIBE.md | 7 ++++++- pr_agent/tools/pr_description.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/DESCRIBE.md b/docs/DESCRIBE.md index 696014d54..777e13a91 100644 --- a/docs/DESCRIBE.md +++ b/docs/DESCRIBE.md @@ -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 @@ -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 diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index e97abafad..64acaab3a 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -356,7 +356,7 @@ def process_pr_files_prediction(self, pr_body, value):
{filename_publish}
    - ({filename})

    + {filename}

    {file_change_description}
From 1b22e59b4b9501da77ea7844cbb1a796201a9bb9 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Thu, 7 Dec 2023 15:35:48 +0200 Subject: [PATCH 6/6] feat: Update RELEASE_NOTES.md with version 0.11 details --- RELEASE_NOTES.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 30b76a0fb..3dab48f92 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -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