Personal Telegram developer console for GitHub
feat/studio-g0-foundation
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) => |
| 5 | /^[0-9a-z]+$/i.test(String(value || '')) ? Number.parseInt(value, 36) : NaN; |
| 6 | const mergeRef = (value) => { |
| 7 | const m = String(value || '').match( |
| 8 | /^mergepr:([0-9a-z]+):([0-9a-z]+):([a-f0-9]{40})$/i |
| 9 | ); |
| 10 | if (!m) return null; |
| 11 | const repoId = from36(m[1]); |
| 12 | const prNumber = from36(m[2]); |
| 13 | return Number.isSafeInteger(repoId) && |
| 14 | Number.isSafeInteger(prNumber) && |
| 15 | prNumber > 0 |
| 16 | ? { repoId, prNumber, headSha: m[3].toLowerCase() } |
| 17 | : null; |
| 18 | }; |
| 19 | |
| 20 | const cp3Pair = (value, prefix) => { |
| 21 | const m = String(value || '').match( |
| 22 | new RegExp('^' + prefix + ':(\\d+):(\\d+)$') |
| 23 | ); |
| 24 | return m ? { repoId: Number(m[1]), runId: Number(m[2]) } : null; |
| 25 | }; |
| 26 | |
| 27 | const appendBeforeBack = (view, row) => { |
| 28 | const rows = [...(view?.reply_markup?.inline_keyboard || [])]; |
| 29 | rows.splice(Math.max(0, rows.length - 1), 0, row); |
| 30 | return { |
| 31 | ...view, |
| 32 | reply_markup: { ...(view.reply_markup || {}), inline_keyboard: rows } |
| 33 | }; |
| 34 | }; |
| 35 | |
| 36 | export function createGitHubPlugin(options = {}) { |
| 37 | const { github } = options; |
| 38 | const base = createLegacyGitHubPlugin(options); |
| 39 | |
| 40 | return { |
| 41 | ...base, |
| 42 | resolveCallback(data, context = {}) { |
| 43 | const dispatch = cp3Pair(data, 'dispatchwf'); |
| 44 | if (dispatch) { |
| 45 | return { |
| 46 | actionId: 'github.workflow.dispatch', |
| 47 | approval: { |
| 48 | input: { repoId: dispatch.repoId, runId: dispatch.runId }, |
| 49 | label: 'اجرای Workflow', |
| 50 | cancelCallback: `run:${dispatch.repoId}:${dispatch.runId}` |
| 51 | }, |
| 52 | execute: async () => { |
| 53 | const run = await github.getWorkflowRun( |
| 54 | dispatch.repoId, |
| 55 | dispatch.runId |
| 56 | ); |
| 57 | if (!Number.isSafeInteger(Number(run.workflowId)) || !run.branch) { |
| 58 | throw new Error('Workflow dispatch target is unavailable'); |
| 59 | } |
| 60 | await github.dispatchWorkflow(dispatch.repoId, run.workflowId, { |
| 61 | ref: run.branch, |
| 62 | inputs: {} |
| 63 | }); |
| 64 | return { |
| 65 | text: '✅ درخواست اجرای Workflow برای GitHub ارسال شد.', |
| 66 | reply_markup: { |
| 67 | inline_keyboard: [ |
| 68 | [ |
| 69 | { |
| 70 | text: '🧪 مشاهده Run', |
| 71 | callback_data: `run:${dispatch.repoId}:${dispatch.runId}` |
| 72 | } |
| 73 | ] |
| 74 | ] |
| 75 | } |
| 76 | }; |
| 77 | } |
| 78 | }; |
| 79 | } |
| 80 | |
| 81 | const rerunJob = cp3Pair(data, 'rerunjob'); |
| 82 | if (rerunJob) { |
| 83 | return { |
| 84 | actionId: 'github.workflow.job.rerun', |
| 85 | approval: { |
| 86 | input: { |
| 87 | repoId: rerunJob.repoId, |
| 88 | runId: rerunJob.runId, |
| 89 | jobId: rerunJob.runId |
| 90 | }, |
| 91 | label: 'اجرای مجدد Job', |
| 92 | cancelCallback: `job:${rerunJob.repoId}:${rerunJob.runId}` |
| 93 | }, |
| 94 | execute: async () => { |
| 95 | const job = await github.getWorkflowJob( |
| 96 | rerunJob.repoId, |
| 97 | rerunJob.runId |
| 98 | ); |
| 99 | if ( |
| 100 | !['failure', 'cancelled'].includes(String(job.conclusion || '')) |
| 101 | ) { |
| 102 | throw new Error('Workflow job is not eligible for rerun'); |
| 103 | } |
| 104 | await github.rerunJob(rerunJob.repoId, rerunJob.runId); |
| 105 | return { |
| 106 | text: '✅ درخواست اجرای مجدد Job برای GitHub ارسال شد.', |
| 107 | reply_markup: { |
| 108 | inline_keyboard: [ |
| 109 | [ |
| 110 | { |
| 111 | text: '👷 مشاهده Job', |
| 112 | callback_data: `job:${rerunJob.repoId}:${rerunJob.runId}` |
| 113 | } |
| 114 | ] |
| 115 | ] |
| 116 | } |
| 117 | }; |
| 118 | } |
| 119 | }; |
| 120 | } |
| 121 | |
| 122 | const merge = mergeRef(data); |
| 123 | if (merge) { |
| 124 | return { |
| 125 | actionId: 'github.pull_request.merge', |
| 126 | approval: { |
| 127 | input: merge, |
| 128 | label: `Merge PR #${merge.prNumber}`, |
| 129 | cancelCallback: `prdetail:${merge.repoId}:${merge.prNumber}` |
| 130 | }, |
| 131 | execute: async () => { |
| 132 | const current = await github.getPullRequest( |
| 133 | merge.repoId, |
| 134 | merge.prNumber |
| 135 | ); |
| 136 | if (current.merged || current.state !== 'open' || current.draft) |
| 137 | throw new Error('Pull request is not mergeable'); |
| 138 | if ( |
| 139 | !FULL_SHA.test(String(current.headSha || '')) || |
| 140 | String(current.headSha).toLowerCase() !== merge.headSha |
| 141 | ) { |
| 142 | throw new Error( |
| 143 | 'Pull request head changed; fresh approval is required' |
| 144 | ); |
| 145 | } |
| 146 | const result = await github.mergePullRequest( |
| 147 | merge.repoId, |
| 148 | merge.prNumber, |
| 149 | { |
| 150 | expectedHeadSha: merge.headSha, |
| 151 | mergeMethod: 'squash' |
| 152 | } |
| 153 | ); |
| 154 | if (!result?.merged) |
| 155 | throw new Error( |
| 156 | result?.message || 'GitHub did not merge the pull request' |
| 157 | ); |
| 158 | return { |
| 159 | text: `✅ <b>PR #${merge.prNumber} با موفقیت Merge شد.</b>`, |
| 160 | reply_markup: { |
| 161 | inline_keyboard: [ |
| 162 | [{ text: '🔙 PRها', callback_data: `prs:${merge.repoId}` }] |
| 163 | ] |
| 164 | } |
| 165 | }; |
| 166 | } |
| 167 | }; |
| 168 | } |
| 169 | |
| 170 | const route = base.resolveCallback(data, context); |
| 171 | if (!route || typeof route.execute !== 'function') return route; |
| 172 | |
| 173 | const detail = String(data || '').match(/^prdetail:(\d+):(\d+)$/); |
| 174 | const runDetail = String(data || '').match(/^run:(\d+):(\d+)$/); |
| 175 | const jobDetail = String(data || '').match(/^job:(\d+):(\d+)$/); |
| 176 | |
| 177 | if (detail) { |
| 178 | const repoId = Number(detail[1]); |
| 179 | const prNumber = Number(detail[2]); |
| 180 | return { |
| 181 | ...route, |
| 182 | execute: async () => { |
| 183 | const view = await route.execute(); |
| 184 | const pr = await github.getPullRequest(repoId, prNumber); |
| 185 | if ( |
| 186 | pr?.state !== 'open' || |
| 187 | pr?.merged || |
| 188 | pr?.draft || |
| 189 | !FULL_SHA.test(String(pr?.headSha || '')) |
| 190 | ) |
| 191 | return view; |
| 192 | const callback = `mergepr:${repoId.toString(36)}:${prNumber.toString(36)}:${String(pr.headSha).toLowerCase()}`; |
| 193 | if (callback.length > 64) return view; |
| 194 | return appendBeforeBack(view, [ |
| 195 | { text: '🔀 Merge امن (Squash)', callback_data: callback } |
| 196 | ]); |
| 197 | } |
| 198 | }; |
| 199 | } |
| 200 | |
| 201 | if (runDetail) { |
| 202 | const repoId = Number(runDetail[1]); |
| 203 | const runId = Number(runDetail[2]); |
| 204 | return { |
| 205 | ...route, |
| 206 | execute: async () => { |
| 207 | const view = await route.execute(); |
| 208 | const run = await github.getWorkflowRun(repoId, runId); |
| 209 | const callback = `dispatchwf:${repoId}:${runId}`; |
| 210 | if ( |
| 211 | !Number.isSafeInteger(Number(run.workflowId)) || |
| 212 | !run.branch || |
| 213 | callback.length > 64 |
| 214 | ) |
| 215 | return view; |
| 216 | return appendBeforeBack(view, [ |
| 217 | { text: '▶️ اجرای دوباره Workflow', callback_data: callback } |
| 218 | ]); |
| 219 | } |
| 220 | }; |
| 221 | } |
| 222 | |
| 223 | if (jobDetail) { |
| 224 | const repoId = Number(jobDetail[1]); |
| 225 | const jobId = Number(jobDetail[2]); |
| 226 | return { |
| 227 | ...route, |
| 228 | execute: async () => { |
| 229 | const view = await route.execute(); |
| 230 | const job = await github.getWorkflowJob(repoId, jobId); |
| 231 | const callback = `rerunjob:${repoId}:${jobId}`; |
| 232 | if ( |
| 233 | !['failure', 'cancelled'].includes( |
| 234 | String(job.conclusion || '') |
| 235 | ) || |
| 236 | callback.length > 64 |
| 237 | ) |
| 238 | return view; |
| 239 | return appendBeforeBack(view, [ |
| 240 | { text: '🔁 اجرای مجدد Job', callback_data: callback } |
| 241 | ]); |
| 242 | } |
| 243 | }; |
| 244 | } |
| 245 | |
| 246 | return route; |
| 247 | } |
| 248 | }; |
| 249 | } |