mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-02 03:40:38 +08:00
feat: integrate Dynaconf for configuration management and enhance config display
This commit is contained in:
@ -1,3 +1,25 @@
|
|||||||
|
## Show possible configurations
|
||||||
|
The possible configurations of pr-agent are stored in [here](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml).
|
||||||
|
In the [tools](https://pr-agent-docs.codium.ai/tools/) page you can find explanations on how to use these configurations for each tool.
|
||||||
|
|
||||||
|
To print all the available configurations as a comment on your PR, you can use the following command:
|
||||||
|
```
|
||||||
|
/config
|
||||||
|
```
|
||||||
|
|
||||||
|
{width=512}
|
||||||
|
|
||||||
|
|
||||||
|
To view the **actual** configurations used for a specific tool, after all the user settings are applied, you can add for each tool a `--config.output_relevant_configurations=true` suffix.
|
||||||
|
For example:
|
||||||
|
```
|
||||||
|
/improve --config.output_relevant_configurations=true
|
||||||
|
```
|
||||||
|
Will output an additional field showing the actual configurations used for the `improve` tool.
|
||||||
|
|
||||||
|
{width=512}
|
||||||
|
|
||||||
|
|
||||||
## Ignoring files from analysis
|
## Ignoring files from analysis
|
||||||
|
|
||||||
In some cases, you may want to exclude specific files or directories from the analysis performed by CodiumAI PR-Agent. This can be useful, for example, when you have files that are generated automatically or files that shouldn't be reviewed, like vendored code.
|
In some cases, you may want to exclude specific files or directories from the analysis performed by CodiumAI PR-Agent. This can be useful, for example, when you have files that are generated automatically or files that shouldn't be reviewed, like vendored code.
|
||||||
|
@ -905,21 +905,24 @@ def github_action_output(output_data: dict, key_name: str):
|
|||||||
|
|
||||||
|
|
||||||
def show_relevant_configurations(relevant_section: str) -> str:
|
def show_relevant_configurations(relevant_section: str) -> str:
|
||||||
forbidden_keys = ['ai_disclaimer', 'ai_disclaimer_title', 'ANALYTICS_FOLDER', 'secret_provider',
|
skip_keys = ['ai_disclaimer', 'ai_disclaimer_title', 'ANALYTICS_FOLDER', 'secret_provider', "skip_keys",
|
||||||
'trial_prefix_message', 'no_eligible_message', 'identity_provider', 'ALLOWED_REPOS','APP_NAME']
|
'trial_prefix_message', 'no_eligible_message', 'identity_provider', 'ALLOWED_REPOS','APP_NAME']
|
||||||
|
extra_skip_keys = get_settings().config.get('config.skip_keys', [])
|
||||||
|
if extra_skip_keys:
|
||||||
|
skip_keys.extend(extra_skip_keys)
|
||||||
|
|
||||||
markdown_text = ""
|
markdown_text = ""
|
||||||
markdown_text += "\n<hr>\n<details> <summary><strong>🛠️ Relevant configurations:</strong></summary> \n\n"
|
markdown_text += "\n<hr>\n<details> <summary><strong>🛠️ Relevant configurations:</strong></summary> \n\n"
|
||||||
markdown_text +="<br>These are the relevant [configurations](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml) for this tool:\n\n"
|
markdown_text +="<br>These are the relevant [configurations](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml) for this tool:\n\n"
|
||||||
markdown_text += f"**[config**]\n```yaml\n\n"
|
markdown_text += f"**[config**]\n```yaml\n\n"
|
||||||
for key, value in get_settings().config.items():
|
for key, value in get_settings().config.items():
|
||||||
if key in forbidden_keys:
|
if key in skip_keys:
|
||||||
continue
|
continue
|
||||||
markdown_text += f"{key}: {value}\n"
|
markdown_text += f"{key}: {value}\n"
|
||||||
markdown_text += "\n```\n"
|
markdown_text += "\n```\n"
|
||||||
markdown_text += f"\n**[{relevant_section}]**\n```yaml\n\n"
|
markdown_text += f"\n**[{relevant_section}]**\n```yaml\n\n"
|
||||||
for key, value in get_settings().get(relevant_section, {}).items():
|
for key, value in get_settings().get(relevant_section, {}).items():
|
||||||
if key in forbidden_keys:
|
if key in skip_keys:
|
||||||
continue
|
continue
|
||||||
markdown_text += f"{key}: {value}\n"
|
markdown_text += f"{key}: {value}\n"
|
||||||
markdown_text += "\n```"
|
markdown_text += "\n```"
|
||||||
|
@ -14,6 +14,7 @@ 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
|
||||||
ai_timeout=120 # 2minutes
|
ai_timeout=120 # 2minutes
|
||||||
|
skip_keys = []
|
||||||
# token limits
|
# token limits
|
||||||
max_description_tokens = 500
|
max_description_tokens = 500
|
||||||
max_commits_tokens = 500
|
max_commits_tokens = 500
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from dynaconf import Dynaconf
|
||||||
|
|
||||||
from pr_agent.config_loader import get_settings
|
from pr_agent.config_loader import get_settings
|
||||||
from pr_agent.git_providers import get_git_provider
|
from pr_agent.git_providers import get_git_provider
|
||||||
from pr_agent.log import get_logger
|
from pr_agent.log import get_logger
|
||||||
@ -28,20 +30,33 @@ class PRConfig:
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
def _prepare_pr_configs(self) -> str:
|
def _prepare_pr_configs(self) -> str:
|
||||||
import tomli
|
conf_file = get_settings().find_file("configuration.toml")
|
||||||
with open(get_settings().find_file("configuration.toml"), "rb") as conf_file:
|
conf_settings = Dynaconf(settings_files=[conf_file])
|
||||||
configuration_headers = [header.lower() for header in tomli.load(conf_file).keys()]
|
configuration_headers = [header.lower() for header in conf_settings.keys()]
|
||||||
relevant_configs = {
|
relevant_configs = {
|
||||||
header: configs for header, configs in get_settings().to_dict().items()
|
header: configs for header, configs in get_settings().to_dict().items()
|
||||||
if header.lower().startswith("pr_") and header.lower() in configuration_headers
|
if (header.lower().startswith("pr_") or header.lower().startswith("config")) and header.lower() in configuration_headers
|
||||||
}
|
}
|
||||||
comment_str = "Possible Configurations:"
|
|
||||||
|
skip_keys = ['ai_disclaimer', 'ai_disclaimer_title', 'ANALYTICS_FOLDER', 'secret_provider', "skip_keys",
|
||||||
|
'trial_prefix_message', 'no_eligible_message', 'identity_provider', 'ALLOWED_REPOS',
|
||||||
|
'APP_NAME']
|
||||||
|
extra_skip_keys = get_settings().config.get('config.skip_keys', [])
|
||||||
|
if extra_skip_keys:
|
||||||
|
skip_keys.extend(extra_skip_keys)
|
||||||
|
|
||||||
|
markdown_text = "<details> <summary><strong>🛠️ PR-Agent Configurations:</strong></summary> \n\n"
|
||||||
|
markdown_text += f"\n\n```yaml\n\n"
|
||||||
for header, configs in relevant_configs.items():
|
for header, configs in relevant_configs.items():
|
||||||
if configs:
|
if configs:
|
||||||
comment_str += "\n"
|
markdown_text += "\n\n"
|
||||||
|
markdown_text += f"==================== {header} ===================="
|
||||||
for key, value in configs.items():
|
for key, value in configs.items():
|
||||||
comment_str += f"\n{header.lower()}.{key.lower()} = {repr(value) if isinstance(value, str) else value}"
|
if key in skip_keys:
|
||||||
comment_str += " "
|
continue
|
||||||
if get_settings().config.verbosity_level >= 2:
|
markdown_text += f"\n{header.lower()}.{key.lower()} = {repr(value) if isinstance(value, str) else value}"
|
||||||
get_logger().info(f"comment_str:\n{comment_str}")
|
markdown_text += " "
|
||||||
return comment_str
|
markdown_text += "\n```"
|
||||||
|
markdown_text += "\n</details>\n"
|
||||||
|
get_logger().info(f"Possible Configurations outputted to PR comment", artifact=markdown_text)
|
||||||
|
return markdown_text
|
||||||
|
Reference in New Issue
Block a user