Personal Telegram developer console for GitHub

fix: expose per-file workspace editors (#59)

davoodmehraban89 committed Oct 7, 2026 at 19:58 UTC c6d457b56b8527a26c1ca97ace82a3b622e586fa
2 files changed +20 -1
src/plugins/github/workspace.js
+9 -1
@@ -66,13 +66,14 @@ function parseCallback(data) {
66 return null;
67 }
68
69 -function editorUrlFor(workspace, editorUrl) {
69 +function editorUrlFor(workspace, editorUrl, path = '') {
70 const configured = String(editorUrl || '').trim();
71 if (!configured) return '';
72 try {
73 const url = new URL(configured);
74 if (url.protocol !== 'https:') return '';
75 url.searchParams.set('workspaceId', workspace.id);
76 + if (path) url.searchParams.set('path', path);
77 return url.toString();
78 } catch {
79 return '';
@@ -208,6 +209,13 @@ export function createWorkspaceController({ github, workspaces, editorUrl = DEFA
209 const commitMessage = workspace.commitMessage ? `<code>${escapeHtml(short(workspace.commitMessage, 120))}</code>` : '<i>ثبت نشده</i>';
210 const list = files.map((file, i) => `${file.draftText !== file.originalText ? '●' : '○'} <code>${escapeHtml(file.path)}</code>${refs[i]?.refId && files.length > 1 ? ` — <i>قابل حذف</i>` : ''}`).join('\n');
211 const buttons = workspaceButtons(workspace, editorUrl);
212 + if (editorUrl && files.length > 1) {
213 + const fileEditors = files.map(file => [{ text: 'Edit ' + short(file.path, 34), web_app: { url: editorUrlFor(workspace, editorUrl, file.path) } }]);
214 + buttons.unshift(...fileEditors);
215 + const genericEditorUrl = editorUrlFor(workspace, editorUrl);
216 + const genericEditorIndex = buttons.findIndex(row => row.some(button => button.web_app?.url === genericEditorUrl));
217 + if (genericEditorIndex >= 0) buttons[genericEditorIndex] = buttons[genericEditorIndex].filter(button => !button.web_app);
218 + }
219 buttons.unshift([{ text: '➕ افزودن فایل', callback_data: `wfiles:${workspace.id}:${workspace.repoId}` }]);
220 if (files.length > 1 && refs[1]?.refId) buttons.unshift([{ text: `➖ حذف ${short(files[1].path, 28)}`, callback_data: `wremove:${refs[1].refId}` }]);
221 return { text: `📝 <b>Repository Workspace</b>\nChange Set: <b>${files.length} فایل</b> · تغییرکرده: <b>${changedCount}</b>\n${list}\nوضعیت: <b>${escapeHtml(workspace.state || 'DRAFT')}</b>\nBase: <code>${escapeHtml(String(workspace.baseHeadSha || '').slice(0, 10))}</code>\nپیام Commit: ${commitMessage}\n\nذخیره فقط Draft محلی را تغییر می‌دهد؛ GitHub فقط بعد از Diff، Ready و Safe Approval تغییر می‌کند.`, reply_markup:{inline_keyboard:buttons} };
test/phase2-controller.test.js
+11
@@ -52,3 +52,14 @@ test('file picker lists candidates from the exact workspace base snapshot', asyn
52 await c.resolveCallback('wfiles:W000000001:1',{ownerId:'42'}).execute();
53 assert.deepEqual(seen,{repoId:1,path:'',options:{ref:ws.baseHeadSha}});
54 });
55 +
56 +test('multi-file workspace exposes a direct editor button for every file', async()=>{
57 + const workspaces={async getWorkspace(){return structuredClone(ws)},async createNavigationRefs({refs}){return refs.map((_,i)=>({refId:'R'+String(i).padStart(9,'0')}))}};
58 + const c=createWorkspaceController({github:{},workspaces,editorUrl:'https://example.com/workspace/editor'});
59 + const v=await c.resolveCallback('ws:W000000001',{ownerId:'42'}).execute();
60 + const editors=v.reply_markup.inline_keyboard.flat().filter(button=>button.web_app?.url);
61 + assert.equal(editors.length,2);
62 + assert.equal(editors[0].web_app.url,'https://example.com/workspace/editor?workspaceId=W000000001&path=README.md');
63 + assert.equal(editors[1].web_app.url,'https://example.com/workspace/editor?workspaceId=W000000001&path=src%2Fa.js');
64 + assert.match(editors[1].text,/src\/a\.js/);
65 +});