2023-07-05 21:21:08 +00:00
|
|
|
import re
|
|
|
|
|
|
2023-07-18 08:34:57 +00:00
|
|
|
from pr_agent.config_loader import settings
|
2023-07-16 12:42:50 +00:00
|
|
|
from pr_agent.tools.pr_code_suggestions import PRCodeSuggestions
|
|
|
|
|
from pr_agent.tools.pr_description import PRDescription
|
2023-07-17 12:49:29 +00:00
|
|
|
from pr_agent.tools.pr_information_from_user import PRInformationFromUser
|
2023-07-05 21:21:08 +00:00
|
|
|
from pr_agent.tools.pr_questions import PRQuestions
|
|
|
|
|
from pr_agent.tools.pr_reviewer import PRReviewer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PRAgent:
|
2023-07-08 05:52:11 +00:00
|
|
|
def __init__(self):
|
|
|
|
|
pass
|
2023-07-05 21:21:08 +00:00
|
|
|
|
2023-07-16 12:42:50 +00:00
|
|
|
async def handle_request(self, pr_url, request) -> bool:
|
2023-07-19 11:22:34 +00:00
|
|
|
action, *args = request.split(" ")
|
|
|
|
|
if any(cmd == action for cmd in ["/answer"]):
|
2023-07-17 12:49:29 +00:00
|
|
|
await PRReviewer(pr_url, is_answer=True).review()
|
2023-07-19 11:22:34 +00:00
|
|
|
elif any(cmd == action for cmd in ["/review", "/review_pr", "/reflect_and_review"]):
|
2023-07-18 07:20:52 +00:00
|
|
|
if settings.pr_reviewer.ask_and_reflect or "/reflect_and_review" in request:
|
2023-07-17 12:49:29 +00:00
|
|
|
await PRInformationFromUser(pr_url).generate_questions()
|
|
|
|
|
else:
|
2023-07-19 14:01:56 +00:00
|
|
|
await PRReviewer(pr_url, args=args).review()
|
2023-07-19 11:22:34 +00:00
|
|
|
elif any(cmd == action for cmd in ["/describe", "/describe_pr"]):
|
2023-07-16 12:42:50 +00:00
|
|
|
await PRDescription(pr_url).describe()
|
2023-07-19 11:22:34 +00:00
|
|
|
elif any(cmd == action for cmd in ["/improve", "/improve_code"]):
|
2023-07-16 12:42:50 +00:00
|
|
|
await PRCodeSuggestions(pr_url).suggest()
|
2023-07-19 11:22:34 +00:00
|
|
|
elif any(cmd == action for cmd in ["/ask", "/ask_question"]):
|
2023-07-19 14:01:56 +00:00
|
|
|
await PRQuestions(pr_url, args).answer()
|
2023-07-06 09:58:05 +00:00
|
|
|
else:
|
2023-07-16 12:42:50 +00:00
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
return True
|