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

fix(CHANGELOG_REG): Improve regular expressions #46

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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