mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-05 05:10:38 +08:00
Safe parse key value in config override
This commit is contained in:
@ -245,14 +245,12 @@ def update_settings_from_args(args: List[str]) -> List[str]:
|
|||||||
arg = arg.strip()
|
arg = arg.strip()
|
||||||
if arg.startswith('--'):
|
if arg.startswith('--'):
|
||||||
arg = arg.strip('-').strip()
|
arg = arg.strip('-').strip()
|
||||||
vals = arg.split('=')
|
vals = arg.split('=', 1)
|
||||||
if len(vals) != 2:
|
if len(vals) != 2:
|
||||||
logging.error(f'Invalid argument format: {arg}')
|
logging.error(f'Invalid argument format: {arg}')
|
||||||
other_args.append(arg)
|
other_args.append(arg)
|
||||||
continue
|
continue
|
||||||
key, value = vals
|
key, value = _fix_key_value(*vals)
|
||||||
key = key.strip().upper()
|
|
||||||
value = value.strip()
|
|
||||||
get_settings().set(key, value)
|
get_settings().set(key, value)
|
||||||
logging.info(f'Updated setting {key} to: "{value}"')
|
logging.info(f'Updated setting {key} to: "{value}"')
|
||||||
else:
|
else:
|
||||||
@ -260,6 +258,16 @@ def update_settings_from_args(args: List[str]) -> List[str]:
|
|||||||
return other_args
|
return other_args
|
||||||
|
|
||||||
|
|
||||||
|
def _fix_key_value(key: str, value: str):
|
||||||
|
key = key.strip().upper()
|
||||||
|
value = value.strip()
|
||||||
|
try:
|
||||||
|
value = yaml.safe_load(value)
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"Failed to parse YAML for config override {key}={value}", exc_info=e)
|
||||||
|
return key, value
|
||||||
|
|
||||||
|
|
||||||
def load_yaml(review_text: str) -> dict:
|
def load_yaml(review_text: str) -> dict:
|
||||||
review_text = review_text.removeprefix('```yaml').rstrip('`')
|
review_text = review_text.removeprefix('```yaml').rstrip('`')
|
||||||
try:
|
try:
|
||||||
|
Reference in New Issue
Block a user