mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-04 21:00:40 +08:00
Refactor CLI argument handling and request processing
This commit is contained in:
@ -46,10 +46,13 @@ class PRAgent:
|
|||||||
apply_repo_settings(pr_url)
|
apply_repo_settings(pr_url)
|
||||||
|
|
||||||
# Then, apply user specific settings if exists
|
# Then, apply user specific settings if exists
|
||||||
|
if isinstance(request, str):
|
||||||
request = request.replace("'", "\\'")
|
request = request.replace("'", "\\'")
|
||||||
lexer = shlex.shlex(request, posix=True)
|
lexer = shlex.shlex(request, posix=True)
|
||||||
lexer.whitespace_split = True
|
lexer.whitespace_split = True
|
||||||
action, *args = list(lexer)
|
action, *args = list(lexer)
|
||||||
|
else:
|
||||||
|
action, *args = request
|
||||||
args = update_settings_from_args(args)
|
args = update_settings_from_args(args)
|
||||||
|
|
||||||
action = action.lstrip("/").lower()
|
action = action.lstrip("/").lower()
|
||||||
|
@ -9,14 +9,6 @@ from pr_agent.log import setup_logger
|
|||||||
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):
|
def run(inargs=None):
|
||||||
parser = argparse.ArgumentParser(description='AI based pull request analyzer', usage=
|
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('command', type=str, help='The', choices=commands, default='review')
|
||||||
parser.add_argument('rest', nargs=argparse.REMAINDER, default=[])
|
parser.add_argument('rest', nargs=argparse.REMAINDER, default=[])
|
||||||
args = parser.parse_args(inargs)
|
args = parser.parse_args(inargs)
|
||||||
args = handle_args_with_quotes(args)
|
|
||||||
if not args.pr_url and not args.issue_url:
|
if not args.pr_url and not args.issue_url:
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
return
|
return
|
||||||
@ -62,9 +53,9 @@ For example: 'python cli.py --pr_url=... review --pr_reviewer.extra_instructions
|
|||||||
command = args.command.lower()
|
command = args.command.lower()
|
||||||
get_settings().set("CONFIG.CLI_MODE", True)
|
get_settings().set("CONFIG.CLI_MODE", True)
|
||||||
if args.issue_url:
|
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:
|
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:
|
if not result:
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user