Merge pull request #55 from Codium-ai/enhancement/github_action_apply

Github action support for new style commands
This commit is contained in:
Ori Kotek
2023-07-16 13:50:57 +03:00
committed by GitHub
2 changed files with 25 additions and 10 deletions

View File

@ -1,8 +1,11 @@
import asyncio
import json
import os
import re
from pr_agent.config_loader import settings
from pr_agent.tools.pr_code_suggestions import PRCodeSuggestions
from pr_agent.tools.pr_description import PRDescription
from pr_agent.tools.pr_questions import PRQuestions
from pr_agent.tools.pr_reviewer import PRReviewer
@ -48,10 +51,19 @@ async def run_action():
if comment_body:
pr_url = event_payload.get("issue", {}).get("pull_request", {}).get("url", None)
if pr_url:
if comment_body.strip().lower() == "review":
body = comment_body.strip().lower()
if any(cmd in body for cmd in ["/review", "/review_pr"]):
await PRReviewer(pr_url).review()
elif comment_body.lstrip().lower().startswith("answer"):
await PRQuestions(pr_url, comment_body).answer()
elif any(cmd in body for cmd in ["/describe", "/describe_pr"]):
await PRDescription(pr_url).describe()
elif any(cmd in body for cmd in ["/improve", "/improve_code"]):
await PRCodeSuggestions(pr_url).suggest()
elif any(cmd in body for cmd in ["/ask", "/ask_question"]):
pattern = r'(/ask|/ask_question)\s*(.*)'
matches = re.findall(pattern, comment_body, re.IGNORECASE)
if matches:
question = matches[0][1]
await PRQuestions(pr_url, question).answer()
if __name__ == '__main__':

View File

@ -96,15 +96,18 @@ class PRReviewer:
if not self.cli_mode:
markdown_text += "\n### How to use\n"
commands_text = "> /review or /review_pr - Ask for a new review after your update the PR\n" \
"> /describe or /describe_pr - Modify the PR title and description based " \
"on the PR's contents.\n" \
"> /improve or /improve_code - Suggest improvements to the code in the PR as pull " \
"request comments ready to commit.\n" \
"> /ask /ask_question <QUESTION> - Ask a question about the PR.\n"
if user and '[bot]' not in user:
markdown_text += f"> Tag me in a comment '@{user}' to ask for a new review after you update the PR.\n"
markdown_text += "> You can also tag me and ask any question, " \
f"for example '@{user} is the PR ready for merge?'"
markdown_text += f"> Tag me in a comment '@{user}' and add one of the following commands:\n" + \
commands_text
else:
markdown_text += "> Add a comment that says 'review' to ask for a new review " \
"after you update the PR.\n"
markdown_text += "> You can also add a comment that says 'answer QUESTION', " \
"for example 'answer is the PR ready for merge?'"
markdown_text += "> Add a comment to to invoke PR-Agent, use one of the following commands:\n" + \
commands_text
if settings.config.verbosity_level >= 2:
logging.info(f"Markdown response:\n{markdown_text}")