Add disable_auto_feedback configuration option to control automatic PR feedback

This commit is contained in:
mrT23
2024-12-02 21:28:48 +02:00
parent 91bf3c0749
commit 8610aa27a4
7 changed files with 45 additions and 14 deletions

View File

@ -57,6 +57,14 @@ For example, if you want to edit the `review` tool configurations, you can run:
``` ```
Any configuration value in [configuration file](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml) file can be similarly edited. Comment `/config` to see the list of available configurations. Any configuration value in [configuration file](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml) file can be similarly edited. Comment `/config` to see the list of available configurations.
## Disabling automatic feedback
To easily disable all automatic feedback from Qodo Merge (GitHub App, GitLab Webhook, BitBucket App, Azure DevOps Webhook), set in a configuration file:
```toml
[config]
disable_auto_feedback = true
```
## GitHub App ## GitHub App
@ -69,7 +77,7 @@ Any configuration value in [configuration file](https://github.com/Codium-ai/pr-
The [github_app](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L108) section defines GitHub app specific configurations. The [github_app](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L108) section defines GitHub app specific configurations.
The configuration parameter `pr_commands` defines the list of tools that will be **run automatically** when a new PR is opened. The configuration parameter `pr_commands` defines the list of tools that will be **run automatically** when a new PR is opened.
``` ```toml
[github_app] [github_app]
pr_commands = [ pr_commands = [
"/describe", "/describe",
@ -83,25 +91,27 @@ For the `improve` tool, for example, the `suggestions_score_threshold` parameter
You can override the default tool parameters by using one the three options for a [configuration file](https://qodo-merge-docs.qodo.ai/usage-guide/configuration_options/): **wiki**, **local**, or **global**. You can override the default tool parameters by using one the three options for a [configuration file](https://qodo-merge-docs.qodo.ai/usage-guide/configuration_options/): **wiki**, **local**, or **global**.
For example, if your local `.pr_agent.toml` file contains: For example, if your local `.pr_agent.toml` file contains:
``` ```toml
[pr_description] [pr_description]
generate_ai_title = true generate_ai_title = true
``` ```
Every time you run the `describe` tool, including automatic runs, the PR title will be generated by the AI. Every time you run the `describe` tool, including automatic runs, the PR title will be generated by the AI.
To cancel the automatic run of all the tools, set: To change which tools will run automatically when a new PR is opened, you can set the `pr_commands` parameter in the configuration file.
``` ```toml
[github_app] [github_app]
pr_commands = [] pr_commands = ["describe", "review"]
``` ```
In this case, only the `describe` and `review` tools will run automatically when a new PR is opened.
### GitHub app automatic tools for push actions (commits to an open PR) ### GitHub app automatic tools for push actions (commits to an open PR)
In addition to running automatic tools when a PR is opened, the GitHub app can also respond to new code that is pushed to an open PR. In addition to running automatic tools when a PR is opened, the GitHub app can also respond to new code that is pushed to an open PR.
The configuration toggle `handle_push_trigger` can be used to enable this feature. The configuration toggle `handle_push_trigger` can be used to enable this feature.
The configuration parameter `push_commands` defines the list of tools that will be **run automatically** when new code is pushed to the PR. The configuration parameter `push_commands` defines the list of tools that will be **run automatically** when new code is pushed to the PR.
``` ```toml
[github_app] [github_app]
handle_push_trigger = true handle_push_trigger = true
push_commands = [ push_commands = [
@ -137,15 +147,18 @@ The JSON structure is equivalent to the yaml data structure defined in [pr_revie
Note that you can give additional config parameters by adding environment variables to `.github/workflows/pr_agent.yml`, or by using a `.pr_agent.toml` [configuration file](https://qodo-merge-docs.qodo.ai/usage-guide/configuration_options/#global-configuration-file) in the root of your repo Note that you can give additional config parameters by adding environment variables to `.github/workflows/pr_agent.yml`, or by using a `.pr_agent.toml` [configuration file](https://qodo-merge-docs.qodo.ai/usage-guide/configuration_options/#global-configuration-file) in the root of your repo
For example, you can set an environment variable: `pr_description.publish_labels=false`, or add a `.pr_agent.toml` file with the following content: For example, you can set an environment variable: `pr_description.publish_labels=false`, or add a `.pr_agent.toml` file with the following content:
```
```toml
[pr_description] [pr_description]
publish_labels = false publish_labels = false
``` ```
to prevent Qodo Merge from publishing labels when running the `describe` tool. to prevent Qodo Merge from publishing labels when running the `describe` tool.
## GitLab Webhook ## GitLab Webhook
After setting up a GitLab webhook, to control which commands will run automatically when a new MR is opened, you can set the `pr_commands` parameter in the configuration file, similar to the GitHub App: After setting up a GitLab webhook, to control which commands will run automatically when a new MR is opened, you can set the `pr_commands` parameter in the configuration file, similar to the GitHub App:
```
```toml
[gitlab] [gitlab]
pr_commands = [ pr_commands = [
"/describe", "/describe",
@ -157,7 +170,7 @@ pr_commands = [
the GitLab webhook can also respond to new code that is pushed to an open MR. the GitLab webhook can also respond to new code that is pushed to an open MR.
The configuration toggle `handle_push_trigger` can be used to enable this feature. The configuration toggle `handle_push_trigger` can be used to enable this feature.
The configuration parameter `push_commands` defines the list of tools that will be **run automatically** when new code is pushed to the MR. The configuration parameter `push_commands` defines the list of tools that will be **run automatically** when new code is pushed to the MR.
``` ```toml
[gitlab] [gitlab]
handle_push_trigger = true handle_push_trigger = true
push_commands = [ push_commands = [
@ -174,7 +187,7 @@ Similar to GitHub app, when running Qodo Merge from BitBucket App, the default [
By uploading a local `.pr_agent.toml` file to the root of the repo's main branch, you can edit and customize any configuration parameter. Note that you need to upload `.pr_agent.toml` prior to creating a PR, in order for the configuration to take effect. By uploading a local `.pr_agent.toml` file to the root of the repo's main branch, you can edit and customize any configuration parameter. Note that you need to upload `.pr_agent.toml` prior to creating a PR, in order for the configuration to take effect.
For example, if your local `.pr_agent.toml` file contains: For example, if your local `.pr_agent.toml` file contains:
``` ```toml
[pr_reviewer] [pr_reviewer]
extra_instructions = "Answer in japanese" extra_instructions = "Answer in japanese"
``` ```
@ -192,7 +205,7 @@ This will prevent Qodo Merge from acquiring the full file content, and will only
To control which commands will run automatically when a new PR is opened, you can set the `pr_commands` parameter in the configuration file: To control which commands will run automatically when a new PR is opened, you can set the `pr_commands` parameter in the configuration file:
Specifically, set the following values: Specifically, set the following values:
``` ```toml
[bitbucket_app] [bitbucket_app]
pr_commands = [ pr_commands = [
"/review", "/review",
@ -203,7 +216,7 @@ Note that we set specifically for bitbucket, we recommend using: `--pr_code_sugg
Since this platform only supports inline code suggestions, we want to limit the number of suggestions, and only present a limited number. Since this platform only supports inline code suggestions, we want to limit the number of suggestions, and only present a limited number.
To enable BitBucket app to respond to each **push** to the PR, set (for example): To enable BitBucket app to respond to each **push** to the PR, set (for example):
``` ```toml
[bitbucket_app] [bitbucket_app]
handle_push_trigger = true handle_push_trigger = true
push_commands = [ push_commands = [
@ -215,7 +228,7 @@ push_commands = [
## Azure DevOps provider ## Azure DevOps provider
To use Azure DevOps provider use the following settings in configuration.toml: To use Azure DevOps provider use the following settings in configuration.toml:
``` ```toml
[config] [config]
git_provider="azure" git_provider="azure"
``` ```
@ -237,7 +250,7 @@ org = "https://dev.azure.com/YOUR_ORGANIZATION/"
### Azure DevOps Webhook ### Azure DevOps Webhook
To control which commands will run automatically when a new PR is opened, you can set the `pr_commands` parameter in the configuration file, similar to the GitHub App: To control which commands will run automatically when a new PR is opened, you can set the `pr_commands` parameter in the configuration file, similar to the GitHub App:
``` ```toml
[azure_devops_server] [azure_devops_server]
pr_commands = [ pr_commands = [
"/describe", "/describe",

View File

@ -64,6 +64,9 @@ def authorize(credentials: HTTPBasicCredentials = Depends(security)):
async def _perform_commands_azure(commands_conf: str, agent: PRAgent, api_url: str, log_context: dict): async def _perform_commands_azure(commands_conf: str, agent: PRAgent, api_url: str, log_context: dict):
apply_repo_settings(api_url) apply_repo_settings(api_url)
if commands_conf == "pr_commands" and get_settings().config.disable_auto_feedback: # auto commands for PR, and auto feedback is disabled
get_logger().info(f"Auto feedback is disabled, skipping auto commands for PR {api_url=}", **log_context)
return
commands = get_settings().get(f"azure_devops_server.{commands_conf}") commands = get_settings().get(f"azure_devops_server.{commands_conf}")
get_settings().set("config.is_auto_command", True) get_settings().set("config.is_auto_command", True)
for command in commands: for command in commands:

View File

@ -77,6 +77,9 @@ async def handle_manifest(request: Request, response: Response):
async def _perform_commands_bitbucket(commands_conf: str, agent: PRAgent, api_url: str, log_context: dict, data: dict): async def _perform_commands_bitbucket(commands_conf: str, agent: PRAgent, api_url: str, log_context: dict, data: dict):
apply_repo_settings(api_url) apply_repo_settings(api_url)
if commands_conf == "pr_commands" and get_settings().config.disable_auto_feedback: # auto commands for PR, and auto feedback is disabled
get_logger().info(f"Auto feedback is disabled, skipping auto commands for PR {api_url=}")
return
if data.get("event", "") == "pullrequest:created": if data.get("event", "") == "pullrequest:created":
if not should_process_pr_logic(data): if not should_process_pr_logic(data):
return return

View File

@ -72,6 +72,11 @@ async def handle_webhook(background_tasks: BackgroundTasks, request: Request):
commands_to_run = [] commands_to_run = []
if data["eventKey"] == "pr:opened": if data["eventKey"] == "pr:opened":
apply_repo_settings(pr_url)
if get_settings().config.disable_auto_feedback: # auto commands for PR, and auto feedback is disabled
get_logger().info(f"Auto feedback is disabled, skipping auto commands for PR {pr_url}", **log_context)
return
get_settings().set("config.is_auto_command", True)
commands_to_run.extend(_get_commands_list_from_settings('BITBUCKET_SERVER.PR_COMMANDS')) commands_to_run.extend(_get_commands_list_from_settings('BITBUCKET_SERVER.PR_COMMANDS'))
elif data["eventKey"] == "pr:comment:added": elif data["eventKey"] == "pr:comment:added":
commands_to_run.append(data["comment"]["text"]) commands_to_run.append(data["comment"]["text"])

View File

@ -374,6 +374,9 @@ def _check_pull_request_event(action: str, body: dict, log_context: dict) -> Tup
async def _perform_auto_commands_github(commands_conf: str, agent: PRAgent, body: dict, api_url: str, async def _perform_auto_commands_github(commands_conf: str, agent: PRAgent, body: dict, api_url: str,
log_context: dict): log_context: dict):
apply_repo_settings(api_url) apply_repo_settings(api_url)
if commands_conf == "pr_commands" and get_settings().config.disable_auto_feedback: # auto commands for PR, and auto feedback is disabled
get_logger().info(f"Auto feedback is disabled, skipping auto commands for PR {api_url=}")
return
if not should_process_pr_logic(body): # Here we already updated the configuration with the repo settings if not should_process_pr_logic(body): # Here we already updated the configuration with the repo settings
return {} return {}
commands = get_settings().get(f"github_app.{commands_conf}") commands = get_settings().get(f"github_app.{commands_conf}")

View File

@ -61,6 +61,9 @@ async def handle_request(api_url: str, body: str, log_context: dict, sender_id:
async def _perform_commands_gitlab(commands_conf: str, agent: PRAgent, api_url: str, async def _perform_commands_gitlab(commands_conf: str, agent: PRAgent, api_url: str,
log_context: dict, data: dict): log_context: dict, data: dict):
apply_repo_settings(api_url) apply_repo_settings(api_url)
if commands_conf == "pr_commands" and get_settings().config.disable_auto_feedback: # auto commands for PR, and auto feedback is disabled
get_logger().info(f"Auto feedback is disabled, skipping auto commands for PR {api_url=}", **log_context)
return
if not should_process_pr_logic(data): # Here we already updated the configurations if not should_process_pr_logic(data): # Here we already updated the configurations
return return
commands = get_settings().get(f"gitlab.{commands_conf}", {}) commands = get_settings().get(f"gitlab.{commands_conf}", {})

View File

@ -14,6 +14,7 @@ use_extra_bad_extensions=false
use_wiki_settings_file=true use_wiki_settings_file=true
use_repo_settings_file=true use_repo_settings_file=true
use_global_settings_file=true use_global_settings_file=true
disable_auto_feedback = false
ai_timeout=120 # 2minutes ai_timeout=120 # 2minutes
skip_keys = [] skip_keys = []
# token limits # token limits