diff --git a/packages/core/src/__tests__/__snapshots__/changelog.test.ts.snap b/packages/core/src/__tests__/__snapshots__/changelog.test.ts.snap index 99db70906..9f28f3986 100644 --- a/packages/core/src/__tests__/__snapshots__/changelog.test.ts.snap +++ b/packages/core/src/__tests__/__snapshots__/changelog.test.ts.snap @@ -22,7 +22,7 @@ exports[`Hooks title 1`] = ` exports[`generateReleaseNotes additional release notes should be able to contain sub-headers 1`] = ` "### Release Notes -_From #1235_ +#### - First Feature [#1235](https://github.custom.com/foobar/auto/pull/1235) Here is how you upgrade @@ -88,7 +88,7 @@ exports[`generateReleaseNotes should add "Push to Next" 1`] = ` exports[`generateReleaseNotes should add additional release notes 1`] = ` "### Release Notes -_From #1235_ +#### - First Feature [#1235](https://github.custom.com/foobar/auto/pull/1235) Here is how you upgrade @@ -245,7 +245,7 @@ exports[`generateReleaseNotes should merge sections with same changelog title 1` exports[`generateReleaseNotes should not add automated comments to additional release notes 1`] = ` "### Release Notes -_From #1235_ +#### - First Feature [#1235](https://github.custom.com/foobar/auto/pull/1235) Here is how you upgrade @@ -269,7 +269,7 @@ exports[`generateReleaseNotes should omit authors with invalid email addresses 1 exports[`generateReleaseNotes should omit changelog item for next branches 1`] = ` "### Release Notes -_From #123_ +#### - V8 [#123](https://github.custom.com/foobar/auto/pull/123) foobar diff --git a/packages/core/src/changelog.ts b/packages/core/src/changelog.ts index a767f0e7f..123c7fa87 100644 --- a/packages/core/src/changelog.ts +++ b/packages/core/src/changelog.ts @@ -271,7 +271,7 @@ export default class Changelog { } /** Transform a commit into a line in the changelog */ - private async generateCommitNote(commit: IExtendedCommit) { + private async generateCommitNote(commit: IExtendedCommit, addUser = true) { const subject = commit.subject ? commit.subject .split("\n")[0] @@ -290,8 +290,15 @@ export default class Changelog { pr = `[#${commit.pullRequest.number}](${prLink})`; } - const user = await this.createUserLinkList(commit); - return `- ${subject}${pr ? ` ${pr}` : ""}${user ? ` (${user})` : ""}`; + const line = `- ${subject}${pr ? ` ${pr}` : ""}`; + + if (addUser) { + const user = await this.createUserLinkList(commit); + + return `${line}${user ? ` (${user})` : ""}`; + } + + return line; } /** Get all the authors in the provided commits */ @@ -432,57 +439,63 @@ export default class Changelog { let section = ""; const visited = new Set(); - const included = await Promise.all( - commits.map(async (commit) => { - const omit = await this.hooks.omitReleaseNotes.promise(commit); - if (!omit) { - return commit; + await Promise.all( + commits.map(async (commit) => { + if (await this.hooks.omitReleaseNotes.promise(commit)) { + return; } - }) - ); - - included.forEach((commit) => { - if (!commit) { - return; - } - const pr = commit.pullRequest; + const pr = commit.pullRequest; - if (!pr || !pr.body) { - return; - } - - const title = /^[#]{0,5}[ ]*[R|r]elease [N|n]otes$/; - const lines = pr.body.split("\n").map((line) => line.replace(/\r$/, "")); - const notesStart = lines.findIndex((line) => Boolean(line.match(title))); + if (!pr || !pr.body) { + return; + } - if (notesStart === -1 || visited.has(pr.number)) { - return; - } + const title = /^[#]{0,5}[ ]*[R|r]elease [N|n]otes$/; + const lines = pr.body - const depth = getHeaderDepth(lines[notesStart]); - visited.add(pr.number); - let notes = ""; + .split("\n") - for (let index = notesStart; index < lines.length; index++) { - const line = lines[index]; - const isTitle = line.match(title); + .map((line) => line.replace(/\r$/, "")); + const notesStart = lines.findIndex((line) => + Boolean(line.match(title)) + ); - if ( - (line.startsWith("#") && getHeaderDepth(line) <= depth && !isTitle) || - line.startsWith(automatedCommentIdentifier) - ) { - break; + if (notesStart === -1 || visited.has(pr.number)) { + return; } - if (!isTitle) { - notes += `${line}\n`; + const depth = getHeaderDepth(lines[notesStart]); + visited.add(pr.number); + let notes = ""; + + for (let index = notesStart; index < lines.length; index++) { + const line = lines[index]; + const isTitle = line.match(title); + + if ( + (line.startsWith("#") && + getHeaderDepth(line) <= depth && + !isTitle) || + line.startsWith(automatedCommentIdentifier) + ) { + break; + } + + if (!isTitle) { + notes += `${line}\n`; + } } - } - section += `_From #${pr.number}_\n\n${notes.trim()}\n\n`; - }); + const line = await this.hooks.renderChangelogLine.promise( + await this.generateCommitNote(commit, false), + commit + ); + + section += `#### ${line}\n\n${notes.trim()}\n\n`; + }) + ); if (!section) { return;