From 3d609541672d4d390d4d4d5b8c6247adb63e2f94 Mon Sep 17 00:00:00 2001 From: KennyDizi Date: Thu, 27 Jun 2024 06:59:49 +0700 Subject: [PATCH 01/11] Add PrReviewTitles enum --- pr_agent/algo/utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pr_agent/algo/utils.py b/pr_agent/algo/utils.py index 73e0a8f7..bf2c5bf3 100644 --- a/pr_agent/algo/utils.py +++ b/pr_agent/algo/utils.py @@ -23,6 +23,10 @@ class ModelType(str, Enum): REGULAR = "regular" TURBO = "turbo" +class PrReviewTitles(str, Enum): + REGULAR = "## PR Reviewer Guide" + INCREMENTAL = "## Incremental PR Reviewer Guide" + def get_setting(key: str) -> Any: try: key = key.upper() From c185b7c6103e50423646617ea28fed323a660cea Mon Sep 17 00:00:00 2001 From: KennyDizi Date: Thu, 27 Jun 2024 07:03:08 +0700 Subject: [PATCH 02/11] Apply PrReviewTitles enum for algo utils file --- pr_agent/algo/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pr_agent/algo/utils.py b/pr_agent/algo/utils.py index bf2c5bf3..a1b438f6 100644 --- a/pr_agent/algo/utils.py +++ b/pr_agent/algo/utils.py @@ -90,9 +90,9 @@ def convert_to_markdown(output_data: dict, gfm_supported: bool = True, increment } markdown_text = "" if not incremental_review: - markdown_text += f"## PR Reviewer Guide ๐Ÿ”\n\n" + markdown_text += f"{PrReviewTitles.REGULAR} ๐Ÿ”\n\n" else: - markdown_text += f"## Incremental PR Reviewer Guide ๐Ÿ”\n\n" + markdown_text += f"{PrReviewTitles.INCREMENTAL} ๐Ÿ”\n\n" markdown_text += f"โฎ๏ธ Review for commits since previous PR-Agent review {incremental_review}.\n\n" if gfm_supported: markdown_text += "\n" From 2d21df61c703d6c3cc235db85edb2f91543cbae9 Mon Sep 17 00:00:00 2001 From: KennyDizi Date: Thu, 27 Jun 2024 07:03:25 +0700 Subject: [PATCH 03/11] Apply PrReviewTitles enum for github provider file --- pr_agent/git_providers/github_provider.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pr_agent/git_providers/github_provider.py b/pr_agent/git_providers/github_provider.py index fc87c84d..f69648b6 100644 --- a/pr_agent/git_providers/github_provider.py +++ b/pr_agent/git_providers/github_provider.py @@ -10,7 +10,7 @@ from starlette_context import context from ..algo.file_filter import filter_ignored from ..algo.language_handler import is_valid_file -from ..algo.utils import load_large_diff, clip_tokens, find_line_number_of_relevant_line_in_file +from ..algo.utils import PrReviewTitles, load_large_diff, clip_tokens, find_line_number_of_relevant_line_in_file from ..config_loader import get_settings from ..log import get_logger from ..servers.utils import RateLimitExceeded @@ -96,9 +96,9 @@ class GithubProvider(GitProvider): self.comments = list(self.pr.get_issue_comments()) prefixes = [] if full: - prefixes.append("## PR Reviewer Guide") + prefixes.append({PrReviewTitles.REGULAR}) if incremental: - prefixes.append("## Incremental PR Reviewer Guide") + prefixes.append({PrReviewTitles.INCREMENTAL}) for index in range(len(self.comments) - 1, -1, -1): if any(self.comments[index].body.startswith(prefix) for prefix in prefixes): return self.comments[index] From 41607b10efc3f7cb0b1549af27240ae15cf42f83 Mon Sep 17 00:00:00 2001 From: KennyDizi Date: Thu, 27 Jun 2024 07:03:43 +0700 Subject: [PATCH 04/11] Apply PrReviewTitles enum for pr review file --- pr_agent/tools/pr_reviewer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pr_agent/tools/pr_reviewer.py b/pr_agent/tools/pr_reviewer.py index 35abe537..120f8396 100644 --- a/pr_agent/tools/pr_reviewer.py +++ b/pr_agent/tools/pr_reviewer.py @@ -8,7 +8,7 @@ from pr_agent.algo.ai_handlers.base_ai_handler import BaseAiHandler from pr_agent.algo.ai_handlers.litellm_ai_handler import LiteLLMAIHandler from pr_agent.algo.pr_processing import get_pr_diff, retry_with_fallback_models from pr_agent.algo.token_handler import TokenHandler -from pr_agent.algo.utils import convert_to_markdown, github_action_output, load_yaml, ModelType, \ +from pr_agent.algo.utils import PrReviewTitles, convert_to_markdown, github_action_output, load_yaml, ModelType, \ show_relevant_configurations from pr_agent.config_loader import get_settings from pr_agent.git_providers import get_git_provider, get_git_provider_with_context @@ -134,7 +134,7 @@ class PRReviewer: if get_settings().pr_reviewer.persistent_comment and not self.incremental.is_incremental: final_update_message = get_settings().pr_reviewer.final_update_message self.git_provider.publish_persistent_comment(pr_review, - initial_header="## PR Reviewer Guide ๐Ÿ”", + initial_header=f"{PrReviewTitles.REGULAR} ๐Ÿ”", update_header=True, final_update_message=final_update_message, ) else: From d0315164be13b8b20b75a720d299b3eda639726c Mon Sep 17 00:00:00 2001 From: KennyDizi Date: Thu, 27 Jun 2024 07:04:02 +0700 Subject: [PATCH 05/11] Apply PrReviewTitles enum for test file --- tests/unittest/test_convert_to_markdown.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unittest/test_convert_to_markdown.py b/tests/unittest/test_convert_to_markdown.py index d701efb2..61ed219b 100644 --- a/tests/unittest/test_convert_to_markdown.py +++ b/tests/unittest/test_convert_to_markdown.py @@ -1,5 +1,5 @@ # Generated by CodiumAI -from pr_agent.algo.utils import convert_to_markdown +from pr_agent.algo.utils import PrReviewTitles, convert_to_markdown from pr_agent.tools.pr_description import insert_br_after_x_chars """ @@ -52,7 +52,7 @@ class TestConvertToMarkdown: 'suggestion': "Consider raising an exception or logging a warning when 'pr_url' attribute is not found. This can help in debugging issues related to the absence of 'pr_url' in instances where it's expected. [important]\n", 'relevant_line': '[return ""](https://github.com/Codium-ai/pr-agent-pro/pull/102/files#diff-52d45f12b836f77ed1aef86e972e65404634ea4e2a6083fb71a9b0f9bb9e062fR199)'}]} - expected_output = '## PR Reviewer Guide ๐Ÿ”\n\n
\n\n\n\n\n
โฑ๏ธ Estimated effort to review [1-5]\n1, because the changes are minimal and straightforward, focusing on a single functionality addition.\n\n\n
๐Ÿงช Relevant tests\nNo\n\n\n
โšก Possible issues\nNo\n\n\n
๐Ÿ”’ Security concerns\nNo\n\n
\n\n\n
Code feedback:\n\n
relevant filepr_agent/git_providers/git_provider.py\n
suggestion      \n\n\n\nConsider raising an exception or logging a warning when \'pr_url\' attribute is not found. This can help in debugging issues related to the absence of \'pr_url\' in instances where it\'s expected. [important]\n\n\n
relevant linereturn ""

\n\n
' + expected_output = f'{PrReviewTitles.REGULAR} ๐Ÿ”\n\n\n\n\n\n\n
โฑ๏ธ Estimated effort to review [1-5]\n1, because the changes are minimal and straightforward, focusing on a single functionality addition.\n\n\n
๐Ÿงช Relevant tests\nNo\n\n\n
โšก Possible issues\nNo\n\n\n
๐Ÿ”’ Security concerns\nNo\n\n
\n\n\n
Code feedback:\n\n
relevant filepr_agent/git_providers/git_provider.py\n
suggestion      \n\n\n\nConsider raising an exception or logging a warning when \'pr_url\' attribute is not found. This can help in debugging issues related to the absence of \'pr_url\' in instances where it\'s expected. [important]\n\n\n
relevant linereturn ""

\n\n
' assert convert_to_markdown(input_data).strip() == expected_output.strip() From 7348d4144ba0f097a418ef64410836c278eba6bc Mon Sep 17 00:00:00 2001 From: KennyDizi Date: Thu, 27 Jun 2024 07:05:03 +0700 Subject: [PATCH 06/11] Rename PrReviewTitle enum --- pr_agent/algo/utils.py | 6 +++--- pr_agent/git_providers/github_provider.py | 6 +++--- pr_agent/tools/pr_reviewer.py | 4 ++-- tests/unittest/test_convert_to_markdown.py | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pr_agent/algo/utils.py b/pr_agent/algo/utils.py index a1b438f6..0858afff 100644 --- a/pr_agent/algo/utils.py +++ b/pr_agent/algo/utils.py @@ -23,7 +23,7 @@ class ModelType(str, Enum): REGULAR = "regular" TURBO = "turbo" -class PrReviewTitles(str, Enum): +class PrReviewTitle(str, Enum): REGULAR = "## PR Reviewer Guide" INCREMENTAL = "## Incremental PR Reviewer Guide" @@ -90,9 +90,9 @@ def convert_to_markdown(output_data: dict, gfm_supported: bool = True, increment } markdown_text = "" if not incremental_review: - markdown_text += f"{PrReviewTitles.REGULAR} ๐Ÿ”\n\n" + markdown_text += f"{PrReviewTitle.REGULAR} ๐Ÿ”\n\n" else: - markdown_text += f"{PrReviewTitles.INCREMENTAL} ๐Ÿ”\n\n" + markdown_text += f"{PrReviewTitle.INCREMENTAL} ๐Ÿ”\n\n" markdown_text += f"โฎ๏ธ Review for commits since previous PR-Agent review {incremental_review}.\n\n" if gfm_supported: markdown_text += "\n" diff --git a/pr_agent/git_providers/github_provider.py b/pr_agent/git_providers/github_provider.py index f69648b6..1905f5cc 100644 --- a/pr_agent/git_providers/github_provider.py +++ b/pr_agent/git_providers/github_provider.py @@ -10,7 +10,7 @@ from starlette_context import context from ..algo.file_filter import filter_ignored from ..algo.language_handler import is_valid_file -from ..algo.utils import PrReviewTitles, load_large_diff, clip_tokens, find_line_number_of_relevant_line_in_file +from ..algo.utils import PrReviewTitle, load_large_diff, clip_tokens, find_line_number_of_relevant_line_in_file from ..config_loader import get_settings from ..log import get_logger from ..servers.utils import RateLimitExceeded @@ -96,9 +96,9 @@ class GithubProvider(GitProvider): self.comments = list(self.pr.get_issue_comments()) prefixes = [] if full: - prefixes.append({PrReviewTitles.REGULAR}) + prefixes.append({PrReviewTitle.REGULAR}) if incremental: - prefixes.append({PrReviewTitles.INCREMENTAL}) + prefixes.append({PrReviewTitle.INCREMENTAL}) for index in range(len(self.comments) - 1, -1, -1): if any(self.comments[index].body.startswith(prefix) for prefix in prefixes): return self.comments[index] diff --git a/pr_agent/tools/pr_reviewer.py b/pr_agent/tools/pr_reviewer.py index 120f8396..559a0f2e 100644 --- a/pr_agent/tools/pr_reviewer.py +++ b/pr_agent/tools/pr_reviewer.py @@ -8,7 +8,7 @@ from pr_agent.algo.ai_handlers.base_ai_handler import BaseAiHandler from pr_agent.algo.ai_handlers.litellm_ai_handler import LiteLLMAIHandler from pr_agent.algo.pr_processing import get_pr_diff, retry_with_fallback_models from pr_agent.algo.token_handler import TokenHandler -from pr_agent.algo.utils import PrReviewTitles, convert_to_markdown, github_action_output, load_yaml, ModelType, \ +from pr_agent.algo.utils import PrReviewTitle, convert_to_markdown, github_action_output, load_yaml, ModelType, \ show_relevant_configurations from pr_agent.config_loader import get_settings from pr_agent.git_providers import get_git_provider, get_git_provider_with_context @@ -134,7 +134,7 @@ class PRReviewer: if get_settings().pr_reviewer.persistent_comment and not self.incremental.is_incremental: final_update_message = get_settings().pr_reviewer.final_update_message self.git_provider.publish_persistent_comment(pr_review, - initial_header=f"{PrReviewTitles.REGULAR} ๐Ÿ”", + initial_header=f"{PrReviewTitle.REGULAR} ๐Ÿ”", update_header=True, final_update_message=final_update_message, ) else: diff --git a/tests/unittest/test_convert_to_markdown.py b/tests/unittest/test_convert_to_markdown.py index 61ed219b..0cc91ee9 100644 --- a/tests/unittest/test_convert_to_markdown.py +++ b/tests/unittest/test_convert_to_markdown.py @@ -1,5 +1,5 @@ # Generated by CodiumAI -from pr_agent.algo.utils import PrReviewTitles, convert_to_markdown +from pr_agent.algo.utils import PrReviewTitle, convert_to_markdown from pr_agent.tools.pr_description import insert_br_after_x_chars """ @@ -52,7 +52,7 @@ class TestConvertToMarkdown: 'suggestion': "Consider raising an exception or logging a warning when 'pr_url' attribute is not found. This can help in debugging issues related to the absence of 'pr_url' in instances where it's expected. [important]\n", 'relevant_line': '[return ""](https://github.com/Codium-ai/pr-agent-pro/pull/102/files#diff-52d45f12b836f77ed1aef86e972e65404634ea4e2a6083fb71a9b0f9bb9e062fR199)'}]} - expected_output = f'{PrReviewTitles.REGULAR} ๐Ÿ”\n\n
\n\n\n\n\n
โฑ๏ธ Estimated effort to review [1-5]\n1, because the changes are minimal and straightforward, focusing on a single functionality addition.\n\n\n
๐Ÿงช Relevant tests\nNo\n\n\n
โšก Possible issues\nNo\n\n\n
๐Ÿ”’ Security concerns\nNo\n\n
\n\n\n
Code feedback:\n\n
relevant filepr_agent/git_providers/git_provider.py\n
suggestion      \n\n\n\nConsider raising an exception or logging a warning when \'pr_url\' attribute is not found. This can help in debugging issues related to the absence of \'pr_url\' in instances where it\'s expected. [important]\n\n\n
relevant linereturn ""

\n\n
' + expected_output = f'{PrReviewTitle.REGULAR} ๐Ÿ”\n\n\n\n\n\n\n
โฑ๏ธ Estimated effort to review [1-5]\n1, because the changes are minimal and straightforward, focusing on a single functionality addition.\n\n\n
๐Ÿงช Relevant tests\nNo\n\n\n
โšก Possible issues\nNo\n\n\n
๐Ÿ”’ Security concerns\nNo\n\n
\n\n\n
Code feedback:\n\n
relevant filepr_agent/git_providers/git_provider.py\n
suggestion      \n\n\n\nConsider raising an exception or logging a warning when \'pr_url\' attribute is not found. This can help in debugging issues related to the absence of \'pr_url\' in instances where it\'s expected. [important]\n\n\n
relevant linereturn ""

\n\n
' assert convert_to_markdown(input_data).strip() == expected_output.strip() From ba963149aceb6811af0e2c1e0dca6439c810a28e Mon Sep 17 00:00:00 2001 From: KennyDizi Date: Thu, 27 Jun 2024 07:10:57 +0700 Subject: [PATCH 07/11] Fix extract PrReviewTitle member value --- pr_agent/algo/utils.py | 4 ++-- pr_agent/git_providers/github_provider.py | 4 ++-- pr_agent/tools/pr_reviewer.py | 2 +- tests/unittest/test_convert_to_markdown.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pr_agent/algo/utils.py b/pr_agent/algo/utils.py index 0858afff..3601bfa0 100644 --- a/pr_agent/algo/utils.py +++ b/pr_agent/algo/utils.py @@ -90,9 +90,9 @@ def convert_to_markdown(output_data: dict, gfm_supported: bool = True, increment } markdown_text = "" if not incremental_review: - markdown_text += f"{PrReviewTitle.REGULAR} ๐Ÿ”\n\n" + markdown_text += f"{PrReviewTitle.REGULAR.value} ๐Ÿ”\n\n" else: - markdown_text += f"{PrReviewTitle.INCREMENTAL} ๐Ÿ”\n\n" + markdown_text += f"{PrReviewTitle.INCREMENTAL.value} ๐Ÿ”\n\n" markdown_text += f"โฎ๏ธ Review for commits since previous PR-Agent review {incremental_review}.\n\n" if gfm_supported: markdown_text += "\n" diff --git a/pr_agent/git_providers/github_provider.py b/pr_agent/git_providers/github_provider.py index 1905f5cc..cb03981e 100644 --- a/pr_agent/git_providers/github_provider.py +++ b/pr_agent/git_providers/github_provider.py @@ -96,9 +96,9 @@ class GithubProvider(GitProvider): self.comments = list(self.pr.get_issue_comments()) prefixes = [] if full: - prefixes.append({PrReviewTitle.REGULAR}) + prefixes.append({PrReviewTitle.REGULAR.value}) if incremental: - prefixes.append({PrReviewTitle.INCREMENTAL}) + prefixes.append({PrReviewTitle.INCREMENTAL.value}) for index in range(len(self.comments) - 1, -1, -1): if any(self.comments[index].body.startswith(prefix) for prefix in prefixes): return self.comments[index] diff --git a/pr_agent/tools/pr_reviewer.py b/pr_agent/tools/pr_reviewer.py index 559a0f2e..f255badb 100644 --- a/pr_agent/tools/pr_reviewer.py +++ b/pr_agent/tools/pr_reviewer.py @@ -134,7 +134,7 @@ class PRReviewer: if get_settings().pr_reviewer.persistent_comment and not self.incremental.is_incremental: final_update_message = get_settings().pr_reviewer.final_update_message self.git_provider.publish_persistent_comment(pr_review, - initial_header=f"{PrReviewTitle.REGULAR} ๐Ÿ”", + initial_header=f"{PrReviewTitle.REGULAR.value} ๐Ÿ”", update_header=True, final_update_message=final_update_message, ) else: diff --git a/tests/unittest/test_convert_to_markdown.py b/tests/unittest/test_convert_to_markdown.py index 0cc91ee9..66b343b3 100644 --- a/tests/unittest/test_convert_to_markdown.py +++ b/tests/unittest/test_convert_to_markdown.py @@ -52,7 +52,7 @@ class TestConvertToMarkdown: 'suggestion': "Consider raising an exception or logging a warning when 'pr_url' attribute is not found. This can help in debugging issues related to the absence of 'pr_url' in instances where it's expected. [important]\n", 'relevant_line': '[return ""](https://github.com/Codium-ai/pr-agent-pro/pull/102/files#diff-52d45f12b836f77ed1aef86e972e65404634ea4e2a6083fb71a9b0f9bb9e062fR199)'}]} - expected_output = f'{PrReviewTitle.REGULAR} ๐Ÿ”\n\n
\n\n\n\n\n
โฑ๏ธ Estimated effort to review [1-5]\n1, because the changes are minimal and straightforward, focusing on a single functionality addition.\n\n\n
๐Ÿงช Relevant tests\nNo\n\n\n
โšก Possible issues\nNo\n\n\n
๐Ÿ”’ Security concerns\nNo\n\n
\n\n\n
Code feedback:\n\n
relevant filepr_agent/git_providers/git_provider.py\n
suggestion      \n\n\n\nConsider raising an exception or logging a warning when \'pr_url\' attribute is not found. This can help in debugging issues related to the absence of \'pr_url\' in instances where it\'s expected. [important]\n\n\n
relevant linereturn ""

\n\n
' + expected_output = f'{PrReviewTitle.REGULAR.value} ๐Ÿ”\n\n\n\n\n\n\n
โฑ๏ธ Estimated effort to review [1-5]\n1, because the changes are minimal and straightforward, focusing on a single functionality addition.\n\n\n
๐Ÿงช Relevant tests\nNo\n\n\n
โšก Possible issues\nNo\n\n\n
๐Ÿ”’ Security concerns\nNo\n\n
\n\n\n
Code feedback:\n\n
relevant filepr_agent/git_providers/git_provider.py\n
suggestion      \n\n\n\nConsider raising an exception or logging a warning when \'pr_url\' attribute is not found. This can help in debugging issues related to the absence of \'pr_url\' in instances where it\'s expected. [important]\n\n\n
relevant linereturn ""

\n\n
' assert convert_to_markdown(input_data).strip() == expected_output.strip() From 692904bb710f1cc4d4d9960b512b36f582601c68 Mon Sep 17 00:00:00 2001 From: KennyDizi Date: Thu, 27 Jun 2024 07:11:57 +0700 Subject: [PATCH 08/11] Use ReviewHeaderTitle in lieu of PrReviewTitle --- pr_agent/algo/utils.py | 6 +++--- pr_agent/git_providers/github_provider.py | 6 +++--- pr_agent/tools/pr_reviewer.py | 4 ++-- tests/unittest/test_convert_to_markdown.py | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pr_agent/algo/utils.py b/pr_agent/algo/utils.py index 3601bfa0..c8915d07 100644 --- a/pr_agent/algo/utils.py +++ b/pr_agent/algo/utils.py @@ -23,7 +23,7 @@ class ModelType(str, Enum): REGULAR = "regular" TURBO = "turbo" -class PrReviewTitle(str, Enum): +class ReviewHeaderTitle(str, Enum): REGULAR = "## PR Reviewer Guide" INCREMENTAL = "## Incremental PR Reviewer Guide" @@ -90,9 +90,9 @@ def convert_to_markdown(output_data: dict, gfm_supported: bool = True, increment } markdown_text = "" if not incremental_review: - markdown_text += f"{PrReviewTitle.REGULAR.value} ๐Ÿ”\n\n" + markdown_text += f"{ReviewHeaderTitle.REGULAR.value} ๐Ÿ”\n\n" else: - markdown_text += f"{PrReviewTitle.INCREMENTAL.value} ๐Ÿ”\n\n" + markdown_text += f"{ReviewHeaderTitle.INCREMENTAL.value} ๐Ÿ”\n\n" markdown_text += f"โฎ๏ธ Review for commits since previous PR-Agent review {incremental_review}.\n\n" if gfm_supported: markdown_text += "\n" diff --git a/pr_agent/git_providers/github_provider.py b/pr_agent/git_providers/github_provider.py index cb03981e..b6170dee 100644 --- a/pr_agent/git_providers/github_provider.py +++ b/pr_agent/git_providers/github_provider.py @@ -10,7 +10,7 @@ from starlette_context import context from ..algo.file_filter import filter_ignored from ..algo.language_handler import is_valid_file -from ..algo.utils import PrReviewTitle, load_large_diff, clip_tokens, find_line_number_of_relevant_line_in_file +from ..algo.utils import ReviewHeaderTitle, load_large_diff, clip_tokens, find_line_number_of_relevant_line_in_file from ..config_loader import get_settings from ..log import get_logger from ..servers.utils import RateLimitExceeded @@ -96,9 +96,9 @@ class GithubProvider(GitProvider): self.comments = list(self.pr.get_issue_comments()) prefixes = [] if full: - prefixes.append({PrReviewTitle.REGULAR.value}) + prefixes.append({ReviewHeaderTitle.REGULAR.value}) if incremental: - prefixes.append({PrReviewTitle.INCREMENTAL.value}) + prefixes.append({ReviewHeaderTitle.INCREMENTAL.value}) for index in range(len(self.comments) - 1, -1, -1): if any(self.comments[index].body.startswith(prefix) for prefix in prefixes): return self.comments[index] diff --git a/pr_agent/tools/pr_reviewer.py b/pr_agent/tools/pr_reviewer.py index f255badb..c4997ca0 100644 --- a/pr_agent/tools/pr_reviewer.py +++ b/pr_agent/tools/pr_reviewer.py @@ -8,7 +8,7 @@ from pr_agent.algo.ai_handlers.base_ai_handler import BaseAiHandler from pr_agent.algo.ai_handlers.litellm_ai_handler import LiteLLMAIHandler from pr_agent.algo.pr_processing import get_pr_diff, retry_with_fallback_models from pr_agent.algo.token_handler import TokenHandler -from pr_agent.algo.utils import PrReviewTitle, convert_to_markdown, github_action_output, load_yaml, ModelType, \ +from pr_agent.algo.utils import ReviewHeaderTitle, convert_to_markdown, github_action_output, load_yaml, ModelType, \ show_relevant_configurations from pr_agent.config_loader import get_settings from pr_agent.git_providers import get_git_provider, get_git_provider_with_context @@ -134,7 +134,7 @@ class PRReviewer: if get_settings().pr_reviewer.persistent_comment and not self.incremental.is_incremental: final_update_message = get_settings().pr_reviewer.final_update_message self.git_provider.publish_persistent_comment(pr_review, - initial_header=f"{PrReviewTitle.REGULAR.value} ๐Ÿ”", + initial_header=f"{ReviewHeaderTitle.REGULAR.value} ๐Ÿ”", update_header=True, final_update_message=final_update_message, ) else: diff --git a/tests/unittest/test_convert_to_markdown.py b/tests/unittest/test_convert_to_markdown.py index 66b343b3..9cf59c85 100644 --- a/tests/unittest/test_convert_to_markdown.py +++ b/tests/unittest/test_convert_to_markdown.py @@ -1,5 +1,5 @@ # Generated by CodiumAI -from pr_agent.algo.utils import PrReviewTitle, convert_to_markdown +from pr_agent.algo.utils import ReviewHeaderTitle, convert_to_markdown from pr_agent.tools.pr_description import insert_br_after_x_chars """ @@ -52,7 +52,7 @@ class TestConvertToMarkdown: 'suggestion': "Consider raising an exception or logging a warning when 'pr_url' attribute is not found. This can help in debugging issues related to the absence of 'pr_url' in instances where it's expected. [important]\n", 'relevant_line': '[return ""](https://github.com/Codium-ai/pr-agent-pro/pull/102/files#diff-52d45f12b836f77ed1aef86e972e65404634ea4e2a6083fb71a9b0f9bb9e062fR199)'}]} - expected_output = f'{PrReviewTitle.REGULAR.value} ๐Ÿ”\n\n
\n\n\n\n\n
โฑ๏ธ Estimated effort to review [1-5]\n1, because the changes are minimal and straightforward, focusing on a single functionality addition.\n\n\n
๐Ÿงช Relevant tests\nNo\n\n\n
โšก Possible issues\nNo\n\n\n
๐Ÿ”’ Security concerns\nNo\n\n
\n\n\n
Code feedback:\n\n
relevant filepr_agent/git_providers/git_provider.py\n
suggestion      \n\n\n\nConsider raising an exception or logging a warning when \'pr_url\' attribute is not found. This can help in debugging issues related to the absence of \'pr_url\' in instances where it\'s expected. [important]\n\n\n
relevant linereturn ""

\n\n
' + expected_output = f'{ReviewHeaderTitle.REGULAR.value} ๐Ÿ”\n\n\n\n\n\n\n
โฑ๏ธ Estimated effort to review [1-5]\n1, because the changes are minimal and straightforward, focusing on a single functionality addition.\n\n\n
๐Ÿงช Relevant tests\nNo\n\n\n
โšก Possible issues\nNo\n\n\n
๐Ÿ”’ Security concerns\nNo\n\n
\n\n\n
Code feedback:\n\n
relevant filepr_agent/git_providers/git_provider.py\n
suggestion      \n\n\n\nConsider raising an exception or logging a warning when \'pr_url\' attribute is not found. This can help in debugging issues related to the absence of \'pr_url\' in instances where it\'s expected. [important]\n\n\n
relevant linereturn ""

\n\n
' assert convert_to_markdown(input_data).strip() == expected_output.strip() From b20f364b152e3a158caaf4fda647f4884d6ec17b Mon Sep 17 00:00:00 2001 From: KennyDizi Date: Thu, 27 Jun 2024 07:16:26 +0700 Subject: [PATCH 09/11] Change the data structure for prefixes to a list to preserve order --- pr_agent/git_providers/github_provider.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pr_agent/git_providers/github_provider.py b/pr_agent/git_providers/github_provider.py index b6170dee..4baccb9e 100644 --- a/pr_agent/git_providers/github_provider.py +++ b/pr_agent/git_providers/github_provider.py @@ -10,7 +10,7 @@ from starlette_context import context from ..algo.file_filter import filter_ignored from ..algo.language_handler import is_valid_file -from ..algo.utils import ReviewHeaderTitle, load_large_diff, clip_tokens, find_line_number_of_relevant_line_in_file +from ..algo.utils import PRReviewHeader, load_large_diff, clip_tokens, find_line_number_of_relevant_line_in_file from ..config_loader import get_settings from ..log import get_logger from ..servers.utils import RateLimitExceeded @@ -96,9 +96,9 @@ class GithubProvider(GitProvider): self.comments = list(self.pr.get_issue_comments()) prefixes = [] if full: - prefixes.append({ReviewHeaderTitle.REGULAR.value}) + prefixes.append(PRReviewHeader.REGULAR.value) if incremental: - prefixes.append({ReviewHeaderTitle.INCREMENTAL.value}) + prefixes.append(PRReviewHeader.INCREMENTAL.value) for index in range(len(self.comments) - 1, -1, -1): if any(self.comments[index].body.startswith(prefix) for prefix in prefixes): return self.comments[index] From 406dcd7b7b36cae2070688050a09339b91f65a82 Mon Sep 17 00:00:00 2001 From: KennyDizi Date: Thu, 27 Jun 2024 07:16:54 +0700 Subject: [PATCH 10/11] Improve code readability by adding a newline after enum definitions --- pr_agent/tools/pr_reviewer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pr_agent/tools/pr_reviewer.py b/pr_agent/tools/pr_reviewer.py index c4997ca0..0487a229 100644 --- a/pr_agent/tools/pr_reviewer.py +++ b/pr_agent/tools/pr_reviewer.py @@ -8,7 +8,7 @@ from pr_agent.algo.ai_handlers.base_ai_handler import BaseAiHandler from pr_agent.algo.ai_handlers.litellm_ai_handler import LiteLLMAIHandler from pr_agent.algo.pr_processing import get_pr_diff, retry_with_fallback_models from pr_agent.algo.token_handler import TokenHandler -from pr_agent.algo.utils import ReviewHeaderTitle, convert_to_markdown, github_action_output, load_yaml, ModelType, \ +from pr_agent.algo.utils import PRReviewHeader, convert_to_markdown, github_action_output, load_yaml, ModelType, \ show_relevant_configurations from pr_agent.config_loader import get_settings from pr_agent.git_providers import get_git_provider, get_git_provider_with_context @@ -134,7 +134,7 @@ class PRReviewer: if get_settings().pr_reviewer.persistent_comment and not self.incremental.is_incremental: final_update_message = get_settings().pr_reviewer.final_update_message self.git_provider.publish_persistent_comment(pr_review, - initial_header=f"{ReviewHeaderTitle.REGULAR.value} ๐Ÿ”", + initial_header=f"{PRReviewHeader.REGULAR.value} ๐Ÿ”", update_header=True, final_update_message=final_update_message, ) else: From 382da3a5b6713aa1f93ea515af7bbcdb11d58aca Mon Sep 17 00:00:00 2001 From: KennyDizi Date: Thu, 27 Jun 2024 07:17:26 +0700 Subject: [PATCH 11/11] Use descriptive name for the ReviewHeaderTitle enum to reflect its specific purpose related to PR headers --- pr_agent/algo/utils.py | 8 +++++--- tests/unittest/test_convert_to_markdown.py | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pr_agent/algo/utils.py b/pr_agent/algo/utils.py index c8915d07..4eb62e91 100644 --- a/pr_agent/algo/utils.py +++ b/pr_agent/algo/utils.py @@ -23,10 +23,12 @@ class ModelType(str, Enum): REGULAR = "regular" TURBO = "turbo" -class ReviewHeaderTitle(str, Enum): + +class PRReviewHeader(str, Enum): REGULAR = "## PR Reviewer Guide" INCREMENTAL = "## Incremental PR Reviewer Guide" + def get_setting(key: str) -> Any: try: key = key.upper() @@ -90,9 +92,9 @@ def convert_to_markdown(output_data: dict, gfm_supported: bool = True, increment } markdown_text = "" if not incremental_review: - markdown_text += f"{ReviewHeaderTitle.REGULAR.value} ๐Ÿ”\n\n" + markdown_text += f"{PRReviewHeader.REGULAR.value} ๐Ÿ”\n\n" else: - markdown_text += f"{ReviewHeaderTitle.INCREMENTAL.value} ๐Ÿ”\n\n" + markdown_text += f"{PRReviewHeader.INCREMENTAL.value} ๐Ÿ”\n\n" markdown_text += f"โฎ๏ธ Review for commits since previous PR-Agent review {incremental_review}.\n\n" if gfm_supported: markdown_text += "\n" diff --git a/tests/unittest/test_convert_to_markdown.py b/tests/unittest/test_convert_to_markdown.py index 9cf59c85..32f4bef5 100644 --- a/tests/unittest/test_convert_to_markdown.py +++ b/tests/unittest/test_convert_to_markdown.py @@ -1,5 +1,5 @@ # Generated by CodiumAI -from pr_agent.algo.utils import ReviewHeaderTitle, convert_to_markdown +from pr_agent.algo.utils import PRReviewHeader, convert_to_markdown from pr_agent.tools.pr_description import insert_br_after_x_chars """ @@ -52,7 +52,7 @@ class TestConvertToMarkdown: 'suggestion': "Consider raising an exception or logging a warning when 'pr_url' attribute is not found. This can help in debugging issues related to the absence of 'pr_url' in instances where it's expected. [important]\n", 'relevant_line': '[return ""](https://github.com/Codium-ai/pr-agent-pro/pull/102/files#diff-52d45f12b836f77ed1aef86e972e65404634ea4e2a6083fb71a9b0f9bb9e062fR199)'}]} - expected_output = f'{ReviewHeaderTitle.REGULAR.value} ๐Ÿ”\n\n
\n\n\n\n\n
โฑ๏ธ Estimated effort to review [1-5]\n1, because the changes are minimal and straightforward, focusing on a single functionality addition.\n\n\n
๐Ÿงช Relevant tests\nNo\n\n\n
โšก Possible issues\nNo\n\n\n
๐Ÿ”’ Security concerns\nNo\n\n
\n\n\n
Code feedback:\n\n
relevant filepr_agent/git_providers/git_provider.py\n
suggestion      \n\n\n\nConsider raising an exception or logging a warning when \'pr_url\' attribute is not found. This can help in debugging issues related to the absence of \'pr_url\' in instances where it\'s expected. [important]\n\n\n
relevant linereturn ""

\n\n
' + expected_output = f'{PRReviewHeader.REGULAR.value} ๐Ÿ”\n\n\n\n\n\n\n
โฑ๏ธ Estimated effort to review [1-5]\n1, because the changes are minimal and straightforward, focusing on a single functionality addition.\n\n\n
๐Ÿงช Relevant tests\nNo\n\n\n
โšก Possible issues\nNo\n\n\n
๐Ÿ”’ Security concerns\nNo\n\n
\n\n\n
Code feedback:\n\n
relevant filepr_agent/git_providers/git_provider.py\n
suggestion      \n\n\n\nConsider raising an exception or logging a warning when \'pr_url\' attribute is not found. This can help in debugging issues related to the absence of \'pr_url\' in instances where it\'s expected. [important]\n\n\n
relevant linereturn ""

\n\n
' assert convert_to_markdown(input_data).strip() == expected_output.strip()