Protect from notifications that may be handled twice by keeping a set of handled notification IDs

This commit is contained in:
Ori Kotek
2023-07-06 17:46:43 +03:00
parent 399d7b7990
commit 6648c04799
3 changed files with 8 additions and 2 deletions

View File

@ -1 +1,2 @@
venv/ venv/
pr_agent/settings/.secrets.toml

View File

@ -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"
]] ]]
) )

View File

@ -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']