Skip to content

Commit 89819b3

Browse files
authored
Merge pull request #910 from Codium-ai/tr/show_config
Tr/show config
2 parents f9af9e4 + 3432d37 commit 89819b3

File tree

7 files changed

+49
-6
lines changed

7 files changed

+49
-6
lines changed

docs/docs/usage-guide/configuration_options.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ There are three ways to set persistent configurations:
1111

1212
In terms of precedence, wiki configurations will override local configurations, and local configurations will override global configurations.
1313

14-
!!! tip "Tip: edit only what you need"
14+
!!! tip "Tip1: edit only what you need"
1515
Your configuration file should be minimal, and edit only the relevant values. Don't copy the entire configuration options, since it can lead to legacy problems when something changes.
16+
!!! tip "Tip2: show relevant configurations"
17+
If you set `config.output_relevant_configurations=true`, each tool will also output in a collapsible section its relevant configurations. This can be useful for debugging, or getting to know the configurations better.
1618

1719
## Wiki configuration file 💎
1820

pr_agent/algo/utils.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,4 +673,26 @@ def github_action_output(output_data: dict, key_name: str):
673673
print(f"{key_name}={json.dumps(key_data, indent=None, ensure_ascii=False)}", file=fh)
674674
except Exception as e:
675675
get_logger().error(f"Failed to write to GitHub Action output: {e}")
676-
return
676+
return
677+
678+
679+
def show_relevant_configurations(relevant_section: str) -> str:
680+
forbidden_keys = ['ai_disclaimer', 'ai_disclaimer_title', 'ANALYTICS_FOLDER', 'secret_provider']
681+
682+
markdown_text = ""
683+
markdown_text += "\n<hr>\n<details> <summary><strong>🛠️ Relevant configurations:</strong></summary> \n\n"
684+
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"
685+
markdown_text += f"**[config**]\n```yaml\n\n"
686+
for key, value in get_settings().config.items():
687+
if key in forbidden_keys:
688+
continue
689+
markdown_text += f"{key}: {value}\n"
690+
markdown_text += "\n```\n"
691+
markdown_text += f"\n**[{relevant_section}]**\n```yaml\n\n"
692+
for key, value in get_settings().get(relevant_section, {}).items():
693+
if key in forbidden_keys:
694+
continue
695+
markdown_text += f"{key}: {value}\n"
696+
markdown_text += "\n```"
697+
markdown_text += "\n</details>\n"
698+
return markdown_text

pr_agent/settings/configuration.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ secret_provider="google_cloud_storage"
1919
cli_mode=false
2020
ai_disclaimer_title="" # Pro feature, title for a collapsible disclaimer to AI outputs
2121
ai_disclaimer="" # Pro feature, full text for the AI disclaimer
22+
output_relevant_configurations=false
2223

2324
[pr_reviewer] # /review #
2425
# enable/disable features

pr_agent/tools/pr_code_suggestions.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pr_agent.algo.ai_handlers.litellm_ai_handler import LiteLLMAIHandler
1010
from pr_agent.algo.pr_processing import get_pr_diff, get_pr_multi_diffs, retry_with_fallback_models
1111
from pr_agent.algo.token_handler import TokenHandler
12-
from pr_agent.algo.utils import load_yaml, replace_code_tags, ModelType
12+
from pr_agent.algo.utils import load_yaml, replace_code_tags, ModelType, show_relevant_configurations
1313
from pr_agent.config_loader import get_settings
1414
from pr_agent.git_providers import get_git_provider
1515
from pr_agent.git_providers.git_provider import get_main_pr_language
@@ -118,6 +118,10 @@ async def run(self):
118118
pr_body += HelpMessage.get_improve_usage_guide()
119119
pr_body += "\n</details>\n"
120120

121+
# Output the relevant configurations if enabled
122+
if get_settings().get('config', {}).get('output_relevant_configurations', False):
123+
pr_body += show_relevant_configurations(relevant_section='pr_code_suggestions')
124+
121125
if get_settings().pr_code_suggestions.persistent_comment:
122126
final_update_message = False
123127
self.git_provider.publish_persistent_comment(pr_body,

pr_agent/tools/pr_description.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pr_agent.algo.ai_handlers.litellm_ai_handler import LiteLLMAIHandler
1010
from pr_agent.algo.pr_processing import get_pr_diff, retry_with_fallback_models
1111
from pr_agent.algo.token_handler import TokenHandler
12-
from pr_agent.algo.utils import load_yaml, set_custom_labels, get_user_labels, ModelType
12+
from pr_agent.algo.utils import load_yaml, set_custom_labels, get_user_labels, ModelType, show_relevant_configurations
1313
from pr_agent.config_loader import get_settings
1414
from pr_agent.git_providers import get_git_provider
1515
from pr_agent.git_providers.git_provider import get_main_pr_language
@@ -116,6 +116,10 @@ async def run(self):
116116
pr_body += "\n\n___\n\n> 💡 **PR-Agent usage**:"
117117
pr_body += "\n>Comment `/help` on the PR to get a list of all available PR-Agent tools and their descriptions\n\n"
118118

119+
# Output the relevant configurations if enabled
120+
if get_settings().get('config', {}).get('output_relevant_configurations', False):
121+
pr_body += show_relevant_configurations(relevant_section='pr_description')
122+
119123
if get_settings().config.publish_output:
120124
# publish labels
121125
if get_settings().pr_description.publish_labels and self.git_provider.is_supported("get_labels"):

pr_agent/tools/pr_reviewer.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
from pr_agent.algo.ai_handlers.litellm_ai_handler import LiteLLMAIHandler
99
from pr_agent.algo.pr_processing import get_pr_diff, retry_with_fallback_models
1010
from pr_agent.algo.token_handler import TokenHandler
11-
from pr_agent.algo.utils import convert_to_markdown, github_action_output, load_yaml, ModelType
11+
from pr_agent.algo.utils import convert_to_markdown, github_action_output, load_yaml, ModelType, \
12+
show_relevant_configurations
1213
from pr_agent.config_loader import get_settings
1314
from pr_agent.git_providers import get_git_provider
1415
from pr_agent.git_providers.git_provider import IncrementalPR, get_main_pr_language
@@ -238,6 +239,10 @@ def _prepare_pr_review(self) -> str:
238239
markdown_text += HelpMessage.get_review_usage_guide()
239240
markdown_text += "\n</details>\n"
240241

242+
# Output the relevant configurations if enabled
243+
if get_settings().get('config', {}).get('output_relevant_configurations', False):
244+
markdown_text += show_relevant_configurations(relevant_section='pr_reviewer')
245+
241246
# Add custom labels from the review prediction (effort, security)
242247
self.set_review_labels(data)
243248

pr_agent/tools/pr_update_changelog.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pr_agent.algo.ai_handlers.litellm_ai_handler import LiteLLMAIHandler
99
from pr_agent.algo.pr_processing import get_pr_diff, retry_with_fallback_models
1010
from pr_agent.algo.token_handler import TokenHandler
11-
from pr_agent.algo.utils import ModelType
11+
from pr_agent.algo.utils import ModelType, show_relevant_configurations
1212
from pr_agent.config_loader import get_settings
1313
from pr_agent.git_providers import get_git_provider, GithubProvider
1414
from pr_agent.git_providers.git_provider import get_main_pr_language
@@ -74,6 +74,11 @@ async def run(self):
7474
await retry_with_fallback_models(self._prepare_prediction, model_type=ModelType.TURBO)
7575

7676
new_file_content, answer = self._prepare_changelog_update()
77+
78+
# Output the relevant configurations if enabled
79+
if get_settings().get('config', {}).get('output_relevant_configurations', False):
80+
answer += show_relevant_configurations(relevant_section='pr_update_changelog')
81+
7782
get_logger().debug(f"PR output", artifact=answer)
7883

7984
if get_settings().config.publish_output:

0 commit comments

Comments
 (0)