-
Notifications
You must be signed in to change notification settings - Fork 3
132 lines (114 loc) · 4.25 KB
/
labeler.yml
File metadata and controls
132 lines (114 loc) · 4.25 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: Label PRs
on:
pull_request:
types: [opened, edited, synchronize]
permissions:
contents: read
pull-requests: write
jobs:
label:
# Disabled: fails on fork PRs due to token permissions
if: false
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Label PR based on files
uses: actions/labeler@v6
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
configuration-path: .github/labeler.yml
- name: Label PR based on size
uses: actions/github-script@v8
with:
script: |
const pr = context.payload.pull_request;
const additions = pr.additions;
const deletions = pr.deletions;
const totalChanges = additions + deletions;
// Remove existing size labels
const existingLabels = pr.labels.map(label => label.name);
const sizeLabels = ['size/XS', 'size/S', 'size/M', 'size/L', 'size/XL'];
const labelsToRemove = existingLabels.filter(label => sizeLabels.includes(label));
for (const label of labelsToRemove) {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
name: label
});
}
// Determine size label
let sizeLabel;
if (totalChanges < 10) {
sizeLabel = 'size/XS';
} else if (totalChanges < 50) {
sizeLabel = 'size/S';
} else if (totalChanges < 200) {
sizeLabel = 'size/M';
} else if (totalChanges < 500) {
sizeLabel = 'size/L';
} else {
sizeLabel = 'size/XL';
}
// Add new size label
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
labels: [sizeLabel]
});
core.info(`Added label: ${sizeLabel} (${totalChanges} changes)`);
- name: Label PR based on title
uses: actions/github-script@v8
with:
script: |
const pr = context.payload.pull_request;
const title = pr.title.toLowerCase();
const labels = [];
// Conventional commit prefixes (case-insensitive with [] or () brackets)
const patterns = {
feat: /^(feat|FEAT)[\[:(]/,
fix: /^(fix|FIX)[\[:(]/,
docs: /^(docs|DOCS)[\[:(]/,
test: /^(test|TEST|tests|TESTS)[\[:(]/,
chore: /^(chore|CHORE)[\[:(]/,
refactor: /^(refactor|REFACTOR)[\[:(]/,
perf: /^(perf|PERF)[\[:(]/,
style: /^(style|STYLE)[\[:(]/,
ci: /^(ci|CI)[\[:(]/,
};
if (patterns.feat.test(pr.title)) {
labels.push('enhancement');
} else if (patterns.fix.test(pr.title)) {
labels.push('bug');
} else if (patterns.docs.test(pr.title)) {
labels.push('documentation');
} else if (patterns.test.test(pr.title)) {
labels.push('tests');
} else if (patterns.chore.test(pr.title)) {
labels.push('maintenance');
} else if (patterns.refactor.test(pr.title)) {
labels.push('refactor');
} else if (patterns.perf.test(pr.title)) {
labels.push('performance');
} else if (patterns.ci.test(pr.title)) {
labels.push('ci');
}
// Keywords
if (title.includes('breaking') || title.includes('breaking change')) {
labels.push('breaking-change');
}
if (title.includes('security')) {
labels.push('security');
}
// Add labels
if (labels.length > 0) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
labels: labels
});
core.info(`Added labels: ${labels.join(', ')}`);
}