Skip to content

Commit 0fdda4d

Browse files
authored
Update: Support conventional commits (#55)
* Update: Accept conventional commits * Formatting * Fix lint errors
1 parent 397557b commit 0fdda4d

File tree

2 files changed

+99
-8
lines changed

2 files changed

+99
-8
lines changed

lib/release-ops.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ const fs = require("fs"),
2727
// Private
2828
//------------------------------------------------------------------------------
2929

30+
const commitTagMap = new Map([
31+
["fix", "fix"],
32+
["fix!", "breaking"],
33+
["build", "build"],
34+
["chore", "chore"],
35+
["perf", "chore"],
36+
["ci", "chore"],
37+
["refactor", "chore"],
38+
["docs", "docs"],
39+
["update", "update"],
40+
["new", "new"],
41+
["feat", "new"],
42+
["breaking", "breaking"],
43+
["feat!", "breaking"]
44+
]);
45+
3046
// var OPEN_SOURCE_LICENSES = [
3147
// /MIT/, /BSD/, /Apache/, /ISC/, /WTF/, /Public Domain/
3248
// ];
@@ -128,7 +144,7 @@ function getVersionTags() {
128144
* @private
129145
*/
130146
function parseLogs(logs) {
131-
const regexp = /^\* ([0-9a-f]{40}) ((?:([a-z]+): ?)?.*) \((.*)\)/i,
147+
const regexp = /^\* ([0-9a-f]{40}) ((?:([a-z]+!?): ?)?.*) \((.*)\)/i,
132148
parsed = [];
133149

134150
logs.forEach(log => {
@@ -139,13 +155,14 @@ function parseLogs(logs) {
139155
raw: match[0],
140156
sha: match[1],
141157
title: match[2],
142-
flag: match[3] ? match[3].toLowerCase() : null,
158+
flag: commitTagMap.get(match[3] ? match[3].toLowerCase() : null),
143159
author: match[4],
144160
body: ""
145161
});
146162
} else if (parsed.length) {
147163
parsed[parsed.length - 1].body += `${log}\n`;
148164
}
165+
149166
});
150167

151168
return parsed;

tests/lib/release-ops.js

Lines changed: 80 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ describe("ReleaseOps", () => {
8282

8383
it("should create a patch release when only bug fixes are present", () => {
8484
const logs = [
85-
"* 5b4812a956935358bf6e48f4d75a9bc998b3fe41 Fix: Something (Foo Bar)",
86-
"* 00a3526f3a6560e4f91d390725b9a70f5d974f89 Docs: Something else (foobar)",
85+
"* 5b4812a956935358bf6e48f4d75a9bc998b3fe41 fix: Something (Foo Bar)",
86+
"* 00b3526f3a6560e4f91d390725b9a70f5d974f80 docs: Something else (foobar)",
87+
"* 00a3526f3a6560e4f91d390725b9a70f5d974f80 Docs: Something else (foobar)",
8788
"* 24b2fdb310b89d7aad134df7e8863a5e055ac63f Fix: Something else (Foo B. Baz)"
8889
],
8990
releaseInfo = ReleaseOps.calculateReleaseFromGitLogs("1.0.0", logs);
@@ -93,16 +94,18 @@ describe("ReleaseOps", () => {
9394
type: "patch",
9495
changelog: {
9596
fix: [
96-
"* [`5b4812a`](https://github.com/eslint/eslint-release/commit/5b4812a956935358bf6e48f4d75a9bc998b3fe41) Fix: Something (Foo Bar)",
97+
"* [`5b4812a`](https://github.com/eslint/eslint-release/commit/5b4812a956935358bf6e48f4d75a9bc998b3fe41) fix: Something (Foo Bar)",
9798
"* [`24b2fdb`](https://github.com/eslint/eslint-release/commit/24b2fdb310b89d7aad134df7e8863a5e055ac63f) Fix: Something else (Foo B. Baz)"
9899
],
99100
docs: [
100-
"* [`00a3526`](https://github.com/eslint/eslint-release/commit/00a3526f3a6560e4f91d390725b9a70f5d974f89) Docs: Something else (foobar)"
101+
"* [`00b3526`](https://github.com/eslint/eslint-release/commit/00b3526f3a6560e4f91d390725b9a70f5d974f80) docs: Something else (foobar)",
102+
"* [`00a3526`](https://github.com/eslint/eslint-release/commit/00a3526f3a6560e4f91d390725b9a70f5d974f80) Docs: Something else (foobar)"
101103
]
102104
},
103105
rawChangelog: [
104-
"* [`5b4812a`](https://github.com/eslint/eslint-release/commit/5b4812a956935358bf6e48f4d75a9bc998b3fe41) Fix: Something (Foo Bar)",
105-
"* [`00a3526`](https://github.com/eslint/eslint-release/commit/00a3526f3a6560e4f91d390725b9a70f5d974f89) Docs: Something else (foobar)",
106+
"* [`5b4812a`](https://github.com/eslint/eslint-release/commit/5b4812a956935358bf6e48f4d75a9bc998b3fe41) fix: Something (Foo Bar)",
107+
"* [`00b3526`](https://github.com/eslint/eslint-release/commit/00b3526f3a6560e4f91d390725b9a70f5d974f80) docs: Something else (foobar)",
108+
"* [`00a3526`](https://github.com/eslint/eslint-release/commit/00a3526f3a6560e4f91d390725b9a70f5d974f80) Docs: Something else (foobar)",
106109
"* [`24b2fdb`](https://github.com/eslint/eslint-release/commit/24b2fdb310b89d7aad134df7e8863a5e055ac63f) Fix: Something else (Foo B. Baz)"
107110
].join("\n")
108111
});
@@ -141,6 +144,39 @@ describe("ReleaseOps", () => {
141144
});
142145
});
143146

147+
it("should create a minor release when conventional enhancements are present", () => {
148+
const logs = [
149+
"* 34d6f550b2c87e61a70cb201abd3eadebb370453 fix: Something (Author Name)",
150+
"* 5c5c361cc338d284cac6d170ab7e105e213e1307 docs: Something else (authorname)",
151+
"* bcdc618488d12184e32a7ba170b443450c3e9e48 fix: Something else (First Last)",
152+
"* 7e4ffad5c91e4f8a99a95955ec65c5dbe9ae1758 feat: Foo (dotstar)"
153+
],
154+
releaseInfo = ReleaseOps.calculateReleaseFromGitLogs("1.0.0", logs);
155+
156+
assert.deepStrictEqual(releaseInfo, {
157+
version: "1.1.0",
158+
type: "minor",
159+
changelog: {
160+
fix: [
161+
"* [`34d6f55`](https://github.com/eslint/eslint-release/commit/34d6f550b2c87e61a70cb201abd3eadebb370453) fix: Something (Author Name)",
162+
"* [`bcdc618`](https://github.com/eslint/eslint-release/commit/bcdc618488d12184e32a7ba170b443450c3e9e48) fix: Something else (First Last)"
163+
],
164+
docs: [
165+
"* [`5c5c361`](https://github.com/eslint/eslint-release/commit/5c5c361cc338d284cac6d170ab7e105e213e1307) docs: Something else (authorname)"
166+
],
167+
new: [
168+
"* [`7e4ffad`](https://github.com/eslint/eslint-release/commit/7e4ffad5c91e4f8a99a95955ec65c5dbe9ae1758) feat: Foo (dotstar)"
169+
]
170+
},
171+
rawChangelog: [
172+
"* [`34d6f55`](https://github.com/eslint/eslint-release/commit/34d6f550b2c87e61a70cb201abd3eadebb370453) fix: Something (Author Name)",
173+
"* [`5c5c361`](https://github.com/eslint/eslint-release/commit/5c5c361cc338d284cac6d170ab7e105e213e1307) docs: Something else (authorname)",
174+
"* [`bcdc618`](https://github.com/eslint/eslint-release/commit/bcdc618488d12184e32a7ba170b443450c3e9e48) fix: Something else (First Last)",
175+
"* [`7e4ffad`](https://github.com/eslint/eslint-release/commit/7e4ffad5c91e4f8a99a95955ec65c5dbe9ae1758) feat: Foo (dotstar)"
176+
].join("\n")
177+
});
178+
});
179+
144180
it("should create a major release when breaking changes are present", () => {
145181
const logs = [
146182
"* 34d6f550b2c87e61a70cb201abd3eadebb370453 Fix: Something (githubhandle)",
@@ -179,6 +215,44 @@ describe("ReleaseOps", () => {
179215
});
180216
});
181217

218+
it("should create a major release when conventional breaking changes are present", () => {
219+
const logs = [
220+
"* 34d6f550b2c87e61a70cb201abd3eadebb370453 fix: Something (githubhandle)",
221+
"* 5c5c361cc338d284cac6d170ab7e105e213e1307 docs: Something else (Committer Name)",
222+
"* bcdc618488d12184e32a7ba170b443450c3e9e48 fix: Something else (Abc D. Efg)",
223+
"* 7e4ffad5c91e4f8a99a95955ec65c5dbe9ae1758 feat: Foo (Tina Tester)",
224+
"* 00a3526f3a6560e4f91d390725b9a70f5d974f89 feat!: Whatever (Toby Testing)"
225+
],
226+
releaseInfo = ReleaseOps.calculateReleaseFromGitLogs("1.0.0", logs);
227+
228+
assert.deepStrictEqual(releaseInfo, {
229+
version: "2.0.0",
230+
type: "major",
231+
changelog: {
232+
fix: [
233+
"* [`34d6f55`](https://github.com/eslint/eslint-release/commit/34d6f550b2c87e61a70cb201abd3eadebb370453) fix: Something (githubhandle)",
234+
"* [`bcdc618`](https://github.com/eslint/eslint-release/commit/bcdc618488d12184e32a7ba170b443450c3e9e48) fix: Something else (Abc D. Efg)"
235+
],
236+
docs: [
237+
"* [`5c5c361`](https://github.com/eslint/eslint-release/commit/5c5c361cc338d284cac6d170ab7e105e213e1307) docs: Something else (Committer Name)"
238+
],
239+
new: [
240+
"* [`7e4ffad`](https://github.com/eslint/eslint-release/commit/7e4ffad5c91e4f8a99a95955ec65c5dbe9ae1758) feat: Foo (Tina Tester)"
241+
],
242+
breaking: [
243+
"* [`00a3526`](https://github.com/eslint/eslint-release/commit/00a3526f3a6560e4f91d390725b9a70f5d974f89) feat!: Whatever (Toby Testing)"
244+
]
245+
},
246+
rawChangelog: [
247+
"* [`34d6f55`](https://github.com/eslint/eslint-release/commit/34d6f550b2c87e61a70cb201abd3eadebb370453) fix: Something (githubhandle)",
248+
"* [`5c5c361`](https://github.com/eslint/eslint-release/commit/5c5c361cc338d284cac6d170ab7e105e213e1307) docs: Something else (Committer Name)",
249+
"* [`bcdc618`](https://github.com/eslint/eslint-release/commit/bcdc618488d12184e32a7ba170b443450c3e9e48) fix: Something else (Abc D. Efg)",
250+
"* [`7e4ffad`](https://github.com/eslint/eslint-release/commit/7e4ffad5c91e4f8a99a95955ec65c5dbe9ae1758) feat: Foo (Tina Tester)",
251+
"* [`00a3526`](https://github.com/eslint/eslint-release/commit/00a3526f3a6560e4f91d390725b9a70f5d974f89) feat!: Whatever (Toby Testing)"
252+
].join("\n")
253+
});
254+
});
255+
182256
it("should disregard reverted commits and sponsor syncs", () => {
183257
const logs = [
184258
"* 34d6f550b2c87e61a70cb201abd3eadebb370453 Docs: Update something in the docs (githubhandle)",

0 commit comments

Comments
 (0)