Personal Telegram developer console for GitHub
feat: add deep in-place repository file navigation
davoodmehraban89 committed
Oct 2, 2026 at 23:05 UTC
7a81ca8adf2594b2478b0c9d8f7d308ec6121ba8
1 file changed
+120
-16
src/menu.js
+120
-16
@@ -8,6 +8,30 @@ function escapeHtml(value = '') {
8
.replaceAll('"', '"');
9
}
10
11
+function decodeBase64Utf8(value = '') {
12
+ const binary = atob(String(value).replace(/\s/g, ''));
13
+ const bytes = Uint8Array.from(binary, char => char.charCodeAt(0));
14
+ return new TextDecoder().decode(bytes);
15
+}
16
+
17
+function callbackFits(value) {
18
+ return new TextEncoder().encode(String(value)).length <= 64;
19
+}
20
+
21
+function fileItemRows(repoId, items) {
22
+ const rows = [];
23
+ for (const item of items.slice(0, 30)) {
24
+ const action = item.type === 'dir' ? 'tree' : 'blob';
25
+ const callbackData = `${action}:${repoId}:${item.sha}`;
26
+ if (!item.sha || !callbackFits(callbackData)) continue;
27
+ rows.push([{
28
+ text: `${item.type === 'dir' ? '📁' : '📄'} ${item.name}`,
29
+ callback_data: callbackData
30
+ }]);
31
+ }
32
+ return rows;
33
+}
34
+
35
/**
36
* Menu Router and UI Generator for Nexa Dev Bot.
37
* Views never claim external service health unless that view was built from a live API response.
@@ -110,7 +134,10 @@ export class MenuManager {
134
}
135
136
async getPullRequestsView(repoId) {
113
- const prs = await this.github.listPullRequests(repoId);
137
+ const [repo, prs] = await Promise.all([
138
+ this.github.getRepository(repoId),
139
+ this.github.listPullRequests(repoId)
140
+ ]);
141
const prListText = prs.length
142
? prs.map(pr => {
143
const state = pr.merged ? '🟣 Merged' : (pr.state === 'open' ? '🟢 Open' : '🔴 Closed');
@@ -119,8 +146,8 @@ export class MenuManager {
146
: '<i>Pull Requestی در پاسخ GitHub یافت نشد.</i>';
147
148
const text =
122
-`🔀 <b>Pull Requestهای پروژه ${escapeHtml(repoId)}</b>
123
-<code>🏠 Nexa Dev > 📁 مخزنها > ${escapeHtml(repoId)} > 🔀 Pull Request</code>
149
+`🔀 <b>Pull Requestهای پروژه ${escapeHtml(repo.name)}</b>
150
+<code>🏠 Nexa Dev > 📁 مخزنها > ${escapeHtml(repo.name)} > 🔀 Pull Request</code>
151
➖➖➖➖➖➖➖➖➖➖
152
${prListText}`;
153
@@ -136,14 +163,17 @@ ${prListText}`;
163
}
164
165
async getCommitsView(repoId) {
139
- const commits = await this.github.listCommits(repoId);
166
+ const [repo, commits] = await Promise.all([
167
+ this.github.getRepository(repoId),
168
+ this.github.listCommits(repoId)
169
+ ]);
170
const commitListText = commits.length
171
? commits.map(c => `• <code>${escapeHtml(c.sha)}</code> - ${escapeHtml(c.message)}\n └ <i>${escapeHtml(c.author)}${c.date ? ` | ${escapeHtml(c.date)}` : ''}</i>`).join('\n\n')
172
: '<i>کامیتی در پاسخ GitHub یافت نشد.</i>';
173
174
const text =
145
-`📝 <b>آخرین Commitهای پروژه ${escapeHtml(repoId)}</b>
146
-<code>🏠 Nexa Dev > 📁 مخزنها > ${escapeHtml(repoId)} > 📝 Commitها</code>
175
+`📝 <b>آخرین Commitهای پروژه ${escapeHtml(repo.name)}</b>
176
+<code>🏠 Nexa Dev > 📁 مخزنها > ${escapeHtml(repo.name)} > 📝 Commitها</code>
177
➖➖➖➖➖➖➖➖➖➖
178
${commitListText}`;
179
@@ -159,27 +189,96 @@ ${commitListText}`;
189
}
190
191
async getFilesView(repoId, subpath = '') {
162
- const files = await this.github.listFiles(repoId, subpath);
163
- const itemsText = files.length
164
- ? files.map(f => {
192
+ const [repo, files] = await Promise.all([
193
+ this.github.getRepository(repoId),
194
+ this.github.listFiles(repoId, subpath)
195
+ ]);
196
+ const visibleItems = files.slice(0, 30);
197
+ const itemsText = visibleItems.length
198
+ ? visibleItems.map(f => {
199
const icon = f.type === 'dir' ? '📁' : '📄';
200
const size = f.type === 'file' && f.size ? ` (${f.size} B)` : '';
201
return `${icon} <code>${escapeHtml(f.name)}</code>${size}`;
202
}).join('\n')
203
: '<i>پوشه خالی است.</i>';
204
+ const omitted = files.length > visibleItems.length
205
+ ? `\n\n<i>${files.length - visibleItems.length} مورد دیگر در این نما نمایش داده نشده است.</i>`
206
+ : '';
207
+
208
+ const text =
209
+`📂 <b>ساختار فایلهای پروژه ${escapeHtml(repo.name)}</b>
210
+<code>🏠 Nexa Dev > 📁 مخزنها > ${escapeHtml(repo.name)} > 📂 فایلها${subpath ? ` > ${escapeHtml(subpath)}` : ''}</code>
211
+➖➖➖➖➖➖➖➖➖➖
212
+${itemsText}${omitted}`;
213
+
214
+ const inlineKeyboard = fileItemRows(repoId, visibleItems);
215
+ inlineKeyboard.push([
216
+ { text: '🔄 بروزرسانی', callback_data: `files:${repoId}${subpath ? `:${subpath}` : ''}` },
217
+ { text: '🔙 بازگشت به پروژه', callback_data: `repo:${repoId}` }
218
+ ]);
219
+
220
+ return { text, reply_markup: { inline_keyboard: inlineKeyboard } };
221
+ }
222
+
223
+ async getTreeView(repoId, sha) {
224
+ const [repo, items] = await Promise.all([
225
+ this.github.getRepository(repoId),
226
+ this.github.listTree(repoId, sha)
227
+ ]);
228
+ const visibleItems = items.slice(0, 30);
229
+ const itemsText = visibleItems.length
230
+ ? visibleItems.map(item => {
231
+ const icon = item.type === 'dir' ? '📁' : '📄';
232
+ const size = item.type === 'file' && item.size ? ` (${item.size} B)` : '';
233
+ return `${icon} <code>${escapeHtml(item.name)}</code>${size}`;
234
+ }).join('\n')
235
+ : '<i>این پوشه خالی است.</i>';
236
+ const omitted = items.length > visibleItems.length
237
+ ? `\n\n<i>${items.length - visibleItems.length} مورد دیگر در این نما نمایش داده نشده است.</i>`
238
+ : '';
239
240
const text =
172
-`📂 <b>ساختار فایلهای پروژه ${escapeHtml(repoId)}</b>
173
-<code>🏠 Nexa Dev > 📁 مخزنها > ${escapeHtml(repoId)} > 📂 فایلها${subpath ? ` > ${escapeHtml(subpath)}` : ''}</code>
241
+`📁 <b>پوشه در ${escapeHtml(repo.name)}</b>
242
+<code>🏠 Nexa Dev > 📁 مخزنها > ${escapeHtml(repo.name)} > 📂 فایلها > پوشه</code>
243
➖➖➖➖➖➖➖➖➖➖
175
-${itemsText}`;
244
+${itemsText}${omitted}`;
245
+
246
+ const inlineKeyboard = fileItemRows(repoId, visibleItems);
247
+ inlineKeyboard.push([
248
+ { text: '🔙 ریشه فایلها', callback_data: `files:${repoId}` },
249
+ { text: '📦 پروژه', callback_data: `repo:${repoId}` }
250
+ ]);
251
+
252
+ return { text, reply_markup: { inline_keyboard: inlineKeyboard } };
253
+ }
254
+
255
+ async getBlobView(repoId, sha) {
256
+ const [repo, blob] = await Promise.all([
257
+ this.github.getRepository(repoId),
258
+ this.github.getBlob(repoId, sha)
259
+ ]);
260
+
261
+ let body;
262
+ if (blob.encoding !== 'base64' || blob.size > 100000) {
263
+ body = '<i>این فایل برای نمایش مستقیم در تلگرام مناسب نیست.</i>';
264
+ } else {
265
+ const decoded = decodeBase64Utf8(blob.content);
266
+ const preview = decoded.length > 2800 ? `${decoded.slice(0, 2800)}\n…` : decoded;
267
+ body = `<pre>${escapeHtml(preview)}</pre>`;
268
+ }
269
+
270
+ const text =
271
+`📄 <b>پیشنمایش فایل در ${escapeHtml(repo.name)}</b>
272
+<code>🏠 Nexa Dev > 📁 مخزنها > ${escapeHtml(repo.name)} > 📂 فایلها > فایل</code>
273
+➖➖➖➖➖➖➖➖➖➖
274
+${body}`;
275
276
return {
277
text,
278
reply_markup: {
279
inline_keyboard: [[
181
- { text: '🔄 بروزرسانی', callback_data: `files:${repoId}${subpath ? `:${subpath}` : ''}` },
182
- { text: '🔙 بازگشت به پروژه', callback_data: `repo:${repoId}` }
280
+ { text: '🔙 ریشه فایلها', callback_data: `files:${repoId}` },
281
+ { text: '📦 پروژه', callback_data: `repo:${repoId}` }
282
]]
283
}
284
};
@@ -194,9 +293,10 @@ ${itemsText}`;
293
}).join('\n')
294
: '<i>Workflow runی در پاسخ GitHub یافت نشد.</i>';
295
296
+ const label = status.repoName || repoId;
297
const text =
198
-`📊 <b>وضعیت پایپلاین ${escapeHtml(repoId)}</b>
199
-<code>🏠 Nexa Dev > 📁 مخزنها > ${escapeHtml(repoId)} > 📊 وضعیت</code>
298
+`📊 <b>وضعیت پایپلاین ${escapeHtml(label)}</b>
299
+<code>🏠 Nexa Dev > 📁 مخزنها > ${escapeHtml(label)} > 📊 وضعیت</code>
300
➖➖➖➖➖➖➖➖➖➖
301
شاخه پیشفرض: <code>${escapeHtml(status.defaultBranch)}</code>
302
آخرین نتایج GitHub Actions:
@@ -311,6 +411,10 @@ ${tools}`;
411
return this.getCommitsView(target);
412
case 'files':
413
return this.getFilesView(target, extra.join(':'));
414
+ case 'tree':
415
+ return this.getTreeView(target, extra[0]);
416
+ case 'blob':
417
+ return this.getBlobView(target, extra[0]);
418
case 'status':
419
return this.getRepoStatusView(target);
420
case 'tool':