Merge pull request #11 from Codium-ai/bugfix/double_notifications

Protect from notifications that may be handled twice
This commit is contained in:
Ori Kotek
2023-07-06 18:17:13 +03:00
committed by GitHub
5 changed files with 25 additions and 15 deletions

View File

@ -14,7 +14,7 @@ from pr_agent.git_providers import get_git_provider
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.main_language = self.git_provider.get_main_pr_language()
@ -22,6 +22,7 @@ class PRReviewer:
self.ai_handler = AiHandler()
self.patches_diff = None
self.prediction = None
self.cli_mode = cli_mode
self.vars = {
"title": self.git_provider.pr.title,
"branch": self.git_provider.get_pr_branch(),
@ -91,16 +92,19 @@ class PRReviewer:
markdown_text = convert_to_markdown(data)
user = self.git_provider.get_user_id()
markdown_text += "\n### How to use\n"
if user and '[bot]' not in user:
markdown_text += f"> Tag me in a comment '@{user}' to ask for a new review after you update the PR.\n"
markdown_text += "> You can also tag me and ask any question, " \
f"for example '@{user} is the PR ready for merge?'"
else:
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 not self.cli_mode:
markdown_text += "\n### How to use\n"
if user and '[bot]' not in user:
markdown_text += "\n### How to use\n"
markdown_text += f"> Tag me in a comment '@{user}' to ask for a new review after you update the PR.\n"
markdown_text += "> You can also tag me and ask any question, " \
f"for example '@{user} is the PR ready for merge?'"
else:
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:
logging.info(f"Markdown response:\n{markdown_text}")