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 @@ -13,6 +13,7 @@ async function createPreset (config) {

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

const dargs = require('dargs')
const execFile = require('child_process').execFile
const split = require('split2')
const { isMatch } = require('micromatch')
const { Readable, Transform } = require('stream')

const DELIMITER = '------------------------ >8 ------------------------'
Expand All @@ -27,7 +27,7 @@ function getGitArgs (gitOpts) {

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 Down Expand Up @@ -65,7 +65,9 @@ function gitRawCommits (rawGitOpts, rawExecOpts) {
transform (chunk, enc, cb) {
isError = false
setImmediate(() => {
readable.push(chunk)
if ( !(gitOpts?.ignore && isMatch(chunk.toString(), gitOpts?.ignore))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use regex instead of glob

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

readable.push(chunk)
}
cb()
})
},
Expand Down
1 change: 1 addition & 0 deletions packages/git-raw-commits/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"dependencies": {
"dargs": "^7.0.0",
"meow": "^12.0.1",
"micromatch": "^4.0.5",
"split2": "^4.0.0"
},
"scripts": {
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