peppa/apps/web/app/api/hooks/bugsink/[secret]/route.ts
Асель 498013472f PEP-58: Bugsink — production errors become Peppa incidents and tasks
- infra: Bugsink 2.6.3 in docker (infra/bugsink, scripts/bugsink-up.sh), database
  bugsink in Peppa's Postgres, Traefik route bugsink.telecom.quest
- packages/bugsink: REST API client + custom-webhook payload parsing
- incidents (migration 0011): incident_settings, error_sources, incidents; ingest from
  webhook POST /api/hooks/bugsink/<secret> and a 2-minute poll in the watchdog
- incident policy per project: notify / backlog (default) / start / ask (Telegram
  buttons) / triage (claude -p with the owner's token, falls back to ask)
- daily task cap, environments, ignore pattern; manual "fixed" until PEP-57;
  REGRESSED returns the task to the backlog
- web «Ошибки» section, bot buttons, MCP tools for agents and the PM, help, RULES.md
- testkit: mock-bugsink, mock-triage, incidents.test.ts (one test per scenario,
  plus a live run against the real Bugsink with PEPPA_LIVE_BUGSINK=1)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 14:31:32 +05:00

16 lines
783 B
TypeScript

import { after } from "next/server";
import { bugsinkFromEnv } from "@peppa/bugsink";
import { processIncidents, receiveBugsinkWebhook } from "@peppa/runner";
import { db } from "@/lib/db";
export const dynamic = "force-dynamic";
/** Bugsink custom-webhook alerts (PEP-58). Unknown secret → 404; the policy runs after the reply. */
export async function POST(req: Request, { params }: { params: Promise<{ secret: string }> }) {
const { secret } = await params;
const body = await req.json().catch(() => null);
const r = await receiveBugsinkWebhook(db, secret, body, bugsinkFromEnv());
if (r.status === 200) after(() => processIncidents(db, { log: (m) => console.error(`[incidents] ${m}`) }).then(() => undefined));
return Response.json(r.body, { status: r.status });
}