Skip to content

Commit e4ede82

Browse files
committed
chore: pr label check
1 parent 63eceda commit e4ede82

1 file changed

Lines changed: 72 additions & 1 deletion

File tree

.github/workflows/pr-label-check.yml

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,76 @@ jobs:
2222
const repo = context.repo.repo;
2323
const marker = "<!-- LABEL_CHECK_BOT -->";
2424
25+
function suggestLabels(files) {
26+
const dirs = new Set();
27+
for (const f of files) {
28+
const p = f.filename.split("/");
29+
dirs.add(p[0]);
30+
if (p.length >= 2) dirs.add(p[0] + "/" + p[1]);
31+
}
32+
const s = [];
33+
34+
// 文档
35+
if (dirs.has("docs") || dirs.has("oseps") || dirs.has("specs") ||
36+
dirs.has("examples")) {
37+
s.push("documentation");
38+
}
39+
40+
// 组件
41+
if (dirs.has("components/egress")) s.push("component/egress");
42+
if (dirs.has("components/ingress")) s.push("component/ingress");
43+
if (dirs.has("components/execd")) s.push("component/execd");
44+
if (dirs.has("components/code-interpreter")) s.push("component/code-interpreter");
45+
if (dirs.has("components/internal")) {
46+
s.push("component/egress", "component/ingress");
47+
}
48+
49+
// k8s / server
50+
if (dirs.has("kubernetes")) s.push("component/k8s");
51+
if (dirs.has("server")) s.push("component/server");
52+
53+
// SDK
54+
if (dirs.has("sdks")) {
55+
s.push("sdks");
56+
if (dirs.has("sdks/go")) s.push("sdk/go");
57+
if (dirs.has("sdks/java")) s.push("sdk/java");
58+
if (dirs.has("sdks/python")) s.push("sdk/python");
59+
if (dirs.has("sdks/js")) s.push("sdk/js");
60+
if (dirs.has("sdks/csharp")) s.push("sdk/c#");
61+
}
62+
63+
return [...new Set(s)].sort();
64+
}
65+
2566
if (labels.length === 0) {
67+
const { data: files } = await github.rest.pulls.listFiles({
68+
owner, repo, pull_number: prNumber,
69+
});
70+
const suggested = suggestLabels(files);
71+
72+
const { data: allLabels } = await github.rest.issues.listLabelsForRepo({
73+
owner, repo,
74+
});
75+
76+
let tip = "";
77+
const suggestedSet = new Set(suggested);
78+
const otherLabels = allLabels.filter(l => !suggestedSet.has(l.name));
79+
if (suggested.length > 0) {
80+
tip = `\n\n📋 **Recommended labels** (based on changed files):\n`;
81+
for (const name of suggested) {
82+
tip += `- \`${name}\` ⬅️\n`;
83+
}
84+
if (otherLabels.length > 0) {
85+
tip += `\nOther available labels:\n`;
86+
for (const lab of otherLabels) {
87+
const desc = lab.description ? ` - ${lab.description}` : "";
88+
tip += `- \`${lab.name}\`${desc}\n`;
89+
}
90+
}
91+
}
92+
93+
const touchedDirs = [...new Set(files.map(f => f.filename.split("/")[0]))].join("、");
94+
const hint = `\n\n💡 Tip: Use \`feature\` for new functionality or improvements, \`bug\` for fixes.`;
2695
const { data: comments } = await github.rest.issues.listComments({
2796
owner, repo, issue_number: prNumber,
2897
});
@@ -33,7 +102,9 @@ jobs:
33102
await github.rest.issues.createComment({
34103
owner, repo, issue_number: prNumber,
35104
body: `${marker}
36-
⚠️ This PR has no labels. Please add one to help categorize this change.
105+
⚠️ This PR has no labels. Please add one based on the changes.
106+
107+
Changed directories: ${touchedDirs}.${tip}${hint}
37108
38109
cc @${pr.user.login}`,
39110
});

0 commit comments

Comments
 (0)