Personal Telegram developer console for GitHub

feat: add GitHub Advanced read navigation

davoodmehraban89 committed Oct 3, 2026 at 09:20 UTC 2b674948a9eeea47d1417acdeb8d0c39268ddecf
1 file changed +289 -62
src/plugins/github/plugin.js
+289 -62
@@ -15,24 +15,49 @@ const escapeHtml = value => String(value ?? '')
15 .replaceAll('>', '>')
16 .replaceAll('"', '"');
17
18 +const short = (value, max = 80) => {
19 + const text = String(value ?? '');
20 + return text.length > max ? `${text.slice(0, max - 1)}…` : text;
21 +};
22 +
23 const numericPair = (value, prefix) => {
24 const match = String(value || '').match(new RegExp(`^${prefix}:(\\d+):(\\d+)$`));
25 if (!match) return null;
26 return { repoId: Number(match[1]), runId: Number(match[2]) };
27 };
28
29 +const numericTriple = (value, prefix) => {
30 + const match = String(value || '').match(new RegExp(`^${prefix}:(\\d+):(\\d+):(\\d+)$`));
31 + if (!match) return null;
32 + return {
33 + repoId: Number(match[1]),
34 + itemId: Number(match[2]),
35 + page: Math.max(1, Math.min(100, Number(match[3]) || 1))
36 + };
37 +};
38 +
39 const numericSingle = (value, prefix) => {
40 const match = String(value || '').match(new RegExp(`^${prefix}:(\\d+)$`));
41 return match ? Number(match[1]) : null;
42 };
43
29 -const workflowRunsPage = value => {
30 - const match = String(value || '').match(/^runs:(\d+)(?::(\d+))?$/);
44 +const pagedSingle = (value, prefix) => {
45 + const match = String(value || '').match(new RegExp(`^${prefix}:(\\d+)(?::(\\d+))?$`));
46 if (!match) return null;
32 - const page = Math.max(1, Math.min(100, Number(match[2]) || 1));
33 - return { repoId: Number(match[1]), page };
47 + return {
48 + repoId: Number(match[1]),
49 + page: Math.max(1, Math.min(100, Number(match[2]) || 1))
50 + };
51 +};
52 +
53 +const compareRef = value => {
54 + const match = String(value || '').match(/^compare:(\d+):([a-f0-9]{40})$/i);
55 + if (!match) return null;
56 + return { repoId: Number(match[1]), sha: match[2] };
57 };
58
59 +const workflowRunsPage = value => pagedSingle(value, 'runs');
60 +
61 const runIcon = run => {
62 if (run.conclusion === 'success') return '✅';
63 if (run.conclusion === 'failure') return '❌';
@@ -40,20 +65,49 @@ const runIcon = run => {
65 return run.status === 'in_progress' ? '🟡' : '⏳';
66 };
67
43 -const addCiButton = (view, repoId) => {
68 +const stateIcon = value => {
69 + if (value === 'success' || value === 'completed') return '✅';
70 + if (value === 'failure') return '❌';
71 + if (value === 'cancelled') return '⏹';
72 + if (value === 'open') return '🟢';
73 + if (value === 'closed') return '⚫';
74 + return '•';
75 +};
76 +
77 +const addRepoAdvancedButtons = (view, repoId) => {
78 const rows = [...(view?.reply_markup?.inline_keyboard || [])];
45 - const ciRow = [{ text: '🧪 CI / Actions', callback_data: `runs:${repoId}` }];
79 const insertAt = Math.max(0, rows.length - 1);
47 - rows.splice(insertAt, 0, ciRow);
80 + rows.splice(insertAt, 0,
81 + [{ text: '🧪 CI / Actions', callback_data: `runs:${repoId}` }],
82 + [
83 + { text: '🌿 Branches', callback_data: `branches:${repoId}` },
84 + { text: '🔎 PRها', callback_data: `prs:${repoId}` }
85 + ],
86 + [
87 + { text: '🐛 Issues', callback_data: `issues:${repoId}` },
88 + { text: '🏷 Releases', callback_data: `releases:${repoId}` }
89 + ]
90 + );
91 return {
92 ...view,
50 - reply_markup: {
51 - ...(view?.reply_markup || {}),
52 - inline_keyboard: rows
53 - }
93 + reply_markup: { ...(view?.reply_markup || {}), inline_keyboard: rows }
94 };
95 };
96
97 +function listPagination(prefix, repoId, page, count, pageSize) {
98 + const row = [];
99 + if (page > 1) row.push({ text: '⬅️ جدیدتر', callback_data: `${prefix}:${repoId}:${page - 1}` });
100 + if (count === pageSize && page < 100) row.push({ text: 'قدیمی‌تر ➡️', callback_data: `${prefix}:${repoId}:${page + 1}` });
101 + return row.length ? [row] : [];
102 +}
103 +
104 +function pairPagination(prefix, repoId, itemId, page, count, pageSize) {
105 + const row = [];
106 + if (page > 1) row.push({ text: '⬅️ جدیدتر', callback_data: `${prefix}:${repoId}:${itemId}:${page - 1}` });
107 + if (count === pageSize && page < 100) row.push({ text: 'قدیمی‌تر ➡️', callback_data: `${prefix}:${repoId}:${itemId}:${page + 1}` });
108 + return row.length ? [row] : [];
109 +}
110 +
111 async function workflowRunsView(github, repoId, page = 1) {
112 const [repo, runs] = await Promise.all([
113 github.getRepository(repoId),
@@ -62,25 +116,16 @@ async function workflowRunsView(github, repoId, page = 1) {
116 const body = runs.length
117 ? runs.slice(0, 10).map(run => `${runIcon(run)} <b>${escapeHtml(run.name)}</b> #${run.runNumber ?? '-'}\n └ ${escapeHtml(run.branch || '-')} · <code>${escapeHtml(run.sha || '-')}</code> · ${escapeHtml(run.conclusion || run.status || 'unknown')}`).join('\n\n')
118 : '<i>Workflow runی یافت نشد.</i>';
65 -
66 - const pagination = [];
67 - if (page > 1) {
68 - pagination.push({ text: '⬅️ جدیدتر', callback_data: `runs:${repoId}:${page - 1}` });
69 - }
70 - if (runs.length === 10 && page < 100) {
71 - pagination.push({ text: 'قدیمی‌تر ➡️', callback_data: `runs:${repoId}:${page + 1}` });
72 - }
119 const refreshCallback = page === 1 ? `runs:${repoId}` : `runs:${repoId}:${page}`;
74 -
120 return {
121 text: `🧪 <b>CI / Actions — ${escapeHtml(repo.name)}</b>\nصفحه: <b>${page}</b>\n➖➖➖➖➖➖➖➖➖➖\n${body}`,
122 reply_markup: {
123 inline_keyboard: [
124 ...runs.slice(0, 10).map(run => [{
80 - text: `${runIcon(run)} ${run.name} #${run.runNumber ?? run.id}`,
125 + text: `${runIcon(run)} ${short(run.name, 32)} #${run.runNumber ?? run.id}`,
126 callback_data: `run:${repoId}:${run.id}`
127 }]),
83 - ...(pagination.length ? [pagination] : []),
128 + ...listPagination('runs', repoId, page, runs.length, 10),
129 [
130 { text: '🔄 بروزرسانی', callback_data: refreshCallback },
131 { text: '🔙 پروژه', callback_data: `repo:${repoId}` }
@@ -96,7 +141,10 @@ async function workflowRunView(github, repoId, runId) {
141 github.getWorkflowRun(repoId, runId)
142 ]);
143 const rows = [
99 - [{ text: '👷 Jobها', callback_data: `jobs:${repoId}:${runId}` }]
144 + [
145 + { text: '👷 Jobها', callback_data: `jobs:${repoId}:${runId}` },
146 + { text: '📦 Artifacts', callback_data: `artifacts:${repoId}:${runId}` }
147 + ]
148 ];
149 if (run.conclusion === 'failure') {
150 rows.push([{ text: '🔁 اجرای مجدد jobهای ناموفق', callback_data: `rerun:${repoId}:${runId}` }]);
@@ -108,7 +156,6 @@ async function workflowRunView(github, repoId, runId) {
156 { text: '🔄 بروزرسانی', callback_data: `run:${repoId}:${runId}` },
157 { text: '🔙 CI / Actions', callback_data: `runs:${repoId}` }
158 ]);
111 -
159 return {
160 text: `🧪 <b>${escapeHtml(run.name)} — ${escapeHtml(repo.name)}</b>\n➖➖➖➖➖➖➖➖➖➖\nوضعیت: ${runIcon(run)} <b>${escapeHtml(run.conclusion || run.status || 'unknown')}</b>\nRun: <code>#${escapeHtml(run.runNumber ?? run.id)}</code>\nBranch: <code>${escapeHtml(run.branch || '-')}</code>\nSHA: <code>${escapeHtml(run.sha || '-')}</code>\nTrigger: <code>${escapeHtml(run.event || '-')}</code>`,
161 reply_markup: { inline_keyboard: rows }
@@ -125,38 +172,192 @@ async function workflowJobsView(github, repoId, runId) {
172 ? jobs.slice(0, 20).map(job => {
173 const jobState = job.conclusion || job.status || 'unknown';
174 const steps = (job.steps || []).slice(0, 30)
128 - .map(step => ` ${step.conclusion === 'success' ? '✅' : step.conclusion === 'failure' ? '❌' : '•'} ${escapeHtml(step.name)} — ${escapeHtml(step.conclusion || step.status || 'unknown')}`)
175 + .map(step => ` ${stateIcon(step.conclusion || step.status)} ${escapeHtml(step.name)} — ${escapeHtml(step.conclusion || step.status || 'unknown')}`)
176 .join('\n');
177 return `<b>${escapeHtml(job.name)}</b> — ${escapeHtml(jobState)}${steps ? `\n${steps}` : ''}`;
178 }).join('\n\n')
179 : '<i>Jobی در این Run یافت نشد.</i>';
133 -
180 return {
181 text: `👷 <b>Jobهای ${escapeHtml(run.name)} — ${escapeHtml(repo.name)}</b>\n➖➖➖➖➖➖➖➖➖➖\n${body}`,
182 reply_markup: {
137 - inline_keyboard: [[
138 - { text: '🔄 بروزرسانی', callback_data: `jobs:${repoId}:${runId}` },
139 - { text: '🔙 Run', callback_data: `run:${repoId}:${runId}` }
140 - ]]
183 + inline_keyboard: [
184 + ...jobs.slice(0, 20).map(job => [{
185 + text: `${stateIcon(job.conclusion || job.status)} ${short(job.name, 40)}`,
186 + callback_data: `job:${repoId}:${job.id}`
187 + }]),
188 + [{ text: '🔄 بروزرسانی', callback_data: `jobs:${repoId}:${runId}` }, { text: '🔙 Run', callback_data: `run:${repoId}:${runId}` }]
189 + ]
190 }
191 };
192 }
193
145 -function workflowActionResultView(repoId, runId, action) {
146 - const rerun = action === 'rerun_failed';
194 +async function workflowJobView(github, repoId, jobId) {
195 + const [repo, job] = await Promise.all([github.getRepository(repoId), github.getWorkflowJob(repoId, jobId)]);
196 + const status = job.conclusion || job.status || 'unknown';
197 + const steps = (job.steps || []).slice(0, 30).map(step => `${stateIcon(step.conclusion || step.status)} ${escapeHtml(step.name)} — ${escapeHtml(step.conclusion || step.status || 'unknown')}`).join('\n');
198 + const rows = [];
199 + if (job.conclusion === 'failure') rows.push([{ text: '📜 مشاهده log ناموفق', callback_data: `joblog:${repoId}:${jobId}` }]);
200 + rows.push([{ text: '🔄 بروزرسانی', callback_data: `job:${repoId}:${jobId}` }, { text: '🔙 CI / Actions', callback_data: `runs:${repoId}` }]);
201 + return {
202 + text: `👷 <b>${escapeHtml(job.name)} — ${escapeHtml(repo.name)}</b>\nوضعیت: ${stateIcon(status)} <b>${escapeHtml(status)}</b>\n➖➖➖➖➖➖➖➖➖➖\n${steps || '<i>Stepی ثبت نشده.</i>'}`,
203 + reply_markup: { inline_keyboard: rows }
204 + };
205 +}
206 +
207 +async function workflowJobLogView(github, repoId, jobId) {
208 + const [job, log] = await Promise.all([
209 + github.getWorkflowJob(repoId, jobId),
210 + github.getWorkflowJobLog(repoId, jobId, { maxChars: 1800 })
211 + ]);
212 + const escaped = escapeHtml(log.text).slice(-3200);
213 + const note = log.truncated ? '⚠️ فقط بخش پایانی log نمایش داده شده است.\n\n' : '';
214 + return {
215 + text: `📜 <b>Log — ${escapeHtml(job.name)}</b>\n${note}<pre>${escaped || '(empty log)'}</pre>`,
216 + reply_markup: { inline_keyboard: [[{ text: '🔙 Job', callback_data: `job:${repoId}:${jobId}` }]] }
217 + };
218 +}
219 +
220 +async function workflowArtifactsView(github, repoId, runId) {
221 + const [repo, artifacts] = await Promise.all([
222 + github.getRepository(repoId),
223 + github.listWorkflowArtifacts(repoId, runId, { perPage: 20, page: 1 })
224 + ]);
225 + const body = artifacts.length
226 + ? artifacts.slice(0, 20).map(item => `📦 <b>${escapeHtml(item.name)}</b>\n ${item.expired ? 'منقضی شده' : 'فعال'} · ${Number(item.size || 0).toLocaleString()} bytes\n expires: ${escapeHtml(item.expiresAt || '-')}`).join('\n\n')
227 + : '<i>Artifactی برای این Run یافت نشد.</i>';
228 + return {
229 + text: `📦 <b>Artifacts — ${escapeHtml(repo.name)}</b>\n➖➖➖➖➖➖➖➖➖➖\n${body}`,
230 + reply_markup: { inline_keyboard: [[{ text: '🔄 بروزرسانی', callback_data: `artifacts:${repoId}:${runId}` }, { text: '🔙 Run', callback_data: `run:${repoId}:${runId}` }]] }
231 + };
232 +}
233 +
234 +async function branchesView(github, repoId, page = 1) {
235 + const [repo, branches] = await Promise.all([
236 + github.getRepository(repoId),
237 + github.listBranches(repoId, { perPage: 20, page })
238 + ]);
239 + const body = branches.length
240 + ? 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')
241 + : '<i>Branchی یافت نشد.</i>';
242 + return {
243 + text: `🌿 <b>Branches — ${escapeHtml(repo.name)}</b>\nصفحه: <b>${page}</b>\n➖➖➖➖➖➖➖➖➖➖\n${body}`,
244 + reply_markup: {
245 + inline_keyboard: [
246 + ...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}` }]),
247 + ...listPagination('branches', repoId, page, branches.length, 20),
248 + [{ text: '🔙 پروژه', callback_data: `repo:${repoId}` }]
249 + ]
250 + }
251 + };
252 +}
253 +
254 +async function compareView(github, repoId, sha) {
255 + const [repo, compare] = await Promise.all([github.getRepository(repoId), github.compareWithDefault(repoId, sha)]);
256 + const files = (compare.files || []).slice(0, 12).map(file => `${stateIcon(file.status)} <code>${escapeHtml(short(file.filename, 90))}</code> · +${file.additions}/-${file.deletions}`).join('\n');
257 + return {
258 + text: `↔️ <b>Compare — ${escapeHtml(repo.name)}</b>\n<code>${escapeHtml(compare.base)}</code> ← <code>${escapeHtml(String(compare.head).slice(0, 10))}</code>\nوضعیت: <b>${escapeHtml(compare.status || '-')}</b>\nAhead: <b>${compare.aheadBy ?? 0}</b> · Behind: <b>${compare.behindBy ?? 0}</b> · Commits: <b>${compare.totalCommits ?? 0}</b>\n➖➖➖➖➖➖➖➖➖➖\n${files || '<i>فایل تغییریافته‌ای نیست.</i>'}`,
259 + reply_markup: { inline_keyboard: [[{ text: '🔙 Branches', callback_data: `branches:${repoId}` }]] }
260 + };
261 +}
262 +
263 +async function pullRequestsView(github, repoId, page = 1) {
264 + const [repo, prs] = await Promise.all([github.getRepository(repoId), github.listPullRequests(repoId, { perPage: 10, page })]);
265 + const body = prs.length
266 + ? prs.slice(0, 10).map(pr => `${pr.merged ? '🟣' : stateIcon(pr.state)} <b>#${pr.number} ${escapeHtml(short(pr.title, 100))}</b>\n ${escapeHtml(pr.author)} · ${escapeHtml(pr.merged ? 'merged' : pr.state)}`).join('\n\n')
267 + : '<i>Pull Requestی یافت نشد.</i>';
268 + return {
269 + text: `🔎 <b>Pull Requests — ${escapeHtml(repo.name)}</b>\nصفحه: <b>${page}</b>\n➖➖➖➖➖➖➖➖➖➖\n${body}`,
270 + reply_markup: {
271 + inline_keyboard: [
272 + ...prs.slice(0, 10).map(pr => [{ text: `#${pr.number} ${short(pr.title, 42)}`, callback_data: `prdetail:${repoId}:${pr.number}` }]),
273 + ...listPagination('prs', repoId, page, prs.length, 10),
274 + [{ text: '🔙 پروژه', callback_data: `repo:${repoId}` }]
275 + ]
276 + }
277 + };
278 +}
279 +
280 +async function pullRequestDetailView(github, repoId, prNumber) {
281 + const [repo, pr] = await Promise.all([github.getRepository(repoId), github.getPullRequest(repoId, prNumber)]);
282 + const body = escapeHtml(short(pr.body || '', 600));
283 + return {
284 + 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>'}`,
285 + reply_markup: {
286 + inline_keyboard: [
287 + [
288 + { text: '🧩 فایل‌ها / Diff', callback_data: `prfiles:${repoId}:${prNumber}:1` },
289 + { text: '✅ Checks', callback_data: `prchecks:${repoId}:${prNumber}:1` }
290 + ],
291 + [{ text: '🔙 PRها', callback_data: `prs:${repoId}` }]
292 + ]
293 + }
294 + };
295 +}
296 +
297 +async function pullRequestFilesView(github, repoId, prNumber, page = 1) {
298 + const files = await github.listPullRequestFiles(repoId, prNumber, { perPage: 20, page });
299 + const body = files.length ? files.slice(0, 8).map(file => {
300 + const patch = escapeHtml(short(file.patch || '', 220));
301 + return `🧩 <code>${escapeHtml(short(file.filename, 100))}</code> · ${escapeHtml(file.status)} · +${file.additions}/-${file.deletions}${patch ? `\n<pre>${patch}</pre>` : ''}`;
302 + }).join('\n\n') : '<i>فایل تغییریافته‌ای یافت نشد.</i>';
303 return {
148 - text: rerun
149 - ? '✅ درخواست اجرای مجدد jobهای ناموفق برای GitHub ارسال شد.'
150 - : '✅ درخواست لغو Workflow برای GitHub ارسال شد.',
304 + text: `🧩 <b>PR #${prNumber} Files / Diff</b>\nصفحه: <b>${page}</b>\n➖➖➖➖➖➖➖➖➖➖\n${body}`,
305 reply_markup: {
152 - inline_keyboard: [[
153 - { text: '🧪 مشاهده Run', callback_data: `run:${repoId}:${runId}` },
154 - { text: '🔙 CI / Actions', callback_data: `runs:${repoId}` }
155 - ]]
306 + inline_keyboard: [
307 + ...pairPagination('prfiles', repoId, prNumber, page, files.length, 20),
308 + [{ text: '🔙 PR', callback_data: `prdetail:${repoId}:${prNumber}` }]
309 + ]
310 + }
311 + };
312 +}
313 +
314 +async function pullRequestChecksView(github, repoId, prNumber, page = 1) {
315 + const pr = await github.getPullRequest(repoId, prNumber);
316 + const checks = await github.listCommitChecks(repoId, pr.headSha, { perPage: 20, page });
317 + const body = checks.length
318 + ? checks.slice(0, 20).map(check => `${stateIcon(check.conclusion || check.status)} <b>${escapeHtml(check.name)}</b> — ${escapeHtml(check.conclusion || check.status || 'unknown')}`).join('\n')
319 + : '<i>Checkی یافت نشد.</i>';
320 + return {
321 + text: `✅ <b>PR #${prNumber} Checks</b>\nصفحه: <b>${page}</b>\n➖➖➖➖➖➖➖➖➖➖\n${body}`,
322 + reply_markup: {
323 + inline_keyboard: [
324 + ...pairPagination('prchecks', repoId, prNumber, page, checks.length, 20),
325 + [{ text: '🔙 PR', callback_data: `prdetail:${repoId}:${prNumber}` }]
326 + ]
327 }
328 };
329 }
330
331 +async function issuesView(github, repoId, page = 1) {
332 + const [repo, issues] = await Promise.all([github.getRepository(repoId), github.listIssues(repoId, { perPage: 10, page })]);
333 + const body = issues.length
334 + ? issues.slice(0, 10).map(issue => `${stateIcon(issue.state)} <b>#${issue.number} ${escapeHtml(short(issue.title, 110))}</b>\n ${escapeHtml(issue.author)} · ${issue.comments} comments`).join('\n\n')
335 + : '<i>Issueی یافت نشد.</i>';
336 + return {
337 + text: `🐛 <b>Issues — ${escapeHtml(repo.name)}</b>\nصفحه: <b>${page}</b>\n➖➖➖➖➖➖➖➖➖➖\n${body}`,
338 + reply_markup: { inline_keyboard: [...listPagination('issues', repoId, page, issues.length, 10), [{ text: '🔙 پروژه', callback_data: `repo:${repoId}` }]] }
339 + };
340 +}
341 +
342 +async function releasesView(github, repoId, page = 1) {
343 + const [repo, releases] = await Promise.all([github.getRepository(repoId), github.listReleases(repoId, { perPage: 10, page })]);
344 + const body = releases.length
345 + ? releases.slice(0, 10).map(release => `🏷 <b>${escapeHtml(release.tag || release.name)}</b>${release.prerelease ? ' · pre-release' : ''}${release.draft ? ' · draft' : ''}\n ${escapeHtml(short(release.name, 110))}\n ${escapeHtml(release.publishedAt || '-')}`).join('\n\n')
346 + : '<i>Releaseی یافت نشد.</i>';
347 + return {
348 + text: `🏷 <b>Releases — ${escapeHtml(repo.name)}</b>\nصفحه: <b>${page}</b>\n➖➖➖➖➖➖➖➖➖➖\n${body}`,
349 + reply_markup: { inline_keyboard: [...listPagination('releases', repoId, page, releases.length, 10), [{ text: '🔙 پروژه', callback_data: `repo:${repoId}` }]] }
350 + };
351 +}
352 +
353 +function workflowActionResultView(repoId, runId, action) {
354 + const rerun = action === 'rerun_failed';
355 + return {
356 + text: rerun ? '✅ درخواست اجرای مجدد jobهای ناموفق برای GitHub ارسال شد.' : '✅ درخواست لغو Workflow برای GitHub ارسال شد.',
357 + reply_markup: { inline_keyboard: [[{ text: '🧪 مشاهده Run', callback_data: `run:${repoId}:${runId}` }, { text: '🔙 CI / Actions', callback_data: `runs:${repoId}` }]] }
358 + };
359 +}
360 +
361 function resolveReadCallback(data) {
362 const value = String(data || '');
363 if (value === 'menu:repos') return { actionId: 'github.repos.list', kind: 'legacy' };
@@ -173,6 +374,39 @@ function resolveReadCallback(data) {
374 const jobs = numericPair(value, 'jobs');
375 if (jobs) return { actionId: 'github.workflow.jobs.list', kind: 'jobs', ...jobs };
376
377 + const job = numericPair(value, 'job');
378 + if (job) return { actionId: 'github.workflow.job.detail', kind: 'job', repoId: job.repoId, jobId: job.runId };
379 +
380 + const joblog = numericPair(value, 'joblog');
381 + if (joblog) return { actionId: 'github.workflow.job.log', kind: 'joblog', repoId: joblog.repoId, jobId: joblog.runId };
382 +
383 + const artifacts = numericPair(value, 'artifacts');
384 + if (artifacts) return { actionId: 'github.workflow.artifacts.list', kind: 'artifacts', ...artifacts };
385 +
386 + const branches = pagedSingle(value, 'branches');
387 + if (branches) return { actionId: 'github.branches.list', kind: 'branches', ...branches };
388 +
389 + const compare = compareRef(value);
390 + if (compare) return { actionId: 'github.compare.read', kind: 'compare', ...compare };
391 +
392 + const prs = pagedSingle(value, 'prs');
393 + if (prs) return { actionId: 'github.pr.advanced.list', kind: 'prs', ...prs };
394 +
395 + const prdetail = numericPair(value, 'prdetail');
396 + if (prdetail) return { actionId: 'github.pr.detail', kind: 'prdetail', repoId: prdetail.repoId, prNumber: prdetail.runId };
397 +
398 + const prfiles = numericTriple(value, 'prfiles');
399 + if (prfiles) return { actionId: 'github.pr.files.list', kind: 'prfiles', repoId: prfiles.repoId, prNumber: prfiles.itemId, page: prfiles.page };
400 +
401 + const prchecks = numericTriple(value, 'prchecks');
402 + if (prchecks) return { actionId: 'github.pr.checks.list', kind: 'prchecks', repoId: prchecks.repoId, prNumber: prchecks.itemId, page: prchecks.page };
403 +
404 + const issues = pagedSingle(value, 'issues');
405 + if (issues) return { actionId: 'github.issues.list', kind: 'issues', ...issues };
406 +
407 + const releases = pagedSingle(value, 'releases');
408 + if (releases) return { actionId: 'github.releases.list', kind: 'releases', ...releases };
409 +
410 for (const [prefix, actionId] of CALLBACK_ACTIONS) {
411 if (value.startsWith(prefix)) return { actionId, kind: 'legacy' };
412 }
@@ -184,25 +418,18 @@ function resolveWriteCallback(data) {
418 if (rerun) {
419 return {
420 actionId: 'github.workflow.run.rerun_failed',
187 - approval: {
188 - input: rerun,
189 - label: 'اجرای مجدد jobهای ناموفق'
190 - },
421 + approval: { input: rerun, label: 'اجرای مجدد jobهای ناموفق' },
422 execute: async github => {
423 await github.rerunFailedWorkflowRun(rerun.repoId, rerun.runId);
424 return workflowActionResultView(rerun.repoId, rerun.runId, 'rerun_failed');
425 }
426 };
427 }
197 -
428 const cancel = numericPair(data, 'cancelrun');
429 if (cancel) {
430 return {
431 actionId: 'github.workflow.run.cancel',
202 - approval: {
203 - input: cancel,
204 - label: 'لغو Workflow در حال اجرا'
205 - },
432 + approval: { input: cancel, label: 'لغو Workflow در حال اجرا' },
433 execute: async github => {
434 await github.cancelWorkflowRun(cancel.repoId, cancel.runId);
435 return workflowActionResultView(cancel.repoId, cancel.runId, 'cancel');
@@ -221,21 +448,12 @@ export function createGitHubPlugin({ github, menu } = {}) {
448
449 resolveCommand(command) {
450 if (command !== '/repos') return null;
224 - return {
225 - actionId: 'github.repos.list',
226 - execute: () => menu.getReposListView()
227 - };
451 + return { actionId: 'github.repos.list', execute: () => menu.getReposListView() };
452 },
453
454 resolveCallback(data) {
455 const write = resolveWriteCallback(data);
232 - if (write) {
233 - return {
234 - actionId: write.actionId,
235 - approval: write.approval,
236 - execute: () => write.execute(github)
237 - };
238 - }
456 + if (write) return { actionId: write.actionId, approval: write.approval, execute: () => write.execute(github) };
457
458 const read = resolveReadCallback(data);
459 if (!read) return null;
@@ -243,12 +461,21 @@ export function createGitHubPlugin({ github, menu } = {}) {
461 return {
462 actionId: read.actionId,
463 execute: async () => {
246 - if (read.kind === 'repo') {
247 - return addCiButton(await menu.renderByCallback(data), read.repoId);
248 - }
464 + if (read.kind === 'repo') return addRepoAdvancedButtons(await menu.renderByCallback(data), read.repoId);
465 if (read.kind === 'runs') return workflowRunsView(github, read.repoId, read.page);
466 if (read.kind === 'run') return workflowRunView(github, read.repoId, read.runId);
467 if (read.kind === 'jobs') return workflowJobsView(github, read.repoId, read.runId);
468 + if (read.kind === 'job') return workflowJobView(github, read.repoId, read.jobId);
469 + if (read.kind === 'joblog') return workflowJobLogView(github, read.repoId, read.jobId);
470 + if (read.kind === 'artifacts') return workflowArtifactsView(github, read.repoId, read.runId);
471 + if (read.kind === 'branches') return branchesView(github, read.repoId, read.page);
472 + if (read.kind === 'compare') return compareView(github, read.repoId, read.sha);
473 + if (read.kind === 'prs') return pullRequestsView(github, read.repoId, read.page);
474 + if (read.kind === 'prdetail') return pullRequestDetailView(github, read.repoId, read.prNumber);
475 + if (read.kind === 'prfiles') return pullRequestFilesView(github, read.repoId, read.prNumber, read.page);
476 + if (read.kind === 'prchecks') return pullRequestChecksView(github, read.repoId, read.prNumber, read.page);
477 + if (read.kind === 'issues') return issuesView(github, read.repoId, read.page);
478 + if (read.kind === 'releases') return releasesView(github, read.repoId, read.page);
479 return menu.renderByCallback(data);
480 }
481 };