Skip to content

Commit dfe29f3

Browse files
authored
chore: generate release notes with the new commit format (#2063)
* chore: generate notes with new commit format * capitalize message and put scope in bold * update PR templates
1 parent c528cae commit dfe29f3

File tree

4 files changed

+114
-46
lines changed

4 files changed

+114
-46
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
<!-- Ticket number and a general summary of your changes in the Title above -->
2-
<!-- e.g. COMPASS-1111: updates ace editor width in agg pipeline view -->
1+
<!--
2+
^^^^^
3+
Please fill the title above according to https://www.conventionalcommits.org/en/v1.0.0/.
34
4-
<!--- The following fields are not obligatory. Use your best judgement on what you think is applicable to the work you've done -->
5+
type(scope): message <TICKET-NUMBER>
6+
7+
eg. fix(crud): updates ace editor width in agg pipeline view COMPASS-1111
8+
9+
NOTE: use `feat`, `fix` and `perf` for user facing changes that will be part of
10+
release notes.
11+
-->
512

613
## Description
714
<!--- Describe your changes in detail -->

release/changelog.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
const { cli } = require('cli-ux');
2+
const chalk = require('chalk');
3+
const _ = require('lodash');
4+
const git = require('./git');
5+
const ux = require('./ux');
6+
7+
function capitalize(s) {
8+
if (typeof s !== 'string') return '';
9+
return s.charAt(0).toUpperCase() + s.slice(1);
10+
}
11+
12+
function renderCommit({ scope, message, pr, ticket }) {
13+
let links = [ticket, pr].filter(Boolean).join(', ');
14+
15+
if (links) {
16+
links = ` (${links})`;
17+
}
18+
19+
return `${scope ? `**${scope}**` + ': ' : ''}${capitalize(message)}${links}`;
20+
}
21+
22+
async function render(previousTag, releaseTag) {
23+
cli.info('');
24+
cli.info(`Changes from ${chalk.bold(previousTag)}:`);
25+
26+
const parseCommit = (commit) => {
27+
const PR_RE = /\s+\((#\d+)\)$/;
28+
const pr = (commit.match(PR_RE) || [])[1];
29+
commit = commit.replace(PR_RE, '');
30+
31+
const TICKET_RE_WITH_BRACES = /\s+\((COMPASS-\d+)\)$/;
32+
let ticket = (commit.match(TICKET_RE_WITH_BRACES) || [])[1];
33+
commit = commit.replace(TICKET_RE_WITH_BRACES, '');
34+
35+
const TICKET_RE_WITHOUT_BRACES = /\s+(COMPASS-\d+)$/;
36+
ticket = (commit.match(TICKET_RE_WITHOUT_BRACES) || [])[1];
37+
commit = commit.replace(TICKET_RE_WITHOUT_BRACES, '');
38+
39+
const COMMIT_RE = /^(?<type>feat|fix|perf)(\((?<scope>[^)]*)\))?:\s*(?<message>\S.*)/;
40+
const groups = (commit.match(COMMIT_RE) || []).groups;
41+
if (!groups) {
42+
return;
43+
}
44+
45+
if (groups.scope && groups.scope.match(/COMPASS-\d+/)) {
46+
ticket = groups.scope;
47+
groups.scope = '';
48+
}
49+
50+
groups.message = groups.message.trim();
51+
return {...groups, pr, ticket};
52+
};
53+
54+
const renderLine = (commit) => `- ${renderCommit(commit)}`;
55+
const renderSection = ({ title, commits }) => `## ${title}\n\n${commits.map(renderLine).join('\n')}\n\n`;
56+
57+
const commits = _.uniq(await git.log(previousTag, releaseTag))
58+
.map(parseCommit)
59+
.filter(Boolean); // only conventional commits
60+
61+
const changes = [
62+
{
63+
title: 'Features',
64+
commits: commits.filter(({ type }) => type === 'feat')
65+
},
66+
{
67+
title: 'Bug Fixes',
68+
commits: commits.filter(({ type }) => type === 'fix')
69+
},
70+
{
71+
title: 'Performance Improvements',
72+
commits: commits.filter(({ type }) => type === 'perf')
73+
}
74+
]
75+
.filter((section) => section.commits.length)
76+
.map(renderSection)
77+
.join('\n');
78+
79+
cli.info(
80+
`${changes}You can see the full list of commits here:`,
81+
'\n' + ux.link(`https://github.com/mongodb-js/compass/compare/${previousTag}...${releaseTag}`)
82+
);
83+
}
84+
85+
module.exports = {
86+
render
87+
};
88+

release/commands.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* eslint-disable no-console */
2-
const _ = require('lodash');
32
const { cli } = require('cli-ux');
43
const chalk = require('chalk');
54
const pkgUp = require('pkg-up');
@@ -17,6 +16,7 @@ const version = require('./version');
1716
const publishRelease = require('./publish');
1817
const waitForAssets = require('./wait-for-assets');
1918
const ux = require('./ux');
19+
const changelog = require('./changelog');
2020

2121
async function getPackageJsonVersion() {
2222
return require(await pkgUp()).version;
@@ -166,18 +166,7 @@ async function releaseChangelog() {
166166
.reverse()
167167
.find((t) => semver.lt(t, releaseTag));
168168

169-
cli.info('');
170-
cli.info(`Changes from ${chalk.bold(previousTag)}:`);
171-
const changes = _.uniq(await git.log(previousTag, releaseTag))
172-
.filter((line) => !semver.valid(line)) // filter out tag commits
173-
.map((line) => `- ${line}`);
174-
175-
cli.info(changes.join('\n'));
176-
177-
cli.info('');
178-
cli.info('You can see the full list of commits here:');
179-
const githubCompareUrl = `https://github.com/mongodb-js/compass/compare/${previousTag}...${releaseTag}`;
180-
cli.url(githubCompareUrl, githubCompareUrl);
169+
await changelog.render(previousTag, releaseTag);
181170
}
182171

183172
async function releasePublish() {

release/index.spec.js

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -278,57 +278,41 @@ describe('release', () => {
278278

279279
describe('when the release tag exist', () => {
280280
beforeEach(async() => {
281-
await commitAll('commit 1', 'v0.1.0');
282-
await commitAll('commit 2', 'v0.2.0-beta.0');
283-
await commitAll('commit 3');
284-
await commitAll('commit 3'); // duplicate
281+
await commitAll('fix: commit 1', 'v0.1.0');
282+
await commitAll('fix: commit 2', 'v0.2.0-beta.0');
283+
await commitAll('feat: commit 3');
284+
await commitAll('feat: commit 3'); // duplicate
285285
await commitAll('v0.2.0-beta.0'); // version bump commit
286286
await commitAll('v0.2.0'); // version bump commit
287287
await checkoutBranch('1.0-releases');
288-
await commitAll('commit 4', 'v1.0.0');
288+
await commitAll('perf: commit 4', 'v1.0.0');
289289
});
290290

291291
it('reports changes between 2 GAs', async() => {
292292
const { stdout } = await runReleaseCommand(['changelog']);
293-
expect(stdout).to.contain(`Changes from v0.1.0:
294-
- commit 4
295-
- commit 3
296-
- commit 2
297-
298-
You can see the full list of commits here:
299-
https://github.com/mongodb-js/compass/compare/v0.1.0...v1.0.0`);
293+
expect(stdout).to.contain('\nChanges from v0.1.0:\n## Features\n\n- Commit 3\n\n\n## Bug Fixes\n\n- Commit 2\n\n\n## Performance Improvements\n\n- Commit 4\n\nYou can see the full list of commits here: \nhttps://github.com/mongodb-js/compass/compare/v0.1.0...v1.0.0');
300294
});
301295

302296
it('reports changes between beta and GA', async() => {
303297
await npm.version('1.0.1-beta.0');
304298
await execa('git', ['add', '.']);
305-
await commitAll('commit 5');
306-
await commitAll('commit 6', 'v1.0.1-beta.0');
299+
await commitAll('fix: commit 5');
300+
await commitAll('fix: commit 6', 'v1.0.1-beta.0');
307301

308302
const { stdout } = await runReleaseCommand(['changelog']);
309-
expect(stdout).to.contain(`Changes from v1.0.0:
310-
- commit 6
311-
- commit 5
312-
313-
You can see the full list of commits here:
314-
https://github.com/mongodb-js/compass/compare/v1.0.0...v1.0.1-beta.0`);
303+
expect(stdout).to.contain('\nChanges from v1.0.0:\n## Bug Fixes\n\n- Commit 6\n- Commit 5\n\nYou can see the full list of commits here: \nhttps://github.com/mongodb-js/compass/compare/v1.0.0...v1.0.1-beta.0');
315304
});
316305

317306
it('reports changes between beta and beta', async() => {
318307
await npm.version('1.0.1-beta.0');
319-
await commitAll('commit 5');
320-
await commitAll('commit 6', 'v1.0.1-beta.0');
308+
await commitAll('feat: commit 5');
309+
await commitAll('feat: commit 6', 'v1.0.1-beta.0');
321310
await npm.version('1.0.1-beta.1');
322-
await commitAll('commit 7');
323-
await commitAll('commit 8', 'v1.0.1-beta.1');
311+
await commitAll('feat: commit 7');
312+
await commitAll('feat: commit 8', 'v1.0.1-beta.1');
324313

325314
const { stdout } = await runReleaseCommand(['changelog']);
326-
expect(stdout).to.contain(`Changes from v1.0.1-beta.0:
327-
- commit 8
328-
- commit 7
329-
330-
You can see the full list of commits here:
331-
https://github.com/mongodb-js/compass/compare/v1.0.1-beta.0...v1.0.1-beta.1`);
315+
expect(stdout).to.contain('\nChanges from v1.0.1-beta.0:\n## Features\n\n- Commit 8\n- Commit 7\n\nYou can see the full list of commits here: \nhttps://github.com/mongodb-js/compass/compare/v1.0.1-beta.0...v1.0.1-beta.1');
332316
});
333317
});
334318
});

0 commit comments

Comments
 (0)