Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancements to 'improve' tool, updates to related documentation and configurations #598

Merged
merged 7 commits into from
Jan 17, 2024

Conversation

mrT23
Copy link
Collaborator

@mrT23 mrT23 commented Jan 17, 2024

Type

Enhancement, Documentation


Description

  • Added a comprehensive usage guide for the 'improve' tool in pr_agent/servers/help.py.
  • Modified the pr_agent/tools/pr_code_suggestions.py to include the usage guide in the PR body if the enable_help_text configuration is set to true.
  • Updated the 'improve' tool documentation in docs/IMPROVE.md to reflect the changes made to the tool.
  • Added a new configuration option enable_help_text in pr_agent/settings/configuration.toml to control whether the usage guide should be included in the PR body.

Changes walkthrough

Relevant files
Enhancement
help.py
Addition of 'improve' tool usage guide                                                     

    pr_agent/servers/help.py

    • Added a new method get_improve_usage_guide which generates a
      comprehensive guide for using the 'improve' tool.
+83/-0   
pr_code_suggestions.py
Enhancements to PR code suggestions tool                                                 

    pr_agent/tools/pr_code_suggestions.py

    • Modified the run method to include the usage guide in the PR body if
      the enable_help_text configuration is set to true.
    • Renamed
      publish_summarizes_suggestions to generate_summarized_suggestions
      and modified it to return the PR body instead of publishing it directly.
+16/-4   
Documentation
IMPROVE.md
Updates to 'improve' tool documentation                                                   

    docs/IMPROVE.md

    • Updated the documentation to reflect the changes made to the 'improve'
      tool.
    • Added information about the new 'summarize' and
      'enable_help_text' configuration options.
+13/-23 
Configuration changes
configuration.toml
Addition of new configuration option                                                         

    pr_agent/settings/configuration.toml

    • Added a new configuration option enable_help_text under the
      pr_code_suggestions section.
+1/-0     

✨ Usage guide:

Overview:
The describe tool scans the PR code changes, and generates a description for the PR - title, type, summary, walkthrough and labels. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.

When commenting, to edit configurations related to the describe tool (pr_description section), use the following template:

/describe --pr_description.some_config1=... --pr_description.some_config2=...

With a configuration file, use the following template:

[pr_description]
some_config1=...
some_config2=...
Enabling\disabling automation
  • When you first install the app, the default mode for the describe tool is:
pr_commands = ["/describe --pr_description.add_original_user_description=true" 
                         "--pr_description.keep_original_user_title=true", ...]

meaning the describe tool will run automatically on every PR, will keep the original title, and will add the original user description above the generated description.

  • Markers are an alternative way to control the generated description, to give maximal control to the user. If you set:
pr_commands = ["/describe --pr_description.use_description_markers=true", ...]

the tool will replace every marker of the form pr_agent:marker_name in the PR description with the relevant content, where marker_name is one of the following:

  • type: the PR type.
  • summary: the PR summary.
  • walkthrough: the PR walkthrough.

Note that when markers are enabled, if the original PR description does not contain any markers, the tool will not alter the description at all.

Custom labels

The default labels of the describe tool are quite generic: [Bug fix, Tests, Enhancement, Documentation, Other].

If you specify custom labels in the repo's labels page or via configuration file, you can get tailored labels for your use cases.
Examples for custom labels:

  • Main topic:performance - pr_agent:The main topic of this PR is performance
  • New endpoint - pr_agent:A new endpoint was added in this PR
  • SQL query - pr_agent:A new SQL query was added in this PR
  • Dockerfile changes - pr_agent:The PR contains changes in the Dockerfile
  • ...

The list above is eclectic, and aims to give an idea of different possibilities. Define custom labels that are relevant for your repo and use cases.
Note that Labels are not mutually exclusive, so you can add multiple label categories.
Make sure to provide proper title, and a detailed and well-phrased description for each label, so the tool will know when to suggest it.

More PR-Agent commands

To invoke the PR-Agent, add a comment using one of the following commands:

  • /review: Request a review of your Pull Request.
  • /describe: Update the PR title and description based on the contents of the PR.
  • /improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
  • /ask <QUESTION>: Ask a question about the PR.
  • /update_changelog: Update the changelog based on the PR's contents.
  • /add_docs 💎: Generate docstring for new components introduced in the PR.
  • /generate_labels 💎: Generate labels for the PR based on the PR's contents.
  • /analyze 💎: Automatically analyzes the PR, and presents changes walkthrough for each component.

See the tools guide for more details.
To list the possible configuration parameters, add a /config comment.

See the describe usage page for a comprehensive guide on using this tool.

@codiumai-pr-agent-pro codiumai-pr-agent-pro bot added documentation Improvements or additions to documentation enhancement New feature or request labels Jan 17, 2024
Copy link

PR Description updated to latest commit (58163e5)

Copy link

PR Analysis

  • 🎯 Main theme: Enhancement and documentation of the 'improve' tool
  • 📝 PR summary: This PR introduces several enhancements to the 'improve' tool including a comprehensive usage guide, renaming of a method, and a new configuration. The usage guide provides detailed instructions on how to use and configure the 'improve' tool. The method publish_summarizes_suggestions was renamed to generate_summarized_suggestions and now returns the PR body as a string instead of publishing it directly. A new configuration enable_help_text was added to control whether the usage guide for the 'improve' tool should be included in the PR body.
  • 📌 Type of PR: Enhancement
  • 🧪 Relevant tests added: No
  • ⏱️ Estimated effort to review [1-5]: 3, because the PR includes changes to both the functionality and documentation of the 'improve' tool, which requires a good understanding of the tool's operation and the changes made to it.
  • 🔒 Security concerns: No security concerns found

PR Feedback

💡 General suggestions: The PR is well-structured and the changes are well-documented. However, it would be beneficial to add tests to verify the new functionality and changes. This would help ensure that the changes work as expected and do not introduce any regressions.

🤖 Code feedback:
relevant filepr_agent/tools/pr_code_suggestions.py
suggestion      

Consider handling the exception in the generate_summarized_suggestions method more gracefully. Instead of returning an empty string when an exception occurs, it might be better to return a meaningful error message. This would help in debugging if something goes wrong. [important]

relevant linereturn ""

relevant filepr_agent/tools/pr_code_suggestions.py
suggestion      

It seems that the generate_summarized_suggestions method is doing more than just generating suggestions. It's also adding a usage guide to the PR body. Consider separating these responsibilities into different methods to adhere to the Single Responsibility Principle. This would make the code easier to maintain and understand. [medium]

relevant linepr_body += HelpMessage.get_improve_usage_guide()


✨ Usage guide:

Overview:
The review tool scans the PR code changes, and generates a PR review. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.
When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:

/review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...

With a configuration file, use the following template:

[pr_reviewer]
some_config1=...
some_config2=...
Utilizing extra instructions

The review tool can be configured with extra instructions, which can be used to guide the model to a feedback tailored to the needs of your project.

Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Specify the relevant sub-tool, and the relevant aspects of the PR that you want to emphasize.

Examples for extra instructions:

[pr_reviewer] # /review #
extra_instructions="""
In the code feedback section, emphasize the following:
- Does the code logic cover relevant edge cases?
- Is the code logic clear and easy to understand?
- Is the code logic efficient?
...
"""

Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable.

How to enable\disable automation
  • When you first install PR-Agent app, the default mode for the review tool is:
pr_commands = ["/review", ...]

meaning the review tool will run automatically on every PR, with the default configuration.
Edit this field to enable/disable the tool, or to change the used configurations

About the 'Code feedback' section

The review tool provides several type of feedbacks, one of them is code suggestions.
If you are interested only in the code suggestions, it is recommended to use the improve feature instead, since it dedicated only to code suggestions, and usually gives better results.
Use the review tool if you want to get a more comprehensive feedback, which includes code suggestions as well.

Auto-labels

The review tool can auto-generate two specific types of labels for a PR:

  • a possible security issue label, that detects possible security issues (enable_review_labels_security flag)
  • a Review effort [1-5]: x label, where x is the estimated effort to review the PR (enable_review_labels_effort flag)
Extra sub-tools

The review tool provides a collection of possible feedbacks about a PR.
It is recommended to review the possible options, and choose the ones relevant for your use case.
Some of the feature that are disabled by default are quite useful, and should be considered for enabling. For example:
require_score_review, require_soc2_review, enable_review_labels_effort, and more.

More PR-Agent commands

To invoke the PR-Agent, add a comment using one of the following commands:

  • /review: Request a review of your Pull Request.
  • /describe: Update the PR title and description based on the contents of the PR.
  • /improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
  • /ask <QUESTION>: Ask a question about the PR.
  • /update_changelog: Update the changelog based on the PR's contents.
  • /add_docs 💎: Generate docstring for new components introduced in the PR.
  • /generate_labels 💎: Generate labels for the PR based on the PR's contents.
  • /analyze 💎: Automatically analyzes the PR, and presents changes walkthrough for each component.

See the tools guide for more details.
To list the possible configuration parameters, add a /config comment.

See the review usage page for a comprehensive guide on using this tool.

@mrT23
Copy link
Collaborator Author

mrT23 commented Jan 17, 2024

PR Code Suggestions

Suggestions                                                                                                                                                         
maintainability
Split a long method into smaller, more manageable methods.                   

The method get_improve_usage_guide is quite long and contains multiple sections. It
would be more maintainable to split this method into smaller methods, each responsible for
generating a specific section of the guide.

pr_agent/servers/help.py [236-316]

 @staticmethod
 def get_improve_usage_guide():
     output = "**Overview:**\n"
-    ...
+    output += self.get_overview_section()
+    output += self.get_automation_section()
+    output += self.get_extra_instructions_section()
+    output += self.get_suggestions_quality_section()
+    output += self.get_general_section()
     return output
 
Split a long method into smaller, more manageable methods.                   

The method run is quite long and contains multiple sections. It would be more
maintainable to split this method into smaller methods, each responsible for a specific
part of the process.

pr_agent/tools/pr_code_suggestions.py [79-95]

 async def run(self):
     if get_settings().config.publish_output:
-        get_logger().info('Pushing PR code suggestions...')
-        self.git_provider.remove_initial_comment()
-        ...
-        self.git_provider.publish_comment(pr_body)
+        self.publish_output()
     else:
         get_logger().info('Pushing inline code suggestions...')
         self.push_inline_code_suggestions(data)
 
+def publish_output(self):
+    get_logger().info('Pushing PR code suggestions...')
+    self.git_provider.remove_initial_comment()
+    ...
+    self.git_provider.publish_comment(pr_body)
+
Split a long method into smaller, more manageable methods.                   

The method generate_summarized_suggestions is quite long and contains multiple sections.
It would be more maintainable to split this method into smaller methods, each responsible
for generating a specific part of the suggestions.

pr_agent/tools/pr_code_suggestions.py [312-393]

 def generate_summarized_suggestions(self, data: Dict) -> str:
     try:
         pr_body = "## PR Code Suggestions\n\n"
+        pr_body += self.generate_suggestions_body(data)
         ...
         return pr_body
     except Exception as e:
         get_logger().info(f"Failed to publish summarized code suggestions, error: {e}")
         return ""
 
Extract repeated condition checks into a separate method.                    

The run method is checking if get_settings().pr_code_suggestions.summarize and
self.git_provider.is_supported("gfm_markdown") are both true. This check is done in
multiple places in the code. It would be better to create a method that performs this
check and call it instead.

pr_agent/tools/pr_code_suggestions.py [83]

-if get_settings().pr_code_suggestions.summarize and self.git_provider.is_supported("gfm_markdown"):
+if self.should_push_summarized_suggestions():
     get_logger().info('Pushing summarize code suggestions...')
 
+def should_push_summarized_suggestions(self):
+    return get_settings().pr_code_suggestions.summarize and self.git_provider.is_supported("gfm_markdown")
+

✨ Usage guide:

Overview:
The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.
When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:

/improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...

With a configuration file, use the following template:

[pr_code_suggestions]
some_config1=...
some_config2=...
Enabling\disabling automation

When you first install the app, the default mode for the improve tool is:

pr_commands = ["/improve --pr_code_suggestions.summarize=true", ...]

meaning the improve tool will run automatically on every PR, with summarization enabled. Delete this line to disable the tool from running automatically.

Utilizing extra instructions

Extra instructions are very important for the improve tool, since they enable to guide the model to suggestions that are more relevant to the specific needs of the project.

Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Specify relevant aspects that you want the model to focus on.

Examples for extra instructions:

[pr_code_suggestions] # /improve #
extra_instructions="""
Emphasize the following aspects:
- Does the code logic cover relevant edge cases?
- Is the code logic clear and easy to understand?
- Is the code logic efficient?
...
"""

Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable.

A note on code suggestions quality
  • While the current AI for code is getting better and better (GPT-4), it's not flawless. Not all the suggestions will be perfect, and a user should not accept all of them automatically.
  • Suggestions are not meant to be simplistic. Instead, they aim to give deep feedback and raise questions, ideas and thoughts to the user, who can then use his judgment, experience, and understanding of the code base.
  • Recommended to use the 'extra_instructions' field to guide the model to suggestions that are more relevant to the specific needs of the project.
  • Best quality will be obtained by using 'improve --extended' mode.
More PR-Agent commands

To invoke the PR-Agent, add a comment using one of the following commands:

  • /review: Request a review of your Pull Request.
  • /describe: Update the PR title and description based on the contents of the PR.
  • /improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
  • /ask <QUESTION>: Ask a question about the PR.
  • /update_changelog: Update the changelog based on the PR's contents.
  • /add_docs 💎: Generate docstring for new components introduced in the PR.
  • /generate_labels 💎: Generate labels for the PR based on the PR's contents.
  • /analyze 💎: Automatically analyzes the PR, and presents changes walkthrough for each component.

See the tools guide for more details.
To list the possible configuration parameters, add a /config comment.

See the improve usage page for a more comprehensive guide on using this tool.

@CodiumAI-Agent CodiumAI-Agent changed the title improve usage guide Enhancements to the 'improve' tool and updates to the related documentation Jan 17, 2024
@CodiumAI-Agent
Copy link

PR Description updated to latest commit (2132771)

@CodiumAI-Agent
Copy link

Preparing PR description...

2 similar comments
@CodiumAI-Agent
Copy link

Preparing PR description...

@CodiumAI-Agent
Copy link

Preparing PR description...

@CodiumAI-Agent
Copy link

PR Description updated to latest commit (8f510dc)

@CodiumAI-Agent
Copy link

Preparing PR description...

1 similar comment
@CodiumAI-Agent
Copy link

Preparing PR description...

@mrT23 mrT23 merged commit 0b811d9 into main Jan 17, 2024
1 check passed
@mrT23 mrT23 deleted the tr/improve_usage_guide branch January 17, 2024 11:13
@CodiumAI-Agent
Copy link

Preparing PR description...

@CodiumAI-Agent
Copy link

PR Description updated to latest commit (8f510dc)

@Codium-ai Codium-ai deleted a comment from CodiumAI-Agent Jan 17, 2024
@Codium-ai Codium-ai deleted a comment from CodiumAI-Agent Jan 17, 2024
@CodiumAI-Agent
Copy link

Preparing PR description...

@CodiumAI-Agent
Copy link

PR Description updated to latest commit (8f510dc)

@Codium-ai Codium-ai deleted a comment from CodiumAI-Agent Jan 17, 2024
@Codium-ai Codium-ai deleted a comment from CodiumAI-Agent Jan 17, 2024
@Codium-ai Codium-ai deleted a comment from CodiumAI-Agent Jan 17, 2024
@Codium-ai Codium-ai deleted a comment from CodiumAI-Agent Jan 17, 2024
@Codium-ai Codium-ai deleted a comment from CodiumAI-Agent Jan 17, 2024
@Codium-ai Codium-ai deleted a comment from CodiumAI-Agent Jan 17, 2024
@Codium-ai Codium-ai deleted a comment from CodiumAI-Agent Jan 17, 2024
@Codium-ai Codium-ai deleted a comment from CodiumAI-Agent Jan 17, 2024
@CodiumAI-Agent
Copy link

PR Description updated to latest commit (8f510dc)

@Codium-ai Codium-ai deleted a comment from CodiumAI-Agent Jan 17, 2024
@CodiumAI-Agent
Copy link

Preparing PR description...

1 similar comment
@CodiumAI-Agent
Copy link

Preparing PR description...

@Codium-ai Codium-ai deleted a comment from CodiumAI-Agent Jan 17, 2024
@CodiumAI-Agent
Copy link

Preparing PR description...

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File changes summary
Main theme - Addition of 'improve' tool usage guide

    • Added a new method get_improve_usage_guide which generates a
      comprehensive guide for using the 'improve' tool.

@CodiumAI-Agent
Copy link

PR Description updated to latest commit (8f510dc)

@mrT23
Copy link
Collaborator Author

mrT23 commented Jan 28, 2024

PR Analysis

Here is a list of code components that were changed in this PR:

fileComponents
help.py
get_improve_usage_guide (method of HelpMessage) +81/-0
pr_code_suggestions.py
run (method of PRCodeSuggestions) +12/-2
generate_summarized_suggestions (method of PRCodeSuggestions) +3/-0

✨ Usage guide:

Using static code analysis capabilities, the analyze tool scans the PR code changes and find the code components (methods, functions, classes) that changed in the PR.
The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR:

/analyze

Language that are currently supported: Python, Java, C++, JavaScript, TypeScript.
See more information about the tool in the docs.

@mrT23
Copy link
Collaborator Author

mrT23 commented Jan 28, 2024

Tests for 'generate_summarized_suggestions' method

PR-Agent tests for code changes in generate_summarized_suggestions:

[happy path]
The function should correctly generate a summarized suggestion HTML table with the correct headers and footers

test_code:

import pytest
from your_module import PRCodeSuggestions  # Adjust the import according to your project structure

@pytest.mark.asyncio
async def test_generate_summarized_suggestions_html_structure():
    pr_code_suggestions = PRCodeSuggestions("dummy_pr_url")
    data = {
        "code_suggestions": [
            {
                "label": "Refactor",
                "relevant_file": "example.py",
                "relevant_lines_start": 10,
                "relevant_lines_end": 12,
                "suggestion_content": "Consider using a context manager.",
                "existing_code": "f = open('file.txt')\nf.close()",
                "improved_code": "with open('file.txt') as f:\n    pass",
                "one_sentence_summary": "Use context manager for file handling."
            }
        ]
    }
    result = pr_code_suggestions.generate_summarized_suggestions(data)
    assert "<table>" in result and "</table>" in result, "The result should contain an HTML table structure."
    assert "<thead>" in result and "</thead>" in result, "The result should contain a table header."
    assert "<tbody>" in result and "</tbody>" in result, "The result should contain a table body."
    assert "Refactor" in result, "The result should include the label 'Refactor'."
    assert "example.py" in result, "The result should include the file name 'example.py'."
    assert "Consider using a context manager." in result, "The suggestion content should be included in the result."
[happy path]
The function should correctly replace code tags in the one sentence summary with HTML entities to avoid breaking the HTML structure

test_code:

import pytest
from your_module import PRCodeSuggestions  # Adjust the import according to your project structure

@pytest.mark.asyncio
async def test_generate_summarized_suggestions_code_tags_replacement():
    pr_code_suggestions = PRCodeSuggestions("dummy_pr_url")
    data = {
        "code_suggestions": [
            {
                "label": "Syntax",
                "relevant_file": "example.py",
                "relevant_lines_start": 5,
                "relevant_lines_end": 5,
                "suggestion_content": "Use `:=` for assignment expressions.",
                "existing_code": "val = get_value()\nif val:",
                "improved_code": "if (val := get_value()):",
                "one_sentence_summary": "Use `:=` for assignment expressions."
            }
        ]
    }
    result = pr_code_suggestions.generate_summarized_suggestions(data)
    assert "&lt;=" in result and "&gt;=" in result, "The result should contain HTML entities for code tags."
[edge case]
The function should handle empty code suggestions gracefully, returning only the initial headers and footers without any suggestion rows

test_code:

import pytest
from your_module import PRCodeSuggestions  # Adjust the import according to your project structure

@pytest.mark.asyncio
async def test_generate_summarized_suggestions_with_empty_data():
    pr_code_suggestions = PRCodeSuggestions("dummy_pr_url")
    data = {"code_suggestions": []}
    result = pr_code_suggestions.generate_summarized_suggestions(data)
    assert "<table>" in result and "</table>" in result, "The result should contain an HTML table structure."
    assert "<tbody>" not in result, "The result should not contain a table body if there are no suggestions."

@mrT23
Copy link
Collaborator Author

mrT23 commented Jan 28, 2024

/test generate_summarized_suggestions

yochail pushed a commit to yochail/pr-agent that referenced this pull request Feb 11, 2024
Enhancements to the 'improve' tool and updates to the related documentation
@hgcdanniel
Copy link

/analyze

Copy link

PR Analysis 🔬

  • This screen contains a list of code components that were changed in this PR.
  • You can initiate specific actions for each component, by checking the relevant boxes.
  • After you check a box, the action will be performed automatically by PR-Agent.
  • Results will appear as a comment on the PR, typically after 30-60 seconds.
fileChanged components
help.py
  • Test
  • Docs
  • Improve
  • Similar
 
get_improve_usage_guide
(method of HelpMessage)
 
+80/-0
 
pr_code_suggestions.py
  • Test
  • Docs
  • Improve
  • Similar
 
run
(method of PRCodeSuggestions)
 
+13/-3
 
  • Test
  • Docs
  • Improve
  • Similar
 
generate_summarized_suggestions
(method of PRCodeSuggestions)
 
+85/-0
 

💡 Usage guide:

Using static code analysis capabilities, the analyze tool scans the PR code changes and find the code components (methods, functions, classes) that changed in the PR.

The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR:

/analyze

Language that are currently supported: Python, Java, C++, JavaScript, TypeScript, C#.
See more information about the tool in the docs.

Copy link
Contributor

@barnett-yuxiang barnett-yuxiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@hgcdanniel
Copy link

/test generate_summarized_suggestions

Copy link

codiumai-pr-agent-pro bot commented May 31, 2024

Generated tests for 'generate_summarized_suggestions' ✏️️

    generate_summarized_suggestions (method) [+85/-0]

    Component signature:

    def generate_summarized_suggestions(self, data: Dict) -> str:


    Tests for code changes in generate_summarized_suggestions method:

    [happy path]
    The function should correctly generate a summarized suggestion table with multiple suggestions under the same label

    test_code:

    import pytest
    from pr_agent.tools.pr_code_suggestions import PRCodeSuggestions
    
    def test_generate_summarized_suggestions_multiple_suggestions_same_label():
        # Given
        data = {
            'code_suggestions': [
                {
                    'label': 'Refactor',
                    'relevant_file': 'file1.py',
                    'relevant_lines_start': 10,
                    'relevant_lines_end': 12,
                    'suggestion_content': 'Refactor this function',
                    'existing_code': 'def old_func():\n    pass\n',
                    'improved_code': 'def new_func():\n    pass\n',
                    'one_sentence_summary': 'Refactor old_func to new_func'
                },
                {
                    'label': 'Refactor',
                    'relevant_file': 'file2.py',
                    'relevant_lines_start': 20,
                    'relevant_lines_end': 22,
                    'suggestion_content': 'Refactor another function',
                    'existing_code': 'def another_old_func():\n    pass\n',
                    'improved_code': 'def another_new_func():\n    pass\n',
                    'one_sentence_summary': 'Refactor another_old_func to another_new_func'
                }
            ]
        }
        pr_code_suggestions = PRCodeSuggestions(pr_url="http://example.com")
    
        # When
        result = pr_code_suggestions.generate_summarized_suggestions(data)
    
        # Then
        assert "<strong>Refactor</strong>" in result
        assert "Refactor this function" in result
        assert "Refactor another function" in result
    [happy path]
    The function should correctly generate a summarized suggestion table with suggestions having different labels

    test_code:

    import pytest
    from pr_agent.tools.pr_code_suggestions import PRCodeSuggestions
    
    def test_generate_summarized_suggestions_different_labels():
        # Given
        data = {
            'code_suggestions': [
                {
                    'label': 'Refactor',
                    'relevant_file': 'file1.py',
                    'relevant_lines_start': 10,
                    'relevant_lines_end': 12,
                    'suggestion_content': 'Refactor this function',
                    'existing_code': 'def old_func():\n    pass\n',
                    'improved_code': 'def new_func():\n    pass\n',
                    'one_sentence_summary': 'Refactor old_func to new_func'
                },
                {
                    'label': 'Bugfix',
                    'relevant_file': 'file2.py',
                    'relevant_lines_start': 20,
                    'relevant_lines_end': 22,
                    'suggestion_content': 'Fix this bug',
                    'existing_code': 'def buggy_func():\n    pass\n',
                    'improved_code': 'def fixed_func():\n    pass\n',
                    'one_sentence_summary': 'Fix buggy_func to fixed_func'
                }
            ]
        }
        pr_code_suggestions = PRCodeSuggestions(pr_url="http://example.com")
    
        # When
        result = pr_code_suggestions.generate_summarized_suggestions(data)
    
        # Then
        assert "<strong>Refactor</strong>" in result
        assert "<strong>Bugfix</strong>" in result
        assert "Refactor this function" in result
        assert "Fix this bug" in result
    [edge case]
    The function should handle the case where there are no code suggestions gracefully

    test_code:

    import pytest
    from pr_agent.tools.pr_code_suggestions import PRCodeSuggestions
    
    def test_generate_summarized_suggestions_no_suggestions():
        # Given
        data = {
            'code_suggestions': []
        }
        pr_code_suggestions = PRCodeSuggestions(pr_url="http://example.com")
    
        # When
        result = pr_code_suggestions.generate_summarized_suggestions(data)
    
        # Then
        assert "No code suggestions found" not in result
        assert "## PR Code Suggestions" in result

@hgcdanniel
Copy link

/analyze

Copy link

PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

PR Analysis 🔬

  • This screen contains a list of code components that were changed in this PR.
  • You can initiate specific actions for each component, by checking the relevant boxes.
  • After you check a box, the action will be performed automatically by PR-Agent.
  • Results will appear as a comment on the PR, typically after 30-60 seconds.
fileChanged components
help.py
  • Test
  • Docs
  • Improve
  • Similar
 
get_improve_usage_guide
(method of HelpMessage)
 
+80/-0
 
pr_code_suggestions.py
  • Test
  • Docs
  • Improve
  • Similar
 
run
(method of PRCodeSuggestions)
 
+13/-3
 
  • Test
  • Docs
  • Improve
  • Similar
 
generate_summarized_suggestions
(method of PRCodeSuggestions)
 
+85/-0
 

💡 Usage guide:

Using static code analysis capabilities, the analyze tool scans the PR code changes and find the code components (methods, functions, classes) that changed in the PR.

The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR:

/analyze

Language that are currently supported: Python, Java, C++, JavaScript, TypeScript, C#.
See more information about the tool in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request Review effort [1-5]: 3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants