diff --git a/index.js b/index.js index bf05da4..16baf42 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ const templates = require('./lib/templates/index.js') const commit = require('./lib/commit.js') +const constants = require('./lib/constants.js') const now = new Date() const year = now.getFullYear() const day = String(now.getDate()).padStart(2, '0') @@ -13,6 +14,7 @@ module.exports = { , parserOpts: { noteKeywords: ['BREAKING CHANGES', 'BREAKING CHANGE', 'BREAKING'] , headerPattern: /^(\w*)(?:\((.*)\))?!?: (.*)$/ + , breakingHeaderPattern: constants.BREAKING_HEADER_REGEX , headerCorrespondence: ['type', 'scope', 'subject'] , issuePrefixes: ['#', 'gh-'] , referenceActions: [ diff --git a/lib/commit.js b/lib/commit.js index 0a8be2a..2a44a3b 100644 --- a/lib/commit.js +++ b/lib/commit.js @@ -28,6 +28,7 @@ function typeOf(type) { function transform(commit) { commit.type = typeOf(commit.type) commit.shortHash = commit.hash.substring(0, 7) + for (const note of commit.notes) { note.title = '**BREAKING CHANGES**' } diff --git a/lib/constants.js b/lib/constants.js new file mode 100644 index 0000000..eb5fa91 --- /dev/null +++ b/lib/constants.js @@ -0,0 +1,5 @@ +'use strict' + +module.exports = { + BREAKING_HEADER_REGEX: /^(\w*)(?:\((.*)\))?!: (.*)$/ +} diff --git a/package.json b/package.json index 228bba3..12489a8 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,13 @@ "extends": "logdna", "parserOptions": { "ecmaVersion": 2019 + }, + "rules": { + "no-unused-vars": [2, { + "vars": "all", + "args": "none", + "varsIgnorePattern": "^_$" + }] } }, "tap": { diff --git a/test/unit/commit/transform.js b/test/unit/commit/transform.js index 5019790..5250f69 100644 --- a/test/unit/commit/transform.js +++ b/test/unit/commit/transform.js @@ -9,13 +9,14 @@ test('commit#transform', async (t) => { 'long': 'c644dd5aa62fa579bef2d793b6bc9d711f308a9b' , 'short': 'c644dd5' } + , notes: [{ + title: '**BREAKING CHANGES**' + , text: 'This will break things' + }] , hash: 'c644dd5aa62fa579bef2d793b6bc9d711f308a9b' , type: 'feat' , scope: 'core' - , notes: [{ - title: 'Does not matter' - , text: 'BREAKING CHANGE: This will break things' - }] + , header: 'feat(core): this is a simple commit' , references: [{ issue: '1000' , raw: 'Ref: gh-1000' diff --git a/test/unit/config.js b/test/unit/config.js index b65c1d9..548158b 100644 --- a/test/unit/config.js +++ b/test/unit/config.js @@ -2,6 +2,7 @@ const {test, threw} = require('tap') const config = require('../../index.js') +const constants = require('../../lib/constants.js') function sortByType(a, b) { return a.type < b.type ? -1 : 1 @@ -16,6 +17,7 @@ test('semantic-release-config-logdna', async (t) => { t.match(config.parserOpts, { noteKeywords: ['BREAKING CHANGES', 'BREAKING CHANGE', 'BREAKING'] , headerPattern: /^(\w*)(?:\((.*)\))?!?: (.*)$/ + , breakingHeaderPattern: constants.BREAKING_HEADER_REGEX , headerCorrespondence: ['type', 'scope', 'subject'] , issuePrefixes: ['#', 'gh-'] , referenceActions: [ diff --git a/test/unit/constants.js b/test/unit/constants.js new file mode 100644 index 0000000..b1fb933 --- /dev/null +++ b/test/unit/constants.js @@ -0,0 +1,34 @@ +'use strict' + +const {test, threw} = require('tap') +const constants = require('../../lib/constants.js') + +test('constants', async (t) => { + t.strictEqual(Object.keys(constants).length, 1, 'expected number of constants') + + t.match(constants, { + BREAKING_HEADER_REGEX: RegExp + }) + + t.test('BREAKING_HEADER_REGEX', async (t) => { + const {BREAKING_HEADER_REGEX} = constants + t.test('breaking change w/o scope', async (t) => { + const match = BREAKING_HEADER_REGEX.exec('test!: this is breaking') + const [_, type, scope, subject] = match + t.strictEqual(type, 'test', 'commit type') + t.strictEqual(scope, undefined, 'commit scope') + t.strictEqual(subject, 'this is breaking', 'commit subject') + }) + t.test('breaking change w/ scope', async (t) => { + const match = BREAKING_HEADER_REGEX.exec('doc(readme)!: this is breaking') + const [_, type, scope, subject] = match + t.strictEqual(type, 'doc', 'commit type') + t.strictEqual(scope, 'readme', 'commit scope') + t.strictEqual(subject, 'this is breaking', 'commit subject') + }) + t.test('non-breaking change', async (t) => { + const match = BREAKING_HEADER_REGEX.exec('doc(readme): this is breaking') + t.notOk(match, 'no match found') + }) + }) +}).catch(threw)