Personal Telegram developer console for GitHub
fix: remove fabricated GitHub fallback data
davoodmehraban89 committed
Oct 2, 2026 at 22:10 UTC
f3d2e5ead61eba81222f1b263b1993d3babe3418
1 file changed
+108
-170
src/github.js
+108
-170
@@ -7,203 +7,141 @@ export class GitHubService {
7
this.baseUrl = 'https://api.github.com';
8
}
9
10
+ requireToken() {
11
+ if (!this.token) {
12
+ throw new Error('GITHUB_TOKEN is not configured');
13
+ }
14
+ }
15
+
16
getHeaders() {
11
- const headers = {
17
+ this.requireToken();
18
+ return {
19
'User-Agent': 'Nexa-Dev-Bot-v1.1',
13
- 'Accept': 'application/vnd.github.v3+json'
20
+ 'Accept': 'application/vnd.github+json',
21
+ 'Authorization': `Bearer ${this.token}`,
22
+ 'X-GitHub-Api-Version': '2022-11-28'
23
};
15
- if (this.token) {
16
- headers['Authorization'] = `token ${this.token}`;
17
- }
18
- return headers;
24
}
25
21
- async listRepositories() {
22
- if (this.token) {
26
+ async requestJson(url, label) {
27
+ const res = await fetch(url, { headers: this.getHeaders() });
28
+ if (!res.ok) {
29
+ let detail = '';
30
try {
24
- const res = await fetch(`${this.baseUrl}/users/${this.owner}/repos?sort=updated&per_page=10`, {
25
- headers: this.getHeaders()
26
- });
27
- if (res.ok) {
28
- const data = await res.json();
29
- return data.map(r => ({
30
- id: r.name,
31
- name: r.name,
32
- title: `${r.name} ${r.private ? '🔒' : '🌐'}`,
33
- stars: r.stargazers_count,
34
- forks: r.forks_count,
35
- description: r.description || ''
36
- }));
37
- }
38
- } catch (err) {
39
- // Fall back to default repo registry
31
+ const body = await res.json();
32
+ detail = body?.message ? ` ${body.message}` : '';
33
+ } catch {
34
+ detail = '';
35
}
36
+ throw new Error(`${label} failed: ${res.status}${detail}`);
37
}
42
- return DEFAULT_CONFIG.defaultRepos;
38
+ return res.json();
39
}
40
45
- async listPullRequests(repo) {
46
- if (this.token) {
47
- try {
48
- const res = await fetch(`${this.baseUrl}/repos/${this.owner}/${repo}/pulls?state=all&per_page=10`, {
49
- headers: this.getHeaders()
50
- });
51
- if (res.ok) {
52
- const data = await res.json();
53
- return data.map(pr => ({
54
- number: pr.number,
55
- title: pr.title,
56
- author: pr.user?.login || 'unknown',
57
- state: pr.state,
58
- merged: !!pr.merged_at,
59
- createdAt: pr.created_at,
60
- url: pr.html_url
61
- }));
62
- }
63
- } catch (err) {
64
- // Fall back to known PRs
65
- }
66
- }
41
+ repoUrl(repo, suffix = '') {
42
+ return `${this.baseUrl}/repos/${encodeURIComponent(this.owner)}/${encodeURIComponent(repo)}${suffix}`;
43
+ }
44
68
- // Default verified PR mock data matching user tests
69
- if (repo.toLowerCase() === 'factor-easy') {
70
- return [
71
- {
72
- number: 43,
73
- title: 'Ops: strengthen long-running execution heartbeat rule',
74
- author: 'davoodmehraban89',
75
- state: 'open',
76
- merged: false
77
- },
78
- {
79
- number: 40,
80
- title: 'UI: structurally bind each scrollbar to its visual layer',
81
- author: 'davoodmehraban89',
82
- state: 'open',
83
- merged: false
84
- },
85
- {
86
- number: 39,
87
- title: 'UI: correct native scrollbar side in mobile RTL views',
88
- author: 'davoodmehraban89',
89
- state: 'closed',
90
- merged: true
91
- },
92
- {
93
- number: 28,
94
- title: 'Docs: record verified Wave 4b gates',
95
- author: 'davoodmehraban89',
96
- state: 'closed',
97
- merged: true
98
- },
99
- {
100
- number: 6,
101
- title: 'Phase 3 recovery & persistent state management',
102
- author: 'davoodmehraban89',
103
- state: 'closed',
104
- merged: true
105
- }
106
- ];
107
- }
45
+ async listRepositories() {
46
+ const data = await this.requestJson(
47
+ `${this.baseUrl}/user/repos?sort=updated&per_page=20&affiliation=owner,collaborator,organization_member`,
48
+ 'GitHub repositories'
49
+ );
50
+
51
+ return data.map(r => ({
52
+ id: r.name,
53
+ name: r.name,
54
+ fullName: r.full_name,
55
+ title: `${r.name} ${r.private ? '🔒' : '🌐'}`,
56
+ private: !!r.private,
57
+ stars: r.stargazers_count ?? 0,
58
+ forks: r.forks_count ?? 0,
59
+ description: r.description || '',
60
+ defaultBranch: r.default_branch || 'main'
61
+ }));
62
+ }
63
109
- return [
110
- { number: 1, title: 'Initial architecture & bootstrap', author: this.owner, state: 'closed', merged: true },
111
- { number: 2, title: 'CI/CD pipeline and automated tests', author: this.owner, state: 'open', merged: false }
112
- ];
64
+ async getRepository(repo) {
65
+ const r = await this.requestJson(this.repoUrl(repo), 'GitHub repository');
66
+ return {
67
+ id: r.name,
68
+ name: r.name,
69
+ fullName: r.full_name,
70
+ private: !!r.private,
71
+ description: r.description || '',
72
+ defaultBranch: r.default_branch || 'main',
73
+ archived: !!r.archived,
74
+ htmlUrl: r.html_url || ''
75
+ };
76
+ }
77
+
78
+ async listPullRequests(repo) {
79
+ const data = await this.requestJson(
80
+ this.repoUrl(repo, '/pulls?state=all&per_page=10'),
81
+ 'GitHub pull requests'
82
+ );
83
+
84
+ return data.map(pr => ({
85
+ number: pr.number,
86
+ title: pr.title,
87
+ author: pr.user?.login || 'unknown',
88
+ state: pr.state,
89
+ merged: !!pr.merged_at,
90
+ createdAt: pr.created_at,
91
+ url: pr.html_url
92
+ }));
93
}
94
95
async listCommits(repo) {
116
- if (this.token) {
117
- try {
118
- const res = await fetch(`${this.baseUrl}/repos/${this.owner}/${repo}/commits?per_page=5`, {
119
- headers: this.getHeaders()
120
- });
121
- if (res.ok) {
122
- const data = await res.json();
123
- return data.map(c => ({
124
- sha: c.sha.slice(0, 7),
125
- message: c.commit.message.split('\n')[0],
126
- author: c.commit.author?.name || c.author?.login || 'Unknown',
127
- date: c.commit.author?.date ? c.commit.author.date.slice(0, 10) : ''
128
- }));
129
- }
130
- } catch (err) {
131
- // Fall back to sample commits
132
- }
133
- }
96
+ const data = await this.requestJson(
97
+ this.repoUrl(repo, '/commits?per_page=5'),
98
+ 'GitHub commits'
99
+ );
100
135
- return [
136
- { sha: '87b25b1', message: 'feat: mobile GitHub repository browser UX', author: this.owner, date: '2026-10-02' },
137
- { sha: 'b8689f1', message: 'fix: enable Telegram callback updates & router', author: this.owner, date: '2026-10-02' },
138
- { sha: '0644e5e', message: 'cleanup: remove temporary /diag command', author: this.owner, date: '2026-10-02' },
139
- { sha: 'dd2da6d', message: 'test: cover automatic Telegram webhook setup', author: this.owner, date: '2026-10-02' }
140
- ];
101
+ return data.map(c => ({
102
+ sha: c.sha.slice(0, 7),
103
+ message: String(c.commit?.message || '').split('\n')[0],
104
+ author: c.author?.login || c.commit?.author?.name || 'Unknown',
105
+ date: c.commit?.author?.date ? c.commit.author.date.slice(0, 10) : ''
106
+ }));
107
}
108
109
async listFiles(repo, path = '') {
144
- if (this.token) {
145
- try {
146
- const endpoint = path ? `${this.baseUrl}/repos/${this.owner}/${repo}/contents/${path}` : `${this.baseUrl}/repos/${this.owner}/${repo}/contents`;
147
- const res = await fetch(endpoint, {
148
- headers: this.getHeaders()
149
- });
150
- if (res.ok) {
151
- const data = await res.json();
152
- if (Array.isArray(data)) {
153
- return data.map(item => ({
154
- name: item.name,
155
- path: item.path,
156
- type: item.type === 'dir' ? 'dir' : 'file',
157
- size: item.size
158
- }));
159
- }
160
- }
161
- } catch (err) {
162
- // Fall back
163
- }
110
+ const suffix = path
111
+ ? `/contents/${path.split('/').map(encodeURIComponent).join('/')}`
112
+ : '/contents';
113
+ const data = await this.requestJson(this.repoUrl(repo, suffix), 'GitHub contents');
114
+
115
+ if (!Array.isArray(data)) {
116
+ throw new Error('GitHub contents response is not a directory listing');
117
}
118
166
- return [
167
- { name: 'src', path: 'src', type: 'dir', size: 0 },
168
- { name: 'tests', path: 'tests', type: 'dir', size: 0 },
169
- { name: 'package.json', path: 'package.json', type: 'file', size: 450 },
170
- { name: 'wrangler.toml', path: 'wrangler.toml', type: 'file', size: 280 },
171
- { name: 'README.md', path: 'README.md', type: 'file', size: 1240 }
172
- ];
119
+ return data.map(item => ({
120
+ name: item.name,
121
+ path: item.path,
122
+ type: item.type === 'dir' ? 'dir' : 'file',
123
+ size: item.size ?? 0,
124
+ sha: item.sha || ''
125
+ }));
126
}
127
128
async getRepoStatus(repo) {
176
- if (this.token) {
177
- try {
178
- const res = await fetch(`${this.baseUrl}/repos/${this.owner}/${repo}/actions/runs?per_page=3`, {
179
- headers: this.getHeaders()
180
- });
181
- if (res.ok) {
182
- const data = await res.json();
183
- const runs = data.workflow_runs || [];
184
- return {
185
- repo,
186
- defaultBranch: 'main',
187
- lastRuns: runs.map(r => ({
188
- name: r.name,
189
- status: r.status,
190
- conclusion: r.conclusion,
191
- commit: r.head_commit?.message?.slice(0, 40) || ''
192
- }))
193
- };
194
- }
195
- } catch (err) {
196
- // Fall back
197
- }
198
- }
129
+ const [repository, runsData] = await Promise.all([
130
+ this.getRepository(repo),
131
+ this.requestJson(this.repoUrl(repo, '/actions/runs?per_page=3'), 'GitHub Actions runs')
132
+ ]);
133
134
+ const runs = runsData.workflow_runs || [];
135
return {
136
repo,
202
- defaultBranch: 'main',
203
- lastRuns: [
204
- { name: 'CI Workflow', status: 'completed', conclusion: 'success', commit: 'UI: structurally bind scrollbar' },
205
- { name: 'Security Checks', status: 'completed', conclusion: 'success', commit: 'Docs: record verified Wave 4b' }
206
- ]
137
+ defaultBranch: repository.defaultBranch,
138
+ lastRuns: runs.map(r => ({
139
+ name: r.name,
140
+ status: r.status,
141
+ conclusion: r.conclusion,
142
+ commit: r.head_commit?.message?.slice(0, 80) || '',
143
+ url: r.html_url || ''
144
+ }))
145
};
146
}
147
}