Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(conventionalcommits): enable glob patterns "scope" and "type" in types #982

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -34,6 +34,7 @@
},
"homepage": "https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-conventionalcommits#readme",
"dependencies": {
"compare-func": "^2.0.0"
"compare-func": "^2.0.0",
"minimatch": "^9.0.0"
}
}
55 changes: 55 additions & 0 deletions packages/conventional-changelog-conventionalcommits/test/test.js
Expand Up @@ -90,6 +90,9 @@ betterThanBefore.setups([
'chore: release at different version',
'Release-As: v3.0.2'
])
},
function () {
gitDummyCommit('fix(awesome): fix the awesome thing')
}
])

Expand Down Expand Up @@ -187,6 +190,28 @@ describe('conventionalcommits.org preset', function () {
}))
})

it('should allow matching "type" to configuration using glob patterns', function (done) {
preparing(1)
conventionalChangelogCore({
config: require('../')({
types: [
{ type: '{chore,ci}', section: 'Chores and CI' }
]
})
})
.on('error', function (err) {
done(err)
})
.pipe(through(function (chunk) {
chunk = chunk.toString()

expect(chunk).to.include('### Chores and CI')
expect(chunk).to.include('add TravisCI pipeline')
expect(chunk).to.include('upgrade example from 1 to 2')
done()
}))
})

it('should allow matching "scope" to configuration', function (done) {
preparing(1)
conventionalChangelogCore({
Expand All @@ -210,6 +235,36 @@ describe('conventionalcommits.org preset', function () {
}))
})

it('should allow matching "scope" to configuration using glob patterns', function (done) {
preparing(1)
conventionalChangelogCore({
config: require('../')({
types: [
{ type: 'feat', scope: '!changelog', section: 'Features' },
{ type: 'fix', scope: '!{changelog,awesome}', section: 'Bug Fixes' }
]
})
})
.on('error', function (err) {
done(err)
})
.pipe(through(function (chunk) {
chunk = chunk.toString()

expect(chunk).to.include('### Features')
expect(chunk).to.include('**awesome:** adress EXAMPLE-1')

expect(chunk).to.not.include('proper issue links')

expect(chunk).to.include('### Bug Fixes')
expect(chunk).to.include('oops')

expect(chunk).to.not.include('**awesome:** fix the awesome thing')
expect(chunk).to.not.include('proper issue links')
done()
}))
})

it('should properly format external repository issues', function (done) {
preparing(1)
conventionalChangelogCore({
Expand Down
Expand Up @@ -4,6 +4,7 @@ const addBangNotes = require('./add-bang-notes')
const compareFunc = require('compare-func')
const { readFile } = require('fs').promises
const { resolve } = require('path')
const { minimatch } = require('minimatch')
const releaseAsRe = /release-as:\s*\w*@?([0-9]+\.[0-9]+\.[0-9a-z]+(-[0-9a-z.]+)?)\s*/i

/**
Expand Down Expand Up @@ -60,10 +61,13 @@ module.exports = async (config) => {
function findTypeEntry (types, commit) {
const typeKey = (commit.revert ? 'revert' : (commit.type || '')).toLowerCase()
return types.find((entry) => {
if (entry.type !== typeKey) {
if (!minimatch(typeKey, entry.type)) {
return false
}
if (entry.scope && entry.scope !== commit.scope) {
if (
entry.scope &&
(!commit.scope || !minimatch(commit.scope, entry.scope))
) {
return false
}
return true
Expand Down
17 changes: 16 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.