Personal Telegram developer console for GitHub
feat: route workspace callbacks through github plugin
davoodmehraban89 committed
Oct 3, 2026 at 12:46 UTC
5ebfec9a3917854f5a8160ac4f2c273fc5f95361
1 file changed
+27
-84
src/plugins/github/plugin.js
+27
-84
@@ -1,4 +1,5 @@
1
import { githubPluginManifest } from './manifest.js';
2
+import { createWorkspaceController } from './workspace.js';
3
4
const CALLBACK_ACTIONS = Object.freeze([
5
['files:', 'github.files.list'],
@@ -163,12 +164,8 @@ async function workflowRunView(github, repoId, runId) {
164
{ text: '📦 Artifacts', callback_data: `artifacts:${repoId}:${runId}` }
165
]
166
];
166
- if (run.conclusion === 'failure') {
167
- rows.push([{ text: '🔁 اجرای مجدد jobهای ناموفق', callback_data: `rerun:${repoId}:${runId}` }]);
168
- }
169
- if (run.status === 'in_progress' || run.status === 'queued') {
170
- rows.push([{ text: '⏹ لغو Workflow', callback_data: `cancelrun:${repoId}:${runId}` }]);
171
- }
167
+ if (run.conclusion === 'failure') rows.push([{ text: '🔁 اجرای مجدد jobهای ناموفق', callback_data: `rerun:${repoId}:${runId}` }]);
168
+ if (run.status === 'in_progress' || run.status === 'queued') rows.push([{ text: '⏹ لغو Workflow', callback_data: `cancelrun:${repoId}:${runId}` }]);
169
rows.push([
170
{ text: '🔄 بروزرسانی', callback_data: `run:${repoId}:${runId}` },
171
{ text: '🔙 CI / Actions', callback_data: `runs:${repoId}` }
@@ -198,10 +195,7 @@ async function workflowJobsView(github, repoId, runId) {
195
text: `👷 <b>Jobهای ${escapeHtml(run.name)} — ${escapeHtml(repo.name)}</b>\n➖➖➖➖➖➖➖➖➖➖\n${body}`,
196
reply_markup: {
197
inline_keyboard: [
201
- ...jobs.slice(0, 20).map(job => [{
202
- text: `${stateIcon(job.conclusion || job.status)} ${short(job.name, 40)}`,
203
- callback_data: `job:${repoId}:${job.id}`
204
- }]),
198
+ ...jobs.slice(0, 20).map(job => [{ text: `${stateIcon(job.conclusion || job.status)} ${short(job.name, 40)}`, callback_data: `job:${repoId}:${job.id}` }]),
199
[{ text: '🔄 بروزرسانی', callback_data: `jobs:${repoId}:${runId}` }, { text: '🔙 Run', callback_data: `run:${repoId}:${runId}` }]
200
]
201
}
@@ -245,32 +239,22 @@ async function workflowArtifactsView(github, repoId, runId, page = 1) {
239
const refreshCallback = page === 1 ? `artifacts:${repoId}:${runId}` : `artifacts:${repoId}:${runId}:${page}`;
240
return {
241
text: `📦 <b>Artifacts — ${escapeHtml(repo.name)}</b>\nصفحه: <b>${page}</b>\n➖➖➖➖➖➖➖➖➖➖\n${body}`,
248
- reply_markup: {
249
- inline_keyboard: [
250
- ...pairPagination('artifacts', repoId, runId, page, artifacts.length, 10),
251
- [{ text: '🔄 بروزرسانی', callback_data: refreshCallback }, { text: '🔙 Run', callback_data: `run:${repoId}:${runId}` }]
252
- ]
253
- }
242
+ reply_markup: { inline_keyboard: [...pairPagination('artifacts', repoId, runId, page, artifacts.length, 10), [{ text: '🔄 بروزرسانی', callback_data: refreshCallback }, { text: '🔙 Run', callback_data: `run:${repoId}:${runId}` }]] }
243
};
244
}
245
246
async function branchesView(github, repoId, page = 1) {
258
- const [repo, branches] = await Promise.all([
259
- github.getRepository(repoId),
260
- github.listBranches(repoId, { perPage: 20, page })
261
- ]);
247
+ const [repo, branches] = await Promise.all([github.getRepository(repoId), github.listBranches(repoId, { perPage: 20, page })]);
248
const body = branches.length
249
? branches.slice(0, 20).map(branch => `🌿 <b>${escapeHtml(short(branch.name, 70))}</b>\n <code>${escapeHtml(String(branch.sha).slice(0, 10))}</code>${branch.protected ? ' · 🛡 protected' : ''}`).join('\n\n')
250
: '<i>Branchی یافت نشد.</i>';
251
return {
252
text: `🌿 <b>Branches — ${escapeHtml(repo.name)}</b>\nصفحه: <b>${page}</b>\n➖➖➖➖➖➖➖➖➖➖\n${body}`,
267
- reply_markup: {
268
- inline_keyboard: [
269
- ...branches.slice(0, 20).filter(branch => /^[a-f0-9]{40}$/i.test(String(branch.sha))).map(branch => [{ text: `↔️ ${short(branch.name, 42)}`, callback_data: `compare:${repoId}:${branch.sha}` }]),
270
- ...listPagination('branches', repoId, page, branches.length, 20),
271
- [{ text: '🔙 پروژه', callback_data: `repo:${repoId}` }]
272
- ]
273
- }
253
+ reply_markup: { inline_keyboard: [
254
+ ...branches.slice(0, 20).filter(branch => /^[a-f0-9]{40}$/i.test(String(branch.sha))).map(branch => [{ text: `↔️ ${short(branch.name, 42)}`, callback_data: `compare:${repoId}:${branch.sha}` }]),
255
+ ...listPagination('branches', repoId, page, branches.length, 20),
256
+ [{ text: '🔙 پروژه', callback_data: `repo:${repoId}` }]
257
+ ] }
258
};
259
}
260
@@ -290,13 +274,11 @@ async function pullRequestsView(github, repoId, page = 1) {
274
: '<i>Pull Requestی یافت نشد.</i>';
275
return {
276
text: `🔎 <b>Pull Requests — ${escapeHtml(repo.name)}</b>\nصفحه: <b>${page}</b>\n➖➖➖➖➖➖➖➖➖➖\n${body}`,
293
- reply_markup: {
294
- inline_keyboard: [
295
- ...prs.slice(0, 10).map(pr => [{ text: `#${pr.number} ${short(pr.title, 42)}`, callback_data: `prdetail:${repoId}:${pr.number}` }]),
296
- ...listPagination('prs', repoId, page, prs.length, 10),
297
- [{ text: '🔙 پروژه', callback_data: `repo:${repoId}` }]
298
- ]
299
- }
277
+ reply_markup: { inline_keyboard: [
278
+ ...prs.slice(0, 10).map(pr => [{ text: `#${pr.number} ${short(pr.title, 42)}`, callback_data: `prdetail:${repoId}:${pr.number}` }]),
279
+ ...listPagination('prs', repoId, page, prs.length, 10),
280
+ [{ text: '🔙 پروژه', callback_data: `repo:${repoId}` }]
281
+ ] }
282
};
283
}
284
@@ -305,15 +287,7 @@ async function pullRequestDetailView(github, repoId, prNumber) {
287
const body = escapeHtml(short(pr.body || '', 600));
288
return {
289
text: `🔎 <b>PR #${pr.number} — ${escapeHtml(repo.name)}</b>\n<b>${escapeHtml(pr.title)}</b>\n${pr.merged ? '🟣 merged' : `${stateIcon(pr.state)} ${escapeHtml(pr.state)}`} · ${escapeHtml(pr.author)}\n<code>${escapeHtml(pr.head || '-')}</code> → <code>${escapeHtml(pr.base || '-')}</code>\n+${pr.additions}/-${pr.deletions} · ${pr.changedFiles} files\n➖➖➖➖➖➖➖➖➖➖\n${body || '<i>بدون توضیح.</i>'}`,
308
- reply_markup: {
309
- inline_keyboard: [
310
- [
311
- { text: '🧩 فایلها / Diff', callback_data: `prfiles:${repoId}:${prNumber}:1` },
312
- { text: '✅ Checks', callback_data: `prchecks:${repoId}:${prNumber}:1` }
313
- ],
314
- [{ text: '🔙 PRها', callback_data: `prs:${repoId}` }]
315
- ]
316
- }
290
+ reply_markup: { inline_keyboard: [[{ text: '🧩 فایلها / Diff', callback_data: `prfiles:${repoId}:${prNumber}:1` }, { text: '✅ Checks', callback_data: `prchecks:${repoId}:${prNumber}:1` }], [{ text: '🔙 PRها', callback_data: `prs:${repoId}` }]] }
291
};
292
}
293
@@ -325,12 +299,7 @@ async function pullRequestFilesView(github, repoId, prNumber, page = 1) {
299
}).join('\n\n') : '<i>فایل تغییریافتهای یافت نشد.</i>';
300
return {
301
text: `🧩 <b>PR #${prNumber} Files / Diff</b>\nصفحه: <b>${page}</b>\n➖➖➖➖➖➖➖➖➖➖\n${body}`,
328
- reply_markup: {
329
- inline_keyboard: [
330
- ...pairPagination('prfiles', repoId, prNumber, page, files.length, 8),
331
- [{ text: '🔙 PR', callback_data: `prdetail:${repoId}:${prNumber}` }]
332
- ]
333
- }
302
+ reply_markup: { inline_keyboard: [...pairPagination('prfiles', repoId, prNumber, page, files.length, 8), [{ text: '🔙 PR', callback_data: `prdetail:${repoId}:${prNumber}` }]] }
303
};
304
}
305
@@ -342,32 +311,19 @@ async function pullRequestChecksView(github, repoId, prNumber, page = 1) {
311
: '<i>Checkی یافت نشد.</i>';
312
return {
313
text: `✅ <b>PR #${prNumber} Checks</b>\nصفحه: <b>${page}</b>\n➖➖➖➖➖➖➖➖➖➖\n${body}`,
345
- reply_markup: {
346
- inline_keyboard: [
347
- ...pairPagination('prchecks', repoId, prNumber, page, checks.length, 20),
348
- [{ text: '🔙 PR', callback_data: `prdetail:${repoId}:${prNumber}` }]
349
- ]
350
- }
314
+ reply_markup: { inline_keyboard: [...pairPagination('prchecks', repoId, prNumber, page, checks.length, 20), [{ text: '🔙 PR', callback_data: `prdetail:${repoId}:${prNumber}` }]] }
315
};
316
}
317
318
async function issuesView(github, repoId, page = 1) {
355
- const [repo, issuePage] = await Promise.all([
356
- github.getRepository(repoId),
357
- github.listIssuesPage(repoId, { page })
358
- ]);
319
+ const [repo, issuePage] = await Promise.all([github.getRepository(repoId), github.listIssuesPage(repoId, { page })]);
320
const issues = issuePage.items || [];
321
const body = issues.length
322
? issues.slice(0, 20).map(issue => `${stateIcon(issue.state)} <b>#${issue.number} ${escapeHtml(short(issue.title, 110))}</b>\n ${escapeHtml(issue.author)} · ${issue.comments} comments`).join('\n\n')
323
: '<i>Issueی یافت نشد.</i>';
324
return {
325
text: `🐛 <b>Issues — ${escapeHtml(repo.name)}</b>\nصفحه: <b>${page}</b>\n➖➖➖➖➖➖➖➖➖➖\n${body}`,
365
- reply_markup: {
366
- inline_keyboard: [
367
- ...explicitPagination('issues', repoId, page, !!issuePage.hasMore),
368
- [{ text: '🔙 پروژه', callback_data: `repo:${repoId}` }]
369
- ]
370
- }
326
+ reply_markup: { inline_keyboard: [...explicitPagination('issues', repoId, page, !!issuePage.hasMore), [{ text: '🔙 پروژه', callback_data: `repo:${repoId}` }]] }
327
};
328
}
329
@@ -393,52 +349,36 @@ function workflowActionResultView(repoId, runId, action) {
349
function resolveReadCallback(data) {
350
const value = String(data || '');
351
if (value === 'menu:repos') return { actionId: 'github.repos.list', kind: 'legacy' };
396
-
352
const repoId = numericSingle(value, 'repo');
353
if (repoId !== null) return { actionId: 'github.repo.detail', kind: 'repo', repoId };
399
-
354
const runs = workflowRunsPage(value);
355
if (runs) return { actionId: 'github.workflow.runs.list', kind: 'runs', ...runs };
402
-
356
const run = numericPair(value, 'run');
357
if (run) return { actionId: 'github.workflow.run.detail', kind: 'run', ...run };
405
-
358
const jobs = numericPair(value, 'jobs');
359
if (jobs) return { actionId: 'github.workflow.jobs.list', kind: 'jobs', ...jobs };
408
-
360
const job = numericPair(value, 'job');
361
if (job) return { actionId: 'github.workflow.job.detail', kind: 'job', repoId: job.repoId, jobId: job.runId };
411
-
362
const joblog = numericPair(value, 'joblog');
363
if (joblog) return { actionId: 'github.workflow.job.log', kind: 'joblog', repoId: joblog.repoId, jobId: joblog.runId };
414
-
364
const artifacts = pagedPair(value, 'artifacts');
365
if (artifacts) return { actionId: 'github.workflow.artifacts.list', kind: 'artifacts', repoId: artifacts.repoId, runId: artifacts.itemId, page: artifacts.page };
417
-
366
const branches = pagedSingle(value, 'branches');
367
if (branches) return { actionId: 'github.branches.list', kind: 'branches', ...branches };
420
-
368
const compare = compareRef(value);
369
if (compare) return { actionId: 'github.compare.read', kind: 'compare', ...compare };
423
-
370
const prs = pagedSingle(value, 'prs');
371
if (prs) return { actionId: 'github.pr.advanced.list', kind: 'prs', ...prs };
426
-
372
const prdetail = numericPair(value, 'prdetail');
373
if (prdetail) return { actionId: 'github.pr.detail', kind: 'prdetail', repoId: prdetail.repoId, prNumber: prdetail.runId };
429
-
374
const prfiles = numericTriple(value, 'prfiles');
375
if (prfiles) return { actionId: 'github.pr.files.list', kind: 'prfiles', repoId: prfiles.repoId, prNumber: prfiles.itemId, page: prfiles.page };
432
-
376
const prchecks = numericTriple(value, 'prchecks');
377
if (prchecks) return { actionId: 'github.pr.checks.list', kind: 'prchecks', repoId: prchecks.repoId, prNumber: prchecks.itemId, page: prchecks.page };
435
-
378
const issues = pagedSingle(value, 'issues');
379
if (issues) return { actionId: 'github.issues.list', kind: 'issues', ...issues };
438
-
380
const releases = pagedSingle(value, 'releases');
381
if (releases) return { actionId: 'github.releases.list', kind: 'releases', ...releases };
441
-
382
for (const [prefix, actionId] of CALLBACK_ACTIONS) {
383
if (value.startsWith(prefix)) return { actionId, kind: 'legacy' };
384
}
@@ -471,9 +411,10 @@ function resolveWriteCallback(data) {
411
return null;
412
}
413
474
-export function createGitHubPlugin({ github, menu } = {}) {
414
+export function createGitHubPlugin({ github, menu, workspaces } = {}) {
415
if (!github) throw new Error('GitHub plugin requires github service');
416
if (!menu) throw new Error('GitHub plugin requires menu manager');
417
+ const workspaceController = workspaces ? createWorkspaceController({ github, workspaces }) : null;
418
419
return {
420
manifest: githubPluginManifest,
@@ -483,13 +424,15 @@ export function createGitHubPlugin({ github, menu } = {}) {
424
return { actionId: 'github.repos.list', execute: () => menu.getReposListView() };
425
},
426
486
- resolveCallback(data) {
427
+ resolveCallback(data, context = {}) {
428
const write = resolveWriteCallback(data);
429
if (write) return { actionId: write.actionId, approval: write.approval, execute: () => write.execute(github) };
430
431
+ const workspaceRoute = workspaceController?.resolveCallback(data, context);
432
+ if (workspaceRoute) return workspaceRoute;
433
+
434
const read = resolveReadCallback(data);
435
if (!read) return null;
492
-
436
return {
437
actionId: read.actionId,
438
execute: async () => {