diff --git a/src/index.js b/src/index.js index 7a3382b..54e635b 100644 --- a/src/index.js +++ b/src/index.js @@ -1,26 +1,17 @@ const { parseRawCommit } = require('conventional-changelog/lib/git') -module.exports = function (pluginConfig, {commits}, cb) { - let type = null +module.exports = function (pluginConfig, {commit}, cb) { + if (commit.message.indexOf('[release skip]') > -1 || + commit.message.indexOf('[skip release]') > -1) { + return cb(null, 'rskip') + } - commits + commit = parseRawCommit(`${commit.hash}\n${commit.message}`) - .map((commit) => parseRawCommit(`${commit.hash}\n${commit.message}`)) + if (!commit) return cb(null, null) + if (commit.breaks.length) return cb(null, 'major') + if (commit.type === 'feat') return cb(null, 'minor') + if (commit.type === 'fix') return cb(null, 'patch') - .filter((commit) => !!commit) - - .every((commit) => { - if (commit.breaks.length) { - type = 'major' - return false - } - - if (commit.type === 'feat') type = 'minor' - - if (!type && commit.type === 'fix') type = 'patch' - - return true - }) - - cb(null, type) + cb(null, null) } diff --git a/test/specs/index.js b/test/specs/index.js index 3eb5757..d313961 100644 --- a/test/specs/index.js +++ b/test/specs/index.js @@ -3,14 +3,16 @@ const { test } = require('tap') const analyzer = require('../../dist') test('derive version number from commits', (t) => { + t.plan(5) + t.test('no change', (tt) => { tt.plan(2) analyzer({}, { - commits: [{ - hash: 'asdf', + commit: { + hash: '1234', message: 'chore: build script' - }] + } }, (err, type) => { tt.error(err) tt.is(type, null) @@ -21,13 +23,10 @@ test('derive version number from commits', (t) => { tt.plan(2) analyzer({}, { - commits: [{ - hash: 'asdf', - message: 'fix: nasty bug' - }, { + commit: { hash: '1234', message: 'fix(scope): even nastier bug' - }] + } }, (err, type) => { tt.error(err) tt.is(type, 'patch') @@ -38,13 +37,10 @@ test('derive version number from commits', (t) => { tt.plan(2) analyzer({}, { - commits: [{ - hash: 'asdf', - message: 'fix: nasty bug' - }, { + commit: { hash: '1234', message: 'feat(scope): cool feature' - }] + } }, (err, type) => { tt.error(err) tt.is(type, 'minor') @@ -55,21 +51,43 @@ test('derive version number from commits', (t) => { tt.plan(2) analyzer({}, { - commits: [{ - hash: 'qwer', - message: 'feat(something): even cooler feature\nBREAKING CHANGE: everything so broken' - }, { + commit: { hash: '1234', - message: 'feat(scope): cool feature' - }, { - hash: 'asdf', - message: 'fix: nasty bug' - }] + message: 'feat(something): even cooler feature\nBREAKING CHANGE: everything so broken' + } }, (err, type) => { tt.error(err) tt.is(type, 'major') }) }) + t.test('[release skip]', (tt) => { + tt.plan(2) + + analyzer({}, { + commit: { + hash: '1234', + message: 'feat(something): even cooler feature\n[release skip]' + } + }, (err, type) => { + tt.error(err) + tt.is(type, 'rskip') + }) + }) + + t.test('[skip release]', (tt) => { + tt.plan(2) + + analyzer({}, { + commit: { + hash: '1234', + message: 'feat(something): even cooler feature\n[skip release]' + } + }, (err, type) => { + tt.error(err) + tt.is(type, 'rskip') + }) + }) + t.end() })