From 6648c04799a79c2d18df894cdf08c5606b6e8721 Mon Sep 17 00:00:00 2001 From: Ori Kotek Date: Thu, 6 Jul 2023 17:46:43 +0300 Subject: [PATCH] Protect from notifications that may be handled twice by keeping a set of handled notification IDs --- .dockerignore | 3 ++- pr_agent/config_loader.py | 3 ++- pr_agent/servers/github_polling.py | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.dockerignore b/.dockerignore index eba74f4c..9c8ebe57 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,2 @@ -venv/ \ No newline at end of file +venv/ +pr_agent/settings/.secrets.toml \ No newline at end of file diff --git a/pr_agent/config_loader.py b/pr_agent/config_loader.py index 394c877f..24dfdea7 100644 --- a/pr_agent/config_loader.py +++ b/pr_agent/config_loader.py @@ -9,6 +9,7 @@ settings = Dynaconf( "settings/.secrets.toml", "settings/configuration.toml", "settings/pr_reviewer_prompts.toml", - "settings/pr_questions_prompts.toml" + "settings/pr_questions_prompts.toml", + "settings_prod/.secrets.toml" ]] ) diff --git a/pr_agent/servers/github_polling.py b/pr_agent/servers/github_polling.py index e1e6fa84..46adb4f0 100644 --- a/pr_agent/servers/github_polling.py +++ b/pr_agent/servers/github_polling.py @@ -20,6 +20,7 @@ def now() -> str: async def polling_loop(): + handled_ids = set() since = [now()] last_modified = [None] git_provider = get_git_provider()() @@ -54,6 +55,9 @@ async def polling_loop(): since[0] = None notifications = await response.json() 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 'subject' in notification and notification['subject']['type'] == 'PullRequest': pr_url = notification['subject']['url']