Skip to content

Commit b8ee3cb

Browse files
grichaclaude
andcommitted
feat(hybridcloud): Propagate ViewerContext in VSTS webhook
Wrap the per-org iteration in handle_status_change with webhook_viewer_context so downstream code has access to the current organization identity via the ViewerContext contextvar. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1de477a commit b8ee3cb

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

src/sentry/integrations/vsts/webhooks.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from sentry.integrations.types import IntegrationProviderSlug
2525
from sentry.integrations.utils.metrics import IntegrationWebhookEvent, IntegrationWebhookEventType
2626
from sentry.integrations.utils.sync import sync_group_assignee_inbound
27+
from sentry.integrations.utils.webhook_viewer_context import webhook_viewer_context
2728
from sentry.ratelimits.config import RateLimitConfig
2829
from sentry.types.ratelimit import RateLimit, RateLimitCategory
2930
from sentry.utils.email import parse_email
@@ -173,24 +174,25 @@ def handle_status_change(
173174
"status_change": status_change,
174175
}
175176
for org_integration in org_integrations:
176-
installation = integration.get_installation(
177-
organization_id=org_integration.organization_id
178-
)
179-
if isinstance(installation, IssueSyncIntegration):
180-
installation.sync_status_inbound(
181-
external_issue_key,
182-
{
183-
"new_state": status_change["newValue"],
184-
# old_state is None when the issue is New
185-
"old_state": status_change.get("oldValue"),
186-
"project": project,
187-
},
188-
)
189-
else:
190-
lifecycle.record_halt(
191-
ProjectManagementHaltReason.SYNC_NON_SYNC_INTEGRATION_PROVIDED,
192-
extra=logging_context,
177+
with webhook_viewer_context(org_integration.organization_id):
178+
installation = integration.get_installation(
179+
organization_id=org_integration.organization_id
193180
)
181+
if isinstance(installation, IssueSyncIntegration):
182+
installation.sync_status_inbound(
183+
external_issue_key,
184+
{
185+
"new_state": status_change["newValue"],
186+
# old_state is None when the issue is New
187+
"old_state": status_change.get("oldValue"),
188+
"project": project,
189+
},
190+
)
191+
else:
192+
lifecycle.record_halt(
193+
ProjectManagementHaltReason.SYNC_NON_SYNC_INTEGRATION_PROVIDED,
194+
extra=logging_context,
195+
)
194196

195197

196198
def handle_updated_workitem(data: Mapping[str, Any], integration: RpcIntegration) -> None:

0 commit comments

Comments
 (0)