plugin-git-manager 1.2.27 → 1.2.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/README.md +133 -108
  2. package/client-v2.d.ts +2 -2
  3. package/client-v2.js +1 -1
  4. package/client.d.ts +3 -3
  5. package/client.js +1 -1
  6. package/dist/client/{326.90c276058682b536.js → 313.d38fc1d40c4589b9.js} +1 -1
  7. package/dist/client/900.a48beac7e2ebee7d.js +10 -0
  8. package/dist/client/index.js +1 -1
  9. package/dist/client-v2/156.445366026c1cc9a8.js +10 -0
  10. package/dist/client-v2/{326.42b7b53651ffab3a.js → 313.3c867179c3a1e817.js} +1 -1
  11. package/dist/client-v2/434.19c7579c06b9077c.js +10 -0
  12. package/dist/client-v2/900.e6155002a9c97e7f.js +10 -0
  13. package/dist/client-v2/928.bba701b5a1ece58e.js +10 -0
  14. package/dist/client-v2/index.js +1 -1
  15. package/dist/externalVersion.js +9 -8
  16. package/dist/locale/en-US.json +307 -297
  17. package/dist/locale/vi-VN.json +295 -292
  18. package/dist/locale/zh-CN.json +61 -51
  19. package/dist/node_modules/simple-git/dist/cjs/index.js +25 -25
  20. package/dist/node_modules/simple-git/package.json +1 -1
  21. package/dist/node_modules/zod/index.cjs +1 -1
  22. package/dist/node_modules/zod/package.json +1 -1
  23. package/dist/server/actions/git-actions.js +90 -36
  24. package/dist/server/actions/gitlab-api.js +4 -2
  25. package/dist/server/actions/poller.js +5 -2
  26. package/dist/server/actions/review.js +20 -10
  27. package/dist/server/plugin.js +6 -4
  28. package/dist/server/poller.js +46 -45
  29. package/dist/server/request-method-policy.js +75 -0
  30. package/dist/server/services/registry-content-service.js +4 -3
  31. package/dist/server/utils/get-repo-account.js +3 -2
  32. package/dist/server/utils/url-security.js +24 -0
  33. package/package.json +61 -43
  34. package/server.d.ts +2 -2
  35. package/server.js +1 -1
  36. package/src/client/__tests__/RunReviewButton.test.tsx +73 -0
  37. package/src/client/ai-context.tsx +114 -114
  38. package/src/client/components/AIEmployeeSelect.tsx +63 -63
  39. package/src/client/components/CommitHistory.tsx +374 -374
  40. package/src/client/components/FileExplorer.tsx +386 -386
  41. package/src/client/components/GitAccounts.tsx +179 -179
  42. package/src/client/components/GitManagerSettings.tsx +160 -160
  43. package/src/client/components/GitOperations.tsx +220 -220
  44. package/src/client/components/LLMModelSelect.tsx +63 -63
  45. package/src/client/components/LLMServiceSelect.tsx +58 -58
  46. package/src/client/components/MarkdownView.tsx +80 -80
  47. package/src/client/components/MergeRequests.tsx +790 -790
  48. package/src/client/components/PollingStatus.tsx +225 -225
  49. package/src/client/components/RepositoryConfig.tsx +335 -335
  50. package/src/client/components/RepositoryPermissions.tsx +123 -123
  51. package/src/client/components/ReviewFlows.tsx +303 -303
  52. package/src/client/components/ReviewHistory.tsx +566 -566
  53. package/src/client/components/RunReviewButton.tsx +63 -55
  54. package/src/client/context/GitManagerContext.tsx +92 -92
  55. package/src/client/index.tsx +91 -82
  56. package/src/client/locale.ts +9 -9
  57. package/src/client/promptTemplates.ts +31 -31
  58. package/src/client-v2/ai-context.tsx +99 -0
  59. package/src/client-v2/components/SubtreeSplits.tsx +547 -547
  60. package/src/client-v2/index.tsx +1 -1
  61. package/src/client-v2/locale.ts +8 -8
  62. package/src/client-v2/plugin.tsx +67 -39
  63. package/src/index.ts +2 -2
  64. package/src/locale/en-US.json +307 -297
  65. package/src/locale/vi-VN.json +295 -292
  66. package/src/locale/zh-CN.json +61 -51
  67. package/src/server/__tests__/git-actions.test.ts +24 -24
  68. package/src/server/__tests__/git-security.test.ts +170 -0
  69. package/src/server/__tests__/plugin-url-security.test.ts +17 -17
  70. package/src/server/__tests__/poller-lifecycle.test.ts +71 -0
  71. package/src/server/__tests__/poller.test.ts +37 -37
  72. package/src/server/__tests__/repository-access.test.ts +752 -752
  73. package/src/server/__tests__/review.test.ts +137 -137
  74. package/src/server/__tests__/role-permissions.test.ts +147 -147
  75. package/src/server/__tests__/smoke.test.ts +139 -17
  76. package/src/server/__tests__/subtree.test.ts +85 -85
  77. package/src/server/actions/git-actions.ts +540 -480
  78. package/src/server/actions/gitlab-api.ts +422 -411
  79. package/src/server/actions/poller.ts +39 -27
  80. package/src/server/actions/review.ts +1388 -1369
  81. package/src/server/actions/role-permissions.ts +321 -321
  82. package/src/server/actions/subtree.ts +508 -508
  83. package/src/server/ai-tools.ts +319 -319
  84. package/src/server/collections/gitAccounts.ts +56 -56
  85. package/src/server/collections/gitCodeReviews.ts +199 -199
  86. package/src/server/collections/gitRepositories.ts +87 -87
  87. package/src/server/collections/gitReviewFlows.ts +108 -108
  88. package/src/server/collections/gitSubtreeConfigs.ts +38 -38
  89. package/src/server/collections/gitSubtreeRuns.ts +30 -30
  90. package/src/server/index.ts +2 -2
  91. package/src/server/migrations/20260508000000-add-auto-review-flow-id.ts +29 -29
  92. package/src/server/migrations/20260712000000-add-git-accounts.ts +198 -198
  93. package/src/server/migrations/20260730000000-migrate-legacy-repository-permissions.ts +81 -81
  94. package/src/server/plugin.ts +372 -361
  95. package/src/server/poller.ts +351 -352
  96. package/src/server/repository-access.ts +773 -773
  97. package/src/server/request-method-policy.ts +55 -0
  98. package/src/server/services/__tests__/registry-content-service.test.ts +359 -345
  99. package/src/server/services/registry-content-service.ts +495 -484
  100. package/src/server/utils/__tests__/redact.test.ts +56 -56
  101. package/src/server/utils/__tests__/url-security.test.ts +85 -85
  102. package/src/server/utils/get-repo-account.ts +51 -41
  103. package/src/server/utils/gitlab-url.ts +38 -38
  104. package/src/server/utils/redact.ts +87 -87
  105. package/src/server/utils/url-security.ts +128 -95
  106. package/dist/client/900.acf7d1fa22f95e71.js +0 -10
  107. package/dist/client-v2/434.7a27051db18526c0.js +0 -10
  108. package/dist/client-v2/900.f32b9dc85249fc0a.js +0 -10
@@ -1,386 +1,386 @@
1
- import React, { useEffect, useState, useCallback, useMemo, useRef } from 'react';
2
- import { Tree, Empty, Spin, Typography, Select, Space, Breadcrumb, Input, theme } from 'antd';
3
- import {
4
- FileOutlined,
5
- FileTextOutlined,
6
- CodeOutlined,
7
- FileImageOutlined,
8
- FileMarkdownOutlined,
9
- Html5Outlined,
10
- } from '@ant-design/icons';
11
- import { useApp } from '@nocobase/client-v2';
12
- import { useGitManager } from '../context/GitManagerContext';
13
- import { RunReviewButton } from './RunReviewButton';
14
- import { useT } from '../locale';
15
-
16
- const { Text } = Typography;
17
- const { Search } = Input;
18
- const { useToken } = theme;
19
-
20
- const FILE_ICONS: Record<string, React.ReactNode> = {
21
- ts: <CodeOutlined style={{ color: '#3178c6' }} />,
22
- tsx: <CodeOutlined style={{ color: '#3178c6' }} />,
23
- js: <CodeOutlined style={{ color: '#f7df1e' }} />,
24
- jsx: <CodeOutlined style={{ color: '#f7df1e' }} />,
25
- json: <CodeOutlined style={{ color: '#5b5b5b' }} />,
26
- md: <FileMarkdownOutlined style={{ color: '#083fa1' }} />,
27
- html: <Html5Outlined style={{ color: '#e34c26' }} />,
28
- css: <FileTextOutlined style={{ color: '#563d7c' }} />,
29
- py: <CodeOutlined style={{ color: '#3572A5' }} />,
30
- png: <FileImageOutlined style={{ color: '#a85e32' }} />,
31
- jpg: <FileImageOutlined style={{ color: '#a85e32' }} />,
32
- svg: <FileImageOutlined style={{ color: '#ffb13b' }} />,
33
- };
34
-
35
- function getFileIcon(name: string, type: string) {
36
- if (type === 'tree') return undefined; // use default folder icons
37
- const ext = name.split('.').pop()?.toLowerCase() || '';
38
- return FILE_ICONS[ext] || <FileOutlined />;
39
- }
40
-
41
- function getLanguage(filename: string): string {
42
- const ext = filename.split('.').pop()?.toLowerCase() || '';
43
- const map: Record<string, string> = {
44
- ts: 'typescript',
45
- tsx: 'typescript',
46
- js: 'javascript',
47
- jsx: 'javascript',
48
- json: 'json',
49
- md: 'markdown',
50
- html: 'html',
51
- css: 'css',
52
- scss: 'scss',
53
- py: 'python',
54
- sh: 'bash',
55
- yml: 'yaml',
56
- yaml: 'yaml',
57
- sql: 'sql',
58
- xml: 'xml',
59
- java: 'java',
60
- go: 'go',
61
- rs: 'rust',
62
- rb: 'ruby',
63
- };
64
- return map[ext] || 'text';
65
- }
66
-
67
- interface TreeNode {
68
- key: string;
69
- title: React.ReactNode;
70
- icon: React.ReactNode;
71
- isLeaf: boolean;
72
- children?: TreeNode[];
73
- filePath: string;
74
- fileType: string;
75
- }
76
-
77
- export const FileExplorer: React.FC = () => {
78
- const t = useT();
79
- const { token } = useToken();
80
- const api = useApp().apiClient;
81
- const { selectedRepo, branches: branchList, currentBranch, refreshBranches } = useGitManager();
82
- const [treeData, setTreeData] = useState<TreeNode[]>([]);
83
- const [loading, setLoading] = useState(false);
84
- const [fileContent, setFileContent] = useState<string | null>(null);
85
- const [selectedFile, setSelectedFile] = useState<string | null>(null);
86
- const [selectedFolder, setSelectedFolder] = useState<string | null>(null);
87
- const [currentRef, setCurrentRef] = useState('HEAD');
88
- const [searchText, setSearchText] = useState('');
89
- const [debouncedSearch, setDebouncedSearch] = useState('');
90
- const [contentLoading, setContentLoading] = useState(false);
91
-
92
- const loadTree = useCallback(
93
- async (treePath = '', ref = currentRef) => {
94
- if (!selectedRepo) return [];
95
- try {
96
- const { data } = await api.request({
97
- url: 'gitManager:fileTree',
98
- params: { repositoryId: selectedRepo.id, ref, treePath },
99
- });
100
- const responseData = data?.data || data || [];
101
- const list = Array.isArray(responseData)
102
- ? responseData
103
- : Array.isArray(responseData?.data)
104
- ? responseData.data
105
- : [];
106
-
107
- return list.map((item: any) => ({
108
- key: item.path,
109
- title: (
110
- <Text style={{ fontSize: 13 }}>
111
- {item.name}
112
- {item.type === 'blob' && item.size > 0 && (
113
- <Text type="secondary" style={{ fontSize: 11, marginLeft: 8 }}>
114
- {item.size > 1024 ? `${(item.size / 1024).toFixed(1)}KB` : `${item.size}B`}
115
- </Text>
116
- )}
117
- </Text>
118
- ),
119
- icon: getFileIcon(item.name, item.type),
120
- isLeaf: item.type === 'blob',
121
- filePath: item.path,
122
- fileType: item.type,
123
- }));
124
- } catch (error) {
125
- console.warn('Failed to load file tree:', error);
126
- return [];
127
- }
128
- },
129
- [api, selectedRepo, currentRef],
130
- );
131
-
132
- const loadRoot = useCallback(async () => {
133
- setLoading(true);
134
- try {
135
- const nodes = await loadTree('', currentRef);
136
- setTreeData(nodes);
137
- } finally {
138
- setLoading(false);
139
- }
140
- }, [loadTree, currentRef]);
141
-
142
- useEffect(() => {
143
- if (selectedRepo?.status === 'connected') {
144
- refreshBranches();
145
- setFileContent(null);
146
- setSelectedFile(null);
147
- setSelectedFolder(null);
148
- } else {
149
- setTreeData([]);
150
- }
151
- }, [selectedRepo]);
152
-
153
- // Sync currentRef when branch data arrives
154
- useEffect(() => {
155
- if (currentBranch && currentRef === 'HEAD') {
156
- setCurrentRef(currentBranch);
157
- }
158
- }, [currentBranch]);
159
-
160
- useEffect(() => {
161
- if (selectedRepo?.status === 'connected') {
162
- loadRoot();
163
- }
164
- }, [currentRef, selectedRepo]);
165
-
166
- const onLoadData = async (node: any) => {
167
- if (node.children) return;
168
- const children = await loadTree(node.filePath, currentRef);
169
- setTreeData((prev) => updateTreeData(prev, node.key, children));
170
- };
171
-
172
- const onSelect = async (_: any, info: any) => {
173
- const node = info.node;
174
- if (!node.isLeaf) {
175
- setSelectedFolder((prev) => (prev === node.filePath ? null : node.filePath));
176
- return;
177
- }
178
- setSelectedFolder(null);
179
- setContentLoading(true);
180
- setSelectedFile(node.filePath);
181
- try {
182
- const { data } = await api.request({
183
- url: 'gitManager:fileContent',
184
- params: { repositoryId: selectedRepo.id, ref: currentRef, filePath: node.filePath },
185
- });
186
- const responseData = data?.data?.data || data?.data;
187
- setFileContent(responseData?.content || '');
188
- } catch {
189
- setFileContent('// Failed to load file content');
190
- } finally {
191
- setContentLoading(false);
192
- }
193
- };
194
-
195
- // Debounce search text by 300ms
196
- const debounceRef = useRef<ReturnType<typeof setTimeout>>();
197
- useEffect(() => {
198
- debounceRef.current = setTimeout(() => setDebouncedSearch(searchText), 300);
199
- return () => clearTimeout(debounceRef.current);
200
- }, [searchText]);
201
-
202
- const folderTarget = useMemo(
203
- () => ({
204
- type: 'folder' as const,
205
- repositoryId: selectedRepo?.id ?? 0,
206
- folderPath: selectedFolder ?? '',
207
- ref: currentRef,
208
- }),
209
- [selectedRepo?.id, selectedFolder, currentRef],
210
- );
211
-
212
- if (!selectedRepo) {
213
- return <Empty description={t('No repository selected')} />;
214
- }
215
-
216
- if (selectedRepo.status !== 'connected') {
217
- return <Empty description={t('Repository not cloned yet')} />;
218
- }
219
-
220
- const filteredTree = debouncedSearch ? filterTree(treeData, debouncedSearch.toLowerCase()) : treeData;
221
-
222
- return (
223
- <div style={{ display: 'flex', height: 'calc(100vh - 280px)', gap: 0 }}>
224
- {/* Left sidebar - file tree */}
225
- <div
226
- style={{
227
- width: 320,
228
- minWidth: 280,
229
- borderRight: `1px solid ${token.colorBorderSecondary}`,
230
- display: 'flex',
231
- flexDirection: 'column',
232
- background: token.colorBgContainer,
233
- }}
234
- >
235
- <div style={{ padding: '8px 12px', borderBottom: `1px solid ${token.colorBorderSecondary}` }}>
236
- <Space direction="vertical" style={{ width: '100%' }} size={6}>
237
- <Select
238
- size="small"
239
- style={{ width: '100%' }}
240
- value={currentRef}
241
- onChange={(val) => {
242
- setCurrentRef(val);
243
- setFileContent(null);
244
- setSelectedFile(null);
245
- setSelectedFolder(null);
246
- }}
247
- options={branchList.map((b) => ({ label: b, value: b }))}
248
- placeholder="Branch"
249
- />
250
- <Search
251
- size="small"
252
- placeholder="Filter files..."
253
- allowClear
254
- onChange={(e) => setSearchText(e.target.value)}
255
- />
256
- <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
257
- <Text
258
- type="secondary"
259
- ellipsis
260
- title={selectedFolder || t('Entire repository')}
261
- style={{ flex: 1, minWidth: 0, fontSize: 12 }}
262
- >
263
- {selectedFolder || t('Entire repository')}
264
- </Text>
265
- <RunReviewButton target={folderTarget} />
266
- </div>
267
- </Space>
268
- </div>
269
- <div style={{ flex: 1, overflow: 'auto', padding: '4px 0' }}>
270
- {loading ? (
271
- <div style={{ textAlign: 'center', padding: 40 }}>
272
- <Spin />
273
- </div>
274
- ) : (
275
- <Tree
276
- showIcon
277
- treeData={filteredTree}
278
- loadData={onLoadData}
279
- onSelect={onSelect}
280
- selectedKeys={selectedFile ? [selectedFile] : selectedFolder ? [selectedFolder] : []}
281
- style={{ fontSize: 13 }}
282
- blockNode
283
- />
284
- )}
285
- </div>
286
- </div>
287
-
288
- {/* Right panel - file content */}
289
- <div style={{ flex: 1, display: 'flex', flexDirection: 'column', background: token.colorBgLayout }}>
290
- {selectedFile ? (
291
- <>
292
- <div
293
- style={{
294
- padding: '6px 16px',
295
- borderBottom: `1px solid ${token.colorBorderSecondary}`,
296
- background: token.colorBgContainer,
297
- display: 'flex',
298
- alignItems: 'center',
299
- gap: 8,
300
- }}
301
- >
302
- <Breadcrumb
303
- items={selectedFile.split('/').map((part, i, arr) => ({
304
- title: i === arr.length - 1 ? <Text strong>{part}</Text> : part,
305
- }))}
306
- />
307
- <Text type="secondary" style={{ marginLeft: 'auto', fontSize: 12 }}>
308
- {getLanguage(selectedFile)}
309
- </Text>
310
- </div>
311
- <div style={{ flex: 1, overflow: 'auto' }}>
312
- {contentLoading ? (
313
- <div style={{ textAlign: 'center', padding: 40 }}>
314
- <Spin />
315
- </div>
316
- ) : (
317
- <pre
318
- style={{
319
- margin: 0,
320
- padding: 16,
321
- fontSize: 13,
322
- lineHeight: 1.6,
323
- fontFamily: "'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace",
324
- whiteSpace: 'pre-wrap',
325
- wordBreak: 'break-all',
326
- background: token.colorBgContainer,
327
- minHeight: '100%',
328
- }}
329
- >
330
- {(fileContent || '').split('\n').map((line, i) => (
331
- <div key={i} style={{ display: 'flex' }}>
332
- <span
333
- style={{
334
- display: 'inline-block',
335
- width: 50,
336
- textAlign: 'right',
337
- paddingRight: 16,
338
- color: token.colorTextQuaternary,
339
- userSelect: 'none',
340
- flexShrink: 0,
341
- }}
342
- >
343
- {i + 1}
344
- </span>
345
- <span style={{ flex: 1 }}>{line || ' '}</span>
346
- </div>
347
- ))}
348
- </pre>
349
- )}
350
- </div>
351
- </>
352
- ) : (
353
- <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', height: '100%' }}>
354
- <Text type="secondary">Select a file to view its content</Text>
355
- </div>
356
- )}
357
- </div>
358
- </div>
359
- );
360
- };
361
-
362
- function updateTreeData(list: TreeNode[], key: string, children: TreeNode[]): TreeNode[] {
363
- return list.map((node) => {
364
- if (node.key === key) {
365
- return { ...node, children };
366
- }
367
- if (node.children) {
368
- return { ...node, children: updateTreeData(node.children, key, children) };
369
- }
370
- return node;
371
- });
372
- }
373
-
374
- function filterTree(nodes: TreeNode[], text: string): TreeNode[] {
375
- return nodes
376
- .map((node) => {
377
- if (node.children) {
378
- const filtered = filterTree(node.children, text);
379
- if (filtered.length > 0) return { ...node, children: filtered };
380
- }
381
- const name = (node.filePath || '').toLowerCase();
382
- if (name.includes(text)) return node;
383
- return null;
384
- })
385
- .filter(Boolean) as TreeNode[];
386
- }
1
+ import React, { useEffect, useState, useCallback, useMemo, useRef } from 'react';
2
+ import { Tree, Empty, Spin, Typography, Select, Space, Breadcrumb, Input, theme } from 'antd';
3
+ import {
4
+ FileOutlined,
5
+ FileTextOutlined,
6
+ CodeOutlined,
7
+ FileImageOutlined,
8
+ FileMarkdownOutlined,
9
+ Html5Outlined,
10
+ } from '@ant-design/icons';
11
+ import { useApp } from '@nocobase/client-v2';
12
+ import { useGitManager } from '../context/GitManagerContext';
13
+ import { RunReviewButton } from './RunReviewButton';
14
+ import { useT } from '../locale';
15
+
16
+ const { Text } = Typography;
17
+ const { Search } = Input;
18
+ const { useToken } = theme;
19
+
20
+ const FILE_ICONS: Record<string, React.ReactNode> = {
21
+ ts: <CodeOutlined style={{ color: '#3178c6' }} />,
22
+ tsx: <CodeOutlined style={{ color: '#3178c6' }} />,
23
+ js: <CodeOutlined style={{ color: '#f7df1e' }} />,
24
+ jsx: <CodeOutlined style={{ color: '#f7df1e' }} />,
25
+ json: <CodeOutlined style={{ color: '#5b5b5b' }} />,
26
+ md: <FileMarkdownOutlined style={{ color: '#083fa1' }} />,
27
+ html: <Html5Outlined style={{ color: '#e34c26' }} />,
28
+ css: <FileTextOutlined style={{ color: '#563d7c' }} />,
29
+ py: <CodeOutlined style={{ color: '#3572A5' }} />,
30
+ png: <FileImageOutlined style={{ color: '#a85e32' }} />,
31
+ jpg: <FileImageOutlined style={{ color: '#a85e32' }} />,
32
+ svg: <FileImageOutlined style={{ color: '#ffb13b' }} />,
33
+ };
34
+
35
+ function getFileIcon(name: string, type: string) {
36
+ if (type === 'tree') return undefined; // use default folder icons
37
+ const ext = name.split('.').pop()?.toLowerCase() || '';
38
+ return FILE_ICONS[ext] || <FileOutlined />;
39
+ }
40
+
41
+ function getLanguage(filename: string): string {
42
+ const ext = filename.split('.').pop()?.toLowerCase() || '';
43
+ const map: Record<string, string> = {
44
+ ts: 'typescript',
45
+ tsx: 'typescript',
46
+ js: 'javascript',
47
+ jsx: 'javascript',
48
+ json: 'json',
49
+ md: 'markdown',
50
+ html: 'html',
51
+ css: 'css',
52
+ scss: 'scss',
53
+ py: 'python',
54
+ sh: 'bash',
55
+ yml: 'yaml',
56
+ yaml: 'yaml',
57
+ sql: 'sql',
58
+ xml: 'xml',
59
+ java: 'java',
60
+ go: 'go',
61
+ rs: 'rust',
62
+ rb: 'ruby',
63
+ };
64
+ return map[ext] || 'text';
65
+ }
66
+
67
+ interface TreeNode {
68
+ key: string;
69
+ title: React.ReactNode;
70
+ icon: React.ReactNode;
71
+ isLeaf: boolean;
72
+ children?: TreeNode[];
73
+ filePath: string;
74
+ fileType: string;
75
+ }
76
+
77
+ export const FileExplorer: React.FC = () => {
78
+ const t = useT();
79
+ const { token } = useToken();
80
+ const api = useApp().apiClient;
81
+ const { selectedRepo, branches: branchList, currentBranch, refreshBranches } = useGitManager();
82
+ const [treeData, setTreeData] = useState<TreeNode[]>([]);
83
+ const [loading, setLoading] = useState(false);
84
+ const [fileContent, setFileContent] = useState<string | null>(null);
85
+ const [selectedFile, setSelectedFile] = useState<string | null>(null);
86
+ const [selectedFolder, setSelectedFolder] = useState<string | null>(null);
87
+ const [currentRef, setCurrentRef] = useState('HEAD');
88
+ const [searchText, setSearchText] = useState('');
89
+ const [debouncedSearch, setDebouncedSearch] = useState('');
90
+ const [contentLoading, setContentLoading] = useState(false);
91
+
92
+ const loadTree = useCallback(
93
+ async (treePath = '', ref = currentRef) => {
94
+ if (!selectedRepo) return [];
95
+ try {
96
+ const { data } = await api.request({
97
+ url: 'gitManager:fileTree',
98
+ params: { repositoryId: selectedRepo.id, ref, treePath },
99
+ });
100
+ const responseData = data?.data || data || [];
101
+ const list = Array.isArray(responseData)
102
+ ? responseData
103
+ : Array.isArray(responseData?.data)
104
+ ? responseData.data
105
+ : [];
106
+
107
+ return list.map((item: any) => ({
108
+ key: item.path,
109
+ title: (
110
+ <Text style={{ fontSize: 13 }}>
111
+ {item.name}
112
+ {item.type === 'blob' && item.size > 0 && (
113
+ <Text type="secondary" style={{ fontSize: 11, marginLeft: 8 }}>
114
+ {item.size > 1024 ? `${(item.size / 1024).toFixed(1)}KB` : `${item.size}B`}
115
+ </Text>
116
+ )}
117
+ </Text>
118
+ ),
119
+ icon: getFileIcon(item.name, item.type),
120
+ isLeaf: item.type === 'blob',
121
+ filePath: item.path,
122
+ fileType: item.type,
123
+ }));
124
+ } catch (error) {
125
+ console.warn('Failed to load file tree:', error);
126
+ return [];
127
+ }
128
+ },
129
+ [api, selectedRepo, currentRef],
130
+ );
131
+
132
+ const loadRoot = useCallback(async () => {
133
+ setLoading(true);
134
+ try {
135
+ const nodes = await loadTree('', currentRef);
136
+ setTreeData(nodes);
137
+ } finally {
138
+ setLoading(false);
139
+ }
140
+ }, [loadTree, currentRef]);
141
+
142
+ useEffect(() => {
143
+ if (selectedRepo?.status === 'connected') {
144
+ refreshBranches();
145
+ setFileContent(null);
146
+ setSelectedFile(null);
147
+ setSelectedFolder(null);
148
+ } else {
149
+ setTreeData([]);
150
+ }
151
+ }, [selectedRepo]);
152
+
153
+ // Sync currentRef when branch data arrives
154
+ useEffect(() => {
155
+ if (currentBranch && currentRef === 'HEAD') {
156
+ setCurrentRef(currentBranch);
157
+ }
158
+ }, [currentBranch]);
159
+
160
+ useEffect(() => {
161
+ if (selectedRepo?.status === 'connected') {
162
+ loadRoot();
163
+ }
164
+ }, [currentRef, selectedRepo]);
165
+
166
+ const onLoadData = async (node: any) => {
167
+ if (node.children) return;
168
+ const children = await loadTree(node.filePath, currentRef);
169
+ setTreeData((prev) => updateTreeData(prev, node.key, children));
170
+ };
171
+
172
+ const onSelect = async (_: any, info: any) => {
173
+ const node = info.node;
174
+ if (!node.isLeaf) {
175
+ setSelectedFolder((prev) => (prev === node.filePath ? null : node.filePath));
176
+ return;
177
+ }
178
+ setSelectedFolder(null);
179
+ setContentLoading(true);
180
+ setSelectedFile(node.filePath);
181
+ try {
182
+ const { data } = await api.request({
183
+ url: 'gitManager:fileContent',
184
+ params: { repositoryId: selectedRepo.id, ref: currentRef, filePath: node.filePath },
185
+ });
186
+ const responseData = data?.data?.data || data?.data;
187
+ setFileContent(responseData?.content || '');
188
+ } catch {
189
+ setFileContent('// Failed to load file content');
190
+ } finally {
191
+ setContentLoading(false);
192
+ }
193
+ };
194
+
195
+ // Debounce search text by 300ms
196
+ const debounceRef = useRef<ReturnType<typeof setTimeout>>();
197
+ useEffect(() => {
198
+ debounceRef.current = setTimeout(() => setDebouncedSearch(searchText), 300);
199
+ return () => clearTimeout(debounceRef.current);
200
+ }, [searchText]);
201
+
202
+ const folderTarget = useMemo(
203
+ () => ({
204
+ type: 'folder' as const,
205
+ repositoryId: selectedRepo?.id ?? 0,
206
+ folderPath: selectedFolder ?? '',
207
+ ref: currentRef,
208
+ }),
209
+ [selectedRepo?.id, selectedFolder, currentRef],
210
+ );
211
+
212
+ if (!selectedRepo) {
213
+ return <Empty description={t('No repository selected')} />;
214
+ }
215
+
216
+ if (selectedRepo.status !== 'connected') {
217
+ return <Empty description={t('Repository not cloned yet')} />;
218
+ }
219
+
220
+ const filteredTree = debouncedSearch ? filterTree(treeData, debouncedSearch.toLowerCase()) : treeData;
221
+
222
+ return (
223
+ <div style={{ display: 'flex', height: 'calc(100vh - 280px)', gap: 0 }}>
224
+ {/* Left sidebar - file tree */}
225
+ <div
226
+ style={{
227
+ width: 320,
228
+ minWidth: 280,
229
+ borderRight: `1px solid ${token.colorBorderSecondary}`,
230
+ display: 'flex',
231
+ flexDirection: 'column',
232
+ background: token.colorBgContainer,
233
+ }}
234
+ >
235
+ <div style={{ padding: '8px 12px', borderBottom: `1px solid ${token.colorBorderSecondary}` }}>
236
+ <Space direction="vertical" style={{ width: '100%' }} size={6}>
237
+ <Select
238
+ size="small"
239
+ style={{ width: '100%' }}
240
+ value={currentRef}
241
+ onChange={(val) => {
242
+ setCurrentRef(val);
243
+ setFileContent(null);
244
+ setSelectedFile(null);
245
+ setSelectedFolder(null);
246
+ }}
247
+ options={branchList.map((b) => ({ label: b, value: b }))}
248
+ placeholder="Branch"
249
+ />
250
+ <Search
251
+ size="small"
252
+ placeholder="Filter files..."
253
+ allowClear
254
+ onChange={(e) => setSearchText(e.target.value)}
255
+ />
256
+ <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
257
+ <Text
258
+ type="secondary"
259
+ ellipsis
260
+ title={selectedFolder || t('Entire repository')}
261
+ style={{ flex: 1, minWidth: 0, fontSize: 12 }}
262
+ >
263
+ {selectedFolder || t('Entire repository')}
264
+ </Text>
265
+ <RunReviewButton target={folderTarget} />
266
+ </div>
267
+ </Space>
268
+ </div>
269
+ <div style={{ flex: 1, overflow: 'auto', padding: '4px 0' }}>
270
+ {loading ? (
271
+ <div style={{ textAlign: 'center', padding: 40 }}>
272
+ <Spin />
273
+ </div>
274
+ ) : (
275
+ <Tree
276
+ showIcon
277
+ treeData={filteredTree}
278
+ loadData={onLoadData}
279
+ onSelect={onSelect}
280
+ selectedKeys={selectedFile ? [selectedFile] : selectedFolder ? [selectedFolder] : []}
281
+ style={{ fontSize: 13 }}
282
+ blockNode
283
+ />
284
+ )}
285
+ </div>
286
+ </div>
287
+
288
+ {/* Right panel - file content */}
289
+ <div style={{ flex: 1, display: 'flex', flexDirection: 'column', background: token.colorBgLayout }}>
290
+ {selectedFile ? (
291
+ <>
292
+ <div
293
+ style={{
294
+ padding: '6px 16px',
295
+ borderBottom: `1px solid ${token.colorBorderSecondary}`,
296
+ background: token.colorBgContainer,
297
+ display: 'flex',
298
+ alignItems: 'center',
299
+ gap: 8,
300
+ }}
301
+ >
302
+ <Breadcrumb
303
+ items={selectedFile.split('/').map((part, i, arr) => ({
304
+ title: i === arr.length - 1 ? <Text strong>{part}</Text> : part,
305
+ }))}
306
+ />
307
+ <Text type="secondary" style={{ marginLeft: 'auto', fontSize: 12 }}>
308
+ {getLanguage(selectedFile)}
309
+ </Text>
310
+ </div>
311
+ <div style={{ flex: 1, overflow: 'auto' }}>
312
+ {contentLoading ? (
313
+ <div style={{ textAlign: 'center', padding: 40 }}>
314
+ <Spin />
315
+ </div>
316
+ ) : (
317
+ <pre
318
+ style={{
319
+ margin: 0,
320
+ padding: 16,
321
+ fontSize: 13,
322
+ lineHeight: 1.6,
323
+ fontFamily: "'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace",
324
+ whiteSpace: 'pre-wrap',
325
+ wordBreak: 'break-all',
326
+ background: token.colorBgContainer,
327
+ minHeight: '100%',
328
+ }}
329
+ >
330
+ {(fileContent || '').split('\n').map((line, i) => (
331
+ <div key={i} style={{ display: 'flex' }}>
332
+ <span
333
+ style={{
334
+ display: 'inline-block',
335
+ width: 50,
336
+ textAlign: 'right',
337
+ paddingRight: 16,
338
+ color: token.colorTextQuaternary,
339
+ userSelect: 'none',
340
+ flexShrink: 0,
341
+ }}
342
+ >
343
+ {i + 1}
344
+ </span>
345
+ <span style={{ flex: 1 }}>{line || ' '}</span>
346
+ </div>
347
+ ))}
348
+ </pre>
349
+ )}
350
+ </div>
351
+ </>
352
+ ) : (
353
+ <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', height: '100%' }}>
354
+ <Text type="secondary">Select a file to view its content</Text>
355
+ </div>
356
+ )}
357
+ </div>
358
+ </div>
359
+ );
360
+ };
361
+
362
+ function updateTreeData(list: TreeNode[], key: string, children: TreeNode[]): TreeNode[] {
363
+ return list.map((node) => {
364
+ if (node.key === key) {
365
+ return { ...node, children };
366
+ }
367
+ if (node.children) {
368
+ return { ...node, children: updateTreeData(node.children, key, children) };
369
+ }
370
+ return node;
371
+ });
372
+ }
373
+
374
+ function filterTree(nodes: TreeNode[], text: string): TreeNode[] {
375
+ return nodes
376
+ .map((node) => {
377
+ if (node.children) {
378
+ const filtered = filterTree(node.children, text);
379
+ if (filtered.length > 0) return { ...node, children: filtered };
380
+ }
381
+ const name = (node.filePath || '').toLowerCase();
382
+ if (name.includes(text)) return node;
383
+ return null;
384
+ })
385
+ .filter(Boolean) as TreeNode[];
386
+ }