Skip to content
This repository was archived by the owner on Sep 18, 2017. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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)
}
62 changes: 40 additions & 22 deletions test/specs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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()
})