Personal Telegram developer console for GitHub

feat: commit detail drill-down

davoodmehraban89 committed Oct 4, 2026 at 17:48 UTC 6ff32e25b48d063f53dc1832d5d793e9c099c845
2 files changed +61 -1
src/github.js
+22 -1
@@ -219,11 +219,32 @@ 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],
222 + sha: c.sha.slice(0, 7), fullSha: c.sha, 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) : ''
224 }));
225 }
226
227 + async getCommit(repoRef, sha) {
228 + const commitSha = fullSha(sha);
229 + const { apiBase } = await this.getRepositoryContext(repoRef);
230 + const c = await this.requestJson(`${apiBase}/commits/${commitSha}`, 'GitHub commit');
231 + return {
232 + sha: c.sha || commitSha,
233 + message: String(c.commit?.message || ''),
234 + author: c.author?.login || c.commit?.author?.name || 'Unknown',
235 + date: c.commit?.author?.date || '',
236 + additions: c.stats?.additions ?? 0,
237 + deletions: c.stats?.deletions ?? 0,
238 + changedFiles: Array.isArray(c.files) ? c.files.length : 0,
239 + files: (c.files || []).slice(0, 20).map(file => ({
240 + filename: file.filename || '',
241 + status: file.status || '',
242 + additions: file.additions ?? 0,
243 + deletions: file.deletions ?? 0
244 + }))
245 + };
246 + }
247 +
248 async listCommitChecks(repoRef, sha, { perPage = 20, page = 1 } = {}) {
249 const commitSha = fullSha(sha); const count = clampPerPage(perPage, 20); const pageNumber = clampPage(page);
250 const { apiBase } = await this.getRepositoryContext(repoRef);
src/plugins/github/plugin.js
+39
@@ -67,6 +67,12 @@ const compareRef = value => {
67 return { repoId: Number(match[1]), sha: match[2] };
68 };
69
70 +const commitRef = 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 => {
@@ -315,6 +321,33 @@ async function pullRequestChecksView(github, repoId, prNumber, page = 1) {
321 };
322 }
323
324 +async function commitsView(github, repoId) {
325 + const [repo, commits] = await Promise.all([github.getRepository(repoId), github.listCommits(repoId)]);
326 + const body = commits.length
327 + ? commits.slice(0, 10).map(commit => `📝 <code>${escapeHtml(commit.sha)}</code> — <b>${escapeHtml(short(commit.message, 100))}</b>\n ${escapeHtml(commit.author)}${commit.date ? ` · ${escapeHtml(commit.date)}` : ''}`).join('\n\n')
328 + : '<i>کامیتی در پاسخ GitHub یافت نشد.</i>';
329 + const rows = commits.slice(0, 10)
330 + .filter(commit => /^[a-f0-9]{40}$/i.test(String(commit.fullSha || '')))
331 + .map(commit => [{ text: `${commit.sha} ${short(commit.message, 34)}`, callback_data: `commitdetail:${repoId}:${commit.fullSha}` }]);
332 + rows.push([{ text: '🔄 بروزرسانی', callback_data: `commits:${repoId}` }, { text: '🔙 پروژه', callback_data: `repo:${repoId}` }]);
333 + return {
334 + text: `📝 <b>آخرین Commitهای پروژه ${escapeHtml(repo.name)}</b>\n➖➖➖➖➖➖➖➖➖➖\n${body}`,
335 + reply_markup: { inline_keyboard: rows }
336 + };
337 +}
338 +
339 +async function commitDetailView(github, repoId, sha) {
340 + const [repo, commit] = await Promise.all([github.getRepository(repoId), github.getCommit(repoId, sha)]);
341 + const files = (commit.files || []).slice(0, 12)
342 + .map(file => `• <code>${escapeHtml(short(file.filename, 90))}</code> · ${escapeHtml(file.status || 'changed')} · +${file.additions ?? 0}/-${file.deletions ?? 0}`)
343 + .join('\n');
344 + const message = escapeHtml(short(commit.message || '', 1200));
345 + return {
346 + text: `📝 <b>Commit — ${escapeHtml(repo.name)}</b>\n<code>${escapeHtml(commit.sha)}</code>\nAuthor: ${escapeHtml(commit.author || 'Unknown')}\nDate: ${escapeHtml(commit.date || '-')}\nChanges: +${commit.additions ?? 0}/-${commit.deletions ?? 0} · ${commit.changedFiles ?? 0} files\n➖➖➖➖➖➖➖➖➖➖\n${message || '<i>بدون پیام.</i>'}\n\n<b>Files</b>\n${files || '<i>فایل تغییریافته‌ای در پاسخ GitHub نیست.</i>'}`,
347 + reply_markup: { inline_keyboard: [[{ text: '🔄 بروزرسانی', callback_data: `commitdetail:${repoId}:${sha}` }, { text: '🔙 Commitها', callback_data: `commits:${repoId}` }]] }
348 + };
349 +}
350 +
351 async function issuesView(github, repoId, page = 1) {
352 const [repo, issuePage] = await Promise.all([github.getRepository(repoId), github.listIssuesPage(repoId, { page })]);
353 const issues = issuePage.items || [];
@@ -392,6 +425,10 @@ function resolveReadCallback(data) {
425 if (joblog) return { actionId: 'github.workflow.job.log', kind: 'joblog', repoId: joblog.repoId, jobId: joblog.runId };
426 const artifacts = pagedPair(value, 'artifacts');
427 if (artifacts) return { actionId: 'github.workflow.artifacts.list', kind: 'artifacts', repoId: artifacts.repoId, runId: artifacts.itemId, page: artifacts.page };
428 + const commits = numericSingle(value, 'commits');
429 + if (commits !== null) return { actionId: 'github.commits.list', kind: 'commits', repoId: commits };
430 + const commitdetail = commitRef(value);
431 + if (commitdetail) return { actionId: 'github.commit.detail', kind: 'commitdetail', ...commitdetail };
432 const branches = pagedSingle(value, 'branches');
433 if (branches) return { actionId: 'github.branches.list', kind: 'branches', ...branches };
434 const compare = compareRef(value);
@@ -480,6 +517,8 @@ export function createGitHubPlugin({ github, menu, workspaces } = {}) {
517 if (read.kind === 'job') return workflowJobView(github, read.repoId, read.jobId);
518 if (read.kind === 'joblog') return workflowJobLogView(github, read.repoId, read.jobId);
519 if (read.kind === 'artifacts') return workflowArtifactsView(github, read.repoId, read.runId, read.page);
520 + if (read.kind === 'commits') return commitsView(github, read.repoId);
521 + if (read.kind === 'commitdetail') return commitDetailView(github, read.repoId, read.sha);
522 if (read.kind === 'branches') return branchesView(github, read.repoId, read.page);
523 if (read.kind === 'compare') return compareView(github, read.repoId, read.sha);
524 if (read.kind === 'prs') return pullRequestsView(github, read.repoId, read.page);