From 74a02576e55674e0ded9d69af8464a9d4836506a Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Wed, 15 Dec 2021 10:19:25 -0800 Subject: [PATCH 1/4] Limit the number of leftovers listed Nobody's going to read through a list of 1,000s of commits, may as well use git log at that point. --- src/utils/__tests__/changelog.test.ts | 10 +++++++++- src/utils/changelog.ts | 16 +++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/utils/__tests__/changelog.test.ts b/src/utils/__tests__/changelog.test.ts index fa384edf..95fe08e6 100644 --- a/src/utils/__tests__/changelog.test.ts +++ b/src/utils/__tests__/changelog.test.ts @@ -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', '', + '(Only listing 3 out of 4.)', + '', '- Upgraded the kernel (abcdef12)', '- Upgraded the manifold (#123) by @alice', '- Refactored the crankshaft (#456) by @bob', @@ -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..8d3c0eb1 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 = 128; // 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,19 @@ 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( + `(Only listing ${maxLeftovers} out of ${nLeftovers}.)` + ); + } + changelogSections.push( + leftovers.slice(0, maxLeftovers).map(formatCommit).join('\n') + ); } return changelogSections.join('\n\n'); From c961ae7b7cc2368b43809094f06b2817ff48f50a Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Wed, 15 Dec 2021 10:25:37 -0800 Subject: [PATCH 2/4] Limit even further. C'mon --- src/utils/changelog.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/changelog.ts b/src/utils/changelog.ts index 8d3c0eb1..c0336be0 100644 --- a/src/utils/changelog.ts +++ b/src/utils/changelog.ts @@ -16,7 +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 = 128; +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. From b303490feab8a05f6af717329ae20f958c26c0e2 Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Wed, 15 Dec 2021 10:50:16 -0800 Subject: [PATCH 3/4] Tighten up wording --- src/utils/__tests__/changelog.test.ts | 2 +- src/utils/changelog.ts | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/utils/__tests__/changelog.test.ts b/src/utils/__tests__/changelog.test.ts index 95fe08e6..d04d8433 100644 --- a/src/utils/__tests__/changelog.test.ts +++ b/src/utils/__tests__/changelog.test.ts @@ -422,7 +422,7 @@ describe('generateChangesetFromGit', () => { [ '### Various fixes & improvements', '', - '(Only listing 3 out of 4.)', + '_Listing 3 out of 4_', '', '- Upgraded the kernel (abcdef12)', '- Upgraded the manifold (#123) by @alice', diff --git a/src/utils/changelog.ts b/src/utils/changelog.ts index c0336be0..e8ef419f 100644 --- a/src/utils/changelog.ts +++ b/src/utils/changelog.ts @@ -344,9 +344,7 @@ export async function generateChangesetFromGit( markdownHeader(SUBSECTION_HEADER_LEVEL, 'Various fixes & improvements') ); if (nLeftovers > maxLeftovers) { - changelogSections.push( - `(Only listing ${maxLeftovers} out of ${nLeftovers}.)` - ); + changelogSections.push(`_Listing ${maxLeftovers} out of ${nLeftovers}_`); } changelogSections.push( leftovers.slice(0, maxLeftovers).map(formatCommit).join('\n') From 2ec7c16299b89e192aae735e61592edea254fe13 Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Wed, 15 Dec 2021 11:32:49 -0800 Subject: [PATCH 4/4] Tinker --- src/utils/__tests__/changelog.test.ts | 4 ++-- src/utils/changelog.ts | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/utils/__tests__/changelog.test.ts b/src/utils/__tests__/changelog.test.ts index d04d8433..3688c124 100644 --- a/src/utils/__tests__/changelog.test.ts +++ b/src/utils/__tests__/changelog.test.ts @@ -422,11 +422,11 @@ describe('generateChangesetFromGit', () => { [ '### Various fixes & improvements', '', - '_Listing 3 out of 4_', - '', '- Upgraded the kernel (abcdef12)', '- Upgraded the manifold (#123) by @alice', '- Refactored the crankshaft (#456) by @bob', + '', + '_Plus 1 more_', ].join('\n'), ], [ diff --git a/src/utils/changelog.ts b/src/utils/changelog.ts index e8ef419f..0192886c 100644 --- a/src/utils/changelog.ts +++ b/src/utils/changelog.ts @@ -16,7 +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; +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. @@ -343,12 +343,12 @@ export async function generateChangesetFromGit( changelogSections.push( markdownHeader(SUBSECTION_HEADER_LEVEL, 'Various fixes & improvements') ); - if (nLeftovers > maxLeftovers) { - changelogSections.push(`_Listing ${maxLeftovers} out of ${nLeftovers}_`); - } changelogSections.push( leftovers.slice(0, maxLeftovers).map(formatCommit).join('\n') ); + if (nLeftovers > maxLeftovers) { + changelogSections.push(`_Plus ${nLeftovers - maxLeftovers} more_`); + } } return changelogSections.join('\n\n');