Skip to content

Commit 77fccb8

Browse files
authored
feat: common auto pr add link (#88)
* feat: common auto pr add link * ci: fix paths * ci: fix paths * chore: print diff
1 parent 0d58bd4 commit 77fccb8

File tree

9 files changed

+102
-15
lines changed

9 files changed

+102
-15
lines changed

.github/workflows/test-tdesign-common-trigger.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on:
33
pull_request:
44
branches: [develop]
55
paths:
6-
- dist/index.js
6+
- dist/*
77

88
jobs:
99
pr-vue:

.github/workflows/test-tdesign-icons-trigger.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on:
33
pull_request:
44
branches: [develop]
55
paths:
6-
- dist/index.js
6+
- dist/*
77

88
jobs:
99
pr-vue:

.github/workflows/test-upgrade-deps-trigger.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on:
33
pull_request:
44
branches: [develop]
55
paths:
6-
- dist/index.js
6+
- dist/*
77

88
jobs:
99
upgrade-deps:

dist/index.mjs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43750,7 +43750,7 @@ var import_lib = require_lib();
4375043750
var import_lib$1 = require_lib$3();
4375143751
const SKIP_CHANGELOG_REG = /\[x\] 本条 PR 不需要纳入 Changelog/i;
4375243752
const CHANGELOG_REG = /-\s([A-Z]+)(?:\(([A-Z\s_-]*)\))?\s*:\s*(.+)/i;
43753-
function addContributor(body, contributor) {
43753+
function addContributor(body, contributor, link) {
4375443754
if (SKIP_CHANGELOG_REG.test(body)) {
4375543755
(0, import_core$6.info)(`不需要纳入 Changelog`);
4375643756
return body;
@@ -43767,7 +43767,11 @@ function addContributor(body, contributor) {
4376743767
isSkip = true;
4376843768
return item;
4376943769
}
43770-
if (CHANGELOG_REG.test(item)) return `${item} @${contributor}`;
43770+
if (CHANGELOG_REG.test(item)) {
43771+
let logContent = `${item} @${contributor}`;
43772+
if (link) logContent += ` ${link}`;
43773+
return logContent;
43774+
}
4377143775
}
4377243776
if (item === "### 📝 更新日志") isSkip = false;
4377343777
return item;
@@ -43930,6 +43934,9 @@ var GitHelper = class {
4393043934
const { stdout } = await (0, import_exec$3.getExecOutput)("git", ["status"], { cwd: this.repoPath });
4393143935
return !stdout.includes("nothing to commit, working tree clean");
4393243936
}
43937+
async printDiff() {
43938+
await (0, import_exec$3.exec)("git", ["diff"], { cwd: this.repoPath });
43939+
}
4393343940
};
4393443941

4393543942
//#endregion
@@ -44028,7 +44035,8 @@ async function start(context$1) {
4402844035
githubHelper.addComment(context$1.pr_number, "PR 还没合并,无法触发");
4402944036
return;
4403044037
}
44031-
const body = addContributor(prData.body || "", prData.user.login);
44038+
const link = `([common#${context$1.pr_number}](https://github.com/Tencent/tdesign-common/pull/${context$1.pr_number}))`;
44039+
const body = addContributor(prData.body || "", prData.user.login, link);
4403244040
const trigger = context$1.trigger;
4403344041
const gitHelper = new GitHelper({
4403444042
repo: repoMap[trigger],
@@ -44055,7 +44063,10 @@ async function start(context$1) {
4405544063
"--NAME",
4405644064
"all"
4405744065
], { cwd: `./${repoMap[trigger]}` });
44058-
if (await gitHelper.isNeedCommit()) await gitHelper.commit("docs: update css vars");
44066+
if (await gitHelper.isNeedCommit()) {
44067+
await gitHelper.printDiff();
44068+
await gitHelper.commit("docs: update css vars");
44069+
}
4405944070
}
4406044071
await gitHelper.push(branchName);
4406144072
const newPrData = await new GithubHelper({

src/tdesign/common.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export default async function start(context: TriggerContext) {
2222
githubHelper.addComment(context.pr_number, 'PR 还没合并,无法触发')
2323
return
2424
}
25-
const body = addContributor(prData.body || '', prData.user.login)
25+
const link = `([common#${context.pr_number}](https://github.com/Tencent/tdesign-common/pull/${context.pr_number}))`
26+
const body = addContributor(prData.body || '', prData.user.login, link)
2627
const trigger = context.trigger as AutoPrTrigger
2728
const gitHelper = new GitHelper({
2829
repo: repoMap[trigger],
@@ -51,6 +52,7 @@ export default async function start(context: TriggerContext) {
5152
}
5253
await exec('node', [scriptPath, '--NAME', 'all'], { cwd: `./${repoMap[trigger]}` })
5354
if (await gitHelper.isNeedCommit()) {
55+
await gitHelper.printDiff()
5456
await gitHelper.commit('docs: update css vars')
5557
}
5658
}

src/utils/common.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { readWorkspaceManifest } from '@pnpm/workspace.read-manifest'
88

99
export const SKIP_CHANGELOG_REG = /\[x\] PR Changelog/i
1010
export const CHANGELOG_REG = /-\s([A-Z]+)(?:\(([A-Z\s_-]*)\))?\s*:\s*(.+)/i
11-
export function addContributor(body: string, contributor: string): string {
11+
export function addContributor(body: string, contributor: string, link?: string): string {
1212
if (SKIP_CHANGELOG_REG.test(body)) {
1313
info(`不需要纳入 Changelog`)
1414
return body
@@ -26,7 +26,12 @@ export function addContributor(body: string, contributor: string): string {
2626
}
2727
if (CHANGELOG_REG.test(item)) {
2828
// info(`匹配到更新日志项: ${item}`)
29-
return `${item} @${contributor}`
29+
let logContent = `${item} @${contributor}`
30+
if (link) {
31+
logContent += ` ${link}`
32+
}
33+
34+
return logContent
3035
}
3136
}
3237
if (item === '### 📝 更新日志') {

src/utils/git-helper.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,8 @@ export class GitHelper {
7171
const { stdout } = await getExecOutput('git', ['status'], { cwd: this.repoPath })
7272
return !stdout.includes('nothing to commit, working tree clean')
7373
}
74+
75+
async printDiff() {
76+
await exec('git', ['diff'], { cwd: this.repoPath })
77+
}
7478
}

test/__snapshots__/utils.test.ts.snap

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`utils > addContributor > one log 1`] = `
3+
exports[`utils > addContributor > no link log 1`] = `
44
"<!--
55
首先,感谢你的贡献!😄
66
请阅读并遵循 [TDesign 贡献指南](https://github.com/Tencent/tdesign/blob/main/docs/contributing.md),填写以下 pull request 的信息。
@@ -58,6 +58,64 @@ from https://github.com/Tencent/tdesign-vue-next/issues/4866
5858
"
5959
`;
6060

61+
exports[`utils > addContributor > one log 1`] = `
62+
"<!--
63+
首先,感谢你的贡献!😄
64+
请阅读并遵循 [TDesign 贡献指南](https://github.com/Tencent/tdesign/blob/main/docs/contributing.md),填写以下 pull request 的信息。
65+
PR 在维护者审核通过后会合并,谢谢!
66+
-->
67+
68+
### 🤔 这个 PR 的性质是?
69+
70+
- [x] 日常 bug 修复
71+
- [ ] 新特性提交
72+
- [ ] 文档改进
73+
- [ ] 演示代码改进
74+
- [ ] 组件样式/交互改进
75+
- [ ] CI/CD 改进
76+
- [ ] 重构
77+
- [ ] 代码风格优化
78+
- [ ] 测试用例
79+
- [ ] 分支合并
80+
- [ ] 其他
81+
82+
### 🔗 相关 Issue
83+
84+
<!--
85+
1. 描述相关需求的来源,如相关的 issue 讨论链接。
86+
-->
87+
88+
from https://github.com/Tencent/tdesign-vue-next/issues/4866
89+
90+
### 💡 需求背景和解决方案
91+
92+
<!--
93+
1. 要解决的具体问题。
94+
2. 列出最终的 API 实现和用法。
95+
3. 涉及UI/交互变动需要有截图或 GIF。
96+
-->
97+
98+
### 📝 更新日志
99+
100+
<!--
101+
从用户角度描述具体变化,以及可能的 breaking change 和其他风险。
102+
-->
103+
104+
- fix(Utils): 修复日志一条 @tdesign-helper ([common#2283](https://github.com/Tencent/tdesign-common/pull/2283))
105+
106+
- [ ] 本条 PR 不需要纳入 Changelog
107+
108+
### ☑️ 请求合并前的自查清单
109+
110+
⚠️ 请自检并全部**勾选全部选项**。⚠️
111+
112+
- [x] 文档已补充或无须补充
113+
- [x] 代码演示已提供或无须提供
114+
- [x] TypeScript 定义已补充或无须补充
115+
- [x] Changelog 已提供或无须提供
116+
"
117+
`;
118+
61119
exports[`utils > addContributor > skip log 1`] = `
62120
"<!--
63121
首先,感谢你的贡献!😄
@@ -159,8 +217,8 @@ from https://github.com/Tencent/tdesign-vue-next/issues/4866
159217
从用户角度描述具体变化,以及可能的 breaking change 和其他风险。
160218
-->
161219
162-
- chore: 第一条日志 @tdesign-helper
163-
- chore: 第二条日志 @tdesign-helper
220+
- chore: 第一条日志 @tdesign-helper ([common#2283](https://github.com/Tencent/tdesign-common/pull/2283))
221+
- chore: 第二条日志 @tdesign-helper ([common#2283](https://github.com/Tencent/tdesign-common/pull/2283))
164222
165223
- [ ] 本条 PR 不需要纳入 Changelog
166224

test/utils.test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@ describe('utils', () => {
66
describe('addContributor', () => {
77
it('one log', () => {
88
const pr_body = readFileSync('test/fixtures/pr_body.md', 'utf8').replaceAll('\n', '\r\n')
9-
10-
const body = addContributor(pr_body, 'tdesign-helper')
9+
const link = `([common#2283](https://github.com/Tencent/tdesign-common/pull/2283))`
10+
const body = addContributor(pr_body, 'tdesign-helper', link)
1111
expect(body).toMatchSnapshot()
1212
})
1313

1414
it('two log', () => {
1515
const pr_body = readFileSync('test/fixtures/pr_body_two_log.md', 'utf8').replaceAll('\n', '\r\n')
16+
const link = `([common#2283](https://github.com/Tencent/tdesign-common/pull/2283))`
17+
const body = addContributor(pr_body, 'tdesign-helper', link)
18+
expect(body).toMatchSnapshot()
19+
})
20+
21+
it('no link log', () => {
22+
const pr_body = readFileSync('test/fixtures/pr_body.md', 'utf8').replaceAll('\n', '\r\n')
1623
const body = addContributor(pr_body, 'tdesign-helper')
1724
expect(body).toMatchSnapshot()
1825
})

0 commit comments

Comments
 (0)