diff --git a/package.json b/package.json index b059274bcd..8ab684c131 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "@semantic-release/error": "^1.0.0", "@semantic-release/last-release-npm": "^1.1.1", "@semantic-release/release-notes-generator": "^2.0.0", + "async": "^1.4.2", "git-head": "^1.2.1", "github": "^0.2.4", "lodash": "^3.9.3", diff --git a/src/lib/type.js b/src/lib/type.js index d22ffa73b7..0daed0a66f 100644 --- a/src/lib/type.js +++ b/src/lib/type.js @@ -1,12 +1,30 @@ const SemanticReleaseError = require('@semantic-release/error') +const _ = require('lodash') +const async = require('async') module.exports = function (config, cb) { - const { plugins, lastRelease } = config + const { plugins, lastRelease, commits } = config - plugins.analyzeCommits(config, (err, type) => { + async.map(commits, (commit, cb) => { + plugins.analyzeCommits(_.defaults({ commit }, config), cb) + }, + (err, types) => { if (err) return cb(err) - if (!type) { + if (types[types.length - 1] === 'rskip') { + return cb(new SemanticReleaseError( + 'The release was skipped', + 'ERSKIP' + )) + } + + const typeOrder = ['patch', 'minor', 'major'] + + const type = types + .map(t => typeOrder.indexOf(t)) + .reduce((type, t) => (type < t) ? t : type, -1) + + if (type < 0) { return cb(new SemanticReleaseError( 'There are no relevant changes, so no new version is released.', 'ENOCHANGE' @@ -15,6 +33,6 @@ module.exports = function (config, cb) { if (!lastRelease.version) return cb(null, 'initial') - cb(null, type) + cb(null, typeOrder[type]) }) } diff --git a/test/specs/type.js b/test/specs/type.js index 399c2a91c1..6a31a1a35f 100644 --- a/test/specs/type.js +++ b/test/specs/type.js @@ -23,8 +23,11 @@ test('get type from commits', (t) => { tt.plan(1) type({ - commits: [], - lastRelease: {}, + commits: [{ + hash: '0', + message: 'a' + }], + lastRelease: {version: '1.0.0'}, plugins: {analyzeCommits: (config, cb) => cb(null, null)} }, (err) => { tt.is(err.code, 'ENOCHANGE') @@ -35,7 +38,10 @@ test('get type from commits', (t) => { tt.plan(2) type({ - commits: [], + commits: [{ + hash: '0', + message: 'a' + }], lastRelease: {}, plugins: {analyzeCommits: (config, cb) => cb(null, 'major')} }, (err, type) => {