From 176a87a7273bd079d46eedbc169ae3172c78ddd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E4=BC=9F=E6=9D=B0?= <674416404@qq.com> Date: Sat, 16 Nov 2024 22:36:22 +0800 Subject: [PATCH] feat(Log): add notice categories --- src/renderer.ts | 6 ++++++ test/__snapshots__/generatorLog.test.ts.snap | 3 +++ test/__snapshots__/regexp.test.ts.snap | 12 ++++++++++++ test/fixtures/changelog.ts | 2 ++ test/regexp.test.ts | 4 ++-- 5 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/renderer.ts b/src/renderer.ts index 21e51a0..0c1654f 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -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 @@ -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`) @@ -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) } @@ -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)}` : '', diff --git a/test/__snapshots__/generatorLog.test.ts.snap b/test/__snapshots__/generatorLog.test.ts.snap index 82270ff..c9613b9 100644 --- a/test/__snapshots__/generatorLog.test.ts.snap +++ b/test/__snapshots__/generatorLog.test.ts.snap @@ -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)) diff --git a/test/__snapshots__/regexp.test.ts.snap b/test/__snapshots__/regexp.test.ts.snap index 54a29d8..c795b91 100644 --- a/test/__snapshots__/regexp.test.ts.snap +++ b/test/__snapshots__/regexp.test.ts.snap @@ -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", + ], ] `; diff --git a/test/fixtures/changelog.ts b/test/fixtures/changelog.ts index 5ce88cb..9618991 100644 --- a/test/fixtures/changelog.ts +++ b/test/fixtures/changelog.ts @@ -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 diff --git a/test/regexp.test.ts b/test/regexp.test.ts index e27d9b1..917b452 100644 --- a/test/regexp.test.ts +++ b/test/regexp.test.ts @@ -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() })