Skip to content

Commit 49c74de

Browse files
committed
refactor(release): extract shared fmtPct/fmtCount to format.ts
Address Cursor Bugbot review — deduplicate the percentage and count formatting helpers into a shared module imported by both list and view.
1 parent e8264ea commit 49c74de

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

src/commands/release/format.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Shared formatting utilities for release commands.
3+
*
4+
* Small helpers used by both `list.ts` and `view.ts` to format
5+
* health/adoption metrics consistently.
6+
*/
7+
8+
/**
9+
* Format a percentage value with one decimal place, or "—" when absent.
10+
*
11+
* @example fmtPct(42.3) // "42.3%"
12+
* @example fmtPct(null) // "—"
13+
*/
14+
export function fmtPct(value: number | null | undefined): string {
15+
if (value === null || value === undefined) {
16+
return "—";
17+
}
18+
return `${value.toFixed(1)}%`;
19+
}
20+
21+
/**
22+
* Format an integer count with thousands separators, or "—" when absent.
23+
*
24+
* @example fmtCount(52000) // "52,000"
25+
* @example fmtCount(null) // "—"
26+
*/
27+
export function fmtCount(value: number | null | undefined): string {
28+
if (value === null || value === undefined) {
29+
return "—";
30+
}
31+
return value.toLocaleString("en-US");
32+
}

src/commands/release/list.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
type OrgListCommandDocs,
1616
} from "../../lib/list-command.js";
1717
import type { OrgListConfig } from "../../lib/org-list.js";
18+
import { fmtPct } from "./format.js";
1819

1920
export const PAGINATION_KEY = "release-list";
2021

@@ -30,14 +31,6 @@ function getHealthData(release: OrgReleaseResponse) {
3031
return release.projects?.find((p) => p.healthData?.hasHealthData)?.healthData;
3132
}
3233

33-
/** Format a percentage value with one decimal, or "—" when absent. */
34-
function fmtPct(value: number | null | undefined): string {
35-
if (value === null || value === undefined) {
36-
return "—";
37-
}
38-
return `${value.toFixed(1)}%`;
39-
}
40-
4134
const RELEASE_COLUMNS: Column<ReleaseWithOrg>[] = [
4235
{ header: "ORG", value: (r) => r.orgSlug || "" },
4336
{

src/commands/release/view.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,9 @@ import {
2727
FRESH_FLAG,
2828
} from "../../lib/list-command.js";
2929
import { resolveOrg } from "../../lib/resolve-target.js";
30+
import { fmtCount, fmtPct } from "./format.js";
3031
import { parseReleaseArg } from "./parse.js";
3132

32-
/** Format a percentage with one decimal, colorized by threshold. */
33-
function fmtPct(value: number | null | undefined): string {
34-
if (value === null || value === undefined) {
35-
return "—";
36-
}
37-
return `${value.toFixed(1)}%`;
38-
}
39-
4033
/** Format a crash-free rate with color coding (green ≥ 99, yellow ≥ 95, red < 95). */
4134
function fmtCrashFree(value: number | null | undefined): string {
4235
if (value === null || value === undefined) {
@@ -52,14 +45,6 @@ function fmtCrashFree(value: number | null | undefined): string {
5245
return colorTag("red", formatted);
5346
}
5447

55-
/** Format a count with thousands separators, or "—" when absent. */
56-
function fmtCount(value: number | null | undefined): string {
57-
if (value === null || value === undefined) {
58-
return "—";
59-
}
60-
return value.toLocaleString("en-US");
61-
}
62-
6348
/**
6449
* Build a markdown table of per-project health data.
6550
*

0 commit comments

Comments
 (0)