Skip to content

Commit c69e045

Browse files
authored
ci: omit empty release contributor sections (#430)
1 parent e693f9d commit c69e045

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

‎scripts/generate-release-notes.test.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,13 @@ test('combines the announcement, configured changelog, and new contributors from
5454
})
5555
})
5656

57-
test('regenerates a published release from its previous tag and states when no new contributors are detected', () => {
57+
test('regenerates a published release from its previous tag and omits the section when there are no new contributors', () => {
5858
withFixture("## What's Changed\n* existing contributor", (directory) => {
5959
git(directory, 'tag', 'v1.0.1')
6060
const notes = generate(directory)
6161
assert.match(notes, /repair runtime connections/)
6262
assert.match(notes, /v1\.0\.0\.\.\.v1\.0\.1/)
63-
assert.match(
64-
notes,
65-
/## New Contributors\n\nNo new contributors were detected for this release\./,
66-
)
63+
assert.doesNotMatch(notes, /New Contributors|No new contributors/)
6764
})
6865
})
6966

‎scripts/generate-release-notes.ts‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type ChangelogFactory = (
2121
* The range ends at the selected commit and starts at its previous reachable release tag.
2222
* Throws if custom notes, the changelog configuration, or GitHub contributor detection are unavailable.
2323
* @param version Exact stable version being released.
24-
* @returns Complete Markdown announcement, changelog, and new contributor section.
24+
* @returns Complete Markdown announcement and changelog, with acknowledgements when new contributors exist.
2525
*/
2626
export async function generateReleaseNotes(version: string): Promise<string> {
2727
if (!/^\d+\.\d+\.\d+$/.test(version)) {
@@ -91,26 +91,32 @@ export async function generateReleaseNotes(version: string): Promise<string> {
9191
throw new Error('GitHub did not return generated release notes.')
9292
}
9393

94-
return `${announcement}\n\n---\n\n${changelog.trim()}\n\n${contributorsSection(githubNotes.body)}\n`
94+
return `${[
95+
announcement,
96+
'---',
97+
changelog.trim(),
98+
contributorsSection(githubNotes.body),
99+
]
100+
.filter(Boolean)
101+
.join('\n\n')}\n`
95102
}
96103

97104
function contributorsSection(notes: string): string {
98105
const lines = notes.split('\n')
99106
const start = lines.findIndex((line) => /^## New Contributors\s*$/.test(line))
100-
if (start === -1) {
101-
return '## New Contributors\n\nNo new contributors were detected for this release.'
102-
}
107+
if (start === -1) return ''
103108

104109
const remaining = lines.slice(start + 1)
105110
const end = remaining.findIndex((line) =>
106111
/^#{1,2} |^\*\*Full Changelog\*\*/.test(line),
107112
)
108-
return [
109-
'## New Contributors',
110-
...remaining.slice(0, end === -1 ? undefined : end),
111-
]
113+
const contributors = remaining
114+
.slice(0, end === -1 ? undefined : end)
112115
.join('\n')
113116
.trim()
117+
if (!contributors) return ''
118+
119+
return `## New Contributors\n${contributors}`
114120
}
115121

116122
function git(...args: string[]): string {

0 commit comments

Comments
 (0)