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

Enhancement: Automatic Tool Configuration for Bitbucket App #519

Merged
merged 2 commits into from
Dec 12, 2023

Conversation

mrT23
Copy link
Collaborator

@mrT23 mrT23 commented Dec 12, 2023

Type

Enhancement


Description

This PR introduces automatic tool configuration for the Bitbucket app. The main changes include:

  • Added automatic tool configuration in bitbucket_app.py to enable or disable automatic tools when a new PR is opened.
  • Updated Usage.md to include instructions on how to set up automatic tools for Bitbucket Self-Hosted App.
  • Added optional settings for automatic tools in configuration.toml.

PR changes walkthrough

Relevant files                                                                                                                                 
Enhancement
1 files
bitbucket_app.py                                                                                       
    pr_agent/servers/bitbucket_app.py

    The file has been updated to include automatic tool
    configuration. This allows for automatic running of tools
    such as PRReviewer, PRDescription, and PRCodeSuggestions
    when a new PR is opened, based on the settings defined in
    the configuration file.
+19/-2
Documentation
1 files
Usage.md                                                                                                       
    Usage.md

    Instructions on how to set up automatic tools for Bitbucket
    Self-Hosted App have been added. This includes setting
    environment variables for `auto_review`, `auto_describe`,
    and `auto_improve` in the `.pr_agent.toml` file.
+14/-0
Configuration changes
1 files
configuration.toml                                                                                   
    pr_agent/settings/configuration.toml

    Optional settings for automatic tools have been added. These
    settings (`auto_review`, `auto_describe`, `auto_improve`)
    can be uncommented and set in the `.pr_agent.toml` file to
    enable or disable automatic tools when a new PR is opened.
+7/-0

…_app.py and configuration.toml, update Usage.md
@mrT23 mrT23 requested a review from okotek December 12, 2023 06:06
@mrT23
Copy link
Collaborator Author

mrT23 commented Dec 12, 2023

/describe

@github-actions github-actions bot changed the title feat: Add automatic tool configuration for Bitbucket app in bitbucket… Enhancement: Automatic Tool Configuration for Bitbucket App Dec 12, 2023
@github-actions github-actions bot added the enhancement New feature or request label Dec 12, 2023
Copy link
Contributor

PR Description updated to latest commit (81da328)

@github-actions github-actions bot added Review effort [1-5]: 3 and removed enhancement New feature or request labels Dec 12, 2023
Copy link
Contributor

PR Analysis

  • 🎯 Main theme: Adding automatic tool configuration for Bitbucket app
  • 📝 PR summary: This PR introduces automatic tool configuration for the Bitbucket app. It allows the user to set conditions in the local .pr_agent.toml file for which tools will run automatically when a new PR is opened. The PR also updates the Usage.md file to reflect these changes.
  • 📌 Type of PR: Enhancement
  • 🧪 Relevant tests added: No
  • ⏱️ Estimated effort to review [1-5]: 3, because the PR introduces new functionality and changes the existing code, which requires a careful review to ensure the changes are correct and don't introduce any bugs.
  • 🔒 Security concerns: No

PR Feedback

  • 💡 General suggestions: The PR is well-structured and the changes are clear. However, it would be beneficial to add tests to verify the new functionality works as expected. Additionally, it would be good to handle potential exceptions that might occur when applying repo settings or running the tools.

  • 🤖 Code feedback:
    • relevant file: pr_agent/servers/bitbucket_app.py
      suggestion: Consider adding error handling around the new functionality. This will help to catch and handle any exceptions that might occur when applying repo settings or running the tools. [important]
      relevant line: apply_repo_settings(pr_url)

    • relevant file: pr_agent/servers/bitbucket_app.py
      suggestion: It would be beneficial to add some logging around the new functionality. This will help to track the execution flow and debug any issues that might occur. [medium]
      relevant line: if auto_review is None or is_true(auto_review): # by default, auto review is enabled

How to use

Instructions

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.
see the tools guide for more details.

To edit any configuration parameter from the configuration.toml, add --config_path=new_value.
For example: /review --pr_reviewer.extra_instructions="focus on the file: ..."
To list the possible configuration parameters, add a /config comment.

Copy link
Contributor

PR Code Suggestions

💡 Suggestion:

Refactor the code to reduce the complexity and improve readability by extracting the logic of applying automatic tools into a separate function.

File: pr_agent/servers/bitbucket_app.py (97-108)

Example code:

Existing code:

if pr_url:
    with get_logger().contextualize(**log_context):
        apply_repo_settings(pr_url)
        auto_review = get_setting_or_env("BITBUCKET_APP.AUTO_REVIEW", None)
        if auto_review is None or is_true(auto_review):  # by default, auto review is enabled
            await PRReviewer(pr_url).run()
        auto_describe = get_setting_or_env("BITBUCKET_APP.AUTO_DESCRIBE", None)
        if is_true(auto_describe):  # by default, auto describe is disabled
            await PRDescription(pr_url).run()
        auto_improve = get_setting_or_env("BITBUCKET_APP.AUTO_IMPROVE", None)
        if is_true(auto_improve):  # by default, auto improve is disabled
            await PRCodeSuggestions(pr_url).run()

Improved code:

if pr_url:
    with get_logger().contextualize(**log_context):
        apply_repo_settings(pr_url)
        await apply_auto_tools(pr_url)

async def apply_auto_tools(pr_url):
    auto_review = get_setting_or_env("BITBUCKET_APP.AUTO_REVIEW", None)
    if auto_review is None or is_true(auto_review):  # by default, auto review is enabled
        await PRReviewer(pr_url).run()
    auto_describe = get_setting_or_env("BITBUCKET_APP.AUTO_DESCRIBE", None)
    if is_true(auto_describe):  # by default, auto describe is disabled
        await PRDescription(pr_url).run()
    auto_improve = get_setting_or_env("BITBUCKET_APP.AUTO_IMPROVE", None)
    if is_true(auto_improve):  # by default, auto improve is disabled
        await PRCodeSuggestions(pr_url).run()

@mrT23 mrT23 merged commit 73a2007 into main Dec 12, 2023
4 checks passed
@mrT23 mrT23 deleted the tr/bitbucket_app branch December 12, 2023 07:26
yochail pushed a commit to yochail/pr-agent that referenced this pull request Feb 11, 2024
Enhancement: Automatic Tool Configuration for Bitbucket App
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants