From a854e1a408fc0d25059a705dc3ab7ae730310068 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Tue, 26 Dec 2023 08:26:18 +0200 Subject: [PATCH] feat: Refactor help text addition in pr_reviewer.py and update tool names in README.md --- README.md | 4 ++-- pr_agent/algo/utils.py | 14 ++++++++++---- pr_agent/servers/help.py | 15 +++++++++------ pr_agent/tools/pr_reviewer.py | 20 ++++++++++---------- tests/unittest/test_convert_to_markdown.py | 2 +- 5 files changed, 32 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 53536404..a528c61c 100644 --- a/README.md +++ b/README.md @@ -128,8 +128,8 @@ See the [Tools Guide](./docs/TOOLS_GUIDE.md) for detailed description of the dif | TOOLS | Review | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | โฎ‘ Incremental | :white_check_mark: | | | | | Ask | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Auto-Description | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Improve Code | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Describe | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Improve | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | โฎ‘ Extended | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | Reflect and Review | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | Update CHANGELOG.md | :white_check_mark: | :white_check_mark: | :white_check_mark: | diff --git a/pr_agent/algo/utils.py b/pr_agent/algo/utils.py index b7449eb4..d3fe47f4 100644 --- a/pr_agent/algo/utils.py +++ b/pr_agent/algo/utils.py @@ -58,10 +58,10 @@ def convert_to_markdown(output_data: dict, gfm_supported: bool=True) -> str: emoji = emojis.get(key, "") if key.lower() == 'code feedback': if gfm_supported: - markdown_text += f"\n\n- " - markdown_text += f"
{ emoji } Code feedback:" + markdown_text += f"\n\n" + markdown_text += f"
{ emoji } Code feedback:" else: - markdown_text += f"\n\n- **{emoji} Code feedback:**\n\n" + markdown_text += f"\n\n**{emoji} Code feedback:**\n\n" else: markdown_text += f"- {emoji} **{key}:**\n\n" for i, item in enumerate(value): @@ -76,7 +76,13 @@ def convert_to_markdown(output_data: dict, gfm_supported: bool=True) -> str: markdown_text += "\n\n" elif value != 'n/a': emoji = emojis.get(key, "") - markdown_text += f"- {emoji} **{key}:** {value}\n" + if key.lower() == 'general suggestions': + if gfm_supported: + markdown_text += f"\n\n{emoji} General suggestions: {value}\n" + else: + markdown_text += f"{emoji} **General suggestions:** {value}\n" + else: + markdown_text += f"- {emoji} **{key}:** {value}\n" return markdown_text diff --git a/pr_agent/servers/help.py b/pr_agent/servers/help.py index 218403b9..a23d7927 100644 --- a/pr_agent/servers/help.py +++ b/pr_agent/servers/help.py @@ -1,9 +1,12 @@ -commands_text = "> **/review**: Request a review of your Pull Request. \n" \ - "> **/describe**: Update the PR title and description based on the contents of the PR. \n" \ - "> **/improve [--extended]**: Suggest code improvements. Extended mode provides a higher quality feedback. \n" \ - "> **/ask \\**: Ask a question about the PR. \n" \ - "> **/update_changelog**: Update the changelog based on the PR's contents. \n" \ - "> see the [tools guide](https://github.com/Codium-ai/pr-agent/blob/main/docs/TOOLS_GUIDE.md) for more details.\n\n" \ +commands_text = "> - **/review**: Request a review of your Pull Request. \n" \ + "> - **/describe**: Update the PR title and description based on the contents of the PR. \n" \ + "> - **/improve [--extended]**: Suggest code improvements. Extended mode provides a higher quality feedback. \n" \ + "> - **/ask \\**: Ask a question about the PR. \n" \ + "> - **/update_changelog**: Update the changelog based on the PR's contents. \n" \ + "> - **/add_docs** ๐Ÿ’Ž: Generate docstring for new components introduced in the PR. \n" \ + "> - **/generate_labels** ๐Ÿ’Ž: Generate labels for the PR based on the PR's contents. \n" \ + "> - **/analyze** ๐Ÿ’Ž: Automatically analyzes the PR, and presents changes walkthrough for each component. \n\n" \ + ">See the [tools guide](https://github.com/Codium-ai/pr-agent/blob/main/docs/TOOLS_GUIDE.md) for more details.\n" \ ">To edit any configuration parameter from the [configuration.toml](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml), add --config_path=new_value. \n" \ ">For example: /review --pr_reviewer.extra_instructions=\"focus on the file: ...\" \n" \ ">To list the possible configuration parameters, add a **/config** comment. \n" \ diff --git a/pr_agent/tools/pr_reviewer.py b/pr_agent/tools/pr_reviewer.py index 6543496f..84f04ca2 100644 --- a/pr_agent/tools/pr_reviewer.py +++ b/pr_agent/tools/pr_reviewer.py @@ -251,18 +251,15 @@ class PRReviewer: markdown_text = convert_to_markdown(data, self.git_provider.is_supported("gfm_markdown")) user = self.git_provider.get_user_id() - # Add help text if not in CLI mode - if not get_settings().get("CONFIG.CLI_MODE", False): - markdown_text += "\n### How to use\n" - if self.git_provider.is_supported("gfm_markdown"): - markdown_text += "\n
Instructions\n\n" + # Add help text if not in CLI mode, and gfm_markdown is supported + if self.git_provider.is_supported("gfm_markdown"): + markdown_text += "\n\n
โœจ Usage tips:
\n\n" bot_user = "[bot]" if get_settings().github_app.override_deployment_type else get_settings().github_app.bot_user if user and bot_user not in user: markdown_text += bot_help_text(user) else: markdown_text += actions_help_text - if self.git_provider.is_supported("gfm_markdown"): - markdown_text += "\n
\n" + markdown_text += "\n
\n" # Add custom labels from the review prediction (effort, security) self.set_review_labels(data) @@ -398,9 +395,12 @@ class PRReviewer: review_labels.append('Possible security concern') current_labels = self.git_provider.get_pr_labels() - current_labels_filtered = [label for label in current_labels if - not label.lower().startswith('review effort [1-5]:') and not label.lower().startswith( - 'possible security concern')] + if current_labels: + current_labels_filtered = [label for label in current_labels if + not label.lower().startswith('review effort [1-5]:') and not label.lower().startswith( + 'possible security concern')] + else: + current_labels_filtered = [] if current_labels or review_labels: get_logger().info(f"Setting review labels: {review_labels + current_labels_filtered}") self.git_provider.publish_labels(review_labels + current_labels_filtered) diff --git a/tests/unittest/test_convert_to_markdown.py b/tests/unittest/test_convert_to_markdown.py index 800d3ada..87f8f983 100644 --- a/tests/unittest/test_convert_to_markdown.py +++ b/tests/unittest/test_convert_to_markdown.py @@ -71,7 +71,7 @@ class TestConvertToMarkdown: - ๐Ÿ“Œ **Type of PR:** Test type\n\ - ๐Ÿงช **Relevant tests added:** no\n\ - โœจ **Focused PR:** Yes\n\ -- **General PR suggestions:** general suggestion...\n\n\n-
๐Ÿค– Code feedback: - **Code example:**\n - **Before:**\n ```\n Code before\n ```\n - **After:**\n ```\n Code after\n ```\n\n - **Code example:**\n - **Before:**\n ```\n Code before 2\n ```\n - **After:**\n ```\n Code after 2\n ```\n\n
\ +- **General PR suggestions:** general suggestion...\n\n\n
๐Ÿค– Code feedback: - **Code example:**\n - **Before:**\n ```\n Code before\n ```\n - **After:**\n ```\n Code after\n ```\n\n - **Code example:**\n - **Before:**\n ```\n Code before 2\n ```\n - **After:**\n ```\n Code after 2\n ```\n\n
\ """ assert convert_to_markdown(input_data).strip() == expected_output.strip()