From 9b19935f471c0f861f6fd122f8d061f2c04666a2 Mon Sep 17 00:00:00 2001 From: "seokcheon.ju" Date: Fri, 13 Jun 2025 19:42:14 +0900 Subject: [PATCH 1/4] Add language-specific instructions to extra instructions based on user settings --- pr_agent/git_providers/utils.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pr_agent/git_providers/utils.py b/pr_agent/git_providers/utils.py index 0cfbe116..75f058a8 100644 --- a/pr_agent/git_providers/utils.py +++ b/pr_agent/git_providers/utils.py @@ -3,6 +3,7 @@ import os import tempfile from dynaconf import Dynaconf +from dynaconf.utils.boxing import DynaBox from starlette_context import context from pr_agent.config_loader import get_settings @@ -62,6 +63,28 @@ def apply_repo_settings(pr_url): if get_settings().config.model.lower() == 'claude-3-5-sonnet': set_claude_model() + # Append the response language in the extra instructions + response_language = get_settings().config.get('response_language', 'en-us') + if response_language.lower() != 'en-us': + get_logger().info(f'User has set the response language to: {response_language}') + + lang_instruction_text = f"Your response MUST be written in the language corresponding to locale code: '{response_language}'. This is crucial." + separator_text = "\n======\n\nIn addition, " + + for key in get_settings(): + setting = get_settings().get(key) + if isinstance(setting, DynaBox): + if key.lower() in ['pr_description', 'pr_code_suggestions', 'pr_reviewer']: + if hasattr(setting, 'extra_instructions'): + extra_instructions = setting.extra_instructions + + if lang_instruction_text not in str(extra_instructions): + updated_instructions = ( + str(extra_instructions) + separator_text + lang_instruction_text + if extra_instructions else lang_instruction_text + ) + setting.extra_instructions = updated_instructions + def handle_configurations_errors(config_errors, git_provider): try: From 5d721376fe59e6c11581e42329dbeb08381754b5 Mon Sep 17 00:00:00 2001 From: "seokcheon.ju" Date: Mon, 16 Jun 2025 10:53:38 +0900 Subject: [PATCH 2/4] Move language-specific instructions to github_action_runner.py --- pr_agent/git_providers/utils.py | 23 ----------------- pr_agent/servers/github_action_runner.py | 32 +++++++++++++++++++++--- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/pr_agent/git_providers/utils.py b/pr_agent/git_providers/utils.py index 75f058a8..0cfbe116 100644 --- a/pr_agent/git_providers/utils.py +++ b/pr_agent/git_providers/utils.py @@ -3,7 +3,6 @@ import os import tempfile from dynaconf import Dynaconf -from dynaconf.utils.boxing import DynaBox from starlette_context import context from pr_agent.config_loader import get_settings @@ -63,28 +62,6 @@ def apply_repo_settings(pr_url): if get_settings().config.model.lower() == 'claude-3-5-sonnet': set_claude_model() - # Append the response language in the extra instructions - response_language = get_settings().config.get('response_language', 'en-us') - if response_language.lower() != 'en-us': - get_logger().info(f'User has set the response language to: {response_language}') - - lang_instruction_text = f"Your response MUST be written in the language corresponding to locale code: '{response_language}'. This is crucial." - separator_text = "\n======\n\nIn addition, " - - for key in get_settings(): - setting = get_settings().get(key) - if isinstance(setting, DynaBox): - if key.lower() in ['pr_description', 'pr_code_suggestions', 'pr_reviewer']: - if hasattr(setting, 'extra_instructions'): - extra_instructions = setting.extra_instructions - - if lang_instruction_text not in str(extra_instructions): - updated_instructions = ( - str(extra_instructions) + separator_text + lang_instruction_text - if extra_instructions else lang_instruction_text - ) - setting.extra_instructions = updated_instructions - def handle_configurations_errors(config_errors, git_provider): try: diff --git a/pr_agent/servers/github_action_runner.py b/pr_agent/servers/github_action_runner.py index bcb5effa..9d6b6ee7 100644 --- a/pr_agent/servers/github_action_runner.py +++ b/pr_agent/servers/github_action_runner.py @@ -3,6 +3,8 @@ import json import os from typing import Union +from dynaconf.utils import DynaBox + from pr_agent.agent.pr_agent import PRAgent from pr_agent.config_loader import get_settings from pr_agent.git_providers import get_git_provider @@ -80,12 +82,35 @@ async def run_action(): except Exception as e: get_logger().info(f"github action: failed to apply repo settings: {e}") + # Append the response language in the extra instructions + response_language = get_settings().config.get('response_language', 'en-us') + if response_language.lower() != 'en-us': + get_logger().info(f'User has set the response language to: {response_language}') + + lang_instruction_text = f"Your response MUST be written in the language corresponding to locale code: '{response_language}'. This is crucial." + separator_text = "\n======\n\nIn addition, " + + for key in get_settings(): + setting = get_settings().get(key) + if isinstance(setting, DynaBox): + if key.lower() in ['pr_description', 'pr_code_suggestions', 'pr_reviewer']: + if hasattr(setting, 'extra_instructions'): + extra_instructions = setting.extra_instructions + + if lang_instruction_text not in str(extra_instructions): + updated_instructions = ( + str(extra_instructions) + separator_text + lang_instruction_text + if extra_instructions else lang_instruction_text + ) + setting.extra_instructions = updated_instructions + # Handle pull request opened event if GITHUB_EVENT_NAME == "pull_request" or GITHUB_EVENT_NAME == "pull_request_target": action = event_payload.get("action") # Retrieve the list of actions from the configuration - pr_actions = get_settings().get("GITHUB_ACTION_CONFIG.PR_ACTIONS", ["opened", "reopened", "ready_for_review", "review_requested"]) + pr_actions = get_settings().get("GITHUB_ACTION_CONFIG.PR_ACTIONS", + ["opened", "reopened", "ready_for_review", "review_requested"]) if action in pr_actions: pr_url = event_payload.get("pull_request", {}).get("url") @@ -102,9 +127,10 @@ async def run_action(): auto_improve = get_setting_or_env("GITHUB_ACTION_CONFIG.AUTO_IMPROVE", None) # Set the configuration for auto actions - get_settings().config.is_auto_command = True # Set the flag to indicate that the command is auto + get_settings().config.is_auto_command = True # Set the flag to indicate that the command is auto get_settings().pr_description.final_update_message = False # No final update message when auto_describe is enabled - get_logger().info(f"Running auto actions: auto_describe={auto_describe}, auto_review={auto_review}, auto_improve={auto_improve}") + get_logger().info( + f"Running auto actions: auto_describe={auto_describe}, auto_review={auto_review}, auto_improve={auto_improve}") # invoke by default all three tools if auto_describe is None or is_true(auto_describe): From f39e0a13f43617bd90fc176885d8929d80d3eca8 Mon Sep 17 00:00:00 2001 From: "seokcheon.ju" Date: Mon, 16 Jun 2025 10:56:24 +0900 Subject: [PATCH 3/4] Revert linted line breaks --- pr_agent/servers/github_action_runner.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pr_agent/servers/github_action_runner.py b/pr_agent/servers/github_action_runner.py index 9d6b6ee7..014268f2 100644 --- a/pr_agent/servers/github_action_runner.py +++ b/pr_agent/servers/github_action_runner.py @@ -109,8 +109,7 @@ async def run_action(): action = event_payload.get("action") # Retrieve the list of actions from the configuration - pr_actions = get_settings().get("GITHUB_ACTION_CONFIG.PR_ACTIONS", - ["opened", "reopened", "ready_for_review", "review_requested"]) + pr_actions = get_settings().get("GITHUB_ACTION_CONFIG.PR_ACTIONS", ["opened", "reopened", "ready_for_review", "review_requested"]) if action in pr_actions: pr_url = event_payload.get("pull_request", {}).get("url") @@ -129,8 +128,7 @@ async def run_action(): # Set the configuration for auto actions get_settings().config.is_auto_command = True # Set the flag to indicate that the command is auto get_settings().pr_description.final_update_message = False # No final update message when auto_describe is enabled - get_logger().info( - f"Running auto actions: auto_describe={auto_describe}, auto_review={auto_review}, auto_improve={auto_improve}") + get_logger().info(f"Running auto actions: auto_describe={auto_describe}, auto_review={auto_review}, auto_improve={auto_improve}") # invoke by default all three tools if auto_describe is None or is_true(auto_describe): From d4e8f618cef730f45246011a00351a759da6e246 Mon Sep 17 00:00:00 2001 From: Tal Date: Tue, 17 Jun 2025 08:34:07 +0300 Subject: [PATCH 4/4] Update pr_agent/servers/github_action_runner.py Co-authored-by: qodo-merge-for-open-source[bot] <189517486+qodo-merge-for-open-source[bot]@users.noreply.github.com> --- pr_agent/servers/github_action_runner.py | 38 +++++++++++++----------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/pr_agent/servers/github_action_runner.py b/pr_agent/servers/github_action_runner.py index 014268f2..45a9bc93 100644 --- a/pr_agent/servers/github_action_runner.py +++ b/pr_agent/servers/github_action_runner.py @@ -83,27 +83,29 @@ async def run_action(): get_logger().info(f"github action: failed to apply repo settings: {e}") # Append the response language in the extra instructions - response_language = get_settings().config.get('response_language', 'en-us') - if response_language.lower() != 'en-us': - get_logger().info(f'User has set the response language to: {response_language}') + try: + response_language = get_settings().config.get('response_language', 'en-us') + if response_language.lower() != 'en-us': + get_logger().info(f'User has set the response language to: {response_language}') - lang_instruction_text = f"Your response MUST be written in the language corresponding to locale code: '{response_language}'. This is crucial." - separator_text = "\n======\n\nIn addition, " + lang_instruction_text = f"Your response MUST be written in the language corresponding to locale code: '{response_language}'. This is crucial." + separator_text = "\n======\n\nIn addition, " - for key in get_settings(): - setting = get_settings().get(key) - if isinstance(setting, DynaBox): - if key.lower() in ['pr_description', 'pr_code_suggestions', 'pr_reviewer']: - if hasattr(setting, 'extra_instructions'): - extra_instructions = setting.extra_instructions - - if lang_instruction_text not in str(extra_instructions): - updated_instructions = ( - str(extra_instructions) + separator_text + lang_instruction_text - if extra_instructions else lang_instruction_text - ) - setting.extra_instructions = updated_instructions + for key in get_settings(): + setting = get_settings().get(key) + if isinstance(setting, DynaBox): + if key.lower() in ['pr_description', 'pr_code_suggestions', 'pr_reviewer']: + if hasattr(setting, 'extra_instructions'): + extra_instructions = setting.extra_instructions + if lang_instruction_text not in str(extra_instructions): + updated_instructions = ( + str(extra_instructions) + separator_text + lang_instruction_text + if extra_instructions else lang_instruction_text + ) + setting.extra_instructions = updated_instructions + except Exception as e: + get_logger().info(f"github action: failed to apply language-specific instructions: {e}") # Handle pull request opened event if GITHUB_EVENT_NAME == "pull_request" or GITHUB_EVENT_NAME == "pull_request_target": action = event_payload.get("action")