Skip to content
This repository was archived by the owner on Sep 18, 2017. It is now read-only.
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
},
"dependencies": {
"conventional-changelog": "0.0.17"
"conventional-commits-parser": "^0.1.0"
},
"devDependencies": {
"babel": "^5.5.8",
Expand Down
30 changes: 8 additions & 22 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
const { parseRawCommit } = require('conventional-changelog/lib/git')
const { sync as parseCommit } = require('conventional-commits-parser')

module.exports = function (pluginConfig, {commits}, cb) {
let type = null
module.exports = function (pluginConfig, {commit}, cb) {
commit = parseCommit(`${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)
}
32 changes: 10 additions & 22 deletions test/specs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand Down