Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit the number of leftovers listed #335

Merged
merged 4 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,11 +411,19 @@ 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' } } },
},
],
{},
[
'### Various fixes & improvements',
'',
'_Listing 3 out of 4_',
'',
'- Upgraded the kernel (abcdef12)',
'- Upgraded the manifold (#123) by @alice',
'- Refactored the crankshaft (#456) by @bob',
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 = 64;

// 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
chadwhitacre marked this conversation as resolved.
Show resolved Hide resolved
): 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'));
if (nLeftovers > maxLeftovers) {
changelogSections.push(`_Listing ${maxLeftovers} out of ${nLeftovers}_`);
}
changelogSections.push(
leftovers.slice(0, maxLeftovers).map(formatCommit).join('\n')
);
}

return changelogSections.join('\n\n');
Expand Down