Personal Telegram developer console for GitHub
fix: preserve GitHub read compatibility and log bounds
davoodmehraban89 committed
Oct 3, 2026 at 09:16 UTC
b25366df1645173587fda86b8afd89e2c78f9543
1 file changed
+85
-311
src/github.js
+85
-311
@@ -22,9 +22,7 @@ export class GitHubService {
22
}
23
24
requireToken() {
25
- if (!this.token) {
26
- throw new Error('GITHUB_TOKEN is not configured');
27
- }
25
+ if (!this.token) throw new Error('GITHUB_TOKEN is not configured');
26
}
27
28
getHeaders() {
@@ -44,32 +42,20 @@ export class GitHubService {
42
options.body = JSON.stringify(body);
43
options.headers = { ...headers, 'Content-Type': 'application/json' };
44
}
47
-
45
const res = await fetch(url, options);
46
const raw = await res.text();
47
let parsed = null;
48
if (raw) {
52
- try {
53
- parsed = JSON.parse(raw);
54
- } catch {
55
- parsed = null;
56
- }
49
+ try { parsed = JSON.parse(raw); } catch { parsed = null; }
50
}
58
-
51
if (!res.ok) {
52
const providerMessage = parsed?.message || raw.slice(0, 240);
53
const detail = providerMessage ? ` ${providerMessage}` : '';
54
throw new Error(`${label} failed: ${res.status}${detail}`);
55
}
64
-
65
- if (allowEmpty) {
66
- return { accepted: true, status: res.status };
67
- }
68
-
56
+ if (allowEmpty) return { accepted: true, status: res.status };
57
if (!raw) return null;
70
- if (parsed === null) {
71
- throw new Error(`${label} failed: invalid JSON response`);
72
- }
58
+ if (parsed === null) throw new Error(`${label} failed: invalid JSON response`);
59
return parsed;
60
}
61
@@ -80,11 +66,8 @@ export class GitHubService {
66
const detail = raw ? ` ${raw.slice(0, 240)}` : '';
67
throw new Error(`${label} failed: ${res.status}${detail}`);
68
}
83
- const limit = Math.max(100, Math.min(20000, Number(maxChars) || 12000));
84
- return {
85
- text: raw.length > limit ? raw.slice(-limit) : raw,
86
- truncated: raw.length > limit
87
- };
69
+ const limit = Math.max(1, Math.min(20000, Number(maxChars) || 12000));
70
+ return { text: raw.length > limit ? raw.slice(-limit) : raw, truncated: raw.length > limit };
71
}
72
73
repoUrl(repo, suffix = '') {
@@ -93,101 +76,56 @@ export class GitHubService {
76
77
repositoryLookupUrl(repoRef) {
78
const value = String(repoRef || '');
96
- if (/^\d+$/.test(value)) {
97
- return `${this.baseUrl}/repositories/${value}`;
98
- }
99
- return this.repoUrl(value);
79
+ return /^\d+$/.test(value) ? `${this.baseUrl}/repositories/${value}` : this.repoUrl(value);
80
}
81
82
repositoryApiBase(fullName) {
83
const parts = String(fullName || '').split('/').filter(Boolean);
104
- if (parts.length !== 2) {
105
- throw new Error('GitHub repository full_name is invalid');
106
- }
84
+ if (parts.length !== 2) throw new Error('GitHub repository full_name is invalid');
85
return `${this.baseUrl}/repos/${parts.map(encodeURIComponent).join('/')}`;
86
}
87
88
async getRepositoryContext(repoRef) {
89
const raw = await this.requestJson(this.repositoryLookupUrl(repoRef), 'GitHub repository');
112
- return {
113
- raw,
114
- apiBase: this.repositoryApiBase(raw.full_name)
115
- };
90
+ return { raw, apiBase: this.repositoryApiBase(raw.full_name) };
91
}
92
93
mapRepository(r) {
94
return {
120
- id: String(r.id ?? r.name),
121
- name: r.name,
122
- fullName: r.full_name,
123
- private: !!r.private,
124
- description: r.description || '',
125
- defaultBranch: r.default_branch || 'main',
126
- archived: !!r.archived,
127
- htmlUrl: r.html_url || '',
128
- stars: r.stargazers_count ?? 0,
129
- forks: r.forks_count ?? 0
95
+ id: String(r.id ?? r.name), name: r.name, fullName: r.full_name, private: !!r.private,
96
+ description: r.description || '', defaultBranch: r.default_branch || 'main', archived: !!r.archived,
97
+ htmlUrl: r.html_url || '', stars: r.stargazers_count ?? 0, forks: r.forks_count ?? 0
98
};
99
}
100
101
mapWorkflowRun(run = {}) {
102
return {
135
- id: run.id,
136
- name: run.name || 'Workflow',
137
- status: run.status || '',
138
- conclusion: run.conclusion || null,
139
- event: run.event || '',
140
- branch: run.head_branch || '',
141
- sha: String(run.head_sha || '').slice(0, 7),
142
- runNumber: run.run_number ?? null,
143
- url: run.html_url || '',
144
- createdAt: run.created_at || '',
145
- updatedAt: run.updated_at || ''
103
+ id: run.id, name: run.name || 'Workflow', status: run.status || '', conclusion: run.conclusion || null,
104
+ event: run.event || '', branch: run.head_branch || '', sha: String(run.head_sha || '').slice(0, 7),
105
+ runNumber: run.run_number ?? null, url: run.html_url || '', createdAt: run.created_at || '', updatedAt: run.updated_at || ''
106
};
107
}
108
109
mapWorkflowJob(job = {}) {
110
return {
151
- id: job.id,
152
- name: job.name || 'Job',
153
- status: job.status || '',
154
- conclusion: job.conclusion || null,
155
- startedAt: job.started_at || '',
156
- completedAt: job.completed_at || '',
157
- url: job.html_url || '',
111
+ id: job.id, name: job.name || 'Job', status: job.status || '', conclusion: job.conclusion || null,
112
+ startedAt: job.started_at || '', completedAt: job.completed_at || '', url: job.html_url || '',
113
steps: (job.steps || []).slice(0, 30).map(step => ({
159
- number: step.number,
160
- name: step.name || 'Step',
161
- status: step.status || '',
162
- conclusion: step.conclusion || null
114
+ number: step.number, name: step.name || 'Step', status: step.status || '', conclusion: step.conclusion || null
115
}))
116
};
117
}
118
119
mapPullRequestFile(file = {}) {
120
return {
169
- filename: file.filename || '',
170
- status: file.status || '',
171
- additions: file.additions ?? 0,
172
- deletions: file.deletions ?? 0,
173
- changes: file.changes ?? 0,
174
- patch: boundedPatch(file.patch)
121
+ filename: file.filename || '', status: file.status || '', additions: file.additions ?? 0,
122
+ deletions: file.deletions ?? 0, changes: file.changes ?? 0, patch: boundedPatch(file.patch)
123
};
124
}
125
126
async listRepositories() {
179
- const data = await this.requestJson(
180
- `${this.baseUrl}/user/repos?sort=updated&per_page=20&affiliation=owner,collaborator,organization_member`,
181
- 'GitHub repositories'
182
- );
183
-
184
- return data.map(r => {
185
- const repo = this.mapRepository(r);
186
- return {
187
- ...repo,
188
- title: `${repo.name} ${repo.private ? '🔒' : '🌐'}`
189
- };
190
- });
127
+ const data = await this.requestJson(`${this.baseUrl}/user/repos?sort=updated&per_page=20&affiliation=owner,collaborator,organization_member`, 'GitHub repositories');
128
+ return data.map(r => { const repo = this.mapRepository(r); return { ...repo, title: `${repo.name} ${repo.private ? '🔒' : '🌐'}` }; });
129
}
130
131
async getRepository(repoRef) {
@@ -198,20 +136,12 @@ export class GitHubService {
136
async listPullRequests(repoRef, { perPage = 10, page = 1 } = {}) {
137
const count = clampPerPage(perPage, 10);
138
const pageNumber = clampPage(page);
139
+ const pageQuery = pageNumber > 1 ? `&page=${pageNumber}` : '';
140
const { apiBase } = await this.getRepositoryContext(repoRef);
202
- const data = await this.requestJson(
203
- `${apiBase}/pulls?state=all&per_page=${count}&page=${pageNumber}`,
204
- 'GitHub pull requests'
205
- );
206
-
141
+ const data = await this.requestJson(`${apiBase}/pulls?state=all&per_page=${count}${pageQuery}`, 'GitHub pull requests');
142
return data.map(pr => ({
208
- number: pr.number,
209
- title: pr.title,
210
- author: pr.user?.login || 'unknown',
211
- state: pr.state,
212
- merged: !!pr.merged_at,
213
- createdAt: pr.created_at,
214
- url: pr.html_url
143
+ number: pr.number, title: pr.title, author: pr.user?.login || 'unknown', state: pr.state,
144
+ merged: !!pr.merged_at, createdAt: pr.created_at, url: pr.html_url
145
}));
146
}
147
@@ -220,306 +150,150 @@ export class GitHubService {
150
const { apiBase } = await this.getRepositoryContext(repoRef);
151
const pr = await this.requestJson(`${apiBase}/pulls/${number}`, 'GitHub pull request');
152
return {
223
- number: pr.number,
224
- title: pr.title || '',
225
- author: pr.user?.login || 'unknown',
226
- state: pr.state || '',
227
- merged: !!(pr.merged ?? pr.merged_at),
228
- body: pr.body || '',
229
- url: pr.html_url || '',
230
- head: pr.head?.ref || '',
231
- headSha: pr.head?.sha || '',
232
- base: pr.base?.ref || '',
233
- additions: pr.additions ?? 0,
234
- deletions: pr.deletions ?? 0,
235
- changedFiles: pr.changed_files ?? 0
153
+ number: pr.number, title: pr.title || '', author: pr.user?.login || 'unknown', state: pr.state || '',
154
+ merged: !!(pr.merged ?? pr.merged_at), body: pr.body || '', url: pr.html_url || '', head: pr.head?.ref || '',
155
+ headSha: pr.head?.sha || '', base: pr.base?.ref || '', additions: pr.additions ?? 0,
156
+ deletions: pr.deletions ?? 0, changedFiles: pr.changed_files ?? 0
157
};
158
}
159
160
async listPullRequestFiles(repoRef, prNumber, { perPage = 20, page = 1 } = {}) {
161
const number = numericId(prNumber, 'pull request');
241
- const count = clampPerPage(perPage, 20);
242
- const pageNumber = clampPage(page);
162
+ const count = clampPerPage(perPage, 20); const pageNumber = clampPage(page);
163
const { apiBase } = await this.getRepositoryContext(repoRef);
244
- const data = await this.requestJson(
245
- `${apiBase}/pulls/${number}/files?per_page=${count}&page=${pageNumber}`,
246
- 'GitHub pull request files'
247
- );
164
+ const data = await this.requestJson(`${apiBase}/pulls/${number}/files?per_page=${count}&page=${pageNumber}`, 'GitHub pull request files');
165
return data.map(file => this.mapPullRequestFile(file));
166
}
167
168
async listCommits(repoRef) {
169
const { apiBase } = await this.getRepositoryContext(repoRef);
253
- const data = await this.requestJson(
254
- `${apiBase}/commits?per_page=5`,
255
- 'GitHub commits'
256
- );
257
-
170
+ const data = await this.requestJson(`${apiBase}/commits?per_page=5`, 'GitHub commits');
171
return data.map(c => ({
259
- sha: c.sha.slice(0, 7),
260
- message: String(c.commit?.message || '').split('\n')[0],
261
- author: c.author?.login || c.commit?.author?.name || 'Unknown',
262
- date: c.commit?.author?.date ? c.commit.author.date.slice(0, 10) : ''
172
+ sha: c.sha.slice(0, 7), message: String(c.commit?.message || '').split('\n')[0],
173
+ author: c.author?.login || c.commit?.author?.name || 'Unknown', date: c.commit?.author?.date ? c.commit.author.date.slice(0, 10) : ''
174
}));
175
}
176
177
async listCommitChecks(repoRef, sha, { perPage = 20, page = 1 } = {}) {
267
- const commitSha = fullSha(sha);
268
- const count = clampPerPage(perPage, 20);
269
- const pageNumber = clampPage(page);
178
+ const commitSha = fullSha(sha); const count = clampPerPage(perPage, 20); const pageNumber = clampPage(page);
179
const { apiBase } = await this.getRepositoryContext(repoRef);
271
- const data = await this.requestJson(
272
- `${apiBase}/commits/${commitSha}/check-runs?per_page=${count}&page=${pageNumber}`,
273
- 'GitHub check runs'
274
- );
275
- return (data.check_runs || []).map(check => ({
276
- id: check.id,
277
- name: check.name || 'Check',
278
- status: check.status || '',
279
- conclusion: check.conclusion || null,
280
- url: check.html_url || ''
281
- }));
180
+ const data = await this.requestJson(`${apiBase}/commits/${commitSha}/check-runs?per_page=${count}&page=${pageNumber}`, 'GitHub check runs');
181
+ return (data.check_runs || []).map(check => ({ id: check.id, name: check.name || 'Check', status: check.status || '', conclusion: check.conclusion || null, url: check.html_url || '' }));
182
}
183
184
async listFiles(repoRef, path = '') {
185
const { apiBase } = await this.getRepositoryContext(repoRef);
286
- const suffix = path
287
- ? `/contents/${path.split('/').map(encodeURIComponent).join('/')}`
288
- : '/contents';
186
+ const suffix = path ? `/contents/${path.split('/').map(encodeURIComponent).join('/')}` : '/contents';
187
const data = await this.requestJson(`${apiBase}${suffix}`, 'GitHub contents');
290
-
291
- if (!Array.isArray(data)) {
292
- throw new Error('GitHub contents response is not a directory listing');
293
- }
294
-
295
- return data.map(item => ({
296
- name: item.name,
297
- path: item.path,
298
- type: item.type === 'dir' ? 'dir' : 'file',
299
- size: item.size ?? 0,
300
- sha: item.sha || ''
301
- }));
188
+ if (!Array.isArray(data)) throw new Error('GitHub contents response is not a directory listing');
189
+ return data.map(item => ({ name: item.name, path: item.path, type: item.type === 'dir' ? 'dir' : 'file', size: item.size ?? 0, sha: item.sha || '' }));
190
}
191
192
async listTree(repoRef, sha) {
305
- if (!/^[a-f0-9]{40}$/i.test(String(sha || ''))) {
306
- throw new Error('Invalid Git tree SHA');
307
- }
308
-
193
+ if (!/^[a-f0-9]{40}$/i.test(String(sha || ''))) throw new Error('Invalid Git tree SHA');
194
const { apiBase } = await this.getRepositoryContext(repoRef);
310
- const data = await this.requestJson(
311
- `${apiBase}/git/trees/${encodeURIComponent(sha)}`,
312
- 'GitHub tree'
313
- );
314
-
315
- return (data.tree || [])
316
- .filter(item => item.type === 'tree' || item.type === 'blob')
317
- .map(item => ({
318
- name: item.path,
319
- path: item.path,
320
- type: item.type === 'tree' ? 'dir' : 'file',
321
- size: item.size ?? 0,
322
- sha: item.sha || ''
323
- }));
195
+ const data = await this.requestJson(`${apiBase}/git/trees/${encodeURIComponent(sha)}`, 'GitHub tree');
196
+ return (data.tree || []).filter(item => item.type === 'tree' || item.type === 'blob').map(item => ({
197
+ name: item.path, path: item.path, type: item.type === 'tree' ? 'dir' : 'file', size: item.size ?? 0, sha: item.sha || ''
198
+ }));
199
}
200
201
async getBlob(repoRef, sha) {
327
- if (!/^[a-f0-9]{40}$/i.test(String(sha || ''))) {
328
- throw new Error('Invalid Git blob SHA');
329
- }
330
-
202
+ if (!/^[a-f0-9]{40}$/i.test(String(sha || ''))) throw new Error('Invalid Git blob SHA');
203
const { apiBase } = await this.getRepositoryContext(repoRef);
332
- const data = await this.requestJson(
333
- `${apiBase}/git/blobs/${encodeURIComponent(sha)}`,
334
- 'GitHub blob'
335
- );
336
-
337
- return {
338
- encoding: data.encoding || '',
339
- size: data.size ?? 0,
340
- content: data.content || ''
341
- };
204
+ const data = await this.requestJson(`${apiBase}/git/blobs/${encodeURIComponent(sha)}`, 'GitHub blob');
205
+ return { encoding: data.encoding || '', size: data.size ?? 0, content: data.content || '' };
206
}
207
208
async getRepoStatus(repoRef) {
209
const { raw, apiBase } = await this.getRepositoryContext(repoRef);
346
- const runsData = await this.requestJson(
347
- `${apiBase}/actions/runs?per_page=3`,
348
- 'GitHub Actions runs'
349
- );
350
-
210
+ const runsData = await this.requestJson(`${apiBase}/actions/runs?per_page=3`, 'GitHub Actions runs');
211
const runs = runsData.workflow_runs || [];
212
return {
353
- repo: String(repoRef),
354
- repoName: raw.name,
355
- defaultBranch: raw.default_branch || 'main',
356
- lastRuns: runs.map(r => ({
357
- name: r.name,
358
- status: r.status,
359
- conclusion: r.conclusion,
360
- commit: r.head_commit?.message?.slice(0, 80) || '',
361
- url: r.html_url || ''
362
- }))
213
+ repo: String(repoRef), repoName: raw.name, defaultBranch: raw.default_branch || 'main',
214
+ lastRuns: runs.map(r => ({ name: r.name, status: r.status, conclusion: r.conclusion, commit: r.head_commit?.message?.slice(0, 80) || '', url: r.html_url || '' }))
215
};
216
}
217
218
async listWorkflowRuns(repoRef, { perPage = 10, page = 1 } = {}) {
367
- const count = clampPerPage(perPage, 10);
368
- const pageNumber = clampPage(page);
219
+ const count = clampPerPage(perPage, 10); const pageNumber = clampPage(page);
220
const { apiBase } = await this.getRepositoryContext(repoRef);
221
const pageQuery = pageNumber > 1 ? `&page=${pageNumber}` : '';
371
- const data = await this.requestJson(
372
- `${apiBase}/actions/runs?per_page=${count}${pageQuery}`,
373
- 'GitHub workflow runs'
374
- );
222
+ const data = await this.requestJson(`${apiBase}/actions/runs?per_page=${count}${pageQuery}`, 'GitHub workflow runs');
223
return (data.workflow_runs || []).map(run => this.mapWorkflowRun(run));
224
}
225
226
async getWorkflowRun(repoRef, runId) {
379
- const id = numericId(runId, 'workflow run');
380
- const { apiBase } = await this.getRepositoryContext(repoRef);
381
- const data = await this.requestJson(
382
- `${apiBase}/actions/runs/${id}`,
383
- 'GitHub workflow run'
384
- );
385
- return this.mapWorkflowRun(data);
227
+ const id = numericId(runId, 'workflow run'); const { apiBase } = await this.getRepositoryContext(repoRef);
228
+ return this.mapWorkflowRun(await this.requestJson(`${apiBase}/actions/runs/${id}`, 'GitHub workflow run'));
229
}
230
231
async listWorkflowJobs(repoRef, runId) {
389
- const id = numericId(runId, 'workflow run');
390
- const { apiBase } = await this.getRepositoryContext(repoRef);
391
- const data = await this.requestJson(
392
- `${apiBase}/actions/runs/${id}/jobs?per_page=20`,
393
- 'GitHub workflow jobs'
394
- );
232
+ const id = numericId(runId, 'workflow run'); const { apiBase } = await this.getRepositoryContext(repoRef);
233
+ const data = await this.requestJson(`${apiBase}/actions/runs/${id}/jobs?per_page=20`, 'GitHub workflow jobs');
234
return (data.jobs || []).map(job => this.mapWorkflowJob(job));
235
}
236
237
async getWorkflowJob(repoRef, jobId) {
399
- const id = numericId(jobId, 'workflow job');
400
- const { apiBase } = await this.getRepositoryContext(repoRef);
401
- const data = await this.requestJson(`${apiBase}/actions/jobs/${id}`, 'GitHub workflow job');
402
- return this.mapWorkflowJob(data);
238
+ const id = numericId(jobId, 'workflow job'); const { apiBase } = await this.getRepositoryContext(repoRef);
239
+ return this.mapWorkflowJob(await this.requestJson(`${apiBase}/actions/jobs/${id}`, 'GitHub workflow job'));
240
}
241
242
async getWorkflowJobLog(repoRef, jobId, { maxChars = 12000 } = {}) {
406
- const id = numericId(jobId, 'workflow job');
407
- const { apiBase } = await this.getRepositoryContext(repoRef);
243
+ const id = numericId(jobId, 'workflow job'); const { apiBase } = await this.getRepositoryContext(repoRef);
244
return this.requestText(`${apiBase}/actions/jobs/${id}/logs`, 'GitHub workflow job log', { maxChars });
245
}
246
247
async listWorkflowArtifacts(repoRef, runId, { perPage = 20, page = 1 } = {}) {
412
- const id = numericId(runId, 'workflow run');
413
- const count = clampPerPage(perPage, 20);
414
- const pageNumber = clampPage(page);
248
+ const id = numericId(runId, 'workflow run'); const count = clampPerPage(perPage, 20); const pageNumber = clampPage(page);
249
const { apiBase } = await this.getRepositoryContext(repoRef);
416
- const data = await this.requestJson(
417
- `${apiBase}/actions/runs/${id}/artifacts?per_page=${count}&page=${pageNumber}`,
418
- 'GitHub workflow artifacts'
419
- );
250
+ const data = await this.requestJson(`${apiBase}/actions/runs/${id}/artifacts?per_page=${count}&page=${pageNumber}`, 'GitHub workflow artifacts');
251
return (data.artifacts || []).map(artifact => ({
421
- id: artifact.id,
422
- name: artifact.name || 'Artifact',
423
- size: artifact.size_in_bytes ?? 0,
424
- expired: !!artifact.expired,
425
- createdAt: artifact.created_at || '',
426
- expiresAt: artifact.expires_at || '',
427
- downloadUrl: artifact.archive_download_url || ''
252
+ id: artifact.id, name: artifact.name || 'Artifact', size: artifact.size_in_bytes ?? 0, expired: !!artifact.expired,
253
+ createdAt: artifact.created_at || '', expiresAt: artifact.expires_at || '', downloadUrl: artifact.archive_download_url || ''
254
}));
255
}
256
257
async listBranches(repoRef, { perPage = 20, page = 1 } = {}) {
432
- const count = clampPerPage(perPage, 20);
433
- const pageNumber = clampPage(page);
434
- const { apiBase } = await this.getRepositoryContext(repoRef);
435
- const data = await this.requestJson(
436
- `${apiBase}/branches?per_page=${count}&page=${pageNumber}`,
437
- 'GitHub branches'
438
- );
439
- return data.map(branch => ({
440
- name: branch.name || '',
441
- sha: branch.commit?.sha || '',
442
- protected: !!branch.protected
443
- }));
258
+ const count = clampPerPage(perPage, 20); const pageNumber = clampPage(page); const { apiBase } = await this.getRepositoryContext(repoRef);
259
+ const data = await this.requestJson(`${apiBase}/branches?per_page=${count}&page=${pageNumber}`, 'GitHub branches');
260
+ return data.map(branch => ({ name: branch.name || '', sha: branch.commit?.sha || '', protected: !!branch.protected }));
261
}
262
263
async compareWithDefault(repoRef, headSha) {
447
- const head = fullSha(headSha);
448
- const { raw, apiBase } = await this.getRepositoryContext(repoRef);
449
- const base = raw.default_branch || 'main';
450
- const data = await this.requestJson(
451
- `${apiBase}/compare/${encodeURIComponent(base)}...${head}`,
452
- 'GitHub compare'
453
- );
264
+ const head = fullSha(headSha); const { raw, apiBase } = await this.getRepositoryContext(repoRef); const base = raw.default_branch || 'main';
265
+ const data = await this.requestJson(`${apiBase}/compare/${encodeURIComponent(base)}...${head}`, 'GitHub compare');
266
return {
455
- base,
456
- head,
457
- status: data.status || '',
458
- aheadBy: data.ahead_by ?? 0,
459
- behindBy: data.behind_by ?? 0,
460
- totalCommits: data.total_commits ?? 0,
461
- baseSha: data.base_commit?.sha || '',
462
- mergeBaseSha: data.merge_base_commit?.sha || '',
267
+ base, head, status: data.status || '', aheadBy: data.ahead_by ?? 0, behindBy: data.behind_by ?? 0,
268
+ totalCommits: data.total_commits ?? 0, baseSha: data.base_commit?.sha || '', mergeBaseSha: data.merge_base_commit?.sha || '',
269
files: (data.files || []).slice(0, 20).map(file => this.mapPullRequestFile(file))
270
};
271
}
272
273
async listIssues(repoRef, { perPage = 10, page = 1 } = {}) {
468
- const count = clampPerPage(perPage, 10);
469
- const pageNumber = clampPage(page);
470
- const { apiBase } = await this.getRepositoryContext(repoRef);
471
- const data = await this.requestJson(
472
- `${apiBase}/issues?state=all&per_page=${count}&page=${pageNumber}`,
473
- 'GitHub issues'
474
- );
475
- return data
476
- .filter(issue => !issue.pull_request)
477
- .map(issue => ({
478
- number: issue.number,
479
- title: issue.title || '',
480
- state: issue.state || '',
481
- author: issue.user?.login || 'unknown',
482
- comments: issue.comments ?? 0,
483
- url: issue.html_url || ''
484
- }));
274
+ const count = clampPerPage(perPage, 10); const pageNumber = clampPage(page); const { apiBase } = await this.getRepositoryContext(repoRef);
275
+ const data = await this.requestJson(`${apiBase}/issues?state=all&per_page=${count}&page=${pageNumber}`, 'GitHub issues');
276
+ return data.filter(issue => !issue.pull_request).map(issue => ({
277
+ number: issue.number, title: issue.title || '', state: issue.state || '', author: issue.user?.login || 'unknown', comments: issue.comments ?? 0, url: issue.html_url || ''
278
+ }));
279
}
280
281
async listReleases(repoRef, { perPage = 10, page = 1 } = {}) {
488
- const count = clampPerPage(perPage, 10);
489
- const pageNumber = clampPage(page);
490
- const { apiBase } = await this.getRepositoryContext(repoRef);
491
- const data = await this.requestJson(
492
- `${apiBase}/releases?per_page=${count}&page=${pageNumber}`,
493
- 'GitHub releases'
494
- );
282
+ const count = clampPerPage(perPage, 10); const pageNumber = clampPage(page); const { apiBase } = await this.getRepositoryContext(repoRef);
283
+ const data = await this.requestJson(`${apiBase}/releases?per_page=${count}&page=${pageNumber}`, 'GitHub releases');
284
return data.map(release => ({
496
- id: release.id,
497
- tag: release.tag_name || '',
498
- name: release.name || release.tag_name || 'Release',
499
- draft: !!release.draft,
500
- prerelease: !!release.prerelease,
501
- publishedAt: release.published_at || release.created_at || '',
502
- url: release.html_url || ''
285
+ id: release.id, tag: release.tag_name || '', name: release.name || release.tag_name || 'Release', draft: !!release.draft,
286
+ prerelease: !!release.prerelease, publishedAt: release.published_at || release.created_at || '', url: release.html_url || ''
287
}));
288
}
289
290
async rerunFailedWorkflowRun(repoRef, runId) {
507
- const id = numericId(runId, 'workflow run');
508
- const { apiBase } = await this.getRepositoryContext(repoRef);
509
- return this.requestJson(
510
- `${apiBase}/actions/runs/${id}/rerun-failed-jobs`,
511
- 'GitHub rerun failed jobs',
512
- { method: 'POST', allowEmpty: true }
513
- );
291
+ const id = numericId(runId, 'workflow run'); const { apiBase } = await this.getRepositoryContext(repoRef);
292
+ return this.requestJson(`${apiBase}/actions/runs/${id}/rerun-failed-jobs`, 'GitHub rerun failed jobs', { method: 'POST', allowEmpty: true });
293
}
294
295
async cancelWorkflowRun(repoRef, runId) {
517
- const id = numericId(runId, 'workflow run');
518
- const { apiBase } = await this.getRepositoryContext(repoRef);
519
- return this.requestJson(
520
- `${apiBase}/actions/runs/${id}/cancel`,
521
- 'GitHub cancel workflow run',
522
- { method: 'POST', allowEmpty: true }
523
- );
296
+ const id = numericId(runId, 'workflow run'); const { apiBase } = await this.getRepositoryContext(repoRef);
297
+ return this.requestJson(`${apiBase}/actions/runs/${id}/cancel`, 'GitHub cancel workflow run', { method: 'POST', allowEmpty: true });
298
}
299
}