Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/sentry/sentry_apps/tasks/sentry_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,10 +786,16 @@ def send_webhooks(installation: RpcSentryAppInstallation, event: str, **kwargs:
def create_or_update_service_hooks_for_sentry_app(
sentry_app_id: int, webhook_url: str, events: list[str], **kwargs: dict
) -> None:
installations = SentryAppInstallation.objects.filter(sentry_app_id=sentry_app_id)
for installation in installations:
create_or_update_service_hooks_for_installation(
installation=installation,
events=events,
webhook_url=webhook_url,
)
with SentryAppInteractionEvent(
operation_type=SentryAppInteractionType.MANAGEMENT,
event_type=SentryAppEventType.WEBHOOK_UPDATE,
).capture() as lifecycle:
lifecycle.add_extras({"sentry_app_id": sentry_app_id, "events": events})
installations = SentryAppInstallation.objects.filter(sentry_app_id=sentry_app_id)

for installation in installations:
create_or_update_service_hooks_for_installation(
installation=installation,
events=events,
webhook_url=webhook_url,
)
14 changes: 13 additions & 1 deletion tests/sentry/sentry_apps/test_sentry_app_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ def test_doesnt_update_status_if_not_superuser(self):
self.updater.run(self.user)
assert self.sentry_app.status == SentryAppStatus.UNPUBLISHED

def test_create_service_hook_on_update(self):
@patch("sentry.integrations.utils.metrics.EventLifecycle.record_event")
def test_create_service_hook_on_update(self, mock_record):
self.create_project(organization=self.org)
internal_app = self.create_internal_integration(
name="Internal", organization=self.org, webhook_url=None, scopes=("event:read",)
Expand All @@ -229,6 +230,17 @@ def test_create_service_hook_on_update(self):
assert service_hook.url == "https://sentry.io/hook"
assert service_hook.events == expand_events(["issue"])

# SLO assertions
assert_success_metric(mock_record=mock_record)

# APP_CREATE (success) -> WEBHOOK_UPDATE (success)
assert_count_of_metric(
mock_record=mock_record, outcome=EventLifecycleOutcome.STARTED, outcome_count=2
)
assert_count_of_metric(
mock_record=mock_record, outcome=EventLifecycleOutcome.SUCCESS, outcome_count=2
)

def test_delete_service_hook_on_update(self):
self.create_project(organization=self.org)
internal_app = self.create_internal_integration(
Expand Down
Loading