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

37 lines
1.6 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
2023-07-26 20:05:18 +03:00
from pr_agent.tools.pr_update_changelog import PRUpdateChangelog
2023-07-06 00:21:08 +03:00
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-30 11:43:44 +03:00
await PRReviewer(pr_url, is_answer=True, args=args).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-30 11:43:44 +03:00
await PRInformationFromUser(pr_url, args=args).generate_questions()
2023-07-17 15:49:29 +03:00
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-27 17:42:50 +03:00
await PRDescription(pr_url, args=args).describe()
2023-07-19 14:22:34 +03:00
elif any(cmd == action for cmd in ["/improve", "/improve_code"]):
2023-07-30 11:43:44 +03:00
await PRCodeSuggestions(pr_url, args=args).suggest()
2023-07-19 14:22:34 +03:00
elif any(cmd == action for cmd in ["/ask", "/ask_question"]):
2023-07-27 08:47:26 +03:00
await PRQuestions(pr_url, args=args).answer()
2023-07-26 20:05:18 +03:00
elif any(cmd == action for cmd in ["/update_changelog"]):
2023-07-27 08:47:26 +03:00
await PRUpdateChangelog(pr_url, args=args).update_changelog()
else:
2023-07-16 15:42:50 +03:00
return False
return True