2023-07-06 11:37:44 +03:00
|
|
|
import argparse
|
|
|
|
import asyncio
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
|
2023-07-15 09:30:50 +03:00
|
|
|
from pr_agent.tools.pr_code_suggestions import PRCodeSuggestions
|
2023-07-13 17:24:56 +03:00
|
|
|
from pr_agent.tools.pr_description import PRDescription
|
2023-07-06 11:37:44 +03:00
|
|
|
from pr_agent.tools.pr_questions import PRQuestions
|
|
|
|
from pr_agent.tools.pr_reviewer import PRReviewer
|
|
|
|
|
|
|
|
|
|
|
|
def run():
|
2023-07-16 13:18:29 +03:00
|
|
|
parser = argparse.ArgumentParser(description='AI based pull request analyzer', usage="""\
|
|
|
|
Usage: cli.py --pr-url <URL on supported git hosting service> <command> [<args>].
|
|
|
|
|
|
|
|
Supported commands:
|
|
|
|
review / review_pr - Add a review that includes a summary of the PR and specific suggestions for improvement.
|
|
|
|
ask / ask_question [question] - Ask a question about the PR.
|
|
|
|
describe / describe_pr - Modify the PR title and description based on the PR's contents.
|
|
|
|
improve / improve_code - Suggest improvements to the code in the PR as pull request comments ready to commit.
|
|
|
|
""")
|
2023-07-06 11:37:44 +03:00
|
|
|
parser.add_argument('--pr_url', type=str, help='The URL of the PR to review', required=True)
|
2023-07-16 13:18:29 +03:00
|
|
|
parser.add_argument('command', type=str, help='The', choices=['review', 'review_pr',
|
|
|
|
'ask', 'ask_question',
|
|
|
|
'describe', 'describe_pr',
|
|
|
|
'improve', 'improve_code'], default='review')
|
|
|
|
parser.add_argument('rest', nargs=argparse.REMAINDER, default=[])
|
2023-07-06 11:37:44 +03:00
|
|
|
args = parser.parse_args()
|
|
|
|
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
|
2023-07-16 13:18:29 +03:00
|
|
|
command = args.command.lower()
|
|
|
|
if command in ['ask', 'ask_question']:
|
|
|
|
question = ' '.join(args.rest).strip()
|
|
|
|
if len(question) == 0:
|
|
|
|
print("Please specify a question")
|
|
|
|
parser.print_help()
|
|
|
|
return
|
|
|
|
print(f"Question: {question} about PR {args.pr_url}")
|
|
|
|
reviewer = PRQuestions(args.pr_url, question)
|
2023-07-06 11:37:44 +03:00
|
|
|
asyncio.run(reviewer.answer())
|
2023-07-16 13:18:29 +03:00
|
|
|
elif command in ['describe', 'describe_pr']:
|
2023-07-13 17:24:56 +03:00
|
|
|
print(f"PR description: {args.pr_url}")
|
|
|
|
reviewer = PRDescription(args.pr_url)
|
|
|
|
asyncio.run(reviewer.describe())
|
2023-07-16 13:18:29 +03:00
|
|
|
elif command in ['improve', 'improve_code']:
|
2023-07-15 09:30:50 +03:00
|
|
|
print(f"PR code suggestions: {args.pr_url}")
|
|
|
|
reviewer = PRCodeSuggestions(args.pr_url)
|
|
|
|
asyncio.run(reviewer.suggest())
|
2023-07-16 13:18:29 +03:00
|
|
|
elif command in ['review', 'review_pr']:
|
2023-07-06 11:37:44 +03:00
|
|
|
print(f"Reviewing PR: {args.pr_url}")
|
2023-07-12 11:31:06 +03:00
|
|
|
reviewer = PRReviewer(args.pr_url, cli_mode=True)
|
2023-07-06 11:37:44 +03:00
|
|
|
asyncio.run(reviewer.review())
|
2023-07-16 13:18:29 +03:00
|
|
|
else:
|
|
|
|
print(f"Unknown command: {command}")
|
|
|
|
parser.print_help()
|
2023-07-06 11:37:44 +03:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
run()
|