fix(bridge): ignore pre-start trigger comments
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
autonomic-bot
2026-06-13 00:27:22 +00:00
parent ddefc96eef
commit 23f1861b7a
4 changed files with 91 additions and 5 deletions

View File

@ -37,6 +37,7 @@ import time
import urllib.error
import urllib.parse
import urllib.request
from datetime import datetime, timezone
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
GITEA_API = os.environ.get("GITEA_API", "https://git.autonomic.zone/api/v1")
@ -81,6 +82,7 @@ GITEA_TOKEN = _read(os.environ["GITEA_TOKEN_FILE"])
# Shared dedup across the poll + webhook paths: a comment id triggers at most one run.
_PROCESSED: set = set()
_PROCESSED_LOCK = threading.Lock()
_PROCESS_STARTED_AT = datetime.now(timezone.utc)
def log(*a):
@ -277,6 +279,23 @@ def _claim(comment_id) -> bool:
return True
def _is_preexisting_comment(comment) -> bool:
"""Treat trigger comments older than this bridge process as already-seen.
This closes the reopened-PR hole where a PR was CLOSED during bridge startup, so its old
`!testme` comments were never marked seen by the first poll pass; when that PR is later reopened,
the poller must not replay those historical comments as fresh triggers.
"""
created = (comment or {}).get("created_at")
if not created:
return False
try:
created_at = datetime.fromisoformat(created.replace("Z", "+00:00"))
except ValueError:
return False
return created_at <= _PROCESS_STARTED_AT
def process_testme(full_name, owner, name, number, user, comment_id, source, quick=False):
"""Shared by both paths. Dedupes by comment id, checks authorization, resolves the PR head,
triggers the build, comments the run link. Returns (run_url|None, reason)."""
@ -389,7 +408,7 @@ def poll_loop():
if not is_trigger:
continue
cid = c.get("id")
if first:
if first or _is_preexisting_comment(c):
_claim(cid) # mark pre-existing comments seen; don't fire on startup
continue
user = (c.get("user") or {}).get("login", "")