Skip to content

Commit

Permalink
fix(CHANGELOG_REG): Improve regular expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
liweijie0812 committed Nov 8, 2024
1 parent 93a7e3b commit a81af11
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const featureLabel = ['feature', 'feat', 'enhancement']
const docsLabel = ['docs', 'doc', 'documentation']
const refactorLabel = ['pref', 'refactor']

export const CHANGELOG_REG = /-\s([A-Z]+)(?:\(([A-Z\s_-]*)\))?\s*:\s(.+)/gi
export const CHANGELOG_REG = /-\s([A-Z]+)(?:\(([A-Z\s_-]*)\))?\s*:\s*(.+)/gi
export const PULL_NUMBER_REG = /in\shttps:\/\/github\.com\/.+\/pull\/(\d+)/g
export const SKIP_CHANGELOG_REG = /\[x\] 本条 PR 不需要纳入 Changelog/i
export function getPullNumbers(body: string) {
Expand Down
1 change: 1 addition & 0 deletions test/__snapshots__/generatorLog.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ exports[`generatorLog > : generatorLogStart 1`] = `
- \`A\`: a bug fix label in hotfix @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29))
- \`A\`: a bug fix label in bug @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29))
- \`CHANGELOG_REG\`: 修复日志冒号前面有空格正则匹配不到 @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29))
- \`CHANGELOG_REG\`: 修复日志冒号后面没空格正则匹配不到 @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29))
- \`test-test\`: test-test @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29))
### 📈 Performance
- \`I\`: a refactor label in refactor @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29))
Expand Down
6 changes: 6 additions & 0 deletions test/__snapshots__/regexp.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ exports[`regexp > : CHANGELOG_REG 1`] = `
"CHANGELOG_REG",
"修复日志冒号前面有空格正则匹配不到",
],
[
"- fix(CHANGELOG_REG):修复日志冒号后面没空格正则匹配不到",
"fix",
"CHANGELOG_REG",
"修复日志冒号后面没空格正则匹配不到",
],
[
"- fix(test-test): test-test",
"fix",
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const changelog = `
- test(J) : test label in test
- test : test label in test
- fix(CHANGELOG_REG): 修复日志冒号前面有空格正则匹配不到
- fix(CHANGELOG_REG):修复日志冒号后面没空格正则匹配不到
- fix(test-test): test-test
`

Expand Down
4 changes: 2 additions & 2 deletions test/regexp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import releaseNotes from './fixtures/release-notes'
describe('regexp', () => {
it(': CHANGELOG_REG', () => {
const records = changelog.matchAll(/-\s/g)
expect([...records].length).toBe(18)
expect([...records].length).toBe(19)

const result = changelog.matchAll(CHANGELOG_REG)
const arr = [...result]
expect(arr.length).toBe(18)
expect(arr.length).toBe(19)
expect(arr).toMatchSnapshot()
})

Expand Down

0 comments on commit a81af11

Please sign in to comment.