Personal Telegram developer console for GitHub
feat: add Telegram CI Actions pagination
davoodmehraban89 committed
Oct 3, 2026 at 08:16 UTC
279d46658a3bc9dba454b27471bd5f6f5396c39d
1 file changed
+25
-8
src/plugins/github/plugin.js
+25
-8
@@ -26,6 +26,13 @@ const numericSingle = (value, prefix) => {
26
return match ? Number(match[1]) : null;
27
};
28
29
+const workflowRunsPage = value => {
30
+ const match = String(value || '').match(/^runs:(\d+)(?::(\d+))?$/);
31
+ if (!match) return null;
32
+ const page = Math.max(1, Math.min(100, Number(match[2]) || 1));
33
+ return { repoId: Number(match[1]), page };
34
+};
35
+
36
const runIcon = run => {
37
if (run.conclusion === 'success') return '✅';
38
if (run.conclusion === 'failure') return '❌';
@@ -41,31 +48,41 @@ const addCiButton = (view, repoId) => {
48
return {
49
...view,
50
reply_markup: {
44
- ...(view?.reply_markup || {}),
51
+ ...(view.reply_markup || {}),
52
inline_keyboard: rows
53
}
54
};
55
};
56
50
-async function workflowRunsView(github, repoId) {
57
+async function workflowRunsView(github, repoId, page = 1) {
58
const [repo, runs] = await Promise.all([
59
github.getRepository(repoId),
53
- github.listWorkflowRuns(repoId)
60
+ github.listWorkflowRuns(repoId, { perPage: 10, page })
61
]);
62
const body = runs.length
63
? 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')
64
: '<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
+ }
73
+ const refreshCallback = page === 1 ? `runs:${repoId}` : `runs:${repoId}:${page}`;
74
+
75
return {
60
- text: `🧪 <b>CI / Actions — ${escapeHtml(repo.name)}</b>\n➖➖➖➖➖➖➖➖➖➖\n${body}`,
76
+ text: `🧪 <b>CI / Actions — ${escapeHtml(repo.name)}</b>\nصفحه: <b>${page}</b>\n➖➖➖➖➖➖➖➖➖➖\n${body}`,
77
reply_markup: {
78
inline_keyboard: [
79
...runs.slice(0, 10).map(run => [{
80
text: `${runIcon(run)} ${run.name} #${run.runNumber ?? run.id}`,
81
callback_data: `run:${repoId}:${run.id}`
82
}]),
83
+ ...(pagination.length ? [pagination] : []),
84
[
68
- { text: '🔄 بروزرسانی', callback_data: `runs:${repoId}` },
85
+ { text: '🔄 بروزرسانی', callback_data: refreshCallback },
86
{ text: '🔙 پروژه', callback_data: `repo:${repoId}` }
87
]
88
]
@@ -147,8 +164,8 @@ function resolveReadCallback(data) {
164
const repoId = numericSingle(value, 'repo');
165
if (repoId !== null) return { actionId: 'github.repo.detail', kind: 'repo', repoId };
166
150
- const runsRepoId = numericSingle(value, 'runs');
151
- if (runsRepoId !== null) return { actionId: 'github.workflow.runs.list', kind: 'runs', repoId: runsRepoId };
167
+ const runs = workflowRunsPage(value);
168
+ if (runs) return { actionId: 'github.workflow.runs.list', kind: 'runs', ...runs };
169
170
const run = numericPair(value, 'run');
171
if (run) return { actionId: 'github.workflow.run.detail', kind: 'run', ...run };
@@ -229,7 +246,7 @@ export function createGitHubPlugin({ github, menu } = {}) {
246
if (read.kind === 'repo') {
247
return addCiButton(await menu.renderByCallback(data), read.repoId);
248
}
232
- if (read.kind === 'runs') return workflowRunsView(github, read.repoId);
249
+ if (read.kind === 'runs') return workflowRunsView(github, read.repoId, read.page);
250
if (read.kind === 'run') return workflowRunView(github, read.repoId, read.runId);
251
if (read.kind === 'jobs') return workflowJobsView(github, read.repoId, read.runId);
252
return menu.renderByCallback(data);