Skip to content

Commit

Permalink
Merge pull request #1662 from intuit/release-notes-readability
Browse files Browse the repository at this point in the history
Improve readability of release notes
  • Loading branch information
hipstersmoothie authored Nov 23, 2020
2 parents 99baf46 + 9275aa1 commit 0aebacc
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
97 changes: 55 additions & 42 deletions packages/core/src/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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 */
Expand Down Expand Up @@ -432,57 +439,63 @@ export default class Changelog {

let section = "";
const visited = new Set<number>();
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;
Expand Down

0 comments on commit 0aebacc

Please sign in to comment.