diff --git a/src/postGithubIssue.ts b/src/postGithubIssue.ts index 7f783ac..401aca2 100644 --- a/src/postGithubIssue.ts +++ b/src/postGithubIssue.ts @@ -3,6 +3,7 @@ import * as path from "node:path"; import { artifactFolderUrlPlaceholder, getArtifactsApiUrlPlaceholder, type Metadata, metadataFileName, type RepoStatus, resultFileNameSuffix, type StatusCounts, type TsEntrypoint } from "./main.js"; import * as git from "./utils/gitUtils.js"; import * as pu from "./utils/packageUtils.js"; +import { formatVersionComparison } from "./utils/markdownUtils.js"; const { argv } = process; @@ -47,7 +48,7 @@ for (const path of metadataFilePaths) { } -const title = `${entrypoint === "tsserver" || entrypoint === "fuzzer" ? `[ServerErrors][${language}]` : `[NewErrors]`} ${newTscResolvedVersion} vs ${oldTscResolvedVersion}`; +const title = `${entrypoint === "tsserver" || entrypoint === "fuzzer" ? `[ServerErrors][${language}]` : `[NewErrors]`} ${formatVersionComparison(newTscResolvedVersion ?? "", oldTscResolvedVersion)}`; const description = entrypoint === "tsserver" ? `The following errors were reported by ${newTscResolvedVersion} vs ${oldTscResolvedVersion}` diff --git a/src/utils/markdownUtils.ts b/src/utils/markdownUtils.ts index 9baa508..61eddab 100644 --- a/src/utils/markdownUtils.ts +++ b/src/utils/markdownUtils.ts @@ -14,3 +14,7 @@ export function formatPrComparison(oldVersion: string | undefined, newVersion: s } return `${asMarkdownInlineCode(oldVersion ?? "old")} and ${asMarkdownInlineCode(newVersion ?? "new")}`; } + +export function formatVersionComparison(newVersion: string, oldVersion: string | undefined): string { + return oldVersion ? `${newVersion} vs ${oldVersion}` : newVersion; +} diff --git a/test/main.test.ts b/test/main.test.ts index a2a5838..9d985ea 100644 --- a/test/main.test.ts +++ b/test/main.test.ts @@ -2,7 +2,7 @@ import { detectTypeScriptImplementation, detectTypeScriptNpmImplementation, down import * as path from "node:path" import { execFileAsync } from '../src/utils/execUtils.js'; import type { SpawnResult } from '../src/utils/execUtils.js'; -import { formatPrComparison } from '../src/utils/markdownUtils.js'; +import { formatPrComparison, formatVersionComparison } from '../src/utils/markdownUtils.js'; import { describe, expect, it, vi } from "vitest"; const testState = vi.hoisted(() => ({ @@ -116,6 +116,12 @@ describe("main", () => { .toBe("`792ffccb90f548cd3bdd7fc0b44f0ca9e1b169a7` and `refs/pull/64558/merge`"); }); + it("omits the comparison when there is no baseline version", () => { + expect(formatVersionComparison("main", undefined)).toBe("main"); + expect(formatVersionComparison("main", "")).toBe("main"); + expect(formatVersionComparison("7.0.0", "6.0.0")).toBe("7.0.0 vs 6.0.0"); + }); + it("detects tsgo from the root package name", () => { expect(detectTypeScriptImplementation({ name: "typescript" })).toBe("strada"); expect(detectTypeScriptImplementation({ name: "typescript-go" })).toBe("corsa");