diff --git a/Usage.md b/Usage.md index a7c64fbc..887bf22a 100644 --- a/Usage.md +++ b/Usage.md @@ -239,6 +239,20 @@ inline_code_comments = true Each time you invoke a `/review` tool, it will use inline code comments. +#### BitBucket Self-Hosted App automatic tools +You can configure in your local `.pr_agent.toml` file conditions for which tools will **run automatically**. + +Specifically, start by setting the following environment variables: +```yaml +[bitbucket_app] +auto_review = true # set as config var in .pr_agent.toml +auto_describe = true # set as config var in .pr_agent.toml +auto_improve = true # set as config var in .pr_agent.toml +``` + +`bitbucket_app.auto_review`, `bitbucket_app.auto_describe` and `bitbucket_app.auto_improve` are used to enable/disable automatic tools that run when a new PR is opened. +If not set, the default option is that only the `review` tool will run automatically when a new PR is opened. + ### Changing a model See [here](pr_agent/algo/__init__.py) for the list of available models. diff --git a/pr_agent/servers/bitbucket_app.py b/pr_agent/servers/bitbucket_app.py index e147fbdd..7ca0bcf0 100644 --- a/pr_agent/servers/bitbucket_app.py +++ b/pr_agent/servers/bitbucket_app.py @@ -16,8 +16,13 @@ from starlette_context.middleware import RawContextMiddleware from pr_agent.agent.pr_agent import PRAgent from pr_agent.config_loader import get_settings, global_settings +from pr_agent.git_providers.utils import apply_repo_settings from pr_agent.log import LoggingFormat, get_logger, setup_logger from pr_agent.secret_providers import get_secret_provider +from pr_agent.servers.github_action_runner import get_setting_or_env, is_true +from pr_agent.tools.pr_code_suggestions import PRCodeSuggestions +from pr_agent.tools.pr_description import PRDescription +from pr_agent.tools.pr_reviewer import PRReviewer setup_logger(fmt=LoggingFormat.JSON) router = APIRouter() @@ -89,8 +94,20 @@ async def handle_github_webhooks(background_tasks: BackgroundTasks, request: Req pr_url = data["data"]["pullrequest"]["links"]["html"]["href"] log_context["api_url"] = pr_url log_context["event"] = "pull_request" - with get_logger().contextualize(**log_context): - await agent.handle_request(pr_url, "review") + 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() + # with get_logger().contextualize(**log_context): + # await agent.handle_request(pr_url, "review") elif event == "pullrequest:comment_created": pr_url = data["data"]["pullrequest"]["links"]["html"]["href"] log_context["api_url"] = pr_url diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index 259383d7..30fc97f8 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -143,6 +143,12 @@ magic_word = "AutoReview" # Polling interval polling_interval_seconds = 30 +[bitbucket_app] +#auto_review = true # set as config var in .pr_agent.toml +#auto_describe = true # set as config var in .pr_agent.toml +#auto_improve = true # set as config var in .pr_agent.toml + + [local] # LocalGitProvider settings - uncomment to use paths other than default # description_path= "path/to/description.md" @@ -170,3 +176,4 @@ max_issues_to_scan = 500 # fill and place in .secrets.toml #api_key = ... # environment = "gcp-starter" +