From 9e5e9afe9216482f4581cb66c5234909b75477bc Mon Sep 17 00:00:00 2001 From: Ori Kotek Date: Sun, 12 Nov 2023 16:11:34 +0200 Subject: [PATCH] Refactor CLI argument handling and request processing --- pr_agent/agent/pr_agent.py | 11 +++++++---- pr_agent/cli.py | 13 ++----------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/pr_agent/agent/pr_agent.py b/pr_agent/agent/pr_agent.py index 6e76c5e0..5608c50a 100644 --- a/pr_agent/agent/pr_agent.py +++ b/pr_agent/agent/pr_agent.py @@ -46,10 +46,13 @@ class PRAgent: apply_repo_settings(pr_url) # Then, apply user specific settings if exists - request = request.replace("'", "\\'") - lexer = shlex.shlex(request, posix=True) - lexer.whitespace_split = True - action, *args = list(lexer) + if isinstance(request, str): + request = request.replace("'", "\\'") + lexer = shlex.shlex(request, posix=True) + lexer.whitespace_split = True + action, *args = list(lexer) + else: + action, *args = request args = update_settings_from_args(args) action = action.lstrip("/").lower() diff --git a/pr_agent/cli.py b/pr_agent/cli.py index 5a8aad7f..91d4889c 100644 --- a/pr_agent/cli.py +++ b/pr_agent/cli.py @@ -9,14 +9,6 @@ from pr_agent.log import setup_logger setup_logger() -def handle_args_with_quotes(args): - if args.rest: - for i, r in enumerate(args.rest): - if r.startswith("--") and r.count("=") == 1 and " " in r: - r_split = r.split("=") - args.rest[i] = r_split[0] + "=" + '"' + r_split[1] + '"' - return args - def run(inargs=None): parser = argparse.ArgumentParser(description='AI based pull request analyzer', usage= @@ -54,7 +46,6 @@ For example: 'python cli.py --pr_url=... review --pr_reviewer.extra_instructions parser.add_argument('command', type=str, help='The', choices=commands, default='review') parser.add_argument('rest', nargs=argparse.REMAINDER, default=[]) args = parser.parse_args(inargs) - args = handle_args_with_quotes(args) if not args.pr_url and not args.issue_url: parser.print_help() return @@ -62,9 +53,9 @@ For example: 'python cli.py --pr_url=... review --pr_reviewer.extra_instructions command = args.command.lower() get_settings().set("CONFIG.CLI_MODE", True) if args.issue_url: - result = asyncio.run(PRAgent().handle_request(args.issue_url, command + " " + " ".join(args.rest))) + result = asyncio.run(PRAgent().handle_request(args.issue_url, [command] + args.rest)) else: - result = asyncio.run(PRAgent().handle_request(args.pr_url, command + " " + " ".join(args.rest))) + result = asyncio.run(PRAgent().handle_request(args.pr_url, [command] + args.rest)) if not result: parser.print_help()