forked from Lamina-dev/Lamina
-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (76 loc) · 2.78 KB
/
label.yml
File metadata and controls
89 lines (76 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: PR Auto Labeler
on:
pull_request:
types: [opened, edited, synchronize]
jobs:
label:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
issues: write
repository-projects: read
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Auto-label PR
uses: actions/labeler@v5
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
configuration-path: .github/labeler.yml
sync-labels: true
dot: true
continue-on-error: true
- name: Fallback labeling (if main labeler fails)
if: failure()
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
try {
// 获取 PR 信息
const { data: pullRequest } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});
// 获取修改的文件
const { data: files } = await github.rest.pulls.listFiles({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});
const labels = [];
// 简单的文件路径标签逻辑
const filePatterns = {
'core': /^interpreter\//,
'extensions': /^extensions\//,
'documentation': /\.(md|txt)$|^docs?\//,
'build': /CMakeLists\.txt$|\.github\/workflows\//,
'examples': /^examples\/|\.lamina$|\.lm$/,
'config': /\.(yml|yaml|json|ini|cfg)$|\.github\//
};
for (const file of files) {
for (const [label, pattern] of Object.entries(filePatterns)) {
if (pattern.test(file.filename) && !labels.includes(label)) {
labels.push(label);
}
}
}
// 添加标签
if (labels.length > 0) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: labels,
});
console.log(`Added labels: ${labels.join(', ')}`);
}
} catch (error) {
console.log(`Fallback labeling failed: ${error.message}`);
// 即使失败也不要让工作流失败
}