Skip to content

Commit 58b766d

Browse files
betegonclaude
andauthored
feat(init): add detect-sentry local-op for cross-language Sentry detection (#657)
## Summary Adds a `detect-sentry` local-op so the server can delegate Sentry detection to the CLI's existing `detectDsn()` instead of doing its own JS-only file scanning. This is the CLI-side half of the fix for getsentry/cli-init-api#30 — the server-side PR will simplify `check-existing-sentry` to use this new operation. ## Changes New `DetectSentryPayload` type and `detectSentry()` handler in the local-ops dispatcher. The handler calls the existing DSN detector which already scans source code, .env files, and env vars across all 140+ supported platforms. Returns `{ status: "installed", signals: [...], dsn: "..." }` when a DSN is found, or `{ status: "none", signals: [] }` otherwise. ## Test plan - Existing local-ops tests pass (51/51) - Server-side PR (getsentry/cli-init-api) has updated tests for the new flow - Manual: `sentry init` in a JS project (regression), then a Python/Go project (new detection) Closes getsentry/cli-init-api#30 --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 915f2bc commit 58b766d

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

src/lib/init/local-ops.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { resolveOrgPrefetched } from "./prefetch.js";
2929
import type {
3030
ApplyPatchsetPayload,
3131
CreateSentryProjectPayload,
32+
DetectSentryPayload,
3233
DirEntry,
3334
FileExistsBatchPayload,
3435
ListDirPayload,
@@ -324,6 +325,8 @@ export async function handleLocalOp(
324325
return await applyPatchset(payload, options.dryRun);
325326
case "create-sentry-project":
326327
return await createSentryProject(payload, options);
328+
case "detect-sentry":
329+
return await detectSentry(payload);
327330
default:
328331
return {
329332
ok: false,
@@ -789,6 +792,26 @@ export async function detectExistingProject(cwd: string): Promise<{
789792
return null;
790793
}
791794

795+
async function detectSentry(
796+
payload: DetectSentryPayload
797+
): Promise<LocalOpResult> {
798+
const { detectDsn } = await import("../dsn/index.js");
799+
const dsn = await detectDsn(payload.cwd);
800+
801+
if (!dsn) {
802+
return { ok: true, data: { status: "none", signals: [] } };
803+
}
804+
805+
const signals = [
806+
`dsn: ${dsn.source}${dsn.sourcePath ? ` (${dsn.sourcePath})` : ""}`,
807+
];
808+
809+
return {
810+
ok: true,
811+
data: { status: "installed", signals, dsn: dsn.raw },
812+
};
813+
}
814+
792815
async function createSentryProject(
793816
payload: CreateSentryProjectPayload,
794817
options: WizardOptions

src/lib/init/types.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export type LocalOpPayload =
2525
| FileExistsBatchPayload
2626
| RunCommandsPayload
2727
| ApplyPatchsetPayload
28-
| CreateSentryProjectPayload;
28+
| CreateSentryProjectPayload
29+
| DetectSentryPayload;
2930

3031
export type ListDirPayload = {
3132
type: "local-op";
@@ -91,6 +92,15 @@ export type CreateSentryProjectPayload = {
9192
};
9293
};
9394

95+
export type DetectSentryPayload = {
96+
type: "local-op";
97+
operation: "detect-sentry";
98+
/** Human-readable spinner hint from the server (≤ 120 chars, sensitive values redacted). */
99+
detail?: string;
100+
cwd: string;
101+
params: Record<string, never>;
102+
};
103+
94104
export type LocalOpResult = {
95105
ok: boolean;
96106
error?: string;

src/lib/init/wizard-runner.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ export function describeLocalOp(payload: LocalOpPayload): string {
129129
return "Listing directory...";
130130
case "create-sentry-project":
131131
return `Creating project "${payload.params.name}" (${payload.params.platform})...`;
132+
case "detect-sentry":
133+
return "Checking for existing Sentry setup...";
132134
default:
133135
return `${(payload as { operation: string }).operation}...`;
134136
}

0 commit comments

Comments
 (0)