Skip to content

Commit

Permalink
Limit the number of leftovers listed (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre authored Dec 15, 2021
1 parent 95677da commit 03fda08
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/utils/__tests__/changelog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' } } },
},
],
{},
[
Expand All @@ -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'),
],
[
Expand Down Expand Up @@ -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);
}
);
Expand Down
14 changes: 11 additions & 3 deletions src/utils/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -246,7 +247,8 @@ function formatCommit(commit: Commit): string {

export async function generateChangesetFromGit(
git: SimpleGit,
rev: string
rev: string,
maxLeftovers: number = MAX_LEFTOVERS
): Promise<string> {
const gitCommits = (await getChangesSince(git, rev)).filter(
({ body }) => !body.includes(SKIP_CHANGELOG_MAGIC_WORD)
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 03fda08

Please sign in to comment.