Skip to content

Commit 295b513

Browse files
committed
Implement git log filter
1 parent 0dad212 commit 295b513

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

__tests__/git.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,30 @@ describe('Git commands', () => {
244244
expect(log[2].hash).toHaveLength(7)
245245
expect(log[2].message).toBe('Third commit')
246246
})
247+
248+
it('Verifies log does not contain commits matching regex', async () => {
249+
const cwd = await initTestRepo()
250+
251+
const settings = {} as Settings
252+
settings.gitPath = await io.which('git', true)
253+
settings.repoPath = cwd
254+
settings.filterRegex = /^\[skip\].*/
255+
const g = new Git(settings)
256+
257+
await createAndCommitFile('first', 'First commit', cwd)
258+
await createAndCommitFile('second', '[skip] Second commit', cwd)
259+
await createAndCommitFile('third', 'Third commit', cwd)
260+
await createAndCommitFile('fourth', 'Fourth commit', cwd)
261+
await createAndCommitFile('fifth', '[skip] Fifth commit', cwd)
262+
await createAndCommitFile('sixth', '[skip] Sixth commit', cwd)
263+
264+
const log = await g.log('', '')
265+
expect(log).toHaveLength(3)
266+
expect(log[0].hash).toHaveLength(7)
267+
expect(log[0].message).toBe('Fourth commit')
268+
expect(log[1].hash).toHaveLength(7)
269+
expect(log[1].message).toBe('Third commit')
270+
expect(log[2].hash).toHaveLength(7)
271+
expect(log[2].message).toBe('First commit')
272+
})
247273
})

src/git.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as io from '@actions/io'
21
import * as exec from '@actions/exec'
32
import {Settings} from './settings'
43

@@ -70,6 +69,10 @@ export class Git {
7069
const split = commit.split(' ')
7170
const hash = split[0]
7271
const message = split.slice(1).join(' ')
72+
73+
if (this.settings.filterRegex && RegExp(this.settings.filterRegex).test(message)) {
74+
return
75+
}
7376
commits.push(new GitCommit(hash, message))
7477
})
7578

0 commit comments

Comments
 (0)