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(Log): add notice categories #51

Merged
merged 1 commit into from
Nov 16, 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
6 changes: 6 additions & 0 deletions src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const breakingLabel = ['break', 'breaking', 'breaking changes']
const featureLabel = ['feature', 'feat', 'enhancement']
const docsLabel = ['docs', 'doc', 'documentation']
const refactorLabel = ['pref', 'refactor']
const noticeLabel = ['notice', 'new component']

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
Expand Down Expand Up @@ -41,6 +42,7 @@ export function renderMarkdown(pullRequestList: PullsData[]) {
bugfix: [] as PRChangelog[],
refactor: [] as PRChangelog[],
docs: [] as PRChangelog[],
notices: [] as PRChangelog[],
extra: [] as PRChangelog[],
}
startGroup(`[renderer] pullRequestList`)
Expand Down Expand Up @@ -96,6 +98,9 @@ export function renderMarkdown(pullRequestList: PullsData[]) {
else if (isInLabel(docsLabel)) {
categories.docs.push(logItem)
}
else if (isInLabel(noticeLabel)) {
categories.notices.push(logItem)
}
else {
categories.extra.push(logItem)
}
Expand All @@ -110,6 +115,7 @@ export function renderMarkdown(pullRequestList: PullsData[]) {
endGroup()

return [
categories.notices.length ? `### 🎉 Notices\n${renderCate(categories.notices)}` : '',
categories.breaking.length ? `### 🚨 Breaking Changes\n${renderCate(categories.breaking)}` : '',
categories.features.length ? `### 🚀 Features\n${renderCate(categories.features)}` : '',
categories.bugfix.length ? `### 🐞 Bug Fixes\n${renderCate(categories.bugfix)}` : '',
Expand Down
3 changes: 3 additions & 0 deletions test/__snapshots__/generatorLog.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
exports[`generatorLog > : generatorLogStart 1`] = `
"(删除此行代表确认该日志): 修改并确认日志后删除这一行,机器人会提交到 本 PR 的 CHANGELOG.md 文件中
## 🌈 x.x.x \`2024-02-24\`
### 🎉 Notices
- \`Component\`: a new component label in notice @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29))
- \`Icon\`: a new icon label in notice @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29))
### 🚨 Breaking Changes
- \`C\`: a major update label in break @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29))
- \`C\`: a major update label in breaking @liweijie0812 ([#29](https://github.com/TDesignOteam/tdesign-changelog-action/pull/29))
Expand Down
12 changes: 12 additions & 0 deletions test/__snapshots__/regexp.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ exports[`regexp > : CHANGELOG_REG 1`] = `
"test-test",
"test-test",
],
[
"- notice(Component): a new component label in notice",
"notice",
"Component",
"a new component label in notice",
],
[
"- notice(Icon): a new icon label in notice",
"notice",
"Icon",
"a new icon label in notice",
],
]
`;

Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export const changelog = `
- fix(CHANGELOG_REG): 修复日志冒号前面有空格正则匹配不到
- fix(CHANGELOG_REG):修复日志冒号后面没空格正则匹配不到
- fix(test-test): test-test
- notice(Component): a new component label in notice
- notice(Icon): a new icon label in notice
`

export default changelog
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(19)
expect([...records].length).toBe(21)

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

Expand Down