Files
simstudioai--sim/apps/sim/lib/webhooks/providers/azure-devops.ts
T
wehub-resource-sync d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:20:55 +08:00

91 lines
2.8 KiB
TypeScript

import { createLogger } from '@sim/logger'
import type {
EventMatchContext,
FormatInputContext,
FormatInputResult,
WebhookProviderHandler,
} from '@/lib/webhooks/providers/types'
import {
AZURE_DEVOPS_BUILD_FAILED_EVENT,
AZURE_DEVOPS_WORK_ITEM_CREATED_EVENT,
formatBuildCompleteInput,
formatWebhookEnvelopeInput,
formatWorkItemCreatedInput,
} from '@/triggers/azure_devops/utils'
const logger = createLogger('WebhookProvider:AzureDevOps')
export const azureDevOpsHandler: WebhookProviderHandler = {
async matchEvent({
body,
requestId,
providerConfig,
webhook,
workflow,
}: EventMatchContext): Promise<boolean> {
const triggerId = providerConfig.triggerId as string | undefined
const b = body as Record<string, unknown>
if (triggerId && triggerId !== 'azure_devops_webhook') {
const { isAzureDevOpsEventMatch } = await import('@/triggers/azure_devops/utils')
if (!isAzureDevOpsEventMatch(triggerId, b)) {
logger.debug(
`[${requestId}] Azure DevOps event mismatch for trigger ${triggerId}. Skipping execution.`,
{
webhookId: webhook.id,
workflowId: workflow.id,
triggerId,
eventType: b.eventType,
}
)
return false
}
}
return true
},
extractIdempotencyId(body: unknown): string | null {
const obj = body as Record<string, unknown> | null
if (!obj) return null
const subscriptionId =
typeof obj.subscriptionId === 'string' && obj.subscriptionId ? obj.subscriptionId : null
const notificationId =
typeof obj.notificationId === 'number' || typeof obj.notificationId === 'string'
? String(obj.notificationId)
: null
if (!subscriptionId || !notificationId) return null
return `azure_devops:${subscriptionId}:${notificationId}`
},
async formatInput({ body, webhook, requestId }: FormatInputContext): Promise<FormatInputResult> {
const b = body as Record<string, unknown>
const providerConfig = (webhook.providerConfig as Record<string, unknown>) || {}
const triggerId = providerConfig.triggerId as string | undefined
const eventType = b.eventType as string | undefined
if (triggerId === 'azure_devops_webhook') {
return { input: formatWebhookEnvelopeInput(b) }
}
if (eventType === AZURE_DEVOPS_BUILD_FAILED_EVENT) {
return { input: formatBuildCompleteInput(b) }
}
if (eventType === AZURE_DEVOPS_WORK_ITEM_CREATED_EVENT) {
return { input: formatWorkItemCreatedInput(b) }
}
logger.warn(`[${requestId}] Azure DevOps: unknown eventType for specialized trigger`, {
triggerId,
eventType,
})
return {
input: null,
skip: {
message: `Unsupported Azure DevOps event type "${eventType ?? 'unknown'}" for trigger ${triggerId ?? 'unknown'}`,
},
}
},
}