diff --git a/src/utils/__tests__/changelog.test.ts b/src/utils/__tests__/changelog.test.ts index fa384edf..3688c124 100644 --- a/src/utils/__tests__/changelog.test.ts +++ b/src/utils/__tests__/changelog.test.ts @@ -411,6 +411,12 @@ describe('generateChangesetFromGit', () => { body: '', pr: { remote: { number: '456', author: { login: 'bob' } } }, }, + { + hash: 'cdef1234567890ad', + title: 'Refactored the crankshaft again', + body: '', + pr: { remote: { number: '458', author: { login: 'bob' } } }, + }, ], {}, [ @@ -419,6 +425,8 @@ describe('generateChangesetFromGit', () => { '- Upgraded the kernel (abcdef12)', '- Upgraded the manifold (#123) by @alice', '- Refactored the crankshaft (#456) by @bob', + '', + '_Plus 1 more_', ].join('\n'), ], [ @@ -706,7 +714,7 @@ describe('generateChangesetFromGit', () => { output: string ) => { setup(commits, milestones); - const changes = await generateChangesetFromGit(dummyGit, '1.0.0'); + const changes = await generateChangesetFromGit(dummyGit, '1.0.0', 3); expect(changes).toBe(output); } ); diff --git a/src/utils/changelog.ts b/src/utils/changelog.ts index 874efacd..0192886c 100644 --- a/src/utils/changelog.ts +++ b/src/utils/changelog.ts @@ -16,6 +16,7 @@ const DEFAULT_CHANGESET_BODY = '- No documented changes.'; const VERSION_HEADER_LEVEL = 2; const SUBSECTION_HEADER_LEVEL = VERSION_HEADER_LEVEL + 1; const MAX_COMMITS_PER_QUERY = 50; +const MAX_LEFTOVERS = 24; // Ensure subsections are nested under version headers otherwise we won't be // able to find them and put on GitHub releases. @@ -246,7 +247,8 @@ function formatCommit(commit: Commit): string { export async function generateChangesetFromGit( git: SimpleGit, - rev: string + rev: string, + maxLeftovers: number = MAX_LEFTOVERS ): Promise { const gitCommits = (await getChangesSince(git, rev)).filter( ({ body }) => !body.includes(SKIP_CHANGELOG_MAGIC_WORD) @@ -336,11 +338,17 @@ export async function generateChangesetFromGit( ); } - if (leftovers.length > 0) { + const nLeftovers = leftovers.length; + if (nLeftovers > 0) { changelogSections.push( markdownHeader(SUBSECTION_HEADER_LEVEL, 'Various fixes & improvements') ); - changelogSections.push(leftovers.map(formatCommit).join('\n')); + changelogSections.push( + leftovers.slice(0, maxLeftovers).map(formatCommit).join('\n') + ); + if (nLeftovers > maxLeftovers) { + changelogSections.push(`_Plus ${nLeftovers - maxLeftovers} more_`); + } } return changelogSections.join('\n\n');