Personal Telegram developer console for GitHub

feat(github): add commit report drill-down

davoodmehraban89 committed Oct 4, 2026 at 17:44 UTC 08d5cea2ada73111c40dea12594e4f34b6a51b34
1 file changed +43
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+<b>${commit.additions ?? 0}</b>/-<b>${commit.deletions ?? 0}</b> · ${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 commitsView(github, read.repoId);
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);