Skip to content

Commit 849aad2

Browse files
committed
refactor: use mdKvTable for dry-run output in project create
Standardize dry-run human output to use the same markdown KV table pattern as formatProjectCreated. Uses ## heading, > blockquote notes for team source, and mdKvTable for key-value data. Removes custom manual alignment formatting. Also fixes interleaved imports: DryRunData type and formatDryRun function are now placed after all import statements.
1 parent 1e91caa commit 849aad2

File tree

2 files changed

+40
-15
lines changed

2 files changed

+40
-15
lines changed

src/commands/project/create.ts

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,17 @@ import {
3030
ContextError,
3131
withAuthGuard,
3232
} from "../../lib/errors.js";
33-
import { muted } from "../../lib/formatters/colors.js";
3433
import {
3534
formatProjectCreated,
3635
type ProjectCreatedResult,
3736
} from "../../lib/formatters/human.js";
38-
import { isPlainOutput } from "../../lib/formatters/markdown.js";
37+
import {
38+
escapeMarkdownInline,
39+
isPlainOutput,
40+
mdKvTable,
41+
renderMarkdown,
42+
safeCodeSpan,
43+
} from "../../lib/formatters/markdown.js";
3944
import { writeOutput } from "../../lib/formatters/output.js";
4045
import { buildMarkdownTable, type Column } from "../../lib/formatters/table.js";
4146
import { renderTextTable } from "../../lib/formatters/text-table.js";
@@ -69,19 +74,39 @@ type DryRunData = {
6974
platform: string;
7075
};
7176

72-
/** Format dry-run preview as human-readable text */
77+
/** Format dry-run preview as human-readable markdown */
7378
function formatDryRun(data: DryRunData): string {
7479
const lines: string[] = [];
75-
lines.push(muted("Dry run — no project created."));
80+
81+
lines.push(
82+
`## <muted>Dry run</muted> — project '${escapeMarkdownInline(data.name)}' in ${escapeMarkdownInline(data.organization)}`
83+
);
7684
lines.push("");
77-
lines.push(` Organization: ${data.organization}`);
78-
const teamSuffix =
79-
data.teamSource !== "explicit" ? ` (${data.teamSource})` : "";
80-
lines.push(` Team: ${data.team}${teamSuffix}`);
81-
lines.push(` Name: ${data.name}`);
82-
lines.push(` Slug: ${data.slug}`);
83-
lines.push(` Platform: ${data.platform}`);
84-
return lines.join("\n");
85+
86+
// Team source notes (same pattern as formatProjectCreated)
87+
if (data.teamSource === "auto-created") {
88+
lines.push(
89+
`> **Note:** Would create team '${escapeMarkdownInline(data.team)}' (org has no teams).`
90+
);
91+
lines.push("");
92+
} else if (data.teamSource === "auto-selected") {
93+
lines.push(
94+
`> **Note:** Would use team '${escapeMarkdownInline(data.team)}'. See all teams: \`sentry team list\``
95+
);
96+
lines.push("");
97+
}
98+
99+
const kvRows: [string, string][] = [
100+
["Name", escapeMarkdownInline(data.name)],
101+
["Slug", safeCodeSpan(data.slug)],
102+
["Org", safeCodeSpan(data.organization)],
103+
["Team", safeCodeSpan(data.team)],
104+
["Platform", data.platform],
105+
];
106+
107+
lines.push(mdKvTable(kvRows));
108+
109+
return renderMarkdown(lines.join("\n"));
85110
}
86111

87112
type CreateFlags = {

test/commands/project/create.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -712,8 +712,8 @@ describe("project create", () => {
712712
);
713713

714714
const output = stdoutWrite.mock.calls.map((c) => c[0]).join("");
715-
// Single team = auto-selected
716-
expect(output).toContain("auto-selected");
715+
// Single team = auto-selected → note about team usage
716+
expect(output).toContain("Would use team");
717717
});
718718

719719
test("dry-run with no teams shows auto-created team without creating it", async () => {
@@ -736,6 +736,6 @@ describe("project create", () => {
736736
const output = stdoutWrite.mock.calls.map((c) => c[0]).join("");
737737
expect(output).toContain("Dry run");
738738
expect(output).toContain("my-app");
739-
expect(output).toContain("auto-created");
739+
expect(output).toContain("Would create team");
740740
});
741741
});

0 commit comments

Comments
 (0)