Personal Telegram developer console for GitHub

feat: add approval gated workspace commit route

davoodmehraban89 committed Oct 3, 2026 at 13:37 UTC 77ad00f1afc621df877086d1cf6db27a6cfe1ba4
1 file changed +66
src/plugins/github/workspace.js
+66
@@ -5,8 +5,12 @@ import {
5 normalizeCommitMessage,
6 validateEditableFile
7 } from '../../core/workspace-policy.js';
8 +import { commitWorkspaceIntent } from './workspace-commit.js';
9 +
10 +export { commitWorkspaceIntent } from './workspace-commit.js';
11
12 const HANDLE_10 = '[A-Za-z0-9_-]{10}';
13 +const INTENT_8 = '[A-Za-z0-9_-]{8}';
14 const escapeHtml = value => String(value ?? '')
15 .replaceAll('&', '&')
16 .replaceAll('<', '&lt;')
@@ -43,6 +47,13 @@ function parseCallback(data) {
47 if (match) return { actionId: 'github.workspace.ready', kind: 'ready', workspaceId: match[1] };
48 match = value.match(new RegExp(`^wcancel:(${HANDLE_10})$`));
49 if (match) return { actionId: 'github.workspace.cancel', kind: 'cancel', workspaceId: match[1] };
50 + match = value.match(new RegExp(`^wscommit:(\\d+):(${INTENT_8})$`));
51 + if (match) return {
52 + actionId: 'github.workspace.commit_branch',
53 + kind: 'commit',
54 + repoId: Number(match[1]),
55 + intentId: match[2]
56 + };
57 return null;
58 }
59
@@ -63,6 +74,20 @@ function workspaceButtons(workspace) {
74 ];
75 }
76
77 +function workspaceCommitResultView(repoId, intent, result) {
78 + const rows = [
79 + [{ text: '🧪 CI / Actions', callback_data: `runs:${repoId}` }]
80 + ];
81 + if (intent?.workspaceId) {
82 + rows.push([{ text: '📝 Workspace', callback_data: `ws:${intent.workspaceId}` }]);
83 + }
84 + rows.push([{ text: '📦 پروژه', callback_data: `repo:${repoId}` }]);
85 + return {
86 + text: `✅ <b>Commit روی branch جدید ایجاد شد</b>\nBranch: <code>${escapeHtml(result.branch)}</code>\nSHA: <code>${escapeHtml(result.commitSha)}</code>${result.idempotent ? '\nوضعیت: <b>reconciled / idempotent</b>' : ''}\n\nشاخهٔ پیش‌فرض تغییر نکرده است.`,
87 + reply_markup: { inline_keyboard: rows }
88 + };
89 +}
90 +
91 export function createWorkspaceController({ github, workspaces } = {}) {
92 if (!github) throw new Error('Workspace controller requires GitHub service');
93 if (!workspaces) throw new Error('Workspace controller requires durable workspace store');
@@ -287,6 +312,47 @@ export function createWorkspaceController({ github, workspaces } = {}) {
312 resolveCallback(data, context = {}) {
313 const parsed = parseCallback(data);
314 if (!parsed) return null;
315 +
316 + if (parsed.kind === 'commit') {
317 + return {
318 + actionId: parsed.actionId,
319 + approval: {
320 + input: { repoId: parsed.repoId, intentId: parsed.intentId },
321 + label: 'Commit روی branch جدید',
322 + cancelCallback: `repo:${parsed.repoId}`
323 + },
324 + audit: { repoId: parsed.repoId, intentId: parsed.intentId },
325 + execute: async () => {
326 + const ownerId = ownerFrom(context);
327 + const result = await commitWorkspaceIntent({
328 + github,
329 + workspaces,
330 + ownerId,
331 + repoId: parsed.repoId,
332 + intentId: parsed.intentId
333 + });
334 + const intent = await workspaces.getIntent({ ownerId, intentId: parsed.intentId });
335 + const view = workspaceCommitResultView(parsed.repoId, intent, result);
336 + return {
337 + ...view,
338 + audit: {
339 + repoId: parsed.repoId,
340 + intentId: parsed.intentId,
341 + workspaceId: intent?.workspaceId,
342 + path: intent?.path,
343 + contentDigest: intent?.contentDigest,
344 + commitMessageDigest: intent?.commitMessageDigest,
345 + baseHeadSha: intent?.baseHeadSha,
346 + targetBranch: intent?.targetBranch,
347 + commitSha: result.commitSha,
348 + branch: result.branch,
349 + idempotent: result.idempotent
350 + }
351 + };
352 + }
353 + };
354 + }
355 +
356 return {
357 actionId: parsed.actionId,
358 execute: async () => {