Files
pr-agent/pr_agent/cli.py

54 lines
2.0 KiB
Python
Raw Normal View History

import argparse
import asyncio
import logging
import os
from pr_agent.agent.pr_agent import PRAgent, commands
from pr_agent.config_loader import get_settings
def run(inargs=None):
2023-07-21 22:12:51 +03:00
parser = argparse.ArgumentParser(description='AI based pull request analyzer', usage=
"""\
2023-08-10 01:30:12 +03:00
Usage: cli.py --pr-url=<URL on supported git hosting service> <command> [<args>].
2023-07-16 14:59:40 +03:00
For example:
2023-08-10 01:30:12 +03:00
- cli.py --pr_url=... review
- cli.py --pr_url=... describe
- cli.py --pr_url=... improve
- cli.py --pr_url=... ask "write me a poem about this PR"
- cli.py --pr_url=... reflect
Supported commands:
2023-08-22 09:42:59 +03:00
-review / review_pr - Add a review that includes a summary of the PR and specific suggestions for improvement.
2023-07-30 11:43:44 +03:00
2023-08-22 09:42:59 +03:00
-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.
Extended mode ('improve --extended') employs several calls, and provides a more thorough feedback
-reflect - Ask the PR author questions about the PR.
-update_changelog - Update the changelog based on the PR's contents.
Configuration:
2023-07-30 11:43:44 +03:00
To edit any configuration parameter from 'configuration.toml', just add -config_path=<value>.
2023-08-10 01:30:12 +03:00
For example: 'python cli.py --pr_url=... review --pr_reviewer.extra_instructions="focus on the file: ..."'
""")
parser.add_argument('--pr_url', type=str, help='The URL of the PR to review', required=True)
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)
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
command = args.command.lower()
get_settings().set("CONFIG.CLI_MODE", True)
result = asyncio.run(PRAgent().handle_request(args.pr_url, command + " " + " ".join(args.rest)))
if not result:
parser.print_help()
if __name__ == '__main__':
run()