mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-04 21:00:40 +08:00
Merge pull request #60 from Codium-ai/enhancement/github_app
Enhancement of PR Agent with new commands
This commit is contained in:
@ -1,5 +1,7 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
|
from pr_agent.tools.pr_code_suggestions import PRCodeSuggestions
|
||||||
|
from pr_agent.tools.pr_description import PRDescription
|
||||||
from pr_agent.tools.pr_questions import PRQuestions
|
from pr_agent.tools.pr_questions import PRQuestions
|
||||||
from pr_agent.tools.pr_reviewer import PRReviewer
|
from pr_agent.tools.pr_reviewer import PRReviewer
|
||||||
|
|
||||||
@ -8,17 +10,20 @@ class PRAgent:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def handle_request(self, pr_url, request):
|
async def handle_request(self, pr_url, request) -> bool:
|
||||||
if 'please review' in request.lower() or 'review' == request.lower().strip() or len(request) == 0:
|
if any(cmd in request for cmd in ["/review", "/review_pr"]):
|
||||||
reviewer = PRReviewer(pr_url)
|
await PRReviewer(pr_url).review()
|
||||||
await reviewer.review()
|
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()
|
||||||
else:
|
else:
|
||||||
if "please answer" in request.lower():
|
return False
|
||||||
question = re.split(r'(?i)please answer', request)[1].strip()
|
|
||||||
elif request.lower().strip().startswith("answer"):
|
return True
|
||||||
question = re.split(r'(?i)answer', request)[1].strip()
|
|
||||||
else:
|
|
||||||
question = request
|
|
||||||
answerer = PRQuestions(pr_url, question)
|
|
||||||
await answerer.answer()
|
|
||||||
|
@ -56,7 +56,7 @@ async def handle_request(body):
|
|||||||
api_url = pull_request.get("url", None)
|
api_url = pull_request.get("url", None)
|
||||||
if api_url is None:
|
if api_url is None:
|
||||||
return {}
|
return {}
|
||||||
await agent.handle_request(api_url, "please review")
|
await agent.handle_request(api_url, "/review")
|
||||||
else:
|
else:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ async def polling_loop():
|
|||||||
last_modified = [None]
|
last_modified = [None]
|
||||||
git_provider = get_git_provider()()
|
git_provider = get_git_provider()()
|
||||||
user_id = git_provider.get_user_id()
|
user_id = git_provider.get_user_id()
|
||||||
|
agent = PRAgent()
|
||||||
try:
|
try:
|
||||||
deployment_type = settings.github.deployment_type
|
deployment_type = settings.github.deployment_type
|
||||||
token = settings.github.user_token
|
token = settings.github.user_token
|
||||||
@ -90,19 +91,8 @@ async def polling_loop():
|
|||||||
continue
|
continue
|
||||||
rest_of_comment = comment_body.split(user_tag)[1].strip()
|
rest_of_comment = comment_body.split(user_tag)[1].strip()
|
||||||
|
|
||||||
if any(cmd in rest_of_comment for cmd in ["/review", "/review_pr"]):
|
success = await agent.handle_request(pr_url, rest_of_comment)
|
||||||
await PRReviewer(pr_url).review()
|
if not success:
|
||||||
elif any(cmd in rest_of_comment for cmd in ["/describe", "/describe_pr"]):
|
|
||||||
await PRDescription(pr_url).describe()
|
|
||||||
elif any(cmd in rest_of_comment for cmd in ["/improve", "/improve_code"]):
|
|
||||||
await PRCodeSuggestions(pr_url).suggest()
|
|
||||||
elif any(cmd in rest_of_comment for cmd in ["/ask", "/ask_question"]):
|
|
||||||
pattern = r'(/ask|/ask_question)\s*(.*)'
|
|
||||||
matches = re.findall(pattern, rest_of_comment, re.IGNORECASE)
|
|
||||||
if matches:
|
|
||||||
question = matches[0][1]
|
|
||||||
await PRQuestions(pr_url, question).answer()
|
|
||||||
else:
|
|
||||||
git_provider.set_pr(pr_url)
|
git_provider.set_pr(pr_url)
|
||||||
git_provider.publish_comment("### How to user PR-Agent\n" +
|
git_provider.publish_comment("### How to user PR-Agent\n" +
|
||||||
bot_help_text(user_id))
|
bot_help_text(user_id))
|
||||||
|
Reference in New Issue
Block a user