Files
pr-agent/pr_agent/agent/pr_agent.py

34 lines
1.4 KiB
Python
Raw Normal View History

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-19 17:14:55 +03:00
action, *args = request.strip().split()
2023-07-19 14:22:34 +03:00
if any(cmd == action for cmd in ["/answer"]):
2023-07-17 15:49:29 +03:00
await PRReviewer(pr_url, is_answer=True).review()
2023-07-19 14:22:34 +03:00
elif any(cmd == action for cmd in ["/review", "/review_pr", "/reflect_and_review"]):
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-19 17:01:56 +03:00
await PRReviewer(pr_url, args=args).review()
2023-07-19 14:22:34 +03:00
elif any(cmd == action for cmd in ["/describe", "/describe_pr"]):
2023-07-16 15:42:50 +03:00
await PRDescription(pr_url).describe()
2023-07-19 14:22:34 +03:00
elif any(cmd == action for cmd in ["/improve", "/improve_code"]):
2023-07-16 15:42:50 +03:00
await PRCodeSuggestions(pr_url).suggest()
2023-07-19 14:22:34 +03:00
elif any(cmd == action for cmd in ["/ask", "/ask_question"]):
2023-07-19 17:01:56 +03:00
await PRQuestions(pr_url, args).answer()
else:
2023-07-16 15:42:50 +03:00
return False
return True