Skip to content

Commit

Permalink
Change behaviour of ignoreCommitPattern to see tags on ignored commits (
Browse files Browse the repository at this point in the history
#102)

* Change behaviour of ignoreCommitPattern to see tags on ignored commits

* Tweak commit filtering
  • Loading branch information
alexbumbacea authored and cookpete committed Apr 11, 2019
1 parent 31a1a71 commit 3d0c5e6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 26 deletions.
6 changes: 0 additions & 6 deletions src/commits.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 16 additions & 12 deletions src/releases.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
}
8 changes: 0 additions & 8 deletions test/commits.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down
7 changes: 7 additions & 0 deletions test/releases.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 3d0c5e6

Please sign in to comment.