forked from aryandas2911/DailyForge
-
Notifications
You must be signed in to change notification settings - Fork 0
209 lines (189 loc) · 6.24 KB
/
Copy pathauto-label.yml
File metadata and controls
209 lines (189 loc) · 6.24 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
name: Auto-label issues
on:
issues:
types: [opened]
permissions:
issues: write
jobs:
label:
runs-on: ubuntu-latest
steps:
- name: Add labels based on keywords
uses: actions/github-script@v7
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const issue_number = context.payload.issue.number;
const issue = context.payload.issue;
const title = (issue.title || '').toLowerCase();
const body = (issue.body || '').toLowerCase();
const text = `${title}\n${body}`;
const normalizeLabel = (s) => s.trim().toLowerCase();
// If any matching rule triggers, we ADD labels only if missing.
// This ensures we don't override user-applied labels.
const patterns = [
{
label: 'GSSoC \'26',
// GSSOC / GSoC / Google Summer of Code / World GSSOC
match: [
/\bgssoc\b/i,
/\bgsoc\b/i,
/g\s*soc/i,
/google\s+summer\s+of\s+code/i,
/world\s+gssoc/i,
/gssoc\s*['’]?\s*26/i,
/gsoc\s*['’]?\s*26/i,
/gssoc\s*26/i,
/gsoc\s*26/i,
],
},
{
label: 'gssoc-2026',
// Existing label support
match: [
/\bgssoc\b/i,
/\bgsoc\b/i,
/google\s+summer\s+of\s+code/i,
/world\s+gssoc/i,
],
},
{
label: 'backend',
match: [
/\bbackend\b/i,
/\bapi\b/i,
/server/i,
/route/i,
/routes/i,
/middleware/i,
/database/i,
/\bdb\b/i,
/auth/i,
/authentication/i,
/token/i,
],
},
{
label: 'frontend',
match: [
/\bfrontend\b/i,
/client\b/i,
/\bui\b/i,
/\bux\b/i,
/react/i,
/vite/i,
/\bcss\b/i,
/\bdesign\b/i,
/\btheme\b/i,
/\bhtml\b/i,
/\bjavascript\b/i,
/\bjs\b/i,
/\btypescript\b/i,
/\bts\b/i,
],
},
{
label: 'bug',
match: [
/\bbug\b/i,
/crash/i,
/error/i,
/fails?/i,
/issue\s+with/i,
/doesn\'t\s+work/i,
/doesnt\s+work/i,
/not\s+working/i,
/regression/i,
],
},
{
label: 'enhancement',
match: [
/\benhancement\b/i,
/\bimprovement\b/i,
/upgrade/i,
/add\s+.*(improvement|capability|support|option)/i,
/feature\s+request/i,
],
},
{
label: 'feature',
match: [
/\bfeature\b/i,
/enhancement/i,
/add\s+.*(feature|support|module)/i,
/implement/i,
/capability/i,
/request\s+for/i,
],
},
{
label: 'documentation',
match: [
/\bdocs?\b/i,
/documentation/i,
/readme/i,
/guide/i,
/improve\s+.*(doc|docs)/i,
/changelog/i,
],
},
{
label: 'good first issue',
match: [
/good first issue/i,
/help\s*wanted/i,
/needs?\s+help/i,
/beginner\b/i,
/easy\b/i,
/starter\b/i,
/first\s+timer/i,
],
},
];
const shouldApply = (pattern, text) => {
if (!pattern || !pattern.length) return false;
return pattern.some((re) => re.test(text));
};
const repoLabels = await github.rest.issues.listLabelsForRepo({
owner,
repo,
per_page: 100,
});
const existingLabelNames = new Set((repoLabels.data || []).map((l) => normalizeLabel(l.name)));
const currentIssueLabels = await github.rest.issues.listLabelsOnIssue({
owner,
repo,
issue_number,
per_page: 100,
});
const currentIssueLabelNames = new Set((currentIssueLabels.data || []).map((l) => normalizeLabel(l.name)));
const labelsToAdd = [];
for (const p of patterns) {
const labelName = p.label;
const labelKey = normalizeLabel(labelName);
// Only consider labels that exist in the repo (prevents API errors).
if (!existingLabelNames.has(labelKey)) continue;
const matched = shouldApply(p.match, text);
if (!matched) continue;
// Don't override/manual-apply: add only if missing.
if (currentIssueLabelNames.has(labelKey)) continue;
labelsToAdd.push(labelName);
currentIssueLabelNames.add(labelKey);
}
// De-dupe
const uniq = [...new Set(labelsToAdd)];
if (uniq.length === 0) {
core.info('No matching labels to add.');
return;
}
core.info(`Adding labels: ${uniq.join(', ')}`);
await github.rest.issues.addLabels({
owner,
repo,
issue_number,
labels: uniq,
});
- name: Summary
run: echo "Auto-label workflow executed."