refactor(alerts): extract notification transport into notifications.ts - #2844
refactor(alerts): extract notification transport into notifications.ts#2844jordan-simonovski wants to merge 1 commit into
Conversation
template.ts mixed Handlebars templating with the HTTP transport for Slack/generic/incident.io webhooks. Move the transport (notifyChannel, handleSendSlackWebhook, handleSendGenericWebhook, sendGenericWebhook, delivery metrics) into tasks/checkAlerts/notifications.ts unchanged, so the upcoming multi-channel dispatch work lands in a focused module.
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🔴 Tier 4 — CriticalTouches authentication, tenancy data models, the public API or shipped database config — or substantially changes background tasks, the OTel pipeline, image build, or release CI. Why this tier:
Review process: Deep review from a domain expert. Synchronous walkthrough may be required. Stats
|
Greptile SummaryThe PR extracts alert webhook delivery from the template module into a dedicated notifications module while preserving the existing behavior and compatibility re-export.
Confidence Score: 5/5The PR appears safe to merge because the extraction preserves the notification call paths, compatibility export, validation, retry, and delivery behavior. The moved webhook implementation remains unchanged, all identified consumers resolve the handlers through valid paths, and the new module does not introduce a concrete initialization or runtime failure.
|
| Filename | Overview |
|---|---|
| packages/api/src/tasks/checkAlerts/notifications.ts | Introduces the dedicated notification transport module using the webhook-delivery implementation extracted from template.ts. |
| packages/api/src/tasks/checkAlerts/template.ts | Removes transport responsibilities and imports the extracted message, helper, and dispatch APIs without changing template behavior. |
| packages/api/src/tasks/checkAlerts/index.ts | Imports the generic webhook handler from its new module while preserving the existing compatibility export. |
| packages/api/src/routers/api/webhooks.ts | Repoints webhook test-delivery handlers to the new notifications module. |
| packages/api/src/routers/api/tests/webhooks.int.test.ts | Repoints webhook-handler spies to the module that now owns those functions. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
AlertTask[Alert evaluation task] --> Template[template.ts: render alert message]
Template --> Notifications[notifications.ts: notifyChannel]
Notifications --> Slack[Slack webhook transport]
Notifications --> Generic[Generic / Incident.io transport]
WebhooksRouter[Webhooks API router] --> Notifications
Reviews (1): Last reviewed commit: "refactor(alerts): extract notification t..." | Re-trigger Greptile
Deep ReviewThis PR moves the webhook notification transport out of ✅ No critical issues found. No P2 issues found. The delivery metrics, retry/redirect-SSRF handling, 🔵 P3 nitpicks (1)
Reviewers (2 of 8 completed at synthesis time): project-standards, reliability. Findings above also reflect orchestrator-level verification of the diff (stale-import grep, re-export preservation, spy-path repointing, byte-identical body diff). The correctness, testing, maintainability, kieran-typescript, security, and api-contract reviewers were dispatched but had not returned when output was required. Testing gaps: none — |
E2E Test Results✅ All tests passed • 276 passed • 1 skipped • 889s
Tests ran across 4 shards in parallel. |
Moves the webhook transport out of
template.tsinto a newtasks/checkAlerts/notifications.ts. Nothing changes at runtime; this is the groundwork for multi-channel alert dispatch, which needs the transport in a module of its own.What changed
template.tswas doing two jobs: building the Handlebars message and performing the HTTP send. The send half —notifyChannel,handleSendSlackWebhook,handleSendGenericWebhook,sendGenericWebhook, and the delivery metrics — now lives innotifications.ts.createHandlebarsWithHelpersmoved with it and is re-exported, sincetemplate.tsstill uses it.Callers were repointed: the alerts task, the webhooks router, and the spy sites in the webhook integration test.
Impact
None. The function bodies moved unchanged, and the
handleSendGenericWebhookre-export fromcheckAlerts/index.tsis preserved because tests spy through it.No changeset: no behaviour change and nothing user-facing.
Implementation detail
The move was verified mechanically rather than by eye — the extracted bodies were diffed against their originals on
mainand are identical apart from addedexportkeywords.notifications.tsimports nothing fromtemplate.tsorcheckAlerts/index.ts, so the pre-existingtemplate <-> indexcycle is unchanged and no new one is introduced.Verification:
tsc --noEmitclean, 268 alert integration tests and 64 webhook integration tests pass with no expectation changes beyond import and spy paths.