pr-agent/pr_agent/agent/pr_agent.py

37 lines
1.6 KiB
Python
Raw Normal View History

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