Skip to content

Commit 66c9240

Browse files
authored
Add action input to set regexes case sensitive (#1)
1 parent 665db0d commit 66c9240

File tree

6 files changed

+48
-12
lines changed

6 files changed

+48
-12
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ The action accepts some properties:
4242
changelog-file-path: 'MyChangelog.md'
4343
```
4444

45+
- `case-insensitive-regex` to make both `tag-regex` and `filter-regex` case insensitive, defaults to `true`.
46+
47+
```
48+
- name: Create Changelog
49+
uses: arduino/create-changelog@v1
50+
with:
51+
case-insensitive-regex: true
52+
```
53+
4554
## Development
4655

4756
To work on the codebase you have to install all the dependencies:

__tests__/git.test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ describe('Git commands', () => {
104104

105105
const settings = {} as Settings
106106
settings.gitPath = await io.which('git', true)
107-
settings.tagRegex = ''
107+
settings.tagRegex = /.*/
108108
const g = new Git(settings)
109109

110110
await createAndCommitFile('first', 'First commit', cwd)
@@ -270,4 +270,28 @@ describe('Git commands', () => {
270270
expect(log[2].hash).toHaveLength(7)
271271
expect(log[2].message).toBe('First commit')
272272
})
273+
274+
it('Verifies log does not contain commit matching case insensitive regex', async () => {
275+
const cwd = await initTestRepo()
276+
process.chdir(cwd)
277+
278+
const settings = {} as Settings
279+
settings.gitPath = await io.which('git', true)
280+
settings.filterRegex = /^\[SkIp\].*/i
281+
const g = new Git(settings)
282+
283+
await createAndCommitFile('first', 'First commit', cwd)
284+
await createAndCommitFile('second', '[Skip] Second commit', cwd)
285+
await createAndCommitFile('third', '[skip] Third commit', cwd)
286+
await createAndCommitFile('fourth', 'Fourth commit', cwd)
287+
await createAndCommitFile('fifth', '[sKiP] Fifth commit', cwd)
288+
await createAndCommitFile('sixth', '[SKIP] Sixth commit', cwd)
289+
290+
const log = await g.log('', '')
291+
expect(log).toHaveLength(2)
292+
expect(log[0].hash).toHaveLength(7)
293+
expect(log[0].message).toBe('Fourth commit')
294+
expect(log[1].hash).toHaveLength(7)
295+
expect(log[1].message).toBe('First commit')
296+
})
273297
})

action.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ branding:
1010
inputs:
1111
tag-regex:
1212
description: 'Regex to select git tags used as boundaries for the changelog.'
13-
default: ''
13+
default: '.*'
1414
filter-regex:
1515
description: 'Regex to filter out commit messages from the changelog.'
16-
default: ''
16+
default: '.*'
1717
changelog-file-path:
1818
description: 'Destination file of the generated changelog.'
1919
default: 'CHANGELOG.md'
20+
case-insensitive-regex:
21+
description: 'If true both tag-regex and filter-regex are case insensitive'
22+
default: true

src/git.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class Git {
1919
// In case there are multiple tags get the first valid version tag
2020
if (this.settings.tagRegex) {
2121
res.stdout.forEach(tag => {
22-
if (RegExp(this.settings.tagRegex).test(tag)) {
22+
if (this.settings.tagRegex.test(tag)) {
2323
return tag
2424
}
2525
})
@@ -40,7 +40,7 @@ export class Git {
4040

4141
if (this.settings.tagRegex) {
4242
const foundTag = res.stdout[0]
43-
if (!RegExp(this.settings.tagRegex).test(foundTag)) {
43+
if (!this.settings.tagRegex.test(foundTag)) {
4444
// If previous tag doesn't match the regex keep searching back
4545
return this.previousTag(foundTag)
4646
}
@@ -70,7 +70,7 @@ export class Git {
7070
const hash = split[0]
7171
const message = split.slice(1).join(' ').trim()
7272

73-
if (this.settings.filterRegex && RegExp(this.settings.filterRegex).test(message)) {
73+
if (this.settings.filterRegex && this.settings.filterRegex.test(message)) {
7474
return
7575
}
7676
commits.push(new GitCommit(hash, message))

src/main.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import * as core from '@actions/core'
2-
import * as io from '@actions/io'
32
import {Changelog} from './changelog'
43
import {Git} from './git'
5-
import {initSettings, Settings} from './settings'
4+
import {initSettings} from './settings'
65

76
async function run(): Promise<void> {
87
try {

src/settings.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@ export interface Settings {
55
// Path to git executable
66
gitPath: string
77
// Regex to select git tags used as boundaries for the changelog
8-
tagRegex: string | RegExp
8+
tagRegex: RegExp
99
// Regex to filter out commit messages from the changelog
10-
filterRegex: string | RegExp
10+
filterRegex: RegExp
1111
// Destination file of the generated changelog
1212
changelogFilePath: string
1313
}
1414

1515
export async function initSettings(): Promise<Settings> {
1616
const settings = {} as Settings
1717
settings.gitPath = await io.which('git', true)
18-
settings.tagRegex = core.getInput('tag-regex') || ''
19-
settings.filterRegex = core.getInput('filter-regex') || ''
18+
const caseInsensitive = core.getInput('case-insensitive-regex')
19+
settings.tagRegex = RegExp(core.getInput('tag-regex'), caseInsensitive)
20+
settings.filterRegex = RegExp(core.getInput('filter-regex'), caseInsensitive)
2021
settings.changelogFilePath = core.getInput('changelog-file-path') || 'CHANGELOG.md'
2122
return settings
2223
}

0 commit comments

Comments
 (0)