Personal Telegram developer console for GitHub
phase2-20261005-g
audit/commit-drilldown
audit/finalize-workspace-menu-security
audit/ops-actionability
audit/pr-menu-consolidation
audit/status-menu-consolidation
audit/telegram-menu-e2e
audit/telegram-menu-e2e-wave2
chore/actions-node24-runtime
cleanup/remove-diag
design/cloudflare-ops-read
docs/control-plane-2-7-design
docs/guide-v2-1-sync
docs/menu-audit-final-sync
docs/phase2-acceptance-closeout
docs/phase2-multifile-design
feat/bootstrap-worker
feat/cloudflare-ops-read
feat/cp2-multifile-final
feat/cp2-multifile-workspace
feat/cp3-github-write-final
feat/cp4-cloudflare-ops-final
feat/cp5-cicd-control-plane
feat/cp6-incident-manager
feat/cp7-automation-engine
feat/deep-file-browser
feat/final-delivery-16-20
feat/github-advanced-read
feat/in-app-guide-v2
feat/navigation-recovery-ux-v2
feat/ops-console-v2-1
feat/persistent-menu-code-input
feat/phase2-multifile-workspace
feat/phase2-multifile-workspace-v2
feat/plugin-foundation-v1
feat/safe-github-ops
feat/self-register-webhook
feat/studio-g0-foundation
feat/telegram-main-inline-menu
feat/telegram-pr-merge
feat/ux-platform-8-12
feat/v3a-readonly-copilot
feat/workspace-file-upload
feature/mobile-repo-browser
feature/multi-file-change-set
fix/approval-expiry-feedback
fix/callback-resilience-and-docs
fix/ci-actions-pagination
fix/cloudflare-fetch-binding
fix/editor-request-body-cap
fix/editor-safe-file-options
fix/issues-permission-release-empty-ux
fix/main-menu-callback-fallback
fix/phase2-file-editor-selection
fix/phase2-final-ux
fix/phase2-workspace-ref-persistence
fix/production-auto-deploy
fix/provider-write-error-feedback
fix/repository-id-navigation-fallback
fix/repository-pr-navigation
fix/telegram-callback-updates
fix/telegram-runtime-diagnostics
fix/workspace-editor-flow-v2
fix/workspace-recovery-validation
hardening/ci-zero-test-telegram-token
hardening/pr1-destructive-totp
hardening/pr2-kill-switch
main
multifile-workspace
nexa/edit-BwJEIIY3PW
nexa/edit-IPHT8irO7b
nexa/edit-b4Od3BIMYd
p2-multifile
phase2-20261005
phase2-20261005-a
phase2-20261005-b
phase2-20261005-c
phase2-20261005-d
phase2-20261005-e
phase2-20261005-f
phase2-20261005-g
phase2-20261005-h
phase2-20261005-i
phase2-20261005-j
phase2-20261005-k
phase2-20261005-l
phase2-20261005-m
phase2-20261005-n
phase2-20261005-o
phase2-20261005-p
phase2-20261005-q
phase2-20261005-r
phase2-20261005-s
phase2-20261005-t
phase2-20261005-u
phase2-20261005-v
phase2-20261005-w
phase2-20261005-x
phase2-20261005-y
phase2-20261005-z
phase2-acceptance-closeout
phase2-add-file-hotfix
phase2-change-set
phase2-design-20261005
phase2-design-final
phase2-implementation
phase2-multifile-implementation
phase2-multifile-spec
phase2-spec-final
phase2-workspace
phase2/multifile-workspace
plan/nexa-studio-v2-reviewed
security/remove-telegram-setup
spec/repository-workspace-editor
v3a/multifile
work/multifile
| 1 | import { createGitHubPlugin as createLegacyGitHubPlugin } from './plugin-legacy.js'; |
| 2 | |
| 3 | const FULL_SHA = /^[a-f0-9]{40}$/i; |
| 4 | const from36 = value => /^[0-9a-z]+$/i.test(String(value || '')) ? Number.parseInt(value, 36) : NaN; |
| 5 | const mergeRef = value => { |
| 6 | const m = String(value || '').match(/^mergepr:([0-9a-z]+):([0-9a-z]+):([a-f0-9]{40})$/i); |
| 7 | if (!m) return null; |
| 8 | const repoId = from36(m[1]); |
| 9 | const prNumber = from36(m[2]); |
| 10 | return Number.isSafeInteger(repoId) && Number.isSafeInteger(prNumber) && prNumber > 0 |
| 11 | ? { repoId, prNumber, headSha: m[3].toLowerCase() } |
| 12 | : null; |
| 13 | }; |
| 14 | |
| 15 | const cp3Pair = (value, prefix) => { |
| 16 | const m = String(value || '').match(new RegExp('^' + prefix + ':(\\d+):(\\d+)$')); |
| 17 | return m ? { repoId: Number(m[1]), runId: Number(m[2]) } : null; |
| 18 | }; |
| 19 | |
| 20 | const appendBeforeBack = (view, row) => { |
| 21 | const rows = [...(view?.reply_markup?.inline_keyboard || [])]; |
| 22 | rows.splice(Math.max(0, rows.length - 1), 0, row); |
| 23 | return { ...view, reply_markup: { ...(view.reply_markup || {}), inline_keyboard: rows } }; |
| 24 | }; |
| 25 | |
| 26 | export function createGitHubPlugin(options = {}) { |
| 27 | const { github } = options; |
| 28 | const base = createLegacyGitHubPlugin(options); |
| 29 | |
| 30 | return { |
| 31 | ...base, |
| 32 | resolveCallback(data, context = {}) { |
| 33 | const dispatch = cp3Pair(data, 'dispatchwf'); |
| 34 | if (dispatch) { |
| 35 | return { |
| 36 | actionId: 'github.workflow.dispatch', |
| 37 | approval: { |
| 38 | input: { repoId: dispatch.repoId, runId: dispatch.runId }, |
| 39 | label: 'اجرای Workflow', |
| 40 | cancelCallback: `run:${dispatch.repoId}:${dispatch.runId}` |
| 41 | }, |
| 42 | execute: async () => { |
| 43 | const run = await github.getWorkflowRun(dispatch.repoId, dispatch.runId); |
| 44 | if (!Number.isSafeInteger(Number(run.workflowId)) || !run.branch) { |
| 45 | throw new Error('Workflow dispatch target is unavailable'); |
| 46 | } |
| 47 | await github.dispatchWorkflow(dispatch.repoId, run.workflowId, { ref: run.branch, inputs: {} }); |
| 48 | return { |
| 49 | text: '✅ درخواست اجرای Workflow برای GitHub ارسال شد.', |
| 50 | reply_markup: { |
| 51 | inline_keyboard: [[{ text: '🧪 مشاهده Run', callback_data: `run:${dispatch.repoId}:${dispatch.runId}` }]] |
| 52 | } |
| 53 | }; |
| 54 | } |
| 55 | }; |
| 56 | } |
| 57 | |
| 58 | const rerunJob = cp3Pair(data, 'rerunjob'); |
| 59 | if (rerunJob) { |
| 60 | return { |
| 61 | actionId: 'github.workflow.job.rerun', |
| 62 | approval: { |
| 63 | input: { repoId: rerunJob.repoId, runId: rerunJob.runId, jobId: rerunJob.runId }, |
| 64 | label: 'اجرای مجدد Job', |
| 65 | cancelCallback: `job:${rerunJob.repoId}:${rerunJob.runId}` |
| 66 | }, |
| 67 | execute: async () => { |
| 68 | const job = await github.getWorkflowJob(rerunJob.repoId, rerunJob.runId); |
| 69 | if (!['failure', 'cancelled'].includes(String(job.conclusion || ''))) { |
| 70 | throw new Error('Workflow job is not eligible for rerun'); |
| 71 | } |
| 72 | await github.rerunJob(rerunJob.repoId, rerunJob.runId); |
| 73 | return { |
| 74 | text: '✅ درخواست اجرای مجدد Job برای GitHub ارسال شد.', |
| 75 | reply_markup: { |
| 76 | inline_keyboard: [[{ text: '👷 مشاهده Job', callback_data: `job:${rerunJob.repoId}:${rerunJob.runId}` }]] |
| 77 | } |
| 78 | }; |
| 79 | } |
| 80 | }; |
| 81 | } |
| 82 | |
| 83 | const merge = mergeRef(data); |
| 84 | if (merge) { |
| 85 | return { |
| 86 | actionId: 'github.pull_request.merge', |
| 87 | approval: { |
| 88 | input: merge, |
| 89 | label: `Merge PR #${merge.prNumber}`, |
| 90 | cancelCallback: `prdetail:${merge.repoId}:${merge.prNumber}` |
| 91 | }, |
| 92 | execute: async () => { |
| 93 | const current = await github.getPullRequest(merge.repoId, merge.prNumber); |
| 94 | if (current.merged || current.state !== 'open' || current.draft) throw new Error('Pull request is not mergeable'); |
| 95 | if (!FULL_SHA.test(String(current.headSha || '')) || String(current.headSha).toLowerCase() !== merge.headSha) { |
| 96 | throw new Error('Pull request head changed; fresh approval is required'); |
| 97 | } |
| 98 | const result = await github.mergePullRequest(merge.repoId, merge.prNumber, { |
| 99 | expectedHeadSha: merge.headSha, |
| 100 | mergeMethod: 'squash' |
| 101 | }); |
| 102 | if (!result?.merged) throw new Error(result?.message || 'GitHub did not merge the pull request'); |
| 103 | return { |
| 104 | text: `✅ <b>PR #${merge.prNumber} با موفقیت Merge شد.</b>`, |
| 105 | reply_markup: { inline_keyboard: [[{ text: '🔙 PRها', callback_data: `prs:${merge.repoId}` }]] } |
| 106 | }; |
| 107 | } |
| 108 | }; |
| 109 | } |
| 110 | |
| 111 | const route = base.resolveCallback(data, context); |
| 112 | if (!route || typeof route.execute !== 'function') return route; |
| 113 | |
| 114 | const detail = String(data || '').match(/^prdetail:(\d+):(\d+)$/); |
| 115 | const runDetail = String(data || '').match(/^run:(\d+):(\d+)$/); |
| 116 | const jobDetail = String(data || '').match(/^job:(\d+):(\d+)$/); |
| 117 | |
| 118 | if (detail) { |
| 119 | const repoId = Number(detail[1]); |
| 120 | const prNumber = Number(detail[2]); |
| 121 | return { |
| 122 | ...route, |
| 123 | execute: async () => { |
| 124 | const view = await route.execute(); |
| 125 | const pr = await github.getPullRequest(repoId, prNumber); |
| 126 | if (pr?.state !== 'open' || pr?.merged || pr?.draft || !FULL_SHA.test(String(pr?.headSha || ''))) return view; |
| 127 | const callback = `mergepr:${repoId.toString(36)}:${prNumber.toString(36)}:${String(pr.headSha).toLowerCase()}`; |
| 128 | if (callback.length > 64) return view; |
| 129 | return appendBeforeBack(view, [{ text: '🔀 Merge امن (Squash)', callback_data: callback }]); |
| 130 | } |
| 131 | }; |
| 132 | } |
| 133 | |
| 134 | if (runDetail) { |
| 135 | const repoId = Number(runDetail[1]); |
| 136 | const runId = Number(runDetail[2]); |
| 137 | return { |
| 138 | ...route, |
| 139 | execute: async () => { |
| 140 | const view = await route.execute(); |
| 141 | const run = await github.getWorkflowRun(repoId, runId); |
| 142 | const callback = `dispatchwf:${repoId}:${runId}`; |
| 143 | if (!Number.isSafeInteger(Number(run.workflowId)) || !run.branch || callback.length > 64) return view; |
| 144 | return appendBeforeBack(view, [{ text: '▶️ اجرای دوباره Workflow', callback_data: callback }]); |
| 145 | } |
| 146 | }; |
| 147 | } |
| 148 | |
| 149 | if (jobDetail) { |
| 150 | const repoId = Number(jobDetail[1]); |
| 151 | const jobId = Number(jobDetail[2]); |
| 152 | return { |
| 153 | ...route, |
| 154 | execute: async () => { |
| 155 | const view = await route.execute(); |
| 156 | const job = await github.getWorkflowJob(repoId, jobId); |
| 157 | const callback = `rerunjob:${repoId}:${jobId}`; |
| 158 | if (!['failure', 'cancelled'].includes(String(job.conclusion || '')) || callback.length > 64) return view; |
| 159 | return appendBeforeBack(view, [{ text: '🔁 اجرای مجدد Job', callback_data: callback }]); |
| 160 | } |
| 161 | }; |
| 162 | } |
| 163 | |
| 164 | return route; |
| 165 | } |
| 166 | }; |
| 167 | } |