mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-02 20:00:41 +08:00
Update Github polling
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import asyncio
|
||||
import logging
|
||||
import re
|
||||
import sys
|
||||
from datetime import datetime, timezone
|
||||
|
||||
@ -8,6 +9,11 @@ import aiohttp
|
||||
from pr_agent.agent.pr_agent import PRAgent
|
||||
from pr_agent.config_loader import settings
|
||||
from pr_agent.git_providers import get_git_provider
|
||||
from pr_agent.servers.help import bot_help_text
|
||||
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_reviewer import PRReviewer
|
||||
|
||||
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
|
||||
NOTIFICATION_URL = "https://api.github.com/notifications"
|
||||
@ -83,8 +89,24 @@ async def polling_loop():
|
||||
if user_tag not in comment_body:
|
||||
continue
|
||||
rest_of_comment = comment_body.split(user_tag)[1].strip()
|
||||
agent = PRAgent()
|
||||
await agent.handle_request(pr_url, rest_of_comment)
|
||||
|
||||
if any(cmd in rest_of_comment for cmd in ["/review", "/review_pr"]):
|
||||
await PRReviewer(pr_url).review()
|
||||
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.publish_comment("### How to user PR-Agent\n" +
|
||||
bot_help_text(user_id))
|
||||
|
||||
elif response.status != 304:
|
||||
print(f"Failed to fetch notifications. Status code: {response.status}")
|
||||
|
||||
|
14
pr_agent/servers/help.py
Normal file
14
pr_agent/servers/help.py
Normal file
@ -0,0 +1,14 @@
|
||||
commands_text = "> /review - Ask for a new review after your update the PR\n" \
|
||||
"> /describe - Modify the PR title and description based " \
|
||||
"on the PR's contents.\n" \
|
||||
"> /improve - Suggest improvements to the code in the PR as pull " \
|
||||
"request comments ready to commit.\n" \
|
||||
"> /ask <QUESTION> - Ask a question about the PR.\n"
|
||||
|
||||
|
||||
def bot_help_text(user: str):
|
||||
return f"> Tag me in a comment '@{user}' and add one of the following commands:\n" + commands_text
|
||||
|
||||
|
||||
actions_help_text = "> Add a comment to to invoke PR-Agent, use one of the following commands:\n" + \
|
||||
commands_text
|
@ -11,6 +11,7 @@ from pr_agent.algo.utils import convert_to_markdown, try_fix_json
|
||||
from pr_agent.config_loader import settings
|
||||
from pr_agent.git_providers import get_git_provider
|
||||
from pr_agent.git_providers.git_provider import get_main_pr_language
|
||||
from pr_agent.servers.help import bot_help_text, actions_help_text
|
||||
|
||||
|
||||
class PRReviewer:
|
||||
@ -43,7 +44,7 @@ class PRReviewer:
|
||||
async def review(self):
|
||||
logging.info('Reviewing PR...')
|
||||
if settings.config.publish_review:
|
||||
self.git_provider.publish_comment("Preparing review...", is_temporary=True)
|
||||
self.git_provider.publish_comment("Preparing review...", is_temporary=True)
|
||||
logging.info('Getting PR diff...')
|
||||
self.patches_diff = get_pr_diff(self.git_provider, self.token_handler)
|
||||
logging.info('Getting AI prediction...')
|
||||
@ -96,18 +97,10 @@ class PRReviewer:
|
||||
|
||||
if not self.cli_mode:
|
||||
markdown_text += "\n### How to use\n"
|
||||
commands_text = "> /review - Ask for a new review after your update the PR\n" \
|
||||
"> /describe - Modify the PR title and description based " \
|
||||
"on the PR's contents.\n" \
|
||||
"> /improve - Suggest improvements to the code in the PR as pull " \
|
||||
"request comments ready to commit.\n" \
|
||||
"> /ask <QUESTION> - Ask a question about the PR.\n"
|
||||
if user and '[bot]' not in user:
|
||||
markdown_text += f"> Tag me in a comment '@{user}' and add one of the following commands:\n" + \
|
||||
commands_text
|
||||
markdown_text += bot_help_text(user)
|
||||
else:
|
||||
markdown_text += "> Add a comment to to invoke PR-Agent, use one of the following commands:\n" + \
|
||||
commands_text
|
||||
markdown_text += actions_help_text
|
||||
|
||||
if settings.config.verbosity_level >= 2:
|
||||
logging.info(f"Markdown response:\n{markdown_text}")
|
||||
|
Reference in New Issue
Block a user