mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-02 11:50:37 +08:00
cli.py - modify command line for a more coherent command invokation
This commit is contained in:
@ -10,29 +10,48 @@ from pr_agent.tools.pr_reviewer import PRReviewer
|
||||
|
||||
|
||||
def run():
|
||||
parser = argparse.ArgumentParser(description='AI based pull request analyzer')
|
||||
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.
|
||||
""")
|
||||
parser.add_argument('--pr_url', type=str, help='The URL of the PR to review', required=True)
|
||||
parser.add_argument('--question', type=str, help='Optional question to ask', required=False)
|
||||
parser.add_argument('--pr_description', action='store_true', required=False)
|
||||
parser.add_argument('--pr_code_suggestions', action='store_true', required=False)
|
||||
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=[])
|
||||
args = parser.parse_args()
|
||||
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
|
||||
if args.question:
|
||||
print(f"Question: {args.question} about PR {args.pr_url}")
|
||||
reviewer = PRQuestions(args.pr_url, args.question)
|
||||
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)
|
||||
asyncio.run(reviewer.answer())
|
||||
elif args.pr_description:
|
||||
elif command in ['describe', 'describe_pr']:
|
||||
print(f"PR description: {args.pr_url}")
|
||||
reviewer = PRDescription(args.pr_url)
|
||||
asyncio.run(reviewer.describe())
|
||||
elif args.pr_code_suggestions:
|
||||
elif command in ['improve', 'improve_code']:
|
||||
print(f"PR code suggestions: {args.pr_url}")
|
||||
reviewer = PRCodeSuggestions(args.pr_url)
|
||||
asyncio.run(reviewer.suggest())
|
||||
else:
|
||||
elif command in ['review', 'review_pr']:
|
||||
print(f"Reviewing PR: {args.pr_url}")
|
||||
reviewer = PRReviewer(args.pr_url, cli_mode=True)
|
||||
asyncio.run(reviewer.review())
|
||||
else:
|
||||
print(f"Unknown command: {command}")
|
||||
parser.print_help()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Reference in New Issue
Block a user