Skip to content

Commit

Permalink
Safe parse key value in config override
Browse files Browse the repository at this point in the history
  • Loading branch information
zmeir committed Aug 20, 2023
1 parent 532dfd2 commit c6f8d98
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions pr_agent/algo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,21 +245,29 @@ def update_settings_from_args(args: List[str]) -> List[str]:
arg = arg.strip()
if arg.startswith('--'):
arg = arg.strip('-').strip()
vals = arg.split('=')
vals = arg.split('=', 1)
if len(vals) != 2:
logging.error(f'Invalid argument format: {arg}')
other_args.append(arg)
continue
key, value = vals
key = key.strip().upper()
value = value.strip()
key, value = _fix_key_value(*vals)
get_settings().set(key, value)
logging.info(f'Updated setting {key} to: "{value}"')
else:
other_args.append(arg)
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:
review_text = review_text.removeprefix('```yaml').rstrip('`')
try:
Expand Down

0 comments on commit c6f8d98

Please sign in to comment.