Personal Telegram developer console for GitHub

feat: add source-backed commit drill-down (#31)

Completes the remaining weak repository report identified by the Telegram menu E2E audit: commit list now drills into source-backed commit detail with changed files, additions/deletions, recovery navigation, Telegram-safe callbacks, provider coverage, and synchronized guide documentation. PR head CI #318 passed before merge.

davoodmehraban89 committed Oct 4, 2026 at 17:47 UTC fd53256479e6b0d7d07626731403a28ccb73fb48
7 files changed +117 -6
src/github.js
+29 -2
@@ -219,11 +219,38 @@ export class GitHubService {
219 const { apiBase } = await this.getRepositoryContext(repoRef);
220 const data = await this.requestJson(`${apiBase}/commits?per_page=5`, 'GitHub commits');
221 return data.map(c => ({
222 - sha: c.sha.slice(0, 7), message: String(c.commit?.message || '').split('\n')[0],
223 - author: c.author?.login || c.commit?.author?.name || 'Unknown', date: c.commit?.author?.date ? c.commit.author.date.slice(0, 10) : ''
222 + sha: String(c.sha || '').slice(0, 7),
223 + fullSha: String(c.sha || ''),
224 + message: String(c.commit?.message || '').split('\n')[0],
225 + author: c.author?.login || c.commit?.author?.name || 'Unknown',
226 + date: c.commit?.author?.date ? c.commit.author.date.slice(0, 10) : ''
227 }));
228 }
229
230 + async getCommit(repoRef, sha) {
231 + const commitSha = fullSha(sha);
232 + const { apiBase } = await this.getRepositoryContext(repoRef);
233 + const c = await this.requestJson(`${apiBase}/commits/${commitSha}`, 'GitHub commit');
234 + const files = (c.files || []).slice(0, 20).map(file => ({
235 + filename: file.filename || '',
236 + status: file.status || '',
237 + additions: file.additions ?? 0,
238 + deletions: file.deletions ?? 0,
239 + changes: file.changes ?? 0
240 + }));
241 + return {
242 + sha: commitSha,
243 + shortSha: commitSha.slice(0, 7),
244 + message: String(c.commit?.message || ''),
245 + author: c.author?.login || c.commit?.author?.name || 'Unknown',
246 + date: c.commit?.author?.date || '',
247 + additions: c.stats?.additions ?? 0,
248 + deletions: c.stats?.deletions ?? 0,
249 + changedFiles: files.length,
250 + files
251 + };
252 + }
253 +
254 async listCommitChecks(repoRef, sha, { perPage = 20, page = 1 } = {}) {
255 const commitSha = fullSha(sha); const count = clampPerPage(perPage, 20); const pageNumber = clampPage(page);
256 const { apiBase } = await this.getRepositoryContext(repoRef);
src/guide-menu.js
+1 -1
@@ -30,7 +30,7 @@ function guidePage(page) {
30 const pages = {
31 1: `📘 <b>راهنمای Nexa Dev — V2.1</b>\n<b>۱. شروع، منوهای اصلی و ابزارهای عملیاتی</b>\n➖➖➖➖➖➖➖➖➖➖\n\n<b>🏠 منوی اصلی</b>\nنقطهٔ برگشت امن شماست و همهٔ بخش‌های اصلی را باز می‌کند.\n\n<b>📁 پروژه‌ها / مخزن‌ها</b>\nRepositoryهای قابل‌دسترسی GitHub را زنده می‌خواند و مسیر فایل، PR، Commit، CI، Branch، Issue، Release و Workspace را باز می‌کند.\n\n<b>📊 وضعیت</b>\nوضعیت واقعی Worker، مرز Owner-only، GitHub READ، WORKSPACE_STORE، Replay Guard، Approval signer و Plugin Registry را نشان می‌دهد. latency یا SLA ساختگی گزارش نمی‌شود.\n\n<b>🔧 ابزارها</b>\nکنسول عیب‌یابی فقط‌خواندنی است. «🩺 خودآزمایی» پیش‌نیازها را کنترل می‌کند؛ «🐙 تست اتصال GitHub» یک READ زنده انجام می‌دهد؛ «🧱 Runtime / Bindings» وضعیت Runtime و Durable Objectها را نشان می‌دهد؛ «🧩 Plugin Registry» Pluginها و Actionها را می‌شمارد؛ Ping فقط مسیر داخلی Bot را تست می‌کند.\n\n<b>⚙️ پیکربندی</b>\nدر V2.1 عمداً فقط‌خواندنی است. Runtime، Providerها، Workspace Editor و Pluginها را بدون نمایش Secret نشان می‌دهد و تنظیم حساس را از Telegram تغییر نمی‌دهد.\n\n<b>🔐 امنیت</b>\nSecurity Center است؛ Owner-only، Safe Approval، Replay protection و Policy عملیات را توضیح می‌دهد.\n\n<b>📘 راهنما</b>\nهمین راهنما را باز می‌کند و از منوی ثابت پایین Telegram هم در دسترس است.\n\n<b>🔄 بروزرسانی / بررسی مجدد</b>\nدادهٔ همان صفحه را دوباره می‌خواند و به‌تنهایی WRITE انجام نمی‌دهد.\n\n<b>🔙 بازگشت</b>\nبه سطح قبلی ناوبری برمی‌گردد.`,
32
33 - 2: `📘 <b>راهنمای Nexa Dev — V2.1</b>\n<b>۲. پروژه، فایل‌ها و مشاهده کد</b>\n➖➖➖➖➖➖➖➖➖➖\n\n<b>نام Repository</b>\nصفحهٔ پروژه را با Metadata زنده GitHub باز می‌کند.\n\n<b>📂 فایل‌ها</b>\nساختار فایل‌ها و پوشه‌ها را باز می‌کند؛ 📁 وارد پوشه و 📄 پیش‌نمایش فایل را باز می‌کند.\n\n<b>✏️ Edit</b>\nبرای فایل متنی مجاز Workspace امن می‌سازد. فایل حساس، باینری، Git LFS یا خارج از Policy قابل Edit نیست.\n\n<b>🔀 Pull Requestها / PR</b>\nPRها و جزئیات آن‌ها را می‌خواند. Files / Diff و Checks برای بررسی تغییر و نتیجهٔ کنترل‌ها هستند.\n\n<b>📝 Commitها</b>\nآخرین Commitهای Repository را نمایش می‌دهد.\n\n<b>📊 وضعیت / تست‌ها</b>\nآخرین وضعیت Workflowهای پروژه را خلاصه می‌کند.\n\n<b>🧪 CI / Actions</b>\nWorkflow Runها را باز می‌کند؛ جزئیات در فصل ۵ است.\n\n<b>🌿 Branches</b>\nBranchها و Compare نسبت به شاخهٔ پیش‌فرض را نشان می‌دهد.\n\n<b>🐛 Issues</b>\nIssueهای Repository را صفحه‌بندی می‌کند. با انتخاب هر مورد، <b>جزئیات Issue</b> شامل وضعیت، نویسنده، برچسب‌ها، مسئول‌ها، زمان بروزرسانی و متن Issue از GitHub نمایش داده می‌شود.\n\n<b>🏷 Releases</b>\nReleaseهای GitHub را نمایش می‌دهد. با انتخاب هر Release، <b>Release notes</b>، Tag، Target، نویسنده، زمان انتشار و وضعیت draft/pre-release از منبع GitHub باز می‌شود.\n\n<b>⬅️ جدیدتر / قدیمی‌تر ➡️</b>\nبین صفحات نتایج جابه‌جا می‌شود و WRITE انجام نمی‌دهد.`,
33 + 2: `📘 <b>راهنمای Nexa Dev — V2.1</b>\n<b>۲. پروژه، فایل‌ها و مشاهده کد</b>\n➖➖➖➖➖➖➖➖➖➖\n\n<b>نام Repository</b>\nصفحهٔ پروژه را با Metadata زنده GitHub باز می‌کند.\n\n<b>📂 فایل‌ها</b>\nساختار فایل‌ها و پوشه‌ها را باز می‌کند؛ 📁 وارد پوشه و 📄 پیش‌نمایش فایل را باز می‌کند.\n\n<b>✏️ Edit</b>\nبرای فایل متنی مجاز Workspace امن می‌سازد. فایل حساس، باینری، Git LFS یا خارج از Policy قابل Edit نیست.\n\n<b>🔀 Pull Requestها / PR</b>\nPRها و جزئیات آن‌ها را می‌خواند. Files / Diff و Checks برای بررسی تغییر و نتیجهٔ کنترل‌ها هستند.\n\n<b>📝 Commitها</b>\nآخرین Commitهای Repository را نمایش می‌دهد. با انتخاب هر مورد، <b>جزئیات Commit</b> شامل SHA، نویسنده، زمان، پیام کامل، تعداد additions/deletions و فایل‌های تغییرکرده مستقیماً از GitHub باز می‌شود.\n\n<b>📊 وضعیت / تست‌ها</b>\nآخرین وضعیت Workflowهای پروژه را خلاصه می‌کند.\n\n<b>🧪 CI / Actions</b>\nWorkflow Runها را باز می‌کند؛ جزئیات در فصل ۵ است.\n\n<b>🌿 Branches</b>\nBranchها و Compare نسبت به شاخهٔ پیش‌فرض را نشان می‌دهد.\n\n<b>🐛 Issues</b>\nIssueهای Repository را صفحه‌بندی می‌کند. با انتخاب هر مورد، <b>جزئیات Issue</b> شامل وضعیت، نویسنده، برچسب‌ها، مسئول‌ها، زمان بروزرسانی و متن Issue از GitHub نمایش داده می‌شود.\n\n<b>🏷 Releases</b>\nReleaseهای GitHub را نمایش می‌دهد. با انتخاب هر Release، <b>Release notes</b>، Tag، Target، نویسنده، زمان انتشار و وضعیت draft/pre-release از منبع GitHub باز می‌شود.\n\n<b>⬅️ جدیدتر / قدیمی‌تر ➡️</b>\nبین صفحات نتایج جابه‌جا می‌شود و WRITE انجام نمی‌دهد.`,
34
35 3: `📘 <b>راهنمای Nexa Dev — V2.1</b>\n<b>۳. Workspace و دکمه‌های ویرایش</b>\n➖➖➖➖➖➖➖➖➖➖\n\nپس از <b>✏️ Edit</b> یک Draft Durable ساخته می‌شود و هنوز GitHub تغییر نکرده است. Workspace در <code>WORKSPACE_STORE</code> نگهداری می‌شود.\n\n<b>📝 Workspace / باز کردن Draft</b>\nوضعیت Draft، Base snapshot و پیام Commit را نشان می‌دهد.\n\n<b>🧑‍💻 Editor</b>\nTelegram Mini App چندخطی را باز می‌کند. «ذخیره Draft» فقط Draft را در WORKSPACE_STORE ذخیره می‌کند و GitHub WRITE ندارد.\n\n<b>📎 بارگذاری فایل</b>\nمحتوای یک فایل متنی UTF-8 را جایگزین Draft می‌کند؛ مسیر مقصد Repository عوض نمی‌شود.\n\n<b>📝 Paste متن</b>\nمسیر fallback قدیمی با ورودی عادی Telegram است؛ مسیر اصلی V2.1 همان Mini App Editor است.\n\n<b>✍️ پیام Commit</b>\nپیام Commit بعدی را ثبت می‌کند.\n\n<b>🔍 Diff</b>\nOriginal و Draft را پیش از WRITE مقایسه می‌کند.\n\n<b>✅ آماده Commit</b>\nتغییر، Base و پیام Commit را اعتبارسنجی و Intent امن می‌سازد.\n\n<b>🗑 لغو Draft</b>\nWorkspace جاری را لغو می‌کند و GitHub دست‌نخورده می‌ماند.`,
36
src/plugins/github/manifest.js
+1
@@ -11,6 +11,7 @@ export const githubPluginManifest = Object.freeze({
11 'github.blob.read': Object.freeze({ risk: 'READ' }),
12 'github.pr.list': Object.freeze({ risk: 'READ' }),
13 'github.commits.list': Object.freeze({ risk: 'READ' }),
14 + 'github.commit.detail': Object.freeze({ risk: 'READ' }),
15 'github.status.read': Object.freeze({ risk: 'READ' }),
16 'github.workflow.runs.list': Object.freeze({ risk: 'READ' }),
17 'github.workflow.run.detail': Object.freeze({ risk: 'READ' }),
src/plugins/github/plugin.js
+43
@@ -67,6 +67,12 @@ const compareRef = value => {
67 return { repoId: Number(match[1]), sha: match[2] };
68 };
69
70 +const commitDetailRef = value => {
71 + const match = String(value || '').match(/^commitdetail:(\d+):([a-f0-9]{40})$/i);
72 + if (!match) return null;
73 + return { repoId: Number(match[1]), sha: match[2] };
74 +};
75 +
76 const workflowRunsPage = value => pagedSingle(value, 'runs');
77
78 const runIcon = run => {
@@ -126,6 +132,37 @@ function pairPagination(prefix, repoId, itemId, page, count, pageSize) {
132 return row.length ? [row] : [];
133 }
134
135 +async function commitsView(github, repoId) {
136 + const [repo, commits] = await Promise.all([github.getRepository(repoId), github.listCommits(repoId)]);
137 + const body = commits.length
138 + ? commits.slice(0, 10).map(commit => `• <code>${escapeHtml(commit.shortSha || commit.sha)}</code> — ${escapeHtml(short(commit.message, 110))}\n ${escapeHtml(commit.author || 'Unknown')}${commit.date ? ` · ${escapeHtml(commit.date)}` : ''}`).join('\n\n')
139 + : '<i>کامیتی در پاسخ GitHub یافت نشد.</i>';
140 + const detailRows = commits.slice(0, 10).map(commit => {
141 + const sha = String(commit.fullSha || commit.sha || '');
142 + return /^[a-f0-9]{40}$/i.test(sha)
143 + ? [{ text: `📝 ${short(commit.message || sha.slice(0, 7), 42)}`, callback_data: `commitdetail:${repoId}:${sha}` }]
144 + : null;
145 + }).filter(Boolean);
146 + return {
147 + text: `📝 <b>آخرین Commitهای ${escapeHtml(repo.name)}</b>\n➖➖➖➖➖➖➖➖➖➖\n${body}`,
148 + reply_markup: { inline_keyboard: [
149 + ...detailRows,
150 + [{ text: '🔄 بروزرسانی', callback_data: `commits:${repoId}` }, { text: '🔙 پروژه', callback_data: `repo:${repoId}` }]
151 + ] }
152 + };
153 +}
154 +
155 +async function commitDetailView(github, repoId, sha) {
156 + const [repo, commit] = await Promise.all([github.getRepository(repoId), github.getCommit(repoId, sha)]);
157 + const files = (commit.files || []).slice(0, 12)
158 + .map(file => `• <code>${escapeHtml(short(file.filename, 90))}</code> · ${escapeHtml(file.status || 'changed')} · +${file.additions ?? 0}/-${file.deletions ?? 0}`)
159 + .join('\n');
160 + return {
161 + text: `📝 <b>Commit — ${escapeHtml(repo.name)}</b>\n<code>${escapeHtml(commit.shortSha || String(commit.sha).slice(0, 7))}</code> · ${escapeHtml(commit.author || 'Unknown')}\n${escapeHtml(commit.date || '-')}\n+${commit.additions ?? 0}/-${commit.deletions ?? 0} · ${commit.changedFiles ?? (commit.files || []).length} files\n➖➖➖➖➖➖➖➖➖➖\n${escapeHtml(short(commit.message || '', 1200)) || '<i>بدون پیام.</i>'}\n\n<b>فایل‌های تغییرکرده</b>\n${files || '<i>فایلی گزارش نشده است.</i>'}`,
162 + reply_markup: { inline_keyboard: [[{ text: '🔄 بروزرسانی', callback_data: `commitdetail:${repoId}:${sha}` }, { text: '🔙 Commitها', callback_data: `commits:${repoId}` }], [{ text: '🔙 پروژه', callback_data: `repo:${repoId}` }]] }
163 + };
164 +}
165 +
166 async function workflowRunsView(github, repoId, page = 1) {
167 const [repo, runs] = await Promise.all([
168 github.getRepository(repoId),
@@ -380,6 +417,10 @@ function resolveReadCallback(data) {
417 if (value === 'menu:repos') return { actionId: 'github.repos.list', kind: 'legacy' };
418 const repoId = numericSingle(value, 'repo');
419 if (repoId !== null) return { actionId: 'github.repo.detail', kind: 'repo', repoId };
420 + const commits = numericSingle(value, 'commits');
421 + if (commits !== null) return { actionId: 'github.commits.list', kind: 'commits', repoId: commits };
422 + const commitdetail = commitDetailRef(value);
423 + if (commitdetail) return { actionId: 'github.commit.detail', kind: 'commitdetail', ...commitdetail };
424 const runs = workflowRunsPage(value);
425 if (runs) return { actionId: 'github.workflow.runs.list', kind: 'runs', ...runs };
426 const run = numericPair(value, 'run');
@@ -474,6 +515,8 @@ export function createGitHubPlugin({ github, menu, workspaces } = {}) {
515 actionId: read.actionId,
516 execute: async () => {
517 if (read.kind === 'repo') return addRepoAdvancedButtons(await menu.renderByCallback(data), read.repoId);
518 + if (read.kind === 'commits') return typeof github.listCommits === 'function' ? commitsView(github, read.repoId) : menu.renderByCallback(data);
519 + if (read.kind === 'commitdetail') return commitDetailView(github, read.repoId, read.sha);
520 if (read.kind === 'runs') return workflowRunsView(github, read.repoId, read.page);
521 if (read.kind === 'run') return workflowRunView(github, read.repoId, read.runId);
522 if (read.kind === 'jobs') return workflowJobsView(github, read.repoId, read.runId);
test/github-advanced-read.test.js
+23
@@ -111,3 +111,26 @@ test('GitHub issues exclude pull requests and releases are source-backed', async
111 assert.equal(releases[0].tag, 'v1.2.0');
112 });
113 });
114 +
115 +
116 +test('GitHub commit detail is source-backed and returns bounded file summaries', async () => {
117 + const sha = 'e'.repeat(40);
118 + await withFetch(async (url) => {
119 + const value = String(url);
120 + if (value === 'https://api.github.com/repositories/123') return json(repo);
121 + if (value === `${repoUrl}/commits?per_page=5`) return json([{ sha, commit: { message: 'subject\n\nbody', author: { name: 'Dev', date: '2026-10-04T12:00:00Z' } }, author: { login: 'dev' } }]);
122 + if (value === `${repoUrl}/commits/${sha}`) return json({ sha, commit: { message: 'subject\n\nbody', author: { name: 'Dev', date: '2026-10-04T12:00:00Z' } }, author: { login: 'dev' }, stats: { additions: 12, deletions: 4 }, files: [{ filename: 'src/menu.js', status: 'modified', additions: 8, deletions: 2, changes: 10 }] });
123 + return json({ message: 'Not Found' }, 404);
124 + }, async () => {
125 + const service = new GitHubService('token');
126 + const list = await service.listCommits(123);
127 + assert.equal(list[0].sha, sha.slice(0, 7));
128 + assert.equal(list[0].fullSha, sha);
129 + const detail = await service.getCommit(123, sha);
130 + assert.equal(detail.sha, sha);
131 + assert.equal(detail.message, 'subject\n\nbody');
132 + assert.equal(detail.additions, 12);
133 + assert.equal(detail.deletions, 4);
134 + assert.deepEqual(detail.files[0], { filename: 'src/menu.js', status: 'modified', additions: 8, deletions: 2, changes: 10 });
135 + });
136 +});
test/help-guide.test.js
+1 -1
@@ -39,7 +39,7 @@ describe('Nexa Dev Bot - in-app V2.1 guide', () => {
39 }
40
41 const repoHelp = await menu.renderByCallback('help:2');
42 - for (const label of ['فایل‌ها', 'Pull Request', 'Commit', 'CI / Actions', 'Branches', 'Issues', 'Releases', 'جزئیات Issue', 'Release notes']) {
42 + for (const label of ['فایل‌ها', 'Pull Request', 'Commit', 'جزئیات Commit', 'CI / Actions', 'Branches', 'Issues', 'Releases', 'جزئیات Issue', 'Release notes']) {
43 assert.ok(repoHelp.text.includes(label), `repo guide missing ${label}`);
44 }
45
test/telegram-menu-e2e.test.js
+19 -2
@@ -3,8 +3,11 @@ import assert from 'node:assert/strict';
3 import { createGitHubPlugin } from '../src/plugins/github/plugin.js';
4
5 const repoId = 123;
6 +const fullSha = '0123456789abcdef0123456789abcdef01234567';
7 const github = {
8 async getRepository() { return { id: repoId, name: 'nexa-dev-bot', fullName: 'davoodmehraban89/nexa-dev-bot', defaultBranch: 'main' }; },
9 + async listCommits() { return [{ sha: fullSha, shortSha: fullSha.slice(0, 7), message: 'Audit commit report', author: 'owner', date: '2026-10-04T12:00:00Z' }]; },
10 + async getCommit() { return { sha: fullSha, shortSha: fullSha.slice(0, 7), message: 'Audit commit report\n\nDetailed commit body', author: 'owner', date: '2026-10-04T12:00:00Z', additions: 12, deletions: 4, changedFiles: 2, files: [{ filename: 'src/menu.js', status: 'modified', additions: 8, deletions: 2 }, { filename: 'test/menu.test.js', status: 'modified', additions: 4, deletions: 2 }] }; },
11 async listIssuesPage() { return { items: [{ number: 7, title: 'Broken report', state: 'open', author: 'owner', comments: 3 }], hasMore: false }; },
12 async getIssue() { return { number: 7, title: 'Broken report', state: 'open', author: 'owner', comments: 3, body: 'Reproduction and expected result', labels: ['bug'], assignees: ['owner'], createdAt: '2026-10-04T10:00:00Z', updatedAt: '2026-10-04T11:00:00Z' }; },
13 async listReleases() { return [{ id: 9, tag: 'v2.1.0', name: 'V2.1', draft: false, prerelease: false, publishedAt: '2026-10-04T10:00:00Z' }]; },
@@ -19,6 +22,19 @@ function assertTelegramContract(view) {
22 for (const callback of callbacks(view)) assert.ok(Buffer.byteLength(callback, 'utf8') <= 64, callback);
23 }
24
25 +test('commit list drills into source-backed commit detail and preserves recovery navigation', async () => {
26 + const plugin = createGitHubPlugin({ github, menu, workspaces });
27 + const list = await plugin.resolveCallback(`commits:${repoId}`).execute();
28 + assertTelegramContract(list);
29 + assert.ok(callbacks(list).includes(`commitdetail:${repoId}:${fullSha}`), 'commit list must expose detail drill-down');
30 + const detail = await plugin.resolveCallback(`commitdetail:${repoId}:${fullSha}`).execute();
31 + assertTelegramContract(detail);
32 + assert.match(detail.text, /Detailed commit body/);
33 + assert.match(detail.text, /src\/menu\.js/);
34 + assert.match(detail.text, /\+12\/-4/);
35 + assert.ok(callbacks(detail).includes(`commits:${repoId}`));
36 +});
37 +
38 test('issue list drills into actionable issue detail and preserves recovery navigation', async () => {
39 const plugin = createGitHubPlugin({ github, menu, workspaces });
40 const list = await plugin.resolveCallback(`issues:${repoId}`).execute();
@@ -44,13 +60,14 @@ test('release list drills into source-backed release notes and preserves recover
60 test('repository report views always retain a project recovery route', async () => {
61 const emptyGithub = {
62 ...github,
63 + async listCommits() { return []; },
64 async listIssuesPage() { return { items: [], hasMore: false }; },
65 async listReleases() { return []; }
66 };
67 const plugin = createGitHubPlugin({ github: emptyGithub, menu, workspaces });
51 - for (const callback of [`issues:${repoId}`, `releases:${repoId}`]) {
68 + for (const callback of [`commits:${repoId}`, `issues:${repoId}`, `releases:${repoId}`]) {
69 const view = await plugin.resolveCallback(callback).execute();
70 assertTelegramContract(view);
71 assert.ok(callbacks(view).includes(`repo:${repoId}`), `${callback} must retain project recovery`);
72 }
56 -});
73 +});
\ No newline at end of file