From 81aa29e09951c403955e6e3bbfbebf0d6b499cee Mon Sep 17 00:00:00 2001 From: Ari Porad Date: Tue, 18 Aug 2015 07:48:10 -0700 Subject: [PATCH 1/6] feat: Change to new version of plugin API Change to the new version of the commit analyzer API. Now the parser is called multiple times with only a single commit each time, and semantic-release takes care of keeping track of the version. This drastically simplifies the code. BREAKING CHANGE: Instead of accepting an array of commits with the `commits` option, we now accept a single commit with the `commit` option. Use that instead, and call the plugin multiple times. --- src/index.js | 28 +++++++--------------------- test/specs/index.js | 32 ++++++++++---------------------- 2 files changed, 17 insertions(+), 43 deletions(-) diff --git a/src/index.js b/src/index.js index 7a3382b..97c4b2d 100644 --- a/src/index.js +++ b/src/index.js @@ -1,26 +1,12 @@ const { parseRawCommit } = require('conventional-changelog/lib/git') -module.exports = function (pluginConfig, {commits}, cb) { - let type = null +module.exports = function (pluginConfig, {commit}, cb) { + commit = parseRawCommit(`${commit.hash}\n${commit.message}`) - commits + 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') - .map((commit) => parseRawCommit(`${commit.hash}\n${commit.message}`)) - - .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..c185eca 100644 --- a/test/specs/index.js +++ b/test/specs/index.js @@ -7,10 +7,10 @@ test('derive version number from commits', (t) => { 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 +21,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 +35,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,16 +49,10 @@ 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') From 733fdb26c4ef286e0d2956c861c4fc71cac49c11 Mon Sep 17 00:00:00 2001 From: Ari Porad Date: Tue, 18 Aug 2015 07:58:08 -0700 Subject: [PATCH 2/6] chore(standard): Comply with standard --- src/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 97c4b2d..2806959 100644 --- a/src/index.js +++ b/src/index.js @@ -3,10 +3,10 @@ const { parseRawCommit } = require('conventional-changelog/lib/git') module.exports = function (pluginConfig, {commit}, cb) { commit = parseRawCommit(`${commit.hash}\n${commit.message}`) - if (!commit) return cb(null, null) - if (commit.breaks.length) return cb(null, 'major') + 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') + if (commit.type === 'fix') return cb(null, 'patch') cb(null, null) } From 45406815e8f154a6d1994f36f6bf1c0fceebecac Mon Sep 17 00:00:00 2001 From: Ari Porad Date: Tue, 18 Aug 2015 11:53:19 -0700 Subject: [PATCH 3/6] feat: Add [release skip] command Add [release skip] command. It will (shockingly,) skip the release for that commit. Also add [skip release] as an alias of that. Fixes semantic-release/semantic-release#41 --- src/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/index.js b/src/index.js index 2806959..d6004cd 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,11 @@ const { parseRawCommit } = require('conventional-changelog/lib/git') module.exports = function (pluginConfig, {commit}, cb) { + if (commit.message.indexOf('[release skip]') > -1 || + commit.message.indexOf('[skip release]') > -1 ){ + return cb(null, null) + } + commit = parseRawCommit(`${commit.hash}\n${commit.message}`) if (!commit) return cb(null, null) From 60f3d70c62d5630c6f88195a0a02716bc4078932 Mon Sep 17 00:00:00 2001 From: Ari Porad Date: Tue, 18 Aug 2015 12:00:30 -0700 Subject: [PATCH 4/6] style: Comply with standard --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index d6004cd..43496ef 100644 --- a/src/index.js +++ b/src/index.js @@ -2,7 +2,7 @@ const { parseRawCommit } = require('conventional-changelog/lib/git') module.exports = function (pluginConfig, {commit}, cb) { if (commit.message.indexOf('[release skip]') > -1 || - commit.message.indexOf('[skip release]') > -1 ){ + commit.message.indexOf('[skip release]') > -1) { return cb(null, null) } From 87fe377db29c5012ffb89fb49cfeb773dbf54596 Mon Sep 17 00:00:00 2001 From: Ari Porad Date: Tue, 18 Aug 2015 12:04:05 -0700 Subject: [PATCH 5/6] feat(commitTypes): Add 'rskip' type Make Analyzer output 'rskip' if the release was skipped, instead of null Refs semantic-release/semantic-release#41 --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 43496ef..54e635b 100644 --- a/src/index.js +++ b/src/index.js @@ -3,7 +3,7 @@ const { parseRawCommit } = require('conventional-changelog/lib/git') module.exports = function (pluginConfig, {commit}, cb) { if (commit.message.indexOf('[release skip]') > -1 || commit.message.indexOf('[skip release]') > -1) { - return cb(null, null) + return cb(null, 'rskip') } commit = parseRawCommit(`${commit.hash}\n${commit.message}`) From 1e03720af656de9e298fb81692f3d9f99f13b35a Mon Sep 17 00:00:00 2001 From: Ari Porad Date: Tue, 18 Aug 2015 12:09:15 -0700 Subject: [PATCH 6/6] test: Add tests for [release skip] and [skip release] Refs semantic-release/semantic-release#41 --- test/specs/index.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/specs/index.js b/test/specs/index.js index c185eca..d313961 100644 --- a/test/specs/index.js +++ b/test/specs/index.js @@ -3,6 +3,8 @@ 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) @@ -59,5 +61,33 @@ test('derive version number from commits', (t) => { }) }) + 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() })