From a1bd02fdfd665eabc47f61fc2058c9503cc58a84 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 20 Apr 2026 13:54:24 +0100 Subject: [PATCH] refactor: share human list formatting --- src/infra/approval-native-route-notice.ts | 14 +------------- src/infra/exec-approval-reply.ts | 14 +------------- src/shared/human-list.ts | 12 ++++++++++++ 3 files changed, 14 insertions(+), 26 deletions(-) create mode 100644 src/shared/human-list.ts diff --git a/src/infra/approval-native-route-notice.ts b/src/infra/approval-native-route-notice.ts index 62b56220be8..2d9ffc1cc5e 100644 --- a/src/infra/approval-native-route-notice.ts +++ b/src/infra/approval-native-route-notice.ts @@ -1,18 +1,6 @@ +import { formatHumanList } from "../shared/human-list.js"; import type { ChannelApprovalNativePlannedTarget } from "./approval-native-delivery.js"; -function formatHumanList(values: readonly string[]): string { - if (values.length === 0) { - return ""; - } - if (values.length === 1) { - return values[0]; - } - if (values.length === 2) { - return `${values[0]} or ${values[1]}`; - } - return `${values.slice(0, -1).join(", ")}, or ${values.at(-1)}`; -} - export function describeApprovalDeliveryDestination(params: { channelLabel: string; deliveredTargets: readonly ChannelApprovalNativePlannedTarget[]; diff --git a/src/infra/exec-approval-reply.ts b/src/infra/exec-approval-reply.ts index 928f072fecd..2322ee74ee9 100644 --- a/src/infra/exec-approval-reply.ts +++ b/src/infra/exec-approval-reply.ts @@ -1,5 +1,6 @@ import type { ReplyPayload } from "../auto-reply/types.js"; import type { InteractiveReply, InteractiveReplyButton } from "../interactive/payload.js"; +import { formatHumanList } from "../shared/human-list.js"; import { normalizeOptionalLowercaseString, normalizeOptionalString, @@ -63,19 +64,6 @@ export type ExecApprovalUnavailableReplyParams = { sentApproverDms?: boolean; }; -function formatHumanList(values: readonly string[]): string { - if (values.length === 0) { - return ""; - } - if (values.length === 1) { - return values[0]; - } - if (values.length === 2) { - return `${values[0]} or ${values[1]}`; - } - return `${values.slice(0, -1).join(", ")}, or ${values.at(-1)}`; -} - function resolveNativeExecApprovalClientList(params?: { excludeChannel?: string }): string { return formatHumanList( listNativeExecApprovalClientLabels({ diff --git a/src/shared/human-list.ts b/src/shared/human-list.ts new file mode 100644 index 00000000000..8f1e8d4ddcd --- /dev/null +++ b/src/shared/human-list.ts @@ -0,0 +1,12 @@ +export function formatHumanList(values: readonly string[]): string { + if (values.length === 0) { + return ""; + } + if (values.length === 1) { + return values[0]; + } + if (values.length === 2) { + return `${values[0]} or ${values[1]}`; + } + return `${values.slice(0, -1).join(", ")}, or ${values.at(-1)}`; +}