Personal Telegram developer console for GitHub

fix: close Advanced read pagination gaps

davoodmehraban89 committed Oct 3, 2026 at 09:29 UTC 602c4d58c967cdb4ed5e6685b72e97e178d61f0d
1 file changed +26 -10
src/plugins/github/plugin.js
+26 -10
@@ -36,6 +36,16 @@ const numericTriple = (value, prefix) => {
36 };
37 };
38
39 +const pagedPair = (value, prefix) => {
40 + const match = String(value || '').match(new RegExp(`^${prefix}:(\\d+):(\\d+)(?::(\\d+))?$`));
41 + if (!match) return null;
42 + return {
43 + repoId: Number(match[1]),
44 + itemId: Number(match[2]),
45 + page: Math.max(1, Math.min(100, Number(match[3]) || 1))
46 + };
47 +};
48 +
49 const numericSingle = (value, prefix) => {
50 const match = String(value || '').match(new RegExp(`^${prefix}:(\\d+)$`));
51 return match ? Number(match[1]) : null;
@@ -217,17 +227,23 @@ async function workflowJobLogView(github, repoId, jobId) {
227 };
228 }
229
220 -async function workflowArtifactsView(github, repoId, runId) {
230 +async function workflowArtifactsView(github, repoId, runId, page = 1) {
231 const [repo, artifacts] = await Promise.all([
232 github.getRepository(repoId),
223 - github.listWorkflowArtifacts(repoId, runId, { perPage: 20, page: 1 })
233 + github.listWorkflowArtifacts(repoId, runId, { perPage: 10, page })
234 ]);
235 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')
236 + ? artifacts.slice(0, 10).map(item => `📦 <b>${escapeHtml(item.name)}</b>\n ${item.expired ? 'منقضی شده' : 'فعال'} · ${Number(item.size || 0).toLocaleString()} bytes\n expires: ${escapeHtml(item.expiresAt || '-')}`).join('\n\n')
237 : '<i>Artifactی برای این Run یافت نشد.</i>';
238 + const refreshCallback = page === 1 ? `artifacts:${repoId}:${runId}` : `artifacts:${repoId}:${runId}:${page}`;
239 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}` }]] }
240 + text: `📦 <b>Artifacts — ${escapeHtml(repo.name)}</b>\nصفحه: <b>${page}</b>\n➖➖➖➖➖➖➖➖➖➖\n${body}`,
241 + reply_markup: {
242 + inline_keyboard: [
243 + ...pairPagination('artifacts', repoId, runId, page, artifacts.length, 10),
244 + [{ text: '🔄 بروزرسانی', callback_data: refreshCallback }, { text: '🔙 Run', callback_data: `run:${repoId}:${runId}` }]
245 + ]
246 + }
247 };
248 }
249
@@ -295,7 +311,7 @@ async function pullRequestDetailView(github, repoId, prNumber) {
311 }
312
313 async function pullRequestFilesView(github, repoId, prNumber, page = 1) {
298 - const files = await github.listPullRequestFiles(repoId, prNumber, { perPage: 20, page });
314 + const files = await github.listPullRequestFiles(repoId, prNumber, { perPage: 8, page });
315 const body = files.length ? files.slice(0, 8).map(file => {
316 const patch = escapeHtml(short(file.patch || '', 220));
317 return `🧩 <code>${escapeHtml(short(file.filename, 100))}</code> · ${escapeHtml(file.status)} · +${file.additions}/-${file.deletions}${patch ? `\n<pre>${patch}</pre>` : ''}`;
@@ -304,7 +320,7 @@ async function pullRequestFilesView(github, repoId, prNumber, page = 1) {
320 text: `🧩 <b>PR #${prNumber} Files / Diff</b>\nصفحه: <b>${page}</b>\n➖➖➖➖➖➖➖➖➖➖\n${body}`,
321 reply_markup: {
322 inline_keyboard: [
307 - ...pairPagination('prfiles', repoId, prNumber, page, files.length, 20),
323 + ...pairPagination('prfiles', repoId, prNumber, page, files.length, 8),
324 [{ text: '🔙 PR', callback_data: `prdetail:${repoId}:${prNumber}` }]
325 ]
326 }
@@ -380,8 +396,8 @@ function resolveReadCallback(data) {
396 const joblog = numericPair(value, 'joblog');
397 if (joblog) return { actionId: 'github.workflow.job.log', kind: 'joblog', repoId: joblog.repoId, jobId: joblog.runId };
398
383 - const artifacts = numericPair(value, 'artifacts');
384 - if (artifacts) return { actionId: 'github.workflow.artifacts.list', kind: 'artifacts', ...artifacts };
399 + const artifacts = pagedPair(value, 'artifacts');
400 + if (artifacts) return { actionId: 'github.workflow.artifacts.list', kind: 'artifacts', repoId: artifacts.repoId, runId: artifacts.itemId, page: artifacts.page };
401
402 const branches = pagedSingle(value, 'branches');
403 if (branches) return { actionId: 'github.branches.list', kind: 'branches', ...branches };
@@ -467,7 +483,7 @@ export function createGitHubPlugin({ github, menu } = {}) {
483 if (read.kind === 'jobs') return workflowJobsView(github, read.repoId, read.runId);
484 if (read.kind === 'job') return workflowJobView(github, read.repoId, read.jobId);
485 if (read.kind === 'joblog') return workflowJobLogView(github, read.repoId, read.jobId);
470 - if (read.kind === 'artifacts') return workflowArtifactsView(github, read.repoId, read.runId);
486 + if (read.kind === 'artifacts') return workflowArtifactsView(github, read.repoId, read.runId, read.page);
487 if (read.kind === 'branches') return branchesView(github, read.repoId, read.page);
488 if (read.kind === 'compare') return compareView(github, read.repoId, read.sha);
489 if (read.kind === 'prs') return pullRequestsView(github, read.repoId, read.page);