-
-
Notifications
You must be signed in to change notification settings - Fork 162
286 lines (245 loc) · 11.1 KB
/
issue-topic-labeler.yml
File metadata and controls
286 lines (245 loc) · 11.1 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
name: Issue Topic Labeler
on:
issues:
types:
- opened
jobs:
label-topic:
if: ${{ !github.event.issue.pull_request }}
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
issues: write
steps:
- name: Classify and label issue
uses: actions/github-script@v7
env:
ISSUE_LABELER_API_KEY: ${{ secrets.ISSUE_LABELER_API_KEY }}
ISSUE_LABELER_BASE_URL: ${{ vars.ISSUE_LABELER_BASE_URL }}
ISSUE_LABELER_MODEL: ${{ vars.ISSUE_LABELER_MODEL }}
ISSUE_LABELER_PROVIDER: ${{ vars.ISSUE_LABELER_PROVIDER }}
with:
script: |
const allowedLabels = [
'topic: UI',
'topic:app',
'topic: player',
'topic: Extractor',
'topic: filter',
'topic: Download',
'topic: gesture',
'spam',
'topic: others',
]
const labelConfig = {
'topic: UI': {
color: '1d76db',
description: 'User interface and visual behavior issues',
},
'topic:app': {
color: '5319e7',
description: 'General app-level behavior and settings',
},
'topic: player': {
color: '0052cc',
description: 'Playback, controls, subtitles, and media behavior',
},
'topic: Extractor': {
color: 'fbca04',
description: 'Service extraction, parsing, and metadata retrieval',
},
'topic: filter': {
color: '0e8a16',
description: 'Filtering, sorting, and feed/search refinement',
},
'topic: Download': {
color: '006b75',
description: 'Downloads, offline saving, and file fetching',
},
'topic: gesture': {
color: 'c5def5',
description: 'Touch gestures such as swipe, tap, and long-press',
},
spam: {
color: 'b60205',
description: 'Spam, ads, nonsense, personal attacks, insults, or irrelevant content',
},
'topic: others': {
color: '6a737d',
description: 'Issues that do not clearly fit another topic',
},
}
const issue = context.payload.issue
const existingTopicLabel = issue.labels
.map((label) => typeof label === 'string' ? label : label.name)
.find((label) => allowedLabels.includes(label))
if (existingTopicLabel) {
core.info(`Issue already has topic label: ${existingTopicLabel}`)
return
}
const providerInput = (process.env.ISSUE_LABELER_PROVIDER || '').trim().toLowerCase()
const baseUrlInput = (process.env.ISSUE_LABELER_BASE_URL || '').trim()
const apiKey = (process.env.ISSUE_LABELER_API_KEY || '').trim()
if (!apiKey) {
throw new Error('Missing ISSUE_LABELER_API_KEY secret.')
}
const provider = providerInput || (baseUrlInput ? 'openai-compatible' : 'github-models')
if (!['github-models', 'openai-compatible'].includes(provider)) {
throw new Error(`Unsupported ISSUE_LABELER_PROVIDER: ${provider}`)
}
const model = (process.env.ISSUE_LABELER_MODEL || '').trim()
|| (provider === 'github-models' ? 'openai/gpt-5-mini' : 'gpt-5-mini')
const clip = (value, limit) => {
if (!value || value.length <= limit) {
return value
}
return `${value.slice(0, limit)}\n\n[truncated]`
}
const issueText = [
`Title: ${issue.title || ''}`,
`Body:\n${issue.body || ''}`,
].join('\n\n')
const systemPrompt = [
'You classify GitHub issues for an Android media app project.',
'Choose exactly one label from this list:',
allowedLabels.join(', '),
'Guidelines:',
'- topic: UI => layout, theme, rendering, icons, screens, navigation, visual glitches.',
'- topic:app => crashes, startup, settings, notifications, intents, backup, import/export, app-level behavior.',
'- topic: player => playback, subtitles, queue, controls, audio/video, fullscreen, speed, PiP.',
'- topic: Extractor => site/service parsing, metadata, stream URLs, login/captcha extraction, service-specific fetching.',
'- topic: filter => local blocking.',
'- topic: Download => downloads, offline saving, download queue, download files, storage of downloaded media.',
'- topic: gesture => swipe, tap, long press, touch gestures, gesture controls.',
'- spam => spam, ads, nonsense/gibberish, personal attacks, insults, harassment, hate speech, trolling, completely irrelevant content.',
'- topic: others => unclear or not covered above.',
'Return only the exact label text and nothing else.',
].join('\n')
const requestBody = {
model,
messages: [
{ role: 'system', content: systemPrompt },
{ role: 'user', content: clip(issueText, 6000) },
],
}
const request = provider === 'github-models'
? {
url: 'https://models.github.ai/inference/chat/completions',
headers: {
Authorization: `Bearer ${apiKey}`,
Accept: 'application/vnd.github+json',
'Content-Type': 'application/json',
'X-GitHub-Api-Version': '2026-03-10',
},
}
: {
url: `${baseUrlInput.replace(/\/$/, '')}/chat/completions`,
headers: {
Authorization: `Bearer ${apiKey}`,
'Content-Type': 'application/json',
},
}
if (provider === 'openai-compatible' && !baseUrlInput) {
throw new Error('ISSUE_LABELER_BASE_URL is required for openai-compatible provider.')
}
const response = await fetch(request.url, {
method: 'POST',
headers: request.headers,
body: JSON.stringify(requestBody),
})
const rawResponse = await response.text()
if (!response.ok) {
throw new Error(`Model request failed (${response.status}): ${rawResponse}`)
}
let responseData
try {
responseData = JSON.parse(rawResponse)
} catch (error) {
throw new Error(`Could not parse model response JSON: ${rawResponse}`)
}
const messageContent = responseData?.choices?.[0]?.message?.content
const content = Array.isArray(messageContent)
? messageContent.map((part) => part?.text || '').join('')
: String(messageContent || '')
const normalizeLabel = (value) => {
const trimmed = value.trim()
if (allowedLabels.includes(trimmed)) {
return trimmed
}
const lowered = trimmed.toLowerCase().replace('topic: app', 'topic:app')
return allowedLabels.find((label) => label.toLowerCase() === lowered)
|| allowedLabels.find((label) => lowered.includes(label.toLowerCase()))
|| null
}
const fallbackLabel = (value) => {
const text = value.toLowerCase()
if (/(\bcasino\b|\bpoker\b|\bgamble|\bcrypto\b|\bSEO\b|\bbuy \b|\bfree money\b|\bclick here\b|\bpromotion\b|\badvertisement\b|\btelegram\b|\bwhatsapp\b|\bstupid\b|\bidiot\b|\bmoron\b|\bfuck\b|\bshit\b|\bdumb\b|\basshole\b|\bbastard\b|\bretard\b|\bkill yourself\b|\bkys\b|\bscrew you\b)/.test(text)) {
return 'spam'
}
if (/(swipe|gesture|double tap|long press|touch control|touch gesture|pinch)/.test(text)) {
return 'topic: gesture'
}
if (/(download|offline|save file|save video|save audio|storage permission|download queue)/.test(text)) {
return 'topic: Download'
}
if (/(player|playback|subtitle|captions|fullscreen|picture-in-picture|pip|seek|pause|resume|play video|play audio|speed control)/.test(text)) {
return 'topic: player'
}
if (/(extractor|parsing|parser|metadata|stream url|video url|audio url|service-specific|youtube|bilibili|soundcloud|bandcamp)/.test(text)) {
return 'topic: Extractor'
}
if (/(filter)/.test(text)) {
return 'topic: filter'
}
if (/(theme|layout|screen|button|icon|font|toolbar|bottom bar|navigation|visual|ui | ux |dark mode|light mode)/.test(text)) {
return 'topic: UI'
}
if (/(crash|startup|settings|notification|intent|share menu|backup|restore|import|export|database|login|account)/.test(text)) {
return 'topic:app'
}
return 'topic: others'
}
const selectedLabel = normalizeLabel(content) || fallbackLabel(issueText)
const { color, description } = labelConfig[selectedLabel]
try {
await github.rest.issues.getLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: selectedLabel,
})
} catch (error) {
if (error.status !== 404) {
throw error
}
await github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: selectedLabel,
color,
description,
})
}
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: [selectedLabel],
})
if (selectedLabel === 'spam') {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: 'This issue has been identified as spam and will be closed.',
})
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: 'closed',
state_reason: 'not_planned',
})
}
core.info(`Model output: ${content}`)
core.info(`Applied label: ${selectedLabel}`)
core.setOutput('label', selectedLabel)