From 987befe4570cdeee5d716f3e7d658aa4110e9f26 Mon Sep 17 00:00:00 2001 From: Ori Kotek Date: Thu, 6 Jul 2023 11:37:44 +0300 Subject: [PATCH] Merge CLI scripts to cli.py, update Dockerfile and README.md --- README.md | 10 +++---- docker/Dockerfile | 6 ++--- pr_agent/cli.py | 27 +++++++++++++++++++ .../scripts/answer_pr_questions_from_url.py | 16 ----------- pr_agent/scripts/review_pr_from_url.py | 14 ---------- 5 files changed, 34 insertions(+), 39 deletions(-) create mode 100644 pr_agent/cli.py delete mode 100644 pr_agent/scripts/answer_pr_questions_from_url.py delete mode 100644 pr_agent/scripts/review_pr_from_url.py diff --git a/README.md b/README.md index 3a86c55c..f4feb895 100644 --- a/README.md +++ b/README.md @@ -35,16 +35,14 @@ Python scripts from the scripts folder. Here's how: 1. To request a review for a PR, run the following command: ``` -docker run --rm -it -e OPENAI.KEY= -e GITHUB.USER_TOKEN= codiumai/pr-agent \ -python pr_agent/scripts/review_pr_from_url.py --pr_url +docker run --rm -it -e OPENAI.KEY= -e GITHUB.USER_TOKEN= codiumai/pr-agent --pr_url ``` --- 2. To ask a question about a PR, run the following command: ``` -docker run --rm -it -e OPENAI.KEY -e GITHUB.USER_TOKEN codiumai/pr-agent \ -python pr_agent/scripts/answer_pr_questions_from_url.py --pr_url --question "" +docker run --rm -it -e OPENAI.KEY= -e GITHUB.USER_TOKEN= codiumai/pr-agent --pr_url --question "" ``` Possible questions you can ask include: @@ -76,8 +74,8 @@ cp pr_agent/settings/.secrets_template.toml pr_agent/settings/.secrets 4. Run the appropriate Python scripts from the scripts folder: ``` -python pr_agent/scripts/review_pr_from_url.py --pr_url -python pr_agent/scripts/answer_pr_questions_from_url.py --pr_url --question "" +python pr_agent/cli.py --pr_url +python pr_agent/cli.py --pr_url --question "" ``` --- diff --git a/docker/Dockerfile b/docker/Dockerfile index aeb8250b..b763985c 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -7,14 +7,14 @@ ENV PYTHONPATH=/app ADD pr_agent pr_agent FROM base as github_app -CMD ["python", "servers/github_app.py"] +CMD ["python", "pr_agent/servers/github_app.py"] FROM base as github_polling -CMD ["python", "servers/github_polling.py"] +CMD ["python", "pr_agent/servers/github_polling.py"] FROM base as test ADD requirements-dev.txt . RUN pip install -r requirements-dev.txt && rm requirements-dev.txt FROM base as cli -CMD ["bash"] +ENTRYPOINT ["python", "pr_agent/cli.py"] diff --git a/pr_agent/cli.py b/pr_agent/cli.py new file mode 100644 index 00000000..44d631a1 --- /dev/null +++ b/pr_agent/cli.py @@ -0,0 +1,27 @@ +import argparse +import asyncio +import logging +import os + +from pr_agent.tools.pr_questions import PRQuestions +from pr_agent.tools.pr_reviewer import PRReviewer + + +def run(): + parser = argparse.ArgumentParser(description='AI based pull request analyzer') + 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) + 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, None) + asyncio.run(reviewer.answer()) + else: + print(f"Reviewing PR: {args.pr_url}") + reviewer = PRReviewer(args.pr_url, None) + asyncio.run(reviewer.review()) + + +if __name__ == '__main__': + run() diff --git a/pr_agent/scripts/answer_pr_questions_from_url.py b/pr_agent/scripts/answer_pr_questions_from_url.py deleted file mode 100644 index ceed9eec..00000000 --- a/pr_agent/scripts/answer_pr_questions_from_url.py +++ /dev/null @@ -1,16 +0,0 @@ -import argparse -import asyncio -import logging -import os - -from pr_agent.tools.pr_questions import PRQuestions - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='Review a PR from a URL') - parser.add_argument('--pr_url', type=str, help='The URL of the PR to review', required=True) - parser.add_argument('--question_str', type=str, help='The question to answer', required=True) - - args = parser.parse_args() - logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO")) - reviewer = PRQuestions(args.pr_url, args.question_str, None) - asyncio.run(reviewer.answer()) diff --git a/pr_agent/scripts/review_pr_from_url.py b/pr_agent/scripts/review_pr_from_url.py deleted file mode 100644 index 6d7388e0..00000000 --- a/pr_agent/scripts/review_pr_from_url.py +++ /dev/null @@ -1,14 +0,0 @@ -import argparse -import asyncio -import logging -import os - -from pr_agent.tools.pr_reviewer import PRReviewer - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='Review a PR from a URL') - parser.add_argument('--pr_url', type=str, help='The URL of the PR to review', required=True) - args = parser.parse_args() - logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO")) - reviewer = PRReviewer(args.pr_url, None) - asyncio.run(reviewer.review())