Skip to content

Commit 00df12e

Browse files
committed
fix(pr-auto-label.yml): improve label detection by matching keyword prefixes to enhance pull request labeling accuracy
1 parent 7aa9c43 commit 00df12e

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: 'Auto Label by Title'
1+
name: "Auto Label by Title"
22

33
on:
44
pull_request:
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
# 添加权限配置
1414
permissions:
15-
issues: write # 或者 contents: write
15+
issues: write # 或者 contents: write
1616
pull-requests: write
1717
steps:
1818
- name: Label PR based on title keywords
@@ -37,13 +37,20 @@ jobs:
3737
'dependabot': 'dependencies',
3838
'upgrade': 'dependencies',
3939
'security': 'security',
40-
'ci':'ci'
40+
'ci': 'ci'
4141
};
4242
43-
// 检查标题是否包含关键词
44-
for (const [keyword, label] of Object.entries(keywordMap)) {
45-
if (title.includes(keyword)) {
46-
labelsToAdd.add(label);
43+
// 提取标题的第一个单词(冒号前的部分)
44+
const firstPart = title.split(':')[0].trim();
45+
const words = firstPart.split(/\s+/); // 分割成单词数组
46+
47+
// 检查第一个单词或前缀是否匹配关键词
48+
for (const word of words) {
49+
const normalizedWord = word.toLowerCase().replace(/^[\W_]+|[\W_]+$/g, '');
50+
51+
if (keywordMap.hasOwnProperty(normalizedWord)) {
52+
labelsToAdd.add(keywordMap[normalizedWord]);
53+
break; // 找到第一个匹配就停止
4754
}
4855
}
4956

0 commit comments

Comments
 (0)