-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
423 lines (386 loc) · 20 KB
/
Copy pathbackfill-community-backlog.yml
File metadata and controls
423 lines (386 loc) · 20 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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
name: Backfill Community Backlog
on:
workflow_dispatch:
inputs:
since_days:
description: 'How many days back to scan closed community issues'
required: false
default: '90'
type: string
permissions:
contents: write
issues: read
pull-requests: write
concurrency:
group: community-backfill
cancel-in-progress: true
jobs:
backfill:
runs-on: ubuntu-latest
timeout-minutes: 15
if: github.repository == 'lingdojo/kana-dojo'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.AUTOMATION_PR_TOKEN }}
- name: Re-enable backlog from closed issues
id: backfill
uses: actions/github-script@v7
with:
github-token: ${{ secrets.AUTOMATION_PR_TOKEN }}
script: |
const fs = require('fs');
const templates = require('./.github/templates/messages.cjs');
const sinceDays = Number((context.payload.inputs && context.payload.inputs.since_days) || 90);
if (Number.isNaN(sinceDays) || sinceDays <= 0) {
throw new Error(`Invalid since_days input: ${context.payload.inputs && context.payload.inputs.since_days}`);
}
const sinceDate = new Date(Date.now() - sinceDays * 24 * 60 * 60 * 1000);
const themeBacklogPath = 'community/backlog/theme-backlog.json';
const factsBacklogPath = 'community/backlog/facts-backlog.json';
const proverbsBacklogPath = 'community/backlog/proverbs-backlog.json';
const haikuBacklogPath = 'community/backlog/haiku-backlog.json';
const triviaBacklogPath = 'community/backlog/trivia-backlog.json';
const grammarBacklogPath = 'community/backlog/grammar-backlog.json';
const animeQuotesBacklogPath = 'community/backlog/anime-quotes-backlog.json';
const idiomsBacklogPath = 'community/backlog/idioms-backlog.json';
const regionalDialectsBacklogPath = 'community/backlog/regional-dialects-backlog.json';
const falseFriendsBacklogPath = 'community/backlog/false-friends-backlog.json';
const culturalEtiquetteBacklogPath = 'community/backlog/cultural-etiquette-backlog.json';
const exampleSentencesBacklogPath = 'community/backlog/example-sentences-backlog.json';
const commonMistakesBacklogPath = 'community/backlog/common-mistakes-backlog.json';
const videoGameQuotesBacklogPath = 'community/backlog/video-game-quotes-backlog.json';
const wallpaperUrlsBacklogPath = 'community/backlog/wallpaper-urls-backlog.json';
const communityNotesBacklogPath = 'community/backlog/community-notes-backlog.json';
const themes = JSON.parse(fs.readFileSync(themeBacklogPath, 'utf8'));
const facts = JSON.parse(fs.readFileSync(factsBacklogPath, 'utf8'));
const proverbs = JSON.parse(fs.readFileSync(proverbsBacklogPath, 'utf8'));
const haiku = JSON.parse(fs.readFileSync(haikuBacklogPath, 'utf8'));
const trivia = JSON.parse(fs.readFileSync(triviaBacklogPath, 'utf8'));
const grammar = JSON.parse(fs.readFileSync(grammarBacklogPath, 'utf8'));
const animeQuotes = JSON.parse(fs.readFileSync(animeQuotesBacklogPath, 'utf8'));
const idioms = JSON.parse(fs.readFileSync(idiomsBacklogPath, 'utf8'));
const regionalDialects = JSON.parse(fs.readFileSync(regionalDialectsBacklogPath, 'utf8'));
const falseFriends = JSON.parse(fs.readFileSync(falseFriendsBacklogPath, 'utf8'));
const culturalEtiquette = JSON.parse(fs.readFileSync(culturalEtiquetteBacklogPath, 'utf8'));
const exampleSentences = JSON.parse(fs.readFileSync(exampleSentencesBacklogPath, 'utf8'));
const commonMistakes = JSON.parse(fs.readFileSync(commonMistakesBacklogPath, 'utf8'));
const videoGameQuotes = JSON.parse(fs.readFileSync(videoGameQuotesBacklogPath, 'utf8'));
const wallpaperUrls = JSON.parse(fs.readFileSync(wallpaperUrlsBacklogPath, 'utf8'));
const communityNotes = JSON.parse(fs.readFileSync(communityNotesBacklogPath, 'utf8'));
let needsCommit = false;
let page = 1;
let processed = 0;
let reenabled = 0;
function reenableFromTitle(title) {
if (title.includes('Add New Color Theme:') || title.includes('Add Theme:')) {
const themeMatch = title.match(/Add (?:New Color )?Theme:\s*(.+?)\s*(?:—|\(good)/i);
if (themeMatch) {
const themeName = themeMatch[1].trim();
const themeIndex = themes.findIndex(function(t) { return t.name === themeName; });
if (themeIndex !== -1 && themes[themeIndex].issued) {
themes[themeIndex].issued = false;
needsCommit = true;
reenabled += 1;
console.log(`Re-enabled theme: ${themeName}`);
}
}
return;
}
if (title.includes('Add Japan Fact #') || title.includes('Add new Japan Fact #')) {
const factIdMatch = title.match(/#(\d+)/);
if (factIdMatch) {
const factId = parseInt(factIdMatch[1]);
const factIndex = facts.findIndex(function(f) { return f.id === factId; });
if (factIndex !== -1 && facts[factIndex].issued) {
facts[factIndex].issued = false;
needsCommit = true;
reenabled += 1;
console.log(`Re-enabled fact #${factId}`);
}
}
return;
}
if (title.includes('Add Japanese Proverb #') || title.includes('Add new Japanese Proverb #')) {
const proverbIdMatch = title.match(/#(\d+)/);
if (proverbIdMatch) {
const proverbId = parseInt(proverbIdMatch[1]);
const proverbIndex = proverbs.findIndex(function(p) { return p.id === proverbId; });
if (proverbIndex !== -1 && proverbs[proverbIndex].issued) {
proverbs[proverbIndex].issued = false;
needsCommit = true;
reenabled += 1;
console.log(`Re-enabled proverb #${proverbId}`);
}
}
return;
}
if (title.includes('Add Classic Japanese Haiku #') || title.includes('Add Japanese Haiku #') || title.includes('Add new Japanese Haiku #')) {
const haikuIdMatch = title.match(/#(\d+)/);
if (haikuIdMatch) {
const haikuId = parseInt(haikuIdMatch[1]);
const haikuIndex = haiku.findIndex(function(h) { return h.id === haikuId; });
if (haikuIndex !== -1 && haiku[haikuIndex].issued) {
haiku[haikuIndex].issued = false;
needsCommit = true;
reenabled += 1;
console.log(`Re-enabled haiku #${haikuId}`);
}
}
return;
}
if (title.includes('Add New Trivia Question #') || title.includes('Add Trivia Question #') || title.includes('Add new Trivia Question #')) {
const triviaIdMatch = title.match(/#(\d+)/);
if (triviaIdMatch) {
const triviaId = parseInt(triviaIdMatch[1]);
const triviaIndex = trivia.findIndex(function(q) { return q.id === triviaId; });
if (triviaIndex !== -1 && trivia[triviaIndex].issued) {
trivia[triviaIndex].issued = false;
needsCommit = true;
reenabled += 1;
console.log(`Re-enabled trivia #${triviaId}`);
}
}
return;
}
if (title.includes('Add New Grammar Point #') || title.includes('Add Grammar Point #') || title.includes('Add new Grammar Point #')) {
const grammarIdMatch = title.match(/#(\d+)/);
if (grammarIdMatch) {
const grammarId = parseInt(grammarIdMatch[1]);
const grammarIndex = grammar.findIndex(function(g) { return g.id === grammarId; });
if (grammarIndex !== -1 && grammar[grammarIndex].issued) {
grammar[grammarIndex].issued = false;
needsCommit = true;
reenabled += 1;
console.log(`Re-enabled grammar #${grammarId}`);
}
}
return;
}
if (title.includes('Add New Japanese Idiom #') || title.includes('Add Japanese Idiom #') || title.includes('Add new Japanese Idiom #')) {
const idiomIdMatch = title.match(/#(\d+)/);
if (idiomIdMatch) {
const idiomId = parseInt(idiomIdMatch[1]);
const idiomIndex = idioms.findIndex(function(i) { return i.id === idiomId; });
if (idiomIndex !== -1 && idioms[idiomIndex].issued) {
idioms[idiomIndex].issued = false;
needsCommit = true;
reenabled += 1;
console.log(`Re-enabled idiom #${idiomId}`);
}
}
return;
}
if (title.includes('Add Regional Dialect Entry #') || title.includes('Add Dialect Entry #') || title.includes('Add new Dialect Entry #')) {
const dialectIdMatch = title.match(/#(\d+)/);
if (dialectIdMatch) {
const dialectId = parseInt(dialectIdMatch[1]);
const dialectIndex = regionalDialects.findIndex(function(d) { return d.id === dialectId; });
if (dialectIndex !== -1 && regionalDialects[dialectIndex].issued) {
regionalDialects[dialectIndex].issued = false;
needsCommit = true;
reenabled += 1;
console.log(`Re-enabled regional dialect #${dialectId}`);
}
}
return;
}
if (title.includes('Add Japanese False Friend #') || title.includes('Add False Friend Pair #') || title.includes('Add new False Friend Pair #')) {
const idMatch = title.match(/#(\d+)/);
if (idMatch) {
const id = parseInt(idMatch[1]);
const idx = falseFriends.findIndex(function(i) { return i.id === id; });
if (idx !== -1 && falseFriends[idx].issued) {
falseFriends[idx].issued = false;
needsCommit = true;
reenabled += 1;
console.log(`Re-enabled false friend #${id}`);
}
}
return;
}
if (title.includes('Add Japanese Cultural Etiquette Tip #') || title.includes('Add Etiquette Tip #') || title.includes('Add new Etiquette Tip #')) {
const idMatch = title.match(/#(\d+)/);
if (idMatch) {
const id = parseInt(idMatch[1]);
const idx = culturalEtiquette.findIndex(function(i) { return i.id === id; });
if (idx !== -1 && culturalEtiquette[idx].issued) {
culturalEtiquette[idx].issued = false;
needsCommit = true;
reenabled += 1;
console.log(`Re-enabled cultural etiquette #${id}`);
}
}
return;
}
if (title.includes('Add Japanese Example Sentence #') || title.includes('Add Example Sentence #') || title.includes('Add new Example Sentence #')) {
const idMatch = title.match(/#(\d+)/);
if (idMatch) {
const id = parseInt(idMatch[1]);
const idx = exampleSentences.findIndex(function(i) { return i.id === id; });
if (idx !== -1 && exampleSentences[idx].issued) {
exampleSentences[idx].issued = false;
needsCommit = true;
reenabled += 1;
console.log(`Re-enabled example sentence #${id}`);
}
}
return;
}
if (title.includes('Add Common Japanese Learner Mistake #') || title.includes('Add Learner Mistake #') || title.includes('Add new Learner Mistake #')) {
const idMatch = title.match(/#(\d+)/);
if (idMatch) {
const id = parseInt(idMatch[1]);
const idx = commonMistakes.findIndex(function(i) { return i.id === id; });
if (idx !== -1 && commonMistakes[idx].issued) {
commonMistakes[idx].issued = false;
needsCommit = true;
reenabled += 1;
console.log(`Re-enabled common mistake #${id}`);
}
}
return;
}
if (title.includes('Add Famous Japanese Video Game Quote #') || title.includes('Add Video Game Quote #') || title.includes('Add new Video Game Quote #')) {
const idMatch = title.match(/#(\d+)/);
if (idMatch) {
const id = parseInt(idMatch[1]);
const idx = videoGameQuotes.findIndex(function(i) { return i.id === id; });
if (idx !== -1 && videoGameQuotes[idx].issued) {
videoGameQuotes[idx].issued = false;
needsCommit = true;
reenabled += 1;
console.log(`Re-enabled video game quote #${id}`);
}
}
return;
}
if (title.includes('Add Wallpaper URL #') || title.includes('Add new Wallpaper URL #')) {
const idMatch = title.match(/#(\d+)/);
if (idMatch) {
const id = parseInt(idMatch[1]);
const idx = wallpaperUrls.findIndex(function(i) { return i.id === id; });
if (idx !== -1 && wallpaperUrls[idx].issued) {
wallpaperUrls[idx].issued = false;
needsCommit = true;
reenabled += 1;
console.log(`Re-enabled wallpaper URL #${id}`);
}
}
return;
}
if (title.includes('Add Community Note Line #') || title.includes('Add new Community Note Line #')) {
const idMatch = title.match(/#(\d+)/);
if (idMatch) {
const id = parseInt(idMatch[1]);
const idx = communityNotes.findIndex(function(i) { return i.id === id; });
if (idx !== -1 && communityNotes[idx].issued) {
communityNotes[idx].issued = false;
needsCommit = true;
reenabled += 1;
console.log(`Re-enabled community note #${id}`);
}
}
return;
}
if (title.includes('Add Famous Anime Quote #') || title.includes('Add Anime Quote #') || title.includes('Add new Anime Quote #')) {
const quoteIdMatch = title.match(/#(\d+)/);
if (quoteIdMatch) {
const quoteId = parseInt(quoteIdMatch[1]);
const quoteIndex = animeQuotes.findIndex(function(q) { return q.id === quoteId; });
if (quoteIndex !== -1 && animeQuotes[quoteIndex].issued) {
animeQuotes[quoteIndex].issued = false;
needsCommit = true;
reenabled += 1;
console.log(`Re-enabled anime quote #${quoteId}`);
}
}
return;
}
}
while (true) {
const { data: pageItems } = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
labels: templates.labels.community,
state: 'closed',
per_page: 100,
page: page
});
if (!pageItems || pageItems.length === 0) {
break;
}
for (const issue of pageItems) {
if (issue.pull_request) {
continue;
}
const closedAt = new Date(issue.closed_at || issue.updated_at);
if (closedAt < sinceDate) {
continue;
}
if (issue.state_reason !== 'not_planned') {
continue;
}
processed += 1;
reenableFromTitle(issue.title || '');
}
if (pageItems.length < 100) {
break;
}
page += 1;
}
console.log(`Backfill scan complete. Scanned=${processed}, re-enabled=${reenabled}`);
if (needsCommit) {
fs.writeFileSync(themeBacklogPath, JSON.stringify(themes, null, 2));
fs.writeFileSync(factsBacklogPath, JSON.stringify(facts, null, 2));
fs.writeFileSync(proverbsBacklogPath, JSON.stringify(proverbs, null, 2));
fs.writeFileSync(haikuBacklogPath, JSON.stringify(haiku, null, 2));
fs.writeFileSync(triviaBacklogPath, JSON.stringify(trivia, null, 2));
fs.writeFileSync(grammarBacklogPath, JSON.stringify(grammar, null, 2));
fs.writeFileSync(animeQuotesBacklogPath, JSON.stringify(animeQuotes, null, 2));
fs.writeFileSync(idiomsBacklogPath, JSON.stringify(idioms, null, 2));
fs.writeFileSync(regionalDialectsBacklogPath, JSON.stringify(regionalDialects, null, 2));
fs.writeFileSync(falseFriendsBacklogPath, JSON.stringify(falseFriends, null, 2));
fs.writeFileSync(culturalEtiquetteBacklogPath, JSON.stringify(culturalEtiquette, null, 2));
fs.writeFileSync(exampleSentencesBacklogPath, JSON.stringify(exampleSentences, null, 2));
fs.writeFileSync(commonMistakesBacklogPath, JSON.stringify(commonMistakes, null, 2));
fs.writeFileSync(videoGameQuotesBacklogPath, JSON.stringify(videoGameQuotes, null, 2));
fs.writeFileSync(wallpaperUrlsBacklogPath, JSON.stringify(wallpaperUrls, null, 2));
fs.writeFileSync(communityNotesBacklogPath, JSON.stringify(communityNotes, null, 2));
core.setOutput('needs_commit', 'true');
} else {
core.setOutput('needs_commit', 'false');
}
- name: Commit backlog updates directly to main
if: steps.backfill.outputs.needs_commit == 'true'
run: |
git config user.name "てんとう虫"
git config user.email "reservecrate@gmail.com"
git add community/backlog/
if git diff --cached --quiet; then
echo "No backlog changes to commit"
exit 0
fi
commit_msg="chore(automation): backfill community backlog"
max_attempts=5
attempt=1
while [ "$attempt" -le "$max_attempts" ]; do
git commit -m "$commit_msg"
if git pull --rebase origin main && git push origin HEAD:main; then
echo "Backlog push succeeded on attempt $attempt"
exit 0
fi
echo "Backlog push attempt $attempt failed; retrying..."
git rebase --abort || true
git fetch origin main
git reset --hard origin/main
git add community/backlog/
if git diff --cached --quiet; then
echo "No backlog changes remain after sync"
exit 0
fi
attempt=$((attempt + 1))
done
echo "Failed to push backlog updates after $max_attempts attempts"
exit 1