forked from angular/angular-ja
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync-untranslated-issue.mjs
More file actions
324 lines (264 loc) · 10.1 KB
/
Copy pathsync-untranslated-issue.mjs
File metadata and controls
324 lines (264 loc) · 10.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
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
/**
* @fileoverview GitHub Actions script to sync untranslated files tracking issue
*/
/**
* @typedef {Object} UntranslatedFile
* @property {string} path - File path relative to adev-ja
* @property {string} category - File category (guide, tutorial, etc.)
* @property {string} extension - File extension without dot
*/
/**
* @typedef {Object} FilesData
* @property {number} count - Total number of untranslated files
* @property {UntranslatedFile[]} files - Array of untranslated files
*/
/**
* @typedef {Object} FileLinks
* @property {string} githubUrl - GitHub blob URL
* @property {string|null} previewUrl - Preview URL on angular.jp (null for non-md files)
* @property {string} issueUrl - Issue creation URL with pre-filled title
*/
/**
* @typedef {Object} GitHubContext
* @property {Object} repo
* @property {string} repo.owner - Repository owner
* @property {string} repo.repo - Repository name
*/
/**
* @typedef {Object} GitHubAPI
* @property {Object} rest
* @property {Object} rest.issues
* @property {Function} rest.issues.listForRepo
* @property {Function} rest.issues.create
* @property {Function} rest.issues.update
*/
/**
* @typedef {Object} ActionsCore
* @property {Function} info - Log info message
*/
const ISSUE_TITLE = 'Tracking: 未翻訳ドキュメント一覧';
const LABELS = ['type: translation', '翻訳者募集中'];
/** @type {Record<string, string>} */
const CATEGORY_EMOJIS = {
guide: '📖 Guide',
tutorial: '🎓 Tutorial',
reference: '📚 Reference',
'best-practices': '⚡ Best Practices',
cli: '🔧 CLI',
tools: '🛠️ Tools',
ecosystem: '🌐 Ecosystem',
app: '🧩 Components/App',
other: '📦 その他'
};
/** @type {string[]} */
const CATEGORY_ORDER = ['guide', 'tutorial', 'reference', 'best-practices', 'cli', 'tools', 'ecosystem', 'app', 'other'];
/**
* Generate preview path from file path
* @param {string} filepath - File path relative to adev-ja
* @returns {string} Preview path for angular.jp
*/
function generatePreviewPath(filepath) {
const basePath = filepath
.replace('src/content/', '')
.replace(/\/README\.md$/, '') // READMEの場合はディレクトリのみ
.replace(/\.md$/, '');
// reference 配下の特殊なパス変換: reference/ プレフィックスを削除
const referenceTopLevelPaths = ['press-kit', 'roadmap', 'cli'];
if (basePath.startsWith('reference/')) {
const subPath = basePath.replace('reference/', '');
// トップレベルパス(press-kit, roadmap, cli)
if (referenceTopLevelPaths.includes(subPath)) {
return subPath;
}
// サブディレクトリパス(errors/*, extended-diagnostics/*)
if (subPath.startsWith('errors/') || subPath.startsWith('extended-diagnostics/')) {
return subPath;
}
}
// チュートリアルの特殊なパス変換
if (basePath.startsWith('tutorials/')) {
// tutorials/first-app/intro -> tutorials/first-app
// tutorials/first-app/steps/01-hello-world -> tutorials/first-app/01-hello-world
return basePath
.replace(/\/intro$/, '') // intro ディレクトリを削除
.replace(/\/steps\//, '/'); // steps/ を削除
}
return basePath;
}
/**
* Generate URLs for a file
* @param {string} filepath - File path relative to adev-ja
* @returns {FileLinks} Object containing GitHub, preview, and issue URLs
*/
function generateLinks(filepath) {
const githubUrl = `https://github.com/angular/angular-ja/blob/main/adev-ja/${filepath}`;
// タイトル生成: パスから拡張子を除去したシンプルな形式
const title = filepath
.replace('src/content/', '')
.replace(/\.(md|ts|html|json)$/, '');
const issueUrl = `https://github.com/angular/angular-ja/issues/new?template=translation-checkout.md&title=${encodeURIComponent('translate: ' + title)}`;
// .mdファイルのみプレビューURL生成
const previewUrl = filepath.endsWith('.md')
? `https://angular.jp/${generatePreviewPath(filepath)}`
: null;
return { githubUrl, previewUrl, issueUrl };
}
/**
* Format a file entry for the issue body
* @param {string} filepath - File path relative to adev-ja
* @param {FileLinks} links - Object containing URLs for the file
* @param {number|null} checkoutIssueNumber - Translation Checkout issue number if exists
* @returns {string} Markdown formatted list item
*/
function formatFileEntry(filepath, links, checkoutIssueNumber = null) {
const displayName = filepath.replace('src/content/', '');
let linksText = `[GitHub](${links.githubUrl})`;
if (links.previewUrl) {
linksText += ` | [プレビュー](${links.previewUrl})`;
}
if (checkoutIssueNumber) {
linksText += ` | #${checkoutIssueNumber}`;
return `- [x] ${displayName} (${linksText})`;
} else {
linksText += ` | [📝 翻訳宣言](${links.issueUrl})`;
return `- [ ] ${displayName} (${linksText})`;
}
}
/**
* Group files by category
* @param {UntranslatedFile[]} files - Array of untranslated files
* @returns {Record<string, UntranslatedFile[]>} Files grouped by category
*/
function groupByCategory(files) {
const groups = {};
for (const file of files) {
const category = file.category;
if (!groups[category]) {
groups[category] = [];
}
groups[category].push(file);
}
return groups;
}
/**
* Generate issue body
* @param {FilesData} filesData - Object containing untranslated files data
* @param {Map<string, number>} checkoutIssuesMap - Map of file paths to issue numbers
* @returns {string} Markdown formatted issue body
*/
function generateIssueBody(filesData, checkoutIssuesMap) {
const { count, files } = filesData;
if (count === 0) {
return `## 🎉 全てのファイルが翻訳されました!
**最終更新**: ${new Date().toISOString()}
現在、未翻訳のファイルはありません。素晴らしい貢献をありがとうございます!
---
## 📝 翻訳ガイド
今後新しい未翻訳ファイルが追加された場合、このIssueが自動的に更新されます。
- [翻訳ガイドライン](https://github.com/angular/angular-ja/blob/main/CONTRIBUTING.md)
`;
}
const groups = groupByCategory(files);
let body = `## 📋 未翻訳ドキュメント一覧
このIssueは自動的に更新されます。翻訳したいファイルの「📝 翻訳宣言」リンクから翻訳宣言Issueを作成してください。
**最終更新**: ${new Date().toISOString()}
**未翻訳ファイル数**: ${count}件
---
`;
// カテゴリ順にセクションを生成
for (const category of CATEGORY_ORDER) {
if (!groups[category] || groups[category].length === 0) continue;
const categoryFiles = groups[category];
const emoji = CATEGORY_EMOJIS[category] || category;
body += `### ${emoji} (${categoryFiles.length}件)\n\n`;
for (const file of categoryFiles) {
const links = generateLinks(file.path);
const checkoutIssueNumber = checkoutIssuesMap.get(file.path) || null;
body += formatFileEntry(file.path, links, checkoutIssueNumber) + '\n';
}
body += '\n';
}
body += `---
## 📝 翻訳の始め方
1. 上記リストから翻訳したいファイルを選ぶ
2. 「📝 翻訳宣言」リンクをクリックしてIssueを作成
3. [翻訳ガイド](https://github.com/angular/angular-ja/blob/main/CONTRIBUTING.md)に従って作業開始
`;
return body;
}
/**
* Main function
* @param {Object} params - Parameters
* @param {GitHubAPI} params.github - GitHub API instance
* @param {GitHubContext} params.context - GitHub Actions context
* @param {ActionsCore} params.core - GitHub Actions core utilities
* @param {FilesData} params.filesData - Untranslated files data
* @returns {Promise<void>}
*/
export default async ({github, context, core, filesData}) => {
const owner = context.repo.owner;
const repo = context.repo.repo;
core.info(`Processing ${filesData.count} untranslated files...`);
// Translation Checkout ラベルの全Issue (open only) を取得
const { data: checkoutIssues } = await github.rest.issues.listForRepo({
owner,
repo,
state: 'open',
labels: 'type: Translation Checkout'
});
core.info(`Found ${checkoutIssues.length} Translation Checkout issues`);
// Issueタイトルからファイルパスを抽出してマップを作成
// タイトル形式: "translate: {ファイルパス}"
// 前方一致でマッチング(ディレクトリ名での宣言に対応)
const checkoutIssuesMap = new Map();
for (const issue of checkoutIssues) {
const match = issue.title.match(/^translate:\s*(.+)$/);
if (match) {
const declaredPath = `src/content/${match[1]}`;
// 各未翻訳ファイルに対して前方一致チェック
for (const file of filesData.files) {
if (file.path.startsWith(declaredPath)) {
checkoutIssuesMap.set(file.path, issue.number);
}
}
}
}
core.info(`Mapped ${checkoutIssuesMap.size} files to checkout issues`);
// 既存のトラッキングIssueを検索 (state: all で closed も含む)
const { data: issues } = await github.rest.issues.listForRepo({
owner,
repo,
state: 'all',
labels: LABELS[0],
creator: 'github-actions[bot]'
});
const trackingIssue = issues.find(issue => issue.title === ISSUE_TITLE);
const issueBody = generateIssueBody(filesData, checkoutIssuesMap);
if (trackingIssue) {
core.info(`Found existing tracking issue #${trackingIssue.number}`);
// Issueを更新 (タイトルも更新して新しい形式に移行)
await github.rest.issues.update({
owner,
repo,
issue_number: trackingIssue.number,
title: ISSUE_TITLE,
body: issueBody,
state: 'open' // closed状態の場合はreopen
});
core.info(`Updated tracking issue #${trackingIssue.number}`);
if (trackingIssue.state === 'closed') {
core.info(`Reopened tracking issue #${trackingIssue.number}`);
}
} else {
// 新規Issueを作成
const { data: newIssue } = await github.rest.issues.create({
owner,
repo,
title: ISSUE_TITLE,
body: issueBody,
labels: LABELS
});
core.info(`Created new tracking issue #${newIssue.number}`);
}
core.info('Done!');
};