From 880618b99789097c1b05c75a86d443f12c1c9332 Mon Sep 17 00:00:00 2001 From: Richard Hallows Date: Sun, 12 Jan 2025 11:58:14 +0000 Subject: [PATCH] Fix rewrite for entries with a summary (#58) --- dist/index.js | 10 ++++++---- src/__tests__/changelogToGithubRelease.test.js | 14 ++++++++++++++ src/changelogToGithubRelease.js | 10 ++++++---- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/dist/index.js b/dist/index.js index e9c49d6..d102960 100644 --- a/dist/index.js +++ b/dist/index.js @@ -50338,10 +50338,12 @@ function extractChangeItems({ version }) { parent && index !== undefined ) { - const nextSibling = parent.children[index + 1]; - if (nextSibling?.type === 'list') { - list = nextSibling; - return EXIT; + const nextSiblings = parent.children.slice(index + 1); + for (const sibling of nextSiblings) { + if (sibling.type === 'list') { + list = sibling; + return EXIT; + } } } return CONTINUE; diff --git a/src/__tests__/changelogToGithubRelease.test.js b/src/__tests__/changelogToGithubRelease.test.js index 1180307..88c7488 100644 --- a/src/__tests__/changelogToGithubRelease.test.js +++ b/src/__tests__/changelogToGithubRelease.test.js @@ -6,6 +6,15 @@ import { changelogToGithubRelease } from '../changelogToGithubRelease.js'; const changelog = ` # Changelog +## 16.13.0 - 2025-01-12 + +Summary. + +Summary 2. + +- fff [#123](https://github.com/foo/bar/pull/123) ([@user](https://github.com/user)). +- ggg. + ## 1.2.0 - reference-style link [#456][] ([@user1]). @@ -29,6 +38,11 @@ test('rewrite change items including reference links', { only: true }, async () assert.equal(result, '* reference-style link #456 (@user1).\n'); }); +test('rewrite change items for version with date in heading and a summary', async () => { + const result = await changelogToGithubRelease(changelog, '16.13.0'); + assert.equal(result, '* fff #123 (@user).\n* ggg.\n'); +}); + test('rewrite change items for version with date in heading', async () => { const result = await changelogToGithubRelease(changelog, '1.1.0'); assert.equal(result, '* ddd #123 (@user).\n* eee.\n'); diff --git a/src/changelogToGithubRelease.js b/src/changelogToGithubRelease.js index bfe354d..33121c7 100644 --- a/src/changelogToGithubRelease.js +++ b/src/changelogToGithubRelease.js @@ -18,10 +18,12 @@ function extractChangeItems({ version }) { parent && index !== undefined ) { - const nextSibling = parent.children[index + 1]; - if (nextSibling?.type === 'list') { - list = nextSibling; - return EXIT; + const nextSiblings = parent.children.slice(index + 1); + for (const sibling of nextSiblings) { + if (sibling.type === 'list') { + list = sibling; + return EXIT; + } } } return CONTINUE;