Skip to content

Commit

Permalink
Update: Support conventional commits (#55)
Browse files Browse the repository at this point in the history
* Update: Accept conventional commits

* Formatting

* Fix lint errors
  • Loading branch information
nzakas authored May 4, 2021
1 parent 397557b commit 0fdda4d
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 8 deletions.
21 changes: 19 additions & 2 deletions lib/release-ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ const fs = require("fs"),
// Private
//------------------------------------------------------------------------------

const commitTagMap = new Map([
["fix", "fix"],
["fix!", "breaking"],
["build", "build"],
["chore", "chore"],
["perf", "chore"],
["ci", "chore"],
["refactor", "chore"],
["docs", "docs"],
["update", "update"],
["new", "new"],
["feat", "new"],
["breaking", "breaking"],
["feat!", "breaking"]
]);

// var OPEN_SOURCE_LICENSES = [
// /MIT/, /BSD/, /Apache/, /ISC/, /WTF/, /Public Domain/
// ];
Expand Down Expand Up @@ -128,7 +144,7 @@ function getVersionTags() {
* @private
*/
function parseLogs(logs) {
const regexp = /^\* ([0-9a-f]{40}) ((?:([a-z]+): ?)?.*) \((.*)\)/i,
const regexp = /^\* ([0-9a-f]{40}) ((?:([a-z]+!?): ?)?.*) \((.*)\)/i,
parsed = [];

logs.forEach(log => {
Expand All @@ -139,13 +155,14 @@ function parseLogs(logs) {
raw: match[0],
sha: match[1],
title: match[2],
flag: match[3] ? match[3].toLowerCase() : null,
flag: commitTagMap.get(match[3] ? match[3].toLowerCase() : null),
author: match[4],
body: ""
});
} else if (parsed.length) {
parsed[parsed.length - 1].body += `${log}\n`;
}

});

return parsed;
Expand Down
86 changes: 80 additions & 6 deletions tests/lib/release-ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ describe("ReleaseOps", () => {

it("should create a patch release when only bug fixes are present", () => {
const logs = [
"* 5b4812a956935358bf6e48f4d75a9bc998b3fe41 Fix: Something (Foo Bar)",
"* 00a3526f3a6560e4f91d390725b9a70f5d974f89 Docs: Something else (foobar)",
"* 5b4812a956935358bf6e48f4d75a9bc998b3fe41 fix: Something (Foo Bar)",
"* 00b3526f3a6560e4f91d390725b9a70f5d974f80 docs: Something else (foobar)",
"* 00a3526f3a6560e4f91d390725b9a70f5d974f80 Docs: Something else (foobar)",
"* 24b2fdb310b89d7aad134df7e8863a5e055ac63f Fix: Something else (Foo B. Baz)"
],
releaseInfo = ReleaseOps.calculateReleaseFromGitLogs("1.0.0", logs);
Expand All @@ -93,16 +94,18 @@ describe("ReleaseOps", () => {
type: "patch",
changelog: {
fix: [
"* [`5b4812a`](https://github.com/eslint/eslint-release/commit/5b4812a956935358bf6e48f4d75a9bc998b3fe41) Fix: Something (Foo Bar)",
"* [`5b4812a`](https://github.com/eslint/eslint-release/commit/5b4812a956935358bf6e48f4d75a9bc998b3fe41) fix: Something (Foo Bar)",
"* [`24b2fdb`](https://github.com/eslint/eslint-release/commit/24b2fdb310b89d7aad134df7e8863a5e055ac63f) Fix: Something else (Foo B. Baz)"
],
docs: [
"* [`00a3526`](https://github.com/eslint/eslint-release/commit/00a3526f3a6560e4f91d390725b9a70f5d974f89) Docs: Something else (foobar)"
"* [`00b3526`](https://github.com/eslint/eslint-release/commit/00b3526f3a6560e4f91d390725b9a70f5d974f80) docs: Something else (foobar)",
"* [`00a3526`](https://github.com/eslint/eslint-release/commit/00a3526f3a6560e4f91d390725b9a70f5d974f80) Docs: Something else (foobar)"
]
},
rawChangelog: [
"* [`5b4812a`](https://github.com/eslint/eslint-release/commit/5b4812a956935358bf6e48f4d75a9bc998b3fe41) Fix: Something (Foo Bar)",
"* [`00a3526`](https://github.com/eslint/eslint-release/commit/00a3526f3a6560e4f91d390725b9a70f5d974f89) Docs: Something else (foobar)",
"* [`5b4812a`](https://github.com/eslint/eslint-release/commit/5b4812a956935358bf6e48f4d75a9bc998b3fe41) fix: Something (Foo Bar)",
"* [`00b3526`](https://github.com/eslint/eslint-release/commit/00b3526f3a6560e4f91d390725b9a70f5d974f80) docs: Something else (foobar)",
"* [`00a3526`](https://github.com/eslint/eslint-release/commit/00a3526f3a6560e4f91d390725b9a70f5d974f80) Docs: Something else (foobar)",
"* [`24b2fdb`](https://github.com/eslint/eslint-release/commit/24b2fdb310b89d7aad134df7e8863a5e055ac63f) Fix: Something else (Foo B. Baz)"
].join("\n")
});
Expand Down Expand Up @@ -141,6 +144,39 @@ describe("ReleaseOps", () => {
});
});

it("should create a minor release when conventional enhancements are present", () => {
const logs = [
"* 34d6f550b2c87e61a70cb201abd3eadebb370453 fix: Something (Author Name)",
"* 5c5c361cc338d284cac6d170ab7e105e213e1307 docs: Something else (authorname)",
"* bcdc618488d12184e32a7ba170b443450c3e9e48 fix: Something else (First Last)",
"* 7e4ffad5c91e4f8a99a95955ec65c5dbe9ae1758 feat: Foo (dotstar)"
],
releaseInfo = ReleaseOps.calculateReleaseFromGitLogs("1.0.0", logs);

assert.deepStrictEqual(releaseInfo, {
version: "1.1.0",
type: "minor",
changelog: {
fix: [
"* [`34d6f55`](https://github.com/eslint/eslint-release/commit/34d6f550b2c87e61a70cb201abd3eadebb370453) fix: Something (Author Name)",
"* [`bcdc618`](https://github.com/eslint/eslint-release/commit/bcdc618488d12184e32a7ba170b443450c3e9e48) fix: Something else (First Last)"
],
docs: [
"* [`5c5c361`](https://github.com/eslint/eslint-release/commit/5c5c361cc338d284cac6d170ab7e105e213e1307) docs: Something else (authorname)"
],
new: [
"* [`7e4ffad`](https://github.com/eslint/eslint-release/commit/7e4ffad5c91e4f8a99a95955ec65c5dbe9ae1758) feat: Foo (dotstar)"
]
},
rawChangelog: [
"* [`34d6f55`](https://github.com/eslint/eslint-release/commit/34d6f550b2c87e61a70cb201abd3eadebb370453) fix: Something (Author Name)",
"* [`5c5c361`](https://github.com/eslint/eslint-release/commit/5c5c361cc338d284cac6d170ab7e105e213e1307) docs: Something else (authorname)",
"* [`bcdc618`](https://github.com/eslint/eslint-release/commit/bcdc618488d12184e32a7ba170b443450c3e9e48) fix: Something else (First Last)",
"* [`7e4ffad`](https://github.com/eslint/eslint-release/commit/7e4ffad5c91e4f8a99a95955ec65c5dbe9ae1758) feat: Foo (dotstar)"
].join("\n")
});
});

it("should create a major release when breaking changes are present", () => {
const logs = [
"* 34d6f550b2c87e61a70cb201abd3eadebb370453 Fix: Something (githubhandle)",
Expand Down Expand Up @@ -179,6 +215,44 @@ describe("ReleaseOps", () => {
});
});

it("should create a major release when conventional breaking changes are present", () => {
const logs = [
"* 34d6f550b2c87e61a70cb201abd3eadebb370453 fix: Something (githubhandle)",
"* 5c5c361cc338d284cac6d170ab7e105e213e1307 docs: Something else (Committer Name)",
"* bcdc618488d12184e32a7ba170b443450c3e9e48 fix: Something else (Abc D. Efg)",
"* 7e4ffad5c91e4f8a99a95955ec65c5dbe9ae1758 feat: Foo (Tina Tester)",
"* 00a3526f3a6560e4f91d390725b9a70f5d974f89 feat!: Whatever (Toby Testing)"
],
releaseInfo = ReleaseOps.calculateReleaseFromGitLogs("1.0.0", logs);

assert.deepStrictEqual(releaseInfo, {
version: "2.0.0",
type: "major",
changelog: {
fix: [
"* [`34d6f55`](https://github.com/eslint/eslint-release/commit/34d6f550b2c87e61a70cb201abd3eadebb370453) fix: Something (githubhandle)",
"* [`bcdc618`](https://github.com/eslint/eslint-release/commit/bcdc618488d12184e32a7ba170b443450c3e9e48) fix: Something else (Abc D. Efg)"
],
docs: [
"* [`5c5c361`](https://github.com/eslint/eslint-release/commit/5c5c361cc338d284cac6d170ab7e105e213e1307) docs: Something else (Committer Name)"
],
new: [
"* [`7e4ffad`](https://github.com/eslint/eslint-release/commit/7e4ffad5c91e4f8a99a95955ec65c5dbe9ae1758) feat: Foo (Tina Tester)"
],
breaking: [
"* [`00a3526`](https://github.com/eslint/eslint-release/commit/00a3526f3a6560e4f91d390725b9a70f5d974f89) feat!: Whatever (Toby Testing)"
]
},
rawChangelog: [
"* [`34d6f55`](https://github.com/eslint/eslint-release/commit/34d6f550b2c87e61a70cb201abd3eadebb370453) fix: Something (githubhandle)",
"* [`5c5c361`](https://github.com/eslint/eslint-release/commit/5c5c361cc338d284cac6d170ab7e105e213e1307) docs: Something else (Committer Name)",
"* [`bcdc618`](https://github.com/eslint/eslint-release/commit/bcdc618488d12184e32a7ba170b443450c3e9e48) fix: Something else (Abc D. Efg)",
"* [`7e4ffad`](https://github.com/eslint/eslint-release/commit/7e4ffad5c91e4f8a99a95955ec65c5dbe9ae1758) feat: Foo (Tina Tester)",
"* [`00a3526`](https://github.com/eslint/eslint-release/commit/00a3526f3a6560e4f91d390725b9a70f5d974f89) feat!: Whatever (Toby Testing)"
].join("\n")
});
});

it("should disregard reverted commits and sponsor syncs", () => {
const logs = [
"* 34d6f550b2c87e61a70cb201abd3eadebb370453 Docs: Update something in the docs (githubhandle)",
Expand Down

0 comments on commit 0fdda4d

Please sign in to comment.