2023-07-06 11:37:44 +03:00
|
|
|
import argparse
|
|
|
|
import asyncio
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
|
2023-08-01 14:43:26 +03:00
|
|
|
from pr_agent.agent.pr_agent import PRAgent, commands
|
|
|
|
from pr_agent.config_loader import get_settings
|
2023-07-06 11:37:44 +03:00
|
|
|
|
|
|
|
|
2023-08-01 14:43:26 +03:00
|
|
|
def run(inargs=None):
|
2023-07-21 22:12:51 +03:00
|
|
|
parser = argparse.ArgumentParser(description='AI based pull request analyzer', usage=
|
|
|
|
"""\
|
2023-07-16 13:18:29 +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-07-17 08:18:42 +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"
|
2023-07-18 08:22:25 +03:00
|
|
|
- cli.py --pr-url=... reflect
|
2023-07-16 13:18:29 +03:00
|
|
|
|
|
|
|
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-18 08:22:25 +03:00
|
|
|
reflect - Ask the PR author questions about the PR.
|
2023-07-26 09:21:31 +03:00
|
|
|
update_changelog - Update the changelog based on the PR's contents.
|
2023-07-30 11:43:44 +03:00
|
|
|
|
|
|
|
To edit any configuration parameter from 'configuration.toml', just add -config_path=<value>.
|
2023-07-30 12:04:57 +03:00
|
|
|
For example: '- cli.py --pr-url=... review --pr_reviewer.extra_instructions="focus on the file: ..."'
|
2023-07-16 13:18:29 +03:00
|
|
|
""")
|
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-08-01 14:43:26 +03:00
|
|
|
parser.add_argument('command', type=str, help='The', choices=commands, default='review')
|
2023-07-16 13:18:29 +03:00
|
|
|
parser.add_argument('rest', nargs=argparse.REMAINDER, default=[])
|
2023-08-01 14:43:26 +03:00
|
|
|
args = parser.parse_args(inargs)
|
2023-07-06 11:37:44 +03:00
|
|
|
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
|
2023-07-16 13:18:29 +03:00
|
|
|
command = args.command.lower()
|
2023-08-01 14:43:26 +03:00
|
|
|
get_settings().set("CONFIG.CLI_MODE", True)
|
|
|
|
result = asyncio.run(PRAgent().handle_request(args.pr_url, command + " " + " ".join(args.rest)))
|
|
|
|
if not result:
|
2023-07-16 13:18:29 +03:00
|
|
|
parser.print_help()
|
2023-07-06 11:37:44 +03:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
run()
|