From 02048f2550c0bfb226ae541baee87bf95a20d8ea Mon Sep 17 00:00:00 2001 From: liweijie <674416404@qq.com> Date: Sat, 29 Aug 2026 14:31:37 +0800 Subject: [PATCH] =?UTF-8?q?fix(upgrade-deps):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=9B=BE=E6=A0=87=20PR=20=E9=93=BE=E6=8E=A5=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E4=B8=8E=E6=9B=B4=E6=96=B0=E6=97=A5=E5=BF=97=E6=8F=92=E5=85=A5?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- actions/upgrade-deps/dist/index.mjs | 7 +++-- actions/upgrade-deps/src/pull-request.ts | 8 ++++-- actions/upgrade-deps/test/main.test.ts | 33 +++++++++++++++++++++++- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/actions/upgrade-deps/dist/index.mjs b/actions/upgrade-deps/dist/index.mjs index c1969d7..005d50c 100644 --- a/actions/upgrade-deps/dist/index.mjs +++ b/actions/upgrade-deps/dist/index.mjs @@ -21573,11 +21573,14 @@ function formatType(type, scoped) { const breaking = type.endsWith("!"); return `${breaking ? type.slice(0, -1) : type}${scoped ? "(Icon)" : ""}${breaking ? "!" : ""}`; } +function formatCrossRepositoryLinks(text) { + return text.replace(/\[#(\d+)\]\((https:\/\/github\.com\/Tencent\/tdesign-icons\/pull\/\1)\)/g, "[icons#$1]($2)"); +} function getChangelogMarkdown(deps, targetRepo) { const scoped = COMPONENT_REPOSITORIES.has(targetRepo); return deps.filter((dep) => !NO_CHANGELOG_DEPENDENCIES.has(dep.name)).flatMap((dep) => { const entries = dep.release ? parseReleaseChangelog(dep.release.body) : []; - return entries.length ? entries.map((entry) => `- ${formatType(entry.type, scoped)}: ${entry.text}`) : [`- ${formatType("chore", scoped)}: upgrade ${dep.name} to ${dep.version}`]; + return entries.length ? entries.map((entry) => `- ${formatType(entry.type, scoped)}: ${formatCrossRepositoryLinks(entry.text)}`) : [`- ${formatType("chore", scoped)}: upgrade ${dep.name} to ${dep.version}`]; }).join("\n"); } function buildNoChangelogBody(template) { @@ -21607,7 +21610,7 @@ function insertChangelog(body, repo, changelog) { return inserted ? { body: result, inserted - } : insertAfter(result, /更新日志|changelog|release notes/i, changelog); + } : insertAfter(result, "📝 更新日志", changelog); } function buildPullRequestBody(template, deps, targetRepo) { if (deps.length && deps.every((dep) => NO_CHANGELOG_DEPENDENCIES.has(dep.name))) return buildNoChangelogBody(template); diff --git a/actions/upgrade-deps/src/pull-request.ts b/actions/upgrade-deps/src/pull-request.ts index 504364b..600b783 100644 --- a/actions/upgrade-deps/src/pull-request.ts +++ b/actions/upgrade-deps/src/pull-request.ts @@ -100,11 +100,15 @@ function formatType(type: ChangelogType, scoped: boolean): string { return `${base}${scoped ? '(Icon)' : ''}${breaking ? '!' : ''}` } +function formatCrossRepositoryLinks(text: string): string { + return text.replace(/\[#(\d+)\]\((https:\/\/github\.com\/Tencent\/tdesign-icons\/pull\/\1)\)/g, '[icons#$1]($2)') +} + export function getChangelogMarkdown(deps: DependencyInfo[], targetRepo: string): string { const scoped = COMPONENT_REPOSITORIES.has(targetRepo) return deps.filter(dep => !NO_CHANGELOG_DEPENDENCIES.has(dep.name)).flatMap((dep) => { const entries = dep.release ? parseReleaseChangelog(dep.release.body) : [] - return entries.length ? entries.map(entry => `- ${formatType(entry.type, scoped)}: ${entry.text}`) : [`- ${formatType('chore', scoped)}: upgrade ${dep.name} to ${dep.version}`] + return entries.length ? entries.map(entry => `- ${formatType(entry.type, scoped)}: ${formatCrossRepositoryLinks(entry.text)}`) : [`- ${formatType('chore', scoped)}: upgrade ${dep.name} to ${dep.version}`] }).join('\n') } @@ -129,7 +133,7 @@ function insertChangelog(body: string, repo: string, changelog: string): { body: result = update.body inserted ||= update.inserted } - return inserted ? { body: result, inserted } : insertAfter(result, /更新日志|changelog|release notes/i, changelog) + return inserted ? { body: result, inserted } : insertAfter(result, '📝 更新日志', changelog) } export function buildPullRequestBody(template: string | undefined, deps: DependencyInfo[], targetRepo: string): string { diff --git a/actions/upgrade-deps/test/main.test.ts b/actions/upgrade-deps/test/main.test.ts index fea4e6d..75ad982 100644 --- a/actions/upgrade-deps/test/main.test.ts +++ b/actions/upgrade-deps/test/main.test.ts @@ -482,13 +482,44 @@ catalogs: expect(body).toContain('- `tdesign-icons-view` 升级至 `0.5.7`') expect(body).toContain('#### [`tdesign-icons-view@0.5.7`]') expect(body).toContain('##### 🌈 0.5.7 `2026-07-15`\n\n###### 🐞 Bug Fixes') - expect(body).toContain('### 📝 更新日志\n\n- fix: 修复 fullscreen、logo-wecom-filled、no-result-filled、tree-list、wifi-no-filled 5 个图标搜索缺失 @liweijie0812 ([#264](https://github.com/Tencent/tdesign-icons/pull/264))') + expect(body).toContain('### 📝 更新日志\n\n- fix: 修复 fullscreen、logo-wecom-filled、no-result-filled、tree-list、wifi-no-filled 5 个图标搜索缺失 @liweijie0812 ([icons#264](https://github.com/Tencent/tdesign-icons/pull/264))') expect(body).not.toContain('fix(组件名称)') expect(body).toContain('- [x] 其他') expect(body).toContain('- [ ] 本条 PR 不需要纳入 Changelog') expect(body).toContain('- [x] Changelog 已提供或无须提供') }) + it('单仓模板不将 CHANGELOG 链接误认为更新日志区块', () => { + const template = `### 💡 需求背景和解决方案 + + + +### 📝 更新日志 + + + +- fix(组件名称): 处理问题或特性描述 ... + +- [ ] 本条 PR 不需要纳入 Changelog + +### ☑️ 请求合并前的自查清单 + +- [ ] Changelog 已提供或无须提供` + const changelog = '- fix(Icon): 修复 usb 原始图标的图层 ID 错误 @uyarn ([icons#298](https://github.com/Tencent/tdesign-icons/pull/298))' + const body = buildPullRequestBody(template, [{ + name: 'tdesign-icons-vue-next', + version: '0.4.11', + release: { + body: '## 🌈 0.4.11 `2026-08-28`\n\n### 🐞 Bug Fixes\n\n- 修复 usb 原始图标的图层 ID 错误 @uyarn ([#298](https://github.com/Tencent/tdesign-icons/pull/298))', + tag: 'tdesign-icons-vue-next@0.4.11', + url: 'https://github.com/Tencent/tdesign-icons/blob/HEAD/packages/vue-next/CHANGELOG.md', + }, + }], 'tdesign-mobile-vue') + + expect(body).toContain(`### 📝 更新日志\n\n${changelog}`) + expect(body).not.toContain(`CHANGELOG.md)\n\n${changelog}`) + }) + it('仅升级无需 Changelog 的依赖时只勾选对应选项', () => { const template = `### 🤔 这个 PR 的性质是?