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(raw-commits): allow hidding by subject pattern #1063

Merged
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ async function createPreset (config) {

return {
gitRawCommitsOpts: {
ignore: config?.ignoreCommits,
noMerges: null
},
parserOpts,
Expand Down
14 changes: 11 additions & 3 deletions packages/git-raw-commits/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict'

const { Readable, Transform } = require('stream')
const { execFile } = require('child_process')
Expand Down Expand Up @@ -28,7 +27,7 @@ async function getGitArgs (gitOpts) {
const gitFromTo = [gitOpts.from, gitOpts.to].filter(Boolean).join('..')
const gitArgs = ['log', gitFormat, gitFromTo]
.concat(dargs(gitOpts, {
excludes: ['debug', 'from', 'to', 'format', 'path']
excludes: ['debug', 'from', 'to', 'format', 'path', 'ignore']
}))

// allow commits to focus on a single directory
Expand All @@ -53,6 +52,13 @@ function gitRawCommits (rawGitOpts, rawExecOpts) {
gitOpts.debug('Your git-log command is:\ngit ' + args.join(' '))
}

const ignoreRegex = typeof gitOpts.ignore === 'string'
? new RegExp(gitOpts.ignore)
: gitOpts.ignore
const shouldNotIgnore = ignoreRegex
? chunk => !ignoreRegex.test(chunk.toString())
: () => true

const child = execFile('git', args, {
cwd: execOpts.cwd,
maxBuffer: Infinity
Expand All @@ -65,7 +71,9 @@ function gitRawCommits (rawGitOpts, rawExecOpts) {
transform (chunk, enc, cb) {
isError = false
setImmediate(() => {
readable.push(chunk)
if (shouldNotIgnore(chunk)) {
readable.push(chunk)
}
cb()
})
},
Expand Down
22 changes: 22 additions & 0 deletions packages/git-raw-commits/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,28 @@ describe('git-raw-commits', () => {
expect(i).toBe(2)
})

it('should honour `options.ignore`', async () => {
let i = 0

for await (let chunk of gitRawCommits({
ignore: 'Second'
}, {
cwd: testTools.cwd
})) {
chunk = chunk.toString()

if (i === 0) {
expect(chunk).toBe('Third commit\n\n')
} else {
expect(chunk).toBe('First commit\n\n')
}

i++
}

expect(i).toBe(2)
})

it('should honour `options.format`', async () => {
let i = 0

Expand Down