diff --git a/src/bot/lib/changelogRender.ts b/src/bot/lib/changelogRender.ts index b7b49a6d..f1cd18a5 100644 --- a/src/bot/lib/changelogRender.ts +++ b/src/bot/lib/changelogRender.ts @@ -284,14 +284,33 @@ export function resolveChangelogRange( if (!from && !to) return { found: false, versions: [], messages: [] }; - const idxFrom = from ? entries.findIndex((entry) => entry.version === from) : 0; - const idxTo = to ? entries.findIndex((entry) => entry.version === to) : entries.length - 1; - if (idxFrom === -1 || idxTo === -1) { - return { found: false, versions: [], messages: [] }; + const indexOf = (version: string): number => + entries.findIndex((entry) => entry.version === version); + + // The file is newest-first, so a LOWER index is a NEWER version. "from.." opens + // toward the newest (index 0); "..to" opens toward the oldest (the last index). + let start: number; + let end: number; + if (from && to) { + const a = indexOf(from); + const b = indexOf(to); + if (a === -1 || b === -1) return { found: false, versions: [], messages: [] }; + start = Math.min(a, b); + end = Math.max(a, b); + } else if (from) { + // "a.." = a and everything newer, up to the newest entry. + const a = indexOf(from); + if (a === -1) return { found: false, versions: [], messages: [] }; + start = 0; + end = a; + } else { + // "..b" = the oldest entry through b. + const b = indexOf(to as string); + if (b === -1) return { found: false, versions: [], messages: [] }; + start = b; + end = entries.length - 1; } - const start = Math.min(idxFrom, idxTo); - const end = Math.max(idxFrom, idxTo); const slice = entries .slice(start, end + 1) .sort((a, b) => compareVersions(a.version, b.version)); diff --git a/tests/int/changelog.int.spec.ts b/tests/int/changelog.int.spec.ts index ba1820ac..ca17be3d 100644 --- a/tests/int/changelog.int.spec.ts +++ b/tests/int/changelog.int.spec.ts @@ -96,14 +96,14 @@ describe("resolveChangelogRange", () => { expect(batch.messages).toHaveLength(3); }); - it("opens the top end (from here to the latest)", () => { + it("opens the top end: 'X..' is X and everything newer", () => { const batch = resolveChangelogRange(DESC_CONTENT, "0.3.0", undefined); - expect(batch.versions).toEqual(["0.1.0", "0.2.0", "0.3.0"]); + expect(batch.versions).toEqual(["0.3.0", "0.4.0", "0.5.0"]); }); - it("opens the bottom end (from the oldest to here)", () => { + it("opens the bottom end: '..X' is the oldest through X", () => { const batch = resolveChangelogRange(DESC_CONTENT, undefined, "0.4.0"); - expect(batch.versions).toEqual(["0.4.0", "0.5.0"]); + expect(batch.versions).toEqual(["0.1.0", "0.2.0", "0.3.0", "0.4.0"]); }); it("normalizes a reversed range", () => { @@ -260,4 +260,14 @@ describe("real CHANGELOG.md", () => { messages.forEach((message) => expect(message.length).toBeLessThanOrEqual(4000)); }); }); + + it("treats 'X..' as X and newer on the shipped file (reported bug)", () => { + const content = readFileSync(CHANGELOG_PATH, "utf8"); + const newest = parseChangelog(content)[0].version; + const batch = resolveChangelogRange(content, "0.6.0", undefined); + expect(batch.found).toBe(true); + expect(batch.versions[0]).toBe("0.6.0"); + expect(batch.versions[batch.versions.length - 1]).toBe(newest); + expect(batch.versions.every((version) => compareVersions(version, "0.6.0") >= 0)).toBe(true); + }); });