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

feat: add persistent comment option for PR descriptions #837

Merged
merged 2 commits into from
Apr 2, 2024

Conversation

mrT23
Copy link
Collaborator

@mrT23 mrT23 commented Apr 2, 2024

User description

[pr_description] # /describe #
publish_description_as_comment=false
publish_description_as_comment_persistent=true

image

Type

enhancement


Description

  • Introduced the ability to publish PR descriptions as persistent comments, enhancing the flexibility and control over how PR descriptions are displayed.
  • Added new settings in configuration.toml to control the publication of PR descriptions as either regular or persistent comments.
  • This change allows for better management of PR descriptions, especially in scenarios where updates to the PR description are frequent.

Changes walkthrough

Relevant files
Enhancement
pr_description.py
Support for Persistent Comments in PR Descriptions             

pr_agent/tools/pr_description.py

  • Added support for publishing persistent comments in PR descriptions.
  • Persistent comments are enabled with a specific setting.
  • Regular comments are published if persistent comments are not enabled.

  • +8/-1     
    Configuration changes
    configuration.toml
    Configuration Changes for Persistent PR Description Comments

    pr_agent/settings/configuration.toml

  • Introduced settings for controlling the publication of PR descriptions
    as persistent comments.
  • Removed the previous setting for publishing descriptions as comments,
    integrating it with the new persistent option.
  • +3/-1     

    PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @codiumai-pr-agent-pro codiumai-pr-agent-pro bot added the enhancement New feature or request label Apr 2, 2024
    Copy link
    Contributor

    PR Description updated to latest commit (3ebb72e)

    Copy link
    Contributor

    PR Review

    ⏱️ Estimated effort to review [1-5]

    2, because the changes are straightforward and localized to specific areas in the codebase. The logic is simple, focusing on adding a new feature for handling persistent comments in PR descriptions, and updating configuration settings accordingly.

    🏅 Score

    85

    🧪 Relevant tests

    No

    🔍 Possible issues

    Missing Validation: There's no explicit validation to check if both publish_description_as_comment and publish_description_as_comment_persistent are set to true, which could lead to unexpected behavior.

    Hardcoded Strings: Usage of hardcoded strings for headers like "## Title" could make future changes more difficult and does not support localization.

    🔒 Security concerns

    No

    🔀 Multiple PR themes

    No


    ✨ Review tool usage guide:

    Overview:
    The review tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be added by configuring the tool.

    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=...
    
    [pr_reviewer]
    some_config1=...
    some_config2=...
    

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

    Copy link
    Contributor

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Maintainability
    Simplify the conditional logic for publishing comments by using a single method with parameters.

    Consider using a single method call with a parameter to toggle between persistent and
    non-persistent comments instead of using an if-else block. This approach simplifies the
    code and makes it easier to maintain.

    pr_agent/tools/pr_description.py [135-142]

    -if get_settings().pr_description.publish_description_as_comment_persistent:
    -    self.git_provider.publish_persistent_comment(full_markdown_description,
    -                                                 initial_header="## Title",
    -                                                 update_header=True,
    -                                                 name="describe",
    -                                                 final_update_message=False, )
    -else:
    -    self.git_provider.publish_comment(full_markdown_description)
    +self.git_provider.publish_comment(full_markdown_description,
    +                                  persistent=get_settings().pr_description.publish_description_as_comment_persistent,
    +                                  initial_header="## Title" if get_settings().pr_description.publish_description_as_comment_persistent else None,
    +                                  update_header=get_settings().pr_description.publish_description_as_comment_persistent,
    +                                  name="describe" if get_settings().pr_description.publish_description_as_comment_persistent else None,
    +                                  final_update_message=False if get_settings().pr_description.publish_description_as_comment_persistent else None)
     
    Enhancement
    Ensure configuration consistency by enabling base feature when the persistent comment feature is enabled.

    It's recommended to ensure consistency in the configuration options for enabling features.
    If publish_description_as_comment_persistent is set to true by default, consider also
    setting publish_description_as_comment to true by default. This ensures that the
    persistent comment feature does not get activated without the base feature being enabled.

    pr_agent/settings/configuration.toml [64-65]

    -publish_description_as_comment=false
    +publish_description_as_comment=true
     publish_description_as_comment_persistent=true
     
    Align the final_update_message parameter with configuration settings for consistency.

    Ensure that the final_update_message parameter aligns with the configuration settings.
    Currently, it is hardcoded to False for persistent comments, which might not always be the
    desired behavior. Consider fetching this value from the configuration settings as well.

    pr_agent/tools/pr_description.py [136-140]

     self.git_provider.publish_persistent_comment(full_markdown_description,
                                                  initial_header="## Title",
                                                  update_header=True,
                                                  name="describe",
    -                                             final_update_message=False, )
    +                                             final_update_message=get_settings().pr_description.final_update_message)
     
    Best practice
    Remove the unnecessary trailing comma for better code readability.

    The method publish_persistent_comment has a trailing comma in its arguments list, which is
    unnecessary. Removing the trailing comma can improve code readability.

    pr_agent/tools/pr_description.py [136-140]

     self.git_provider.publish_persistent_comment(full_markdown_description,
                                                  initial_header="## Title",
                                                  update_header=True,
                                                  name="describe",
    -                                             final_update_message=False, )
    +                                             final_update_message=False)
     
    Define a variable for repeated settings access to improve readability and maintainability.

    For better code readability and to avoid potential future errors, consider defining a
    variable for get_settings().pr_description.publish_description_as_comment_persistent since
    it is used multiple times. This will make the code cleaner and easier to maintain.

    pr_agent/tools/pr_description.py [135-142]

    -if get_settings().pr_description.publish_description_as_comment_persistent:
    +publish_persistent = get_settings().pr_description.publish_description_as_comment_persistent
    +if publish_persistent:
         self.git_provider.publish_persistent_comment(full_markdown_description,
                                                      initial_header="## Title",
                                                      update_header=True,
                                                      name="describe",
    -                                                 final_update_message=False, )
    +                                                 final_update_message=False)
     else:
         self.git_provider.publish_comment(full_markdown_description)
     

    ✨ Improve tool 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=...
    
    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    

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

    @Codium-ai Codium-ai deleted a comment from codiumai-pr-agent-pro bot Apr 2, 2024
    @mrT23 mrT23 merged commit a13c6e9 into main Apr 2, 2024
    1 check passed
    @mrT23 mrT23 deleted the tr/persistent_describe branch April 2, 2024 14:59
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    None yet

    1 participant