diff --git a/README.md b/README.md index 554592e0..6f1a9169 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ Options: --issue-pattern [regex] # override regex pattern for issues in commit messages --breaking-pattern [regex] # regex pattern for breaking change commits --merge-pattern [regex] # add custom regex pattern for merge commits + --commit-pattern [regex] # pattern to include when parsing commits --ignore-commit-pattern [regex] # pattern to ignore when parsing commits --tag-pattern [regex] # override regex pattern for version tags --tag-prefix [prefix] # prefix used in version tags, default: v diff --git a/src/commits.js b/src/commits.js index c5ad3685..664775f9 100644 --- a/src/commits.js +++ b/src/commits.js @@ -135,10 +135,13 @@ const getMerge = (commit, message, options = {}) => { return null } -const filterCommit = (commit, { ignoreCommitPattern }) => { +const filterCommit = (commit, { ignoreCommitPattern, commitPattern }) => { if (ignoreCommitPattern && new RegExp(ignoreCommitPattern).test(commit.subject)) { return false } + if (commitPattern) { + return new RegExp(commitPattern).test(commit.subject) + } return true } diff --git a/src/run.js b/src/run.js index 3ec4df9e..95e30b28 100644 --- a/src/run.js +++ b/src/run.js @@ -41,6 +41,7 @@ const getOptions = async argv => { .option('--issue-pattern ', 'override regex pattern for issues in commit messages') .option('--breaking-pattern ', 'regex pattern for breaking change commits') .option('--merge-pattern ', 'add custom regex pattern for merge commits') + .option('--commit-pattern ', 'pattern to include when parsing commits') .option('--ignore-commit-pattern ', 'pattern to ignore when parsing commits') .option('--tag-pattern ', 'override regex pattern for version tags') .option('--tag-prefix ', 'prefix used in version tags') diff --git a/test/commits.js b/test/commits.js index 60f1bee2..112688a4 100644 --- a/test/commits.js +++ b/test/commits.js @@ -65,6 +65,16 @@ describe('parseCommits', () => { const result = parseCommits(gitLog, options) expect(result.filter(c => c.subject === 'Some **BREAKING** change')).to.have.length(1) }) + + it('supports commitPattern option', async () => { + const gitLog = await readFile(join(__dirname, 'data', 'git-log.txt')) + const options = { + commitPattern: 'First', + ...remotes.github + } + const result = parseCommits(gitLog, options) + expect(result).to.have.length(1) + }) }) describe('getFixes', () => {