Personal Telegram developer console for GitHub
fix: paginate CI Actions runs in Telegram
* test: require CI Actions pagination * feat: page GitHub workflow runs * feat: add Telegram CI Actions pagination * fix: preserve first-page workflow URL contract * fix: keep repository view augmentation null-safe
davoodmehraban89 committed
Oct 3, 2026 at 08:20 UTC
074033f5a067283727a38e034a6d19436fcce475
3 files changed
+106
-9
src/github.js
+4
-2
@@ -271,11 +271,13 @@ export class GitHubService {
271
};
272
}
273
274
- async listWorkflowRuns(repoRef, { perPage = 10 } = {}) {
274
+ async listWorkflowRuns(repoRef, { perPage = 10, page = 1 } = {}) {
275
const count = Math.max(1, Math.min(20, Number(perPage) || 10));
276
+ const pageNumber = Math.max(1, Math.min(100, Number(page) || 1));
277
const { apiBase } = await this.getRepositoryContext(repoRef);
278
+ const pageQuery = pageNumber > 1 ? `&page=${pageNumber}` : '';
279
const data = await this.requestJson(
278
- `${apiBase}/actions/runs?per_page=${count}`,
280
+ `${apiBase}/actions/runs?per_page=${count}${pageQuery}`,
281
'GitHub workflow runs'
282
);
283
return (data.workflow_runs || []).map(run => this.mapWorkflowRun(run));
src/plugins/github/plugin.js
+24
-7
@@ -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 '❌';
@@ -47,25 +54,35 @@ const addCiButton = (view, repoId) => {
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);
test/github-pagination.test.js
new
+78
@@ -0,0 +1,78 @@
1
+import test from 'node:test';
2
+import assert from 'node:assert/strict';
3
+import { GitHubService } from '../src/github.js';
4
+import { createGitHubPlugin } from '../src/plugins/github/plugin.js';
5
+
6
+async function withFetch(mock, fn) {
7
+ const originalFetch = globalThis.fetch;
8
+ globalThis.fetch = mock;
9
+ try {
10
+ return await fn();
11
+ } finally {
12
+ globalThis.fetch = originalFetch;
13
+ }
14
+}
15
+
16
+function json(data, status = 200) {
17
+ return new Response(JSON.stringify(data), {
18
+ status,
19
+ headers: { 'content-type': 'application/json' }
20
+ });
21
+}
22
+
23
+test('GitHubService requests a bounded workflow-runs page', async () => {
24
+ const requested = [];
25
+ await withFetch(async url => {
26
+ const value = String(url);
27
+ requested.push(value);
28
+ if (value === 'https://api.github.com/repositories/123') {
29
+ return json({ id: 123, name: 'nexa-dev-bot', full_name: 'davoodmehraban89/nexa-dev-bot' });
30
+ }
31
+ if (value === 'https://api.github.com/repos/davoodmehraban89/nexa-dev-bot/actions/runs?per_page=10&page=2') {
32
+ return json({ workflow_runs: [] });
33
+ }
34
+ return json({ message: 'Not Found' }, 404);
35
+ }, async () => {
36
+ const service = new GitHubService('token');
37
+ await service.listWorkflowRuns(123, { perPage: 10, page: 2 });
38
+ });
39
+
40
+ assert.equal(requested.at(-1), 'https://api.github.com/repos/davoodmehraban89/nexa-dev-bot/actions/runs?per_page=10&page=2');
41
+});
42
+
43
+test('GitHub plugin navigates older and newer CI pages without write side effects', async () => {
44
+ const calls = [];
45
+ const github = {
46
+ async getRepository(repoId) {
47
+ return { id: String(repoId), name: 'nexa-dev-bot' };
48
+ },
49
+ async listWorkflowRuns(repoId, options) {
50
+ calls.push({ repoId, options });
51
+ return Array.from({ length: 10 }, (_, index) => ({
52
+ id: 200 - index,
53
+ name: 'CI',
54
+ status: 'completed',
55
+ conclusion: index === 9 ? 'failure' : 'success',
56
+ branch: 'main',
57
+ sha: `abcde${index}`,
58
+ runNumber: 140 - index
59
+ }));
60
+ }
61
+ };
62
+ const menu = {
63
+ async getReposListView() { return { text: 'repos', reply_markup: { inline_keyboard: [] } }; },
64
+ async renderByCallback(data) { return { text: data, reply_markup: { inline_keyboard: [] } }; }
65
+ };
66
+
67
+ const plugin = createGitHubPlugin({ github, menu });
68
+ const route = plugin.resolveCallback('runs:123:2');
69
+ assert.ok(route);
70
+ assert.equal(route.actionId, 'github.workflow.runs.list');
71
+ assert.deepEqual(calls, []);
72
+
73
+ const view = await route.execute();
74
+ assert.deepEqual(calls, [{ repoId: 123, options: { perPage: 10, page: 2 } }]);
75
+ const callbacks = view.reply_markup.inline_keyboard.flat().map(button => button.callback_data);
76
+ assert.ok(callbacks.includes('runs:123:1'));
77
+ assert.ok(callbacks.includes('runs:123:3'));
78
+});