mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-06 13:50:44 +08:00
Merge pull request #11 from Codium-ai/bugfix/double_notifications
Protect from notifications that may be handled twice
This commit is contained in:
@ -1 +1,2 @@
|
|||||||
venv/
|
venv/
|
||||||
|
pr_agent/settings/.secrets.toml
|
@ -15,11 +15,11 @@ def run():
|
|||||||
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
|
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
|
||||||
if args.question:
|
if args.question:
|
||||||
print(f"Question: {args.question} about PR {args.pr_url}")
|
print(f"Question: {args.question} about PR {args.pr_url}")
|
||||||
reviewer = PRQuestions(args.pr_url, args.question, None)
|
reviewer = PRQuestions(args.pr_url, args.question, installation_id=None)
|
||||||
asyncio.run(reviewer.answer())
|
asyncio.run(reviewer.answer())
|
||||||
else:
|
else:
|
||||||
print(f"Reviewing PR: {args.pr_url}")
|
print(f"Reviewing PR: {args.pr_url}")
|
||||||
reviewer = PRReviewer(args.pr_url, None)
|
reviewer = PRReviewer(args.pr_url, installation_id=None, cli_mode=True)
|
||||||
asyncio.run(reviewer.review())
|
asyncio.run(reviewer.review())
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ settings = Dynaconf(
|
|||||||
"settings/.secrets.toml",
|
"settings/.secrets.toml",
|
||||||
"settings/configuration.toml",
|
"settings/configuration.toml",
|
||||||
"settings/pr_reviewer_prompts.toml",
|
"settings/pr_reviewer_prompts.toml",
|
||||||
"settings/pr_questions_prompts.toml"
|
"settings/pr_questions_prompts.toml",
|
||||||
|
"settings_prod/.secrets.toml"
|
||||||
]]
|
]]
|
||||||
)
|
)
|
||||||
|
@ -20,6 +20,7 @@ def now() -> str:
|
|||||||
|
|
||||||
|
|
||||||
async def polling_loop():
|
async def polling_loop():
|
||||||
|
handled_ids = set()
|
||||||
since = [now()]
|
since = [now()]
|
||||||
last_modified = [None]
|
last_modified = [None]
|
||||||
git_provider = get_git_provider()()
|
git_provider = get_git_provider()()
|
||||||
@ -54,6 +55,9 @@ async def polling_loop():
|
|||||||
since[0] = None
|
since[0] = None
|
||||||
notifications = await response.json()
|
notifications = await response.json()
|
||||||
for notification in notifications:
|
for notification in notifications:
|
||||||
|
if 'id' in notification and notification['id'] in handled_ids:
|
||||||
|
continue
|
||||||
|
handled_ids.add(notification['id'])
|
||||||
if 'reason' in notification and notification['reason'] == 'mention':
|
if 'reason' in notification and notification['reason'] == 'mention':
|
||||||
if 'subject' in notification and notification['subject']['type'] == 'PullRequest':
|
if 'subject' in notification and notification['subject']['type'] == 'PullRequest':
|
||||||
pr_url = notification['subject']['url']
|
pr_url = notification['subject']['url']
|
||||||
|
@ -14,7 +14,7 @@ from pr_agent.git_providers import get_git_provider
|
|||||||
|
|
||||||
|
|
||||||
class PRReviewer:
|
class PRReviewer:
|
||||||
def __init__(self, pr_url: str, installation_id: Optional[int] = None):
|
def __init__(self, pr_url: str, installation_id: Optional[int] = None, cli_mode=False):
|
||||||
|
|
||||||
self.git_provider = get_git_provider()(pr_url, installation_id)
|
self.git_provider = get_git_provider()(pr_url, installation_id)
|
||||||
self.main_language = self.git_provider.get_main_pr_language()
|
self.main_language = self.git_provider.get_main_pr_language()
|
||||||
@ -22,6 +22,7 @@ class PRReviewer:
|
|||||||
self.ai_handler = AiHandler()
|
self.ai_handler = AiHandler()
|
||||||
self.patches_diff = None
|
self.patches_diff = None
|
||||||
self.prediction = None
|
self.prediction = None
|
||||||
|
self.cli_mode = cli_mode
|
||||||
self.vars = {
|
self.vars = {
|
||||||
"title": self.git_provider.pr.title,
|
"title": self.git_provider.pr.title,
|
||||||
"branch": self.git_provider.get_pr_branch(),
|
"branch": self.git_provider.get_pr_branch(),
|
||||||
@ -91,16 +92,19 @@ class PRReviewer:
|
|||||||
|
|
||||||
markdown_text = convert_to_markdown(data)
|
markdown_text = convert_to_markdown(data)
|
||||||
user = self.git_provider.get_user_id()
|
user = self.git_provider.get_user_id()
|
||||||
markdown_text += "\n### How to use\n"
|
|
||||||
if user and '[bot]' not in user:
|
if not self.cli_mode:
|
||||||
markdown_text += f"> Tag me in a comment '@{user}' to ask for a new review after you update the PR.\n"
|
markdown_text += "\n### How to use\n"
|
||||||
markdown_text += "> You can also tag me and ask any question, " \
|
if user and '[bot]' not in user:
|
||||||
f"for example '@{user} is the PR ready for merge?'"
|
markdown_text += "\n### How to use\n"
|
||||||
else:
|
markdown_text += f"> Tag me in a comment '@{user}' to ask for a new review after you update the PR.\n"
|
||||||
markdown_text += "> Add a comment that says 'review' to ask for a new review " \
|
markdown_text += "> You can also tag me and ask any question, " \
|
||||||
"after you update the PR.\n"
|
f"for example '@{user} is the PR ready for merge?'"
|
||||||
markdown_text += "> You can also add a comment that says 'answer QUESTION', " \
|
else:
|
||||||
"for example 'answer is the PR ready for merge?'"
|
markdown_text += "> Add a comment that says 'review' to ask for a new review " \
|
||||||
|
"after you update the PR.\n"
|
||||||
|
markdown_text += "> You can also add a comment that says 'answer QUESTION', " \
|
||||||
|
"for example 'answer is the PR ready for merge?'"
|
||||||
|
|
||||||
if settings.config.verbosity_level >= 2:
|
if settings.config.verbosity_level >= 2:
|
||||||
logging.info(f"Markdown response:\n{markdown_text}")
|
logging.info(f"Markdown response:\n{markdown_text}")
|
||||||
|
Reference in New Issue
Block a user