This commit is contained in:
mrT23
2023-07-21 22:12:51 +03:00
parent 74572e1768
commit f5e2838fc3

View File

@ -11,7 +11,8 @@ from pr_agent.tools.pr_reviewer import PRReviewer
def run(args=None): def run(args=None):
parser = argparse.ArgumentParser(description='AI based pull request analyzer', usage="""\ parser = argparse.ArgumentParser(description='AI based pull request analyzer', usage=
"""\
Usage: cli.py --pr-url <URL on supported git hosting service> <command> [<args>]. Usage: cli.py --pr-url <URL on supported git hosting service> <command> [<args>].
For example: For example:
- cli.py --pr-url=... review - cli.py --pr-url=... review
@ -33,43 +34,68 @@ reflect - Ask the PR author questions about the PR.
'describe', 'describe_pr', 'describe', 'describe_pr',
'improve', 'improve_code', 'improve', 'improve_code',
'reflect', 'review_after_reflect'], 'reflect', 'review_after_reflect'],
default='review') default='review')
parser.add_argument('rest', nargs=argparse.REMAINDER, default=[]) parser.add_argument('rest', nargs=argparse.REMAINDER, default=[])
args = parser.parse_args(args) args = parser.parse_args(args)
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO")) logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
command = args.command.lower() command = args.command.lower()
if command in ['ask', 'ask_question']: commands = {
if len(args.rest) == 0: 'ask': _handle_ask_command,
print("Please specify a question") 'ask_question': _handle_ask_command,
parser.print_help() 'describe': _handle_describe_command,
return 'describe_pr': _handle_describe_command,
print(f"Question: {' '.join(args.rest)} about PR {args.pr_url}") 'improve': _handle_improve_command,
reviewer = PRQuestions(args.pr_url, args.rest) 'improve_code': _handle_improve_command,
asyncio.run(reviewer.answer()) 'review': _handle_review_command,
elif command in ['describe', 'describe_pr']: 'review_pr': _handle_review_command,
print(f"PR description: {args.pr_url}") 'reflect': _handle_reflect_command,
reviewer = PRDescription(args.pr_url) 'review_after_reflect': _handle_review_after_reflect_command
asyncio.run(reviewer.describe()) }
elif command in ['improve', 'improve_code']: if command in commands:
print(f"PR code suggestions: {args.pr_url}") commands[command](args.pr_url, args.rest)
reviewer = PRCodeSuggestions(args.pr_url)
asyncio.run(reviewer.suggest())
elif command in ['review', 'review_pr']:
print(f"Reviewing PR: {args.pr_url}")
reviewer = PRReviewer(args.pr_url, cli_mode=True, args=args.rest)
asyncio.run(reviewer.review())
elif command in ['reflect']:
print(f"Asking the PR author questions: {args.pr_url}")
reviewer = PRInformationFromUser(args.pr_url)
asyncio.run(reviewer.generate_questions())
elif command in ['review_after_reflect']:
print(f"Processing author's answers and sending review: {args.pr_url}")
reviewer = PRReviewer(args.pr_url, cli_mode=True, is_answer=True)
asyncio.run(reviewer.review())
else: else:
print(f"Unknown command: {command}") print(f"Unknown command: {command}")
parser.print_help() parser.print_help()
def _handle_ask_command(pr_url: str, rest: list):
if len(rest) == 0:
print("Please specify a question")
return
print(f"Question: {' '.join(rest)} about PR {pr_url}")
reviewer = PRQuestions(pr_url, rest)
asyncio.run(reviewer.answer())
def _handle_describe_command(pr_url: str, rest: list):
print(f"PR description: {pr_url}")
reviewer = PRDescription(pr_url)
asyncio.run(reviewer.describe())
def _handle_improve_command(pr_url: str, rest: list):
print(f"PR code suggestions: {pr_url}")
reviewer = PRCodeSuggestions(pr_url)
asyncio.run(reviewer.suggest())
def _handle_review_command(pr_url: str, rest: list):
print(f"Reviewing PR: {pr_url}")
reviewer = PRReviewer(pr_url, cli_mode=True, args=rest)
asyncio.run(reviewer.review())
def _handle_reflect_command(pr_url: str, rest: list):
print(f"Asking the PR author questions: {pr_url}")
reviewer = PRInformationFromUser(pr_url)
asyncio.run(reviewer.generate_questions())
def _handle_review_after_reflect_command(pr_url: str, rest: list):
print(f"Processing author's answers and sending review: {pr_url}")
reviewer = PRReviewer(pr_url, cli_mode=True, is_answer=True)
asyncio.run(reviewer.review())
if __name__ == '__main__': if __name__ == '__main__':
run() run()