diff --git a/src/commits.js b/src/commits.js index fce76be4..7df4fbe3 100644 --- a/src/commits.js +++ b/src/commits.js @@ -36,12 +36,6 @@ function parseCommits (string, remote, options = {}) { .split(COMMIT_SEPARATOR) .slice(1) .map(commit => parseCommit(commit, remote, options)) - .filter(commit => { - if (options.ignoreCommitPattern) { - return new RegExp(options.ignoreCommitPattern).test(commit.subject) === false - } - return true - }) if (options.startingCommit) { const index = commits.findIndex(c => c.hash.indexOf(options.startingCommit) === 0) diff --git a/src/releases.js b/src/releases.js index db8430f0..653da537 100644 --- a/src/releases.js +++ b/src/releases.js @@ -33,7 +33,7 @@ export function parseReleases (commits, remote, latestVersion, options) { fixes: commit.fixes, commit }) - } else if (filterCommit(commit, release, options.commitLimit)) { + } else if (filterCommit(commit, options, release)) { release.commits.push(commit) } } @@ -76,10 +76,24 @@ function newRelease (tag = null, date = new Date().toISOString(), summary = null } } -function filterCommit (commit, release, limit) { +function sliceCommits (commits, { commitLimit, backfillLimit }, release) { + if (commitLimit === false) { + return commits + } + const emptyRelease = release.fixes.length === 0 && release.merges.length === 0 + const limit = emptyRelease ? backfillLimit : commitLimit + const minLimit = commits.filter(c => c.breaking).length + return commits.slice(0, Math.max(minLimit, limit)) +} + +function filterCommit (commit, { ignoreCommitPattern }, release) { if (commit.breaking) { return true } + if (ignoreCommitPattern) { + // Filter out commits that match ignoreCommitPattern + return new RegExp(ignoreCommitPattern).test(commit.subject) === false + } if (semver.valid(commit.subject)) { // Filter out version commits return false @@ -126,13 +140,3 @@ function commitSorter ({ sortCommits }) { return (b.insertions + b.deletions) - (a.insertions + a.deletions) } } - -function sliceCommits (commits, options, release) { - if (options.commitLimit === false) { - return commits - } - const emptyRelease = release.fixes.length === 0 && release.merges.length === 0 - const limit = emptyRelease ? options.backfillLimit : options.commitLimit - const minLimit = commits.filter(c => c.breaking).length - return commits.slice(0, Math.max(minLimit, limit)) -} diff --git a/test/commits.js b/test/commits.js index 10ec5df8..e1e09f04 100644 --- a/test/commits.js +++ b/test/commits.js @@ -54,14 +54,6 @@ describe('parseCommits', () => { expect(parseCommits(gitLog, remotes.github, options)).to.have.length(10) }) - it('supports ignoreCommitPattern option', async () => { - const gitLog = await readFile(join(__dirname, 'data', 'git-log.txt')) - const options = { ignoreCommitPattern: 'Second commit' } - const result = parseCommits(gitLog, remotes.github, options) - expect(result).to.have.length(commits.length - 1) - expect(JSON.stringify(result)).to.not.contain('Second commit') - }) - it('supports breakingPattern option', async () => { const gitLog = await readFile(join(__dirname, 'data', 'git-log.txt')) const options = { breakingPattern: 'Some breaking change' } diff --git a/test/releases.js b/test/releases.js index 4f63b534..e77e5424 100644 --- a/test/releases.js +++ b/test/releases.js @@ -87,6 +87,13 @@ describe('parseReleases', () => { '2015-12-29T21:57:19.000Z' ]) }) + + it('supports ignoreCommitPattern option', () => { + const options = { ignoreCommitPattern: 'Some breaking change' } + const result = parseReleases(commits, remotes.github, null, options) + expect(result).to.have.length(4) + expect(JSON.stringify(result)).to.not.contain('Some breaking change') + }) }) describe('sortReleases', () => {