From 508d97b7ded90200fba3fd3a2f26113a73d84029 Mon Sep 17 00:00:00 2001 From: Dan Fuller Date: Mon, 21 Sep 2026 17:00:13 -0700 Subject: [PATCH] feat(cursor-origin): Track pushes to a pull request's branches --- .../integrations/cursor_origin/webhook.py | 2 ++ .../cursor_origin/test_pull_request.py | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/sentry/integrations/cursor_origin/webhook.py b/src/sentry/integrations/cursor_origin/webhook.py index 23f96863736b..db7525eb70ad 100644 --- a/src/sentry/integrations/cursor_origin/webhook.py +++ b/src/sentry/integrations/cursor_origin/webhook.py @@ -147,8 +147,10 @@ def verify_delivery(request: HttpRequest, body: bytes) -> Verification: "installation.suspended": InstallationRemovedHandler, "installation.unsuspended": InstallationRestoredHandler, "installation.updated": InstallationUpdatedHandler, + "pull_request.base_ref.updated": PullRequestLifecycleHandler, "pull_request.closed": PullRequestLifecycleHandler, "pull_request.created": PullRequestLifecycleHandler, + "pull_request.head_ref.pushed": PullRequestLifecycleHandler, "pull_request.merged": PullRequestLifecycleHandler, "pull_request.metadata.updated": PullRequestLifecycleHandler, "pull_request.published": PullRequestLifecycleHandler, diff --git a/tests/sentry/integrations/cursor_origin/test_pull_request.py b/tests/sentry/integrations/cursor_origin/test_pull_request.py index 4c788baf828b..ccc749fe1ddf 100644 --- a/tests/sentry/integrations/cursor_origin/test_pull_request.py +++ b/tests/sentry/integrations/cursor_origin/test_pull_request.py @@ -6,6 +6,7 @@ from sentry.constants import ObjectStatus from sentry.integrations.cursor_origin.pull_request import PullRequestLifecycleHandler +from sentry.integrations.cursor_origin.webhook import HANDLERS from sentry.integrations.cursor_origin.webhook_types import OriginPayloadError, PullRequestEvent from sentry.integrations.services.integration import integration_service from sentry.models.pullrequest import PullRequest, PullRequestLifecycleState @@ -127,6 +128,34 @@ def test_a_later_event_updates_the_same_row(self) -> None: assert len(pull_requests) == 1 assert pull_requests[0].title == "Add launch telemetry, take two" + def test_a_push_to_the_head_branch_moves_the_head_commit(self) -> None: + """`head_ref.pushed` carries the same snapshot, with the new tip.""" + self._handle(_payload()) + self._handle( + _payload( + head={"ref": "add-telemetry", "sha": "c0ffee00"}, updatedAt="2026-08-01T11:00:00Z" + ) + ) + + assert self._pull_requests()[0].head_commit_sha == "c0ffee00" + + def test_every_lifecycle_event_is_routed_to_the_handler(self) -> None: + """Origin sends the whole pull request with each of these, so one handler serves all.""" + routed = sorted( + event for event, handler in HANDLERS.items() if handler is PullRequestLifecycleHandler + ) + + assert routed == [ + "pull_request.base_ref.updated", + "pull_request.closed", + "pull_request.created", + "pull_request.head_ref.pushed", + "pull_request.merged", + "pull_request.metadata.updated", + "pull_request.published", + "pull_request.reopened", + ] + def test_a_stale_snapshot_is_dropped(self) -> None: """Deliveries can arrive out of order, so the shared upsert compares timestamps.""" self._handle(