2023-07-06 00:21:08 +03:00
|
|
|
import re
|
|
|
|
|
2023-07-18 11:34:57 +03:00
|
|
|
from pr_agent.config_loader import settings
|
2023-07-16 15:42:50 +03:00
|
|
|
from pr_agent.tools.pr_code_suggestions import PRCodeSuggestions
|
|
|
|
from pr_agent.tools.pr_description import PRDescription
|
2023-07-17 15:49:29 +03:00
|
|
|
from pr_agent.tools.pr_information_from_user import PRInformationFromUser
|
2023-07-06 00:21:08 +03:00
|
|
|
from pr_agent.tools.pr_questions import PRQuestions
|
|
|
|
from pr_agent.tools.pr_reviewer import PRReviewer
|
|
|
|
|
|
|
|
|
|
|
|
class PRAgent:
|
2023-07-08 08:52:11 +03:00
|
|
|
def __init__(self):
|
|
|
|
pass
|
2023-07-06 00:21:08 +03:00
|
|
|
|
2023-07-16 15:42:50 +03:00
|
|
|
async def handle_request(self, pr_url, request) -> bool:
|
2023-07-17 15:49:29 +03:00
|
|
|
if any(cmd in request for cmd in ["/answer"]):
|
|
|
|
await PRReviewer(pr_url, is_answer=True).review()
|
2023-07-18 08:22:25 +03:00
|
|
|
elif any(cmd in request for cmd in ["/review", "/review_pr", "/reflect_and_review"]):
|
2023-07-18 23:14:47 +03:00
|
|
|
words = request.split(" ")
|
|
|
|
incremental_review = False
|
|
|
|
if len(words) > 1:
|
|
|
|
arg = words[1]
|
|
|
|
if arg == "-i":
|
|
|
|
incremental_review = True
|
2023-07-18 10:20:52 +03:00
|
|
|
if settings.pr_reviewer.ask_and_reflect or "/reflect_and_review" in request:
|
2023-07-17 15:49:29 +03:00
|
|
|
await PRInformationFromUser(pr_url).generate_questions()
|
|
|
|
else:
|
2023-07-18 23:14:47 +03:00
|
|
|
await PRReviewer(pr_url, is_incremental=incremental_review).review()
|
2023-07-16 15:42:50 +03:00
|
|
|
elif any(cmd in request for cmd in ["/describe", "/describe_pr"]):
|
|
|
|
await PRDescription(pr_url).describe()
|
|
|
|
elif any(cmd in request for cmd in ["/improve", "/improve_code"]):
|
|
|
|
await PRCodeSuggestions(pr_url).suggest()
|
|
|
|
elif any(cmd in request for cmd in ["/ask", "/ask_question"]):
|
|
|
|
pattern = r'(/ask|/ask_question)\s*(.*)'
|
|
|
|
matches = re.findall(pattern, request, re.IGNORECASE)
|
|
|
|
if matches:
|
|
|
|
question = matches[0][1]
|
|
|
|
await PRQuestions(pr_url, question).answer()
|
2023-07-06 12:58:05 +03:00
|
|
|
else:
|
2023-07-16 15:42:50 +03:00
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|