plugin-git-manager 1.2.26 → 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.
- package/README.md +133 -108
- package/client-v2.d.ts +2 -2
- package/client-v2.js +1 -1
- package/client.d.ts +3 -3
- package/client.js +1 -1
- package/dist/client/{326.90c276058682b536.js → 313.d38fc1d40c4589b9.js} +1 -1
- package/dist/client/900.a48beac7e2ebee7d.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/156.445366026c1cc9a8.js +10 -0
- package/dist/client-v2/{326.42b7b53651ffab3a.js → 313.3c867179c3a1e817.js} +1 -1
- package/dist/client-v2/434.19c7579c06b9077c.js +10 -0
- package/dist/client-v2/900.e6155002a9c97e7f.js +10 -0
- package/dist/client-v2/928.bba701b5a1ece58e.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +9 -8
- package/dist/locale/en-US.json +307 -297
- package/dist/locale/vi-VN.json +295 -292
- package/dist/locale/zh-CN.json +61 -51
- package/dist/node_modules/simple-git/dist/cjs/index.js +25 -25
- package/dist/node_modules/simple-git/package.json +1 -1
- package/dist/node_modules/zod/index.cjs +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/actions/git-actions.js +90 -36
- package/dist/server/actions/gitlab-api.js +4 -2
- package/dist/server/actions/poller.js +5 -2
- package/dist/server/actions/review.js +20 -10
- package/dist/server/plugin.js +6 -4
- package/dist/server/poller.js +46 -45
- package/dist/server/request-method-policy.js +75 -0
- package/dist/server/services/registry-content-service.js +23 -10
- package/dist/server/utils/get-repo-account.js +3 -2
- package/dist/server/utils/url-security.js +24 -0
- package/package.json +61 -43
- package/server.d.ts +2 -2
- package/server.js +1 -1
- package/src/client/__tests__/RunReviewButton.test.tsx +73 -0
- package/src/client/ai-context.tsx +114 -114
- package/src/client/components/AIEmployeeSelect.tsx +63 -63
- package/src/client/components/CommitHistory.tsx +374 -374
- package/src/client/components/FileExplorer.tsx +386 -386
- package/src/client/components/GitAccounts.tsx +179 -179
- package/src/client/components/GitManagerSettings.tsx +160 -160
- package/src/client/components/GitOperations.tsx +220 -220
- package/src/client/components/LLMModelSelect.tsx +63 -63
- package/src/client/components/LLMServiceSelect.tsx +58 -58
- package/src/client/components/MarkdownView.tsx +80 -80
- package/src/client/components/MergeRequests.tsx +790 -790
- package/src/client/components/PollingStatus.tsx +225 -225
- package/src/client/components/RepositoryConfig.tsx +335 -335
- package/src/client/components/RepositoryPermissions.tsx +123 -123
- package/src/client/components/ReviewFlows.tsx +303 -303
- package/src/client/components/ReviewHistory.tsx +566 -566
- package/src/client/components/RunReviewButton.tsx +63 -55
- package/src/client/context/GitManagerContext.tsx +92 -92
- package/src/client/index.tsx +91 -82
- package/src/client/locale.ts +9 -9
- package/src/client/promptTemplates.ts +31 -31
- package/src/client-v2/ai-context.tsx +99 -0
- package/src/client-v2/components/SubtreeSplits.tsx +547 -547
- package/src/client-v2/index.tsx +1 -1
- package/src/client-v2/locale.ts +8 -8
- package/src/client-v2/plugin.tsx +67 -39
- package/src/index.ts +2 -2
- package/src/locale/en-US.json +307 -297
- package/src/locale/vi-VN.json +295 -292
- package/src/locale/zh-CN.json +61 -51
- package/src/server/__tests__/git-actions.test.ts +24 -24
- package/src/server/__tests__/git-security.test.ts +170 -0
- package/src/server/__tests__/plugin-url-security.test.ts +17 -17
- package/src/server/__tests__/poller-lifecycle.test.ts +71 -0
- package/src/server/__tests__/poller.test.ts +37 -37
- package/src/server/__tests__/repository-access.test.ts +752 -752
- package/src/server/__tests__/review.test.ts +137 -137
- package/src/server/__tests__/role-permissions.test.ts +147 -147
- package/src/server/__tests__/smoke.test.ts +139 -17
- package/src/server/__tests__/subtree.test.ts +85 -85
- package/src/server/actions/git-actions.ts +540 -480
- package/src/server/actions/gitlab-api.ts +422 -411
- package/src/server/actions/poller.ts +39 -27
- package/src/server/actions/review.ts +1388 -1369
- package/src/server/actions/role-permissions.ts +321 -321
- package/src/server/actions/subtree.ts +508 -508
- package/src/server/ai-tools.ts +319 -319
- package/src/server/collections/gitAccounts.ts +56 -56
- package/src/server/collections/gitCodeReviews.ts +199 -199
- package/src/server/collections/gitRepositories.ts +87 -87
- package/src/server/collections/gitReviewFlows.ts +108 -108
- package/src/server/collections/gitSubtreeConfigs.ts +38 -38
- package/src/server/collections/gitSubtreeRuns.ts +30 -30
- package/src/server/index.ts +2 -2
- package/src/server/migrations/20260508000000-add-auto-review-flow-id.ts +29 -29
- package/src/server/migrations/20260712000000-add-git-accounts.ts +198 -198
- package/src/server/migrations/20260730000000-migrate-legacy-repository-permissions.ts +81 -81
- package/src/server/plugin.ts +372 -361
- package/src/server/poller.ts +351 -352
- package/src/server/repository-access.ts +773 -773
- package/src/server/request-method-policy.ts +55 -0
- package/src/server/services/__tests__/registry-content-service.test.ts +359 -345
- package/src/server/services/registry-content-service.ts +33 -11
- package/src/server/utils/__tests__/redact.test.ts +56 -56
- package/src/server/utils/__tests__/url-security.test.ts +85 -85
- package/src/server/utils/get-repo-account.ts +51 -41
- package/src/server/utils/gitlab-url.ts +38 -38
- package/src/server/utils/redact.ts +87 -87
- package/src/server/utils/url-security.ts +128 -95
- package/dist/client/900.acf7d1fa22f95e71.js +0 -10
- package/dist/client-v2/434.7a27051db18526c0.js +0 -10
- package/dist/client-v2/900.f32b9dc85249fc0a.js +0 -10
|
@@ -1,374 +1,374 @@
|
|
|
1
|
-
import React, { useEffect, useState, useCallback, memo } from 'react';
|
|
2
|
-
import { Table, Empty, Spin, Typography, Tag, Drawer, List, Button, Space, Select, Input, theme } from 'antd';
|
|
3
|
-
import {
|
|
4
|
-
BranchesOutlined,
|
|
5
|
-
UserOutlined,
|
|
6
|
-
ClockCircleOutlined,
|
|
7
|
-
FileTextOutlined,
|
|
8
|
-
PlusCircleOutlined,
|
|
9
|
-
EditOutlined,
|
|
10
|
-
DeleteOutlined,
|
|
11
|
-
DiffOutlined,
|
|
12
|
-
} from '@ant-design/icons';
|
|
13
|
-
import { useApp } from '@nocobase/client-v2';
|
|
14
|
-
import { useGitManager } from '../context/GitManagerContext';
|
|
15
|
-
import { RunReviewButton } from './RunReviewButton';
|
|
16
|
-
import { useT } from '../locale';
|
|
17
|
-
|
|
18
|
-
const { Text } = Typography;
|
|
19
|
-
const { useToken } = theme;
|
|
20
|
-
|
|
21
|
-
const STATUS_COLORS: Record<string, { color: string; icon: React.ReactNode; label: string }> = {
|
|
22
|
-
A: { color: 'green', icon: <PlusCircleOutlined />, label: 'Added' },
|
|
23
|
-
M: { color: 'blue', icon: <EditOutlined />, label: 'Modified' },
|
|
24
|
-
D: { color: 'red', icon: <DeleteOutlined />, label: 'Deleted' },
|
|
25
|
-
R: { color: 'orange', icon: <EditOutlined />, label: 'Renamed' },
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export const CommitHistory: React.FC = () => {
|
|
29
|
-
const t = useT();
|
|
30
|
-
const { token } = useToken();
|
|
31
|
-
const api = useApp().apiClient;
|
|
32
|
-
const { selectedRepo, branches: branchList, currentBranch } = useGitManager();
|
|
33
|
-
const [commits, setCommits] = useState<any[]>([]);
|
|
34
|
-
const [loading, setLoading] = useState(false);
|
|
35
|
-
const [selectedCommit, setSelectedCommit] = useState<any>(null);
|
|
36
|
-
const [commitDetail, setCommitDetail] = useState<any>(null);
|
|
37
|
-
const [detailLoading, setDetailLoading] = useState(false);
|
|
38
|
-
const [diffContent, setDiffContent] = useState<string | null>(null);
|
|
39
|
-
const [diffFile, setDiffFile] = useState<string | null>(null);
|
|
40
|
-
const [searchKeyword, setSearchKeyword] = useState('');
|
|
41
|
-
|
|
42
|
-
const loadHistory = useCallback(async () => {
|
|
43
|
-
if (!selectedRepo) return;
|
|
44
|
-
setLoading(true);
|
|
45
|
-
try {
|
|
46
|
-
const { data } = await api.request({
|
|
47
|
-
url: 'gitManager:log',
|
|
48
|
-
params: { repositoryId: selectedRepo.id, maxCount: 100 },
|
|
49
|
-
});
|
|
50
|
-
const responseData = data?.data?.data || data?.data;
|
|
51
|
-
setCommits(responseData?.all || []);
|
|
52
|
-
} catch (error) {
|
|
53
|
-
console.warn('Failed to load commit history:', error);
|
|
54
|
-
setCommits([]);
|
|
55
|
-
} finally {
|
|
56
|
-
setLoading(false);
|
|
57
|
-
}
|
|
58
|
-
}, [api, selectedRepo]);
|
|
59
|
-
|
|
60
|
-
useEffect(() => {
|
|
61
|
-
if (selectedRepo?.status === 'connected') {
|
|
62
|
-
loadHistory();
|
|
63
|
-
} else {
|
|
64
|
-
setCommits([]);
|
|
65
|
-
}
|
|
66
|
-
}, [selectedRepo]);
|
|
67
|
-
|
|
68
|
-
const filteredCommits = commits.filter((commit) => {
|
|
69
|
-
const keyword = searchKeyword.trim().toLowerCase();
|
|
70
|
-
if (!keyword) return true;
|
|
71
|
-
return String(commit.message || commit.subject || commit.body || '')
|
|
72
|
-
.toLowerCase()
|
|
73
|
-
.includes(keyword);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
const openCommitDetail = async (commit: any) => {
|
|
77
|
-
setSelectedCommit(commit);
|
|
78
|
-
setDetailLoading(true);
|
|
79
|
-
setDiffContent(null);
|
|
80
|
-
setDiffFile(null);
|
|
81
|
-
try {
|
|
82
|
-
const { data } = await api.request({
|
|
83
|
-
url: 'gitManager:commitDetail',
|
|
84
|
-
params: { repositoryId: selectedRepo.id, commitHash: commit.hash },
|
|
85
|
-
});
|
|
86
|
-
const responseData = data?.data?.data || data?.data;
|
|
87
|
-
setCommitDetail(responseData);
|
|
88
|
-
} catch {
|
|
89
|
-
setCommitDetail(null);
|
|
90
|
-
} finally {
|
|
91
|
-
setDetailLoading(false);
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const loadFileDiff = async (commitHash: string, file: string) => {
|
|
96
|
-
setDiffFile(file);
|
|
97
|
-
try {
|
|
98
|
-
const { data } = await api.request({
|
|
99
|
-
url: 'gitManager:diff',
|
|
100
|
-
params: { repositoryId: selectedRepo.id, commitHash, file },
|
|
101
|
-
});
|
|
102
|
-
const responseData = data?.data?.data || data?.data;
|
|
103
|
-
setDiffContent(responseData || '');
|
|
104
|
-
} catch {
|
|
105
|
-
setDiffContent('// Failed to load diff');
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
if (!selectedRepo) {
|
|
110
|
-
return <Empty description={t('No repository selected')} />;
|
|
111
|
-
}
|
|
112
|
-
if (selectedRepo.status !== 'connected') {
|
|
113
|
-
return <Empty description={t('Repository not cloned yet')} />;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const columns = [
|
|
117
|
-
{
|
|
118
|
-
title: '',
|
|
119
|
-
key: 'graph',
|
|
120
|
-
width: 40,
|
|
121
|
-
render: (_: any, __: any, index: number) => (
|
|
122
|
-
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', height: '100%' }}>
|
|
123
|
-
<div
|
|
124
|
-
style={{
|
|
125
|
-
width: 10,
|
|
126
|
-
height: 10,
|
|
127
|
-
borderRadius: '50%',
|
|
128
|
-
background: index === 0 ? token.colorPrimary : token.colorBorder,
|
|
129
|
-
border: `2px solid ${index === 0 ? token.colorPrimary : token.colorBorder}`,
|
|
130
|
-
zIndex: 1,
|
|
131
|
-
}}
|
|
132
|
-
/>
|
|
133
|
-
</div>
|
|
134
|
-
),
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
title: t('Message'),
|
|
138
|
-
dataIndex: 'message',
|
|
139
|
-
key: 'message',
|
|
140
|
-
render: (text: string, record: any) => (
|
|
141
|
-
<div>
|
|
142
|
-
<Text strong style={{ fontSize: 13 }}>
|
|
143
|
-
{text}
|
|
144
|
-
</Text>
|
|
145
|
-
<div style={{ marginTop: 2 }}>
|
|
146
|
-
<Text type="secondary" style={{ fontSize: 12 }}>
|
|
147
|
-
<UserOutlined style={{ marginRight: 4 }} />
|
|
148
|
-
{record.author_name}
|
|
149
|
-
<span style={{ margin: '0 8px' }}>·</span>
|
|
150
|
-
<ClockCircleOutlined style={{ marginRight: 4 }} />
|
|
151
|
-
{formatDate(record.date)}
|
|
152
|
-
</Text>
|
|
153
|
-
</div>
|
|
154
|
-
</div>
|
|
155
|
-
),
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
title: 'Hash',
|
|
159
|
-
dataIndex: 'hash',
|
|
160
|
-
key: 'hash',
|
|
161
|
-
width: 100,
|
|
162
|
-
render: (hash: string) => (
|
|
163
|
-
<Text code copyable style={{ fontSize: 12 }}>
|
|
164
|
-
{hash?.substring(0, 7)}
|
|
165
|
-
</Text>
|
|
166
|
-
),
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
title: '',
|
|
170
|
-
key: 'action',
|
|
171
|
-
width: 80,
|
|
172
|
-
render: (_: any, record: any) => (
|
|
173
|
-
<Button size="small" icon={<DiffOutlined />} onClick={() => openCommitDetail(record)}>
|
|
174
|
-
Detail
|
|
175
|
-
</Button>
|
|
176
|
-
),
|
|
177
|
-
},
|
|
178
|
-
];
|
|
179
|
-
|
|
180
|
-
return (
|
|
181
|
-
<div>
|
|
182
|
-
<div style={{ marginBottom: 12, display: 'flex', alignItems: 'center', gap: 12 }}>
|
|
183
|
-
<BranchesOutlined />
|
|
184
|
-
<Select
|
|
185
|
-
size="small"
|
|
186
|
-
style={{ width: 200 }}
|
|
187
|
-
value={currentBranch}
|
|
188
|
-
options={branchList.map((b) => ({ label: b, value: b }))}
|
|
189
|
-
disabled
|
|
190
|
-
/>
|
|
191
|
-
<Input.Search
|
|
192
|
-
allowClear
|
|
193
|
-
size="small"
|
|
194
|
-
style={{ width: 280 }}
|
|
195
|
-
placeholder={t('Search commit title or message')}
|
|
196
|
-
value={searchKeyword}
|
|
197
|
-
onChange={(event) => setSearchKeyword(event.target.value)}
|
|
198
|
-
/>
|
|
199
|
-
<Text type="secondary">{filteredCommits.length} commits</Text>
|
|
200
|
-
</div>
|
|
201
|
-
|
|
202
|
-
{loading ? (
|
|
203
|
-
<Spin />
|
|
204
|
-
) : (
|
|
205
|
-
<Table
|
|
206
|
-
dataSource={filteredCommits}
|
|
207
|
-
columns={columns}
|
|
208
|
-
rowKey="hash"
|
|
209
|
-
size="small"
|
|
210
|
-
pagination={{ pageSize: 30, showSizeChanger: true }}
|
|
211
|
-
onRow={(record) => ({ style: { cursor: 'pointer' }, onClick: () => openCommitDetail(record) })}
|
|
212
|
-
/>
|
|
213
|
-
)}
|
|
214
|
-
|
|
215
|
-
<Drawer
|
|
216
|
-
title={
|
|
217
|
-
selectedCommit ? (
|
|
218
|
-
<div>
|
|
219
|
-
<Text strong>{selectedCommit.message}</Text>
|
|
220
|
-
<div>
|
|
221
|
-
<Text type="secondary" style={{ fontSize: 12 }}>
|
|
222
|
-
{selectedCommit.hash?.substring(0, 7)} · {selectedCommit.author_name} ·{' '}
|
|
223
|
-
{formatDate(selectedCommit.date)}
|
|
224
|
-
</Text>
|
|
225
|
-
</div>
|
|
226
|
-
</div>
|
|
227
|
-
) : (
|
|
228
|
-
'Commit Detail'
|
|
229
|
-
)
|
|
230
|
-
}
|
|
231
|
-
open={!!selectedCommit}
|
|
232
|
-
onClose={() => {
|
|
233
|
-
setSelectedCommit(null);
|
|
234
|
-
setCommitDetail(null);
|
|
235
|
-
setDiffContent(null);
|
|
236
|
-
setDiffFile(null);
|
|
237
|
-
}}
|
|
238
|
-
width={800}
|
|
239
|
-
extra={
|
|
240
|
-
selectedCommit && selectedRepo ? (
|
|
241
|
-
<RunReviewButton
|
|
242
|
-
target={{
|
|
243
|
-
type: 'commit',
|
|
244
|
-
repositoryId: selectedRepo.id,
|
|
245
|
-
commitSha: selectedCommit.hash,
|
|
246
|
-
title: selectedCommit.message,
|
|
247
|
-
}}
|
|
248
|
-
size="small"
|
|
249
|
-
/>
|
|
250
|
-
) : null
|
|
251
|
-
}
|
|
252
|
-
>
|
|
253
|
-
{detailLoading ? (
|
|
254
|
-
<Spin />
|
|
255
|
-
) : commitDetail ? (
|
|
256
|
-
<div>
|
|
257
|
-
<Text strong>Changed Files ({commitDetail.files?.length || 0})</Text>
|
|
258
|
-
<List
|
|
259
|
-
size="small"
|
|
260
|
-
style={{ marginTop: 8 }}
|
|
261
|
-
dataSource={commitDetail.files || []}
|
|
262
|
-
renderItem={(item: any) => {
|
|
263
|
-
const info = STATUS_COLORS[item.status] || STATUS_COLORS.M;
|
|
264
|
-
const isActive = diffFile === item.file;
|
|
265
|
-
return (
|
|
266
|
-
<List.Item
|
|
267
|
-
style={{
|
|
268
|
-
cursor: 'pointer',
|
|
269
|
-
background: isActive ? token.colorPrimaryBg : undefined,
|
|
270
|
-
padding: '6px 12px',
|
|
271
|
-
borderRadius: 4,
|
|
272
|
-
}}
|
|
273
|
-
onClick={() => loadFileDiff(selectedCommit.hash, item.file)}
|
|
274
|
-
>
|
|
275
|
-
<Space>
|
|
276
|
-
<Tag color={info.color} style={{ minWidth: 70, textAlign: 'center' }}>
|
|
277
|
-
{info.icon} {info.label}
|
|
278
|
-
</Tag>
|
|
279
|
-
<Text style={{ fontSize: 13 }}>{item.file}</Text>
|
|
280
|
-
</Space>
|
|
281
|
-
</List.Item>
|
|
282
|
-
);
|
|
283
|
-
}}
|
|
284
|
-
/>
|
|
285
|
-
|
|
286
|
-
{diffContent !== null && (
|
|
287
|
-
<div style={{ marginTop: 16 }}>
|
|
288
|
-
<Text strong style={{ display: 'block', marginBottom: 8 }}>
|
|
289
|
-
<FileTextOutlined /> {diffFile}
|
|
290
|
-
</Text>
|
|
291
|
-
<DiffViewer content={diffContent} />
|
|
292
|
-
</div>
|
|
293
|
-
)}
|
|
294
|
-
</div>
|
|
295
|
-
) : null}
|
|
296
|
-
</Drawer>
|
|
297
|
-
</div>
|
|
298
|
-
);
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
const DiffViewer: React.FC<{ content: string }> = memo(({ content }) => {
|
|
302
|
-
const { token } = useToken();
|
|
303
|
-
const lines = content.split('\n');
|
|
304
|
-
|
|
305
|
-
return (
|
|
306
|
-
<div
|
|
307
|
-
style={{
|
|
308
|
-
fontFamily: "'JetBrains Mono', 'Fira Code', Consolas, monospace",
|
|
309
|
-
fontSize: 12,
|
|
310
|
-
lineHeight: 1.5,
|
|
311
|
-
border: `1px solid ${token.colorBorderSecondary}`,
|
|
312
|
-
borderRadius: 6,
|
|
313
|
-
overflow: 'auto',
|
|
314
|
-
maxHeight: 500,
|
|
315
|
-
}}
|
|
316
|
-
>
|
|
317
|
-
{lines.map((line, i) => {
|
|
318
|
-
let bg = 'transparent';
|
|
319
|
-
let color = token.colorText;
|
|
320
|
-
if (line.startsWith('+') && !line.startsWith('+++')) {
|
|
321
|
-
bg = 'rgba(46, 160, 67, 0.12)';
|
|
322
|
-
color = '#2ea043';
|
|
323
|
-
} else if (line.startsWith('-') && !line.startsWith('---')) {
|
|
324
|
-
bg = 'rgba(248, 81, 73, 0.12)';
|
|
325
|
-
color = '#f85149';
|
|
326
|
-
} else if (line.startsWith('@@')) {
|
|
327
|
-
bg = 'rgba(56, 139, 253, 0.08)';
|
|
328
|
-
color = '#388bfd';
|
|
329
|
-
} else if (line.startsWith('diff') || line.startsWith('index')) {
|
|
330
|
-
color = token.colorTextSecondary;
|
|
331
|
-
}
|
|
332
|
-
return (
|
|
333
|
-
<div
|
|
334
|
-
key={i}
|
|
335
|
-
style={{
|
|
336
|
-
padding: '0 12px',
|
|
337
|
-
background: bg,
|
|
338
|
-
color,
|
|
339
|
-
whiteSpace: 'pre',
|
|
340
|
-
minHeight: 20,
|
|
341
|
-
}}
|
|
342
|
-
>
|
|
343
|
-
<span
|
|
344
|
-
style={{
|
|
345
|
-
display: 'inline-block',
|
|
346
|
-
width: 40,
|
|
347
|
-
color: token.colorTextQuaternary,
|
|
348
|
-
userSelect: 'none',
|
|
349
|
-
textAlign: 'right',
|
|
350
|
-
marginRight: 12,
|
|
351
|
-
}}
|
|
352
|
-
>
|
|
353
|
-
{i + 1}
|
|
354
|
-
</span>
|
|
355
|
-
{line}
|
|
356
|
-
</div>
|
|
357
|
-
);
|
|
358
|
-
})}
|
|
359
|
-
</div>
|
|
360
|
-
);
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
function formatDate(dateStr: string): string {
|
|
364
|
-
if (!dateStr) return '';
|
|
365
|
-
const d = new Date(dateStr);
|
|
366
|
-
const now = new Date();
|
|
367
|
-
const diffMs = now.getTime() - d.getTime();
|
|
368
|
-
const diffHours = diffMs / (1000 * 60 * 60);
|
|
369
|
-
|
|
370
|
-
if (diffHours < 1) return `${Math.round(diffMs / 60000)}m ago`;
|
|
371
|
-
if (diffHours < 24) return `${Math.round(diffHours)}h ago`;
|
|
372
|
-
if (diffHours < 168) return `${Math.round(diffHours / 24)}d ago`;
|
|
373
|
-
return d.toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' });
|
|
374
|
-
}
|
|
1
|
+
import React, { useEffect, useState, useCallback, memo } from 'react';
|
|
2
|
+
import { Table, Empty, Spin, Typography, Tag, Drawer, List, Button, Space, Select, Input, theme } from 'antd';
|
|
3
|
+
import {
|
|
4
|
+
BranchesOutlined,
|
|
5
|
+
UserOutlined,
|
|
6
|
+
ClockCircleOutlined,
|
|
7
|
+
FileTextOutlined,
|
|
8
|
+
PlusCircleOutlined,
|
|
9
|
+
EditOutlined,
|
|
10
|
+
DeleteOutlined,
|
|
11
|
+
DiffOutlined,
|
|
12
|
+
} from '@ant-design/icons';
|
|
13
|
+
import { useApp } from '@nocobase/client-v2';
|
|
14
|
+
import { useGitManager } from '../context/GitManagerContext';
|
|
15
|
+
import { RunReviewButton } from './RunReviewButton';
|
|
16
|
+
import { useT } from '../locale';
|
|
17
|
+
|
|
18
|
+
const { Text } = Typography;
|
|
19
|
+
const { useToken } = theme;
|
|
20
|
+
|
|
21
|
+
const STATUS_COLORS: Record<string, { color: string; icon: React.ReactNode; label: string }> = {
|
|
22
|
+
A: { color: 'green', icon: <PlusCircleOutlined />, label: 'Added' },
|
|
23
|
+
M: { color: 'blue', icon: <EditOutlined />, label: 'Modified' },
|
|
24
|
+
D: { color: 'red', icon: <DeleteOutlined />, label: 'Deleted' },
|
|
25
|
+
R: { color: 'orange', icon: <EditOutlined />, label: 'Renamed' },
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const CommitHistory: React.FC = () => {
|
|
29
|
+
const t = useT();
|
|
30
|
+
const { token } = useToken();
|
|
31
|
+
const api = useApp().apiClient;
|
|
32
|
+
const { selectedRepo, branches: branchList, currentBranch } = useGitManager();
|
|
33
|
+
const [commits, setCommits] = useState<any[]>([]);
|
|
34
|
+
const [loading, setLoading] = useState(false);
|
|
35
|
+
const [selectedCommit, setSelectedCommit] = useState<any>(null);
|
|
36
|
+
const [commitDetail, setCommitDetail] = useState<any>(null);
|
|
37
|
+
const [detailLoading, setDetailLoading] = useState(false);
|
|
38
|
+
const [diffContent, setDiffContent] = useState<string | null>(null);
|
|
39
|
+
const [diffFile, setDiffFile] = useState<string | null>(null);
|
|
40
|
+
const [searchKeyword, setSearchKeyword] = useState('');
|
|
41
|
+
|
|
42
|
+
const loadHistory = useCallback(async () => {
|
|
43
|
+
if (!selectedRepo) return;
|
|
44
|
+
setLoading(true);
|
|
45
|
+
try {
|
|
46
|
+
const { data } = await api.request({
|
|
47
|
+
url: 'gitManager:log',
|
|
48
|
+
params: { repositoryId: selectedRepo.id, maxCount: 100 },
|
|
49
|
+
});
|
|
50
|
+
const responseData = data?.data?.data || data?.data;
|
|
51
|
+
setCommits(responseData?.all || []);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.warn('Failed to load commit history:', error);
|
|
54
|
+
setCommits([]);
|
|
55
|
+
} finally {
|
|
56
|
+
setLoading(false);
|
|
57
|
+
}
|
|
58
|
+
}, [api, selectedRepo]);
|
|
59
|
+
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (selectedRepo?.status === 'connected') {
|
|
62
|
+
loadHistory();
|
|
63
|
+
} else {
|
|
64
|
+
setCommits([]);
|
|
65
|
+
}
|
|
66
|
+
}, [selectedRepo]);
|
|
67
|
+
|
|
68
|
+
const filteredCommits = commits.filter((commit) => {
|
|
69
|
+
const keyword = searchKeyword.trim().toLowerCase();
|
|
70
|
+
if (!keyword) return true;
|
|
71
|
+
return String(commit.message || commit.subject || commit.body || '')
|
|
72
|
+
.toLowerCase()
|
|
73
|
+
.includes(keyword);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const openCommitDetail = async (commit: any) => {
|
|
77
|
+
setSelectedCommit(commit);
|
|
78
|
+
setDetailLoading(true);
|
|
79
|
+
setDiffContent(null);
|
|
80
|
+
setDiffFile(null);
|
|
81
|
+
try {
|
|
82
|
+
const { data } = await api.request({
|
|
83
|
+
url: 'gitManager:commitDetail',
|
|
84
|
+
params: { repositoryId: selectedRepo.id, commitHash: commit.hash },
|
|
85
|
+
});
|
|
86
|
+
const responseData = data?.data?.data || data?.data;
|
|
87
|
+
setCommitDetail(responseData);
|
|
88
|
+
} catch {
|
|
89
|
+
setCommitDetail(null);
|
|
90
|
+
} finally {
|
|
91
|
+
setDetailLoading(false);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const loadFileDiff = async (commitHash: string, file: string) => {
|
|
96
|
+
setDiffFile(file);
|
|
97
|
+
try {
|
|
98
|
+
const { data } = await api.request({
|
|
99
|
+
url: 'gitManager:diff',
|
|
100
|
+
params: { repositoryId: selectedRepo.id, commitHash, file },
|
|
101
|
+
});
|
|
102
|
+
const responseData = data?.data?.data || data?.data;
|
|
103
|
+
setDiffContent(responseData || '');
|
|
104
|
+
} catch {
|
|
105
|
+
setDiffContent('// Failed to load diff');
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
if (!selectedRepo) {
|
|
110
|
+
return <Empty description={t('No repository selected')} />;
|
|
111
|
+
}
|
|
112
|
+
if (selectedRepo.status !== 'connected') {
|
|
113
|
+
return <Empty description={t('Repository not cloned yet')} />;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const columns = [
|
|
117
|
+
{
|
|
118
|
+
title: '',
|
|
119
|
+
key: 'graph',
|
|
120
|
+
width: 40,
|
|
121
|
+
render: (_: any, __: any, index: number) => (
|
|
122
|
+
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', height: '100%' }}>
|
|
123
|
+
<div
|
|
124
|
+
style={{
|
|
125
|
+
width: 10,
|
|
126
|
+
height: 10,
|
|
127
|
+
borderRadius: '50%',
|
|
128
|
+
background: index === 0 ? token.colorPrimary : token.colorBorder,
|
|
129
|
+
border: `2px solid ${index === 0 ? token.colorPrimary : token.colorBorder}`,
|
|
130
|
+
zIndex: 1,
|
|
131
|
+
}}
|
|
132
|
+
/>
|
|
133
|
+
</div>
|
|
134
|
+
),
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
title: t('Message'),
|
|
138
|
+
dataIndex: 'message',
|
|
139
|
+
key: 'message',
|
|
140
|
+
render: (text: string, record: any) => (
|
|
141
|
+
<div>
|
|
142
|
+
<Text strong style={{ fontSize: 13 }}>
|
|
143
|
+
{text}
|
|
144
|
+
</Text>
|
|
145
|
+
<div style={{ marginTop: 2 }}>
|
|
146
|
+
<Text type="secondary" style={{ fontSize: 12 }}>
|
|
147
|
+
<UserOutlined style={{ marginRight: 4 }} />
|
|
148
|
+
{record.author_name}
|
|
149
|
+
<span style={{ margin: '0 8px' }}>·</span>
|
|
150
|
+
<ClockCircleOutlined style={{ marginRight: 4 }} />
|
|
151
|
+
{formatDate(record.date)}
|
|
152
|
+
</Text>
|
|
153
|
+
</div>
|
|
154
|
+
</div>
|
|
155
|
+
),
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
title: 'Hash',
|
|
159
|
+
dataIndex: 'hash',
|
|
160
|
+
key: 'hash',
|
|
161
|
+
width: 100,
|
|
162
|
+
render: (hash: string) => (
|
|
163
|
+
<Text code copyable style={{ fontSize: 12 }}>
|
|
164
|
+
{hash?.substring(0, 7)}
|
|
165
|
+
</Text>
|
|
166
|
+
),
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
title: '',
|
|
170
|
+
key: 'action',
|
|
171
|
+
width: 80,
|
|
172
|
+
render: (_: any, record: any) => (
|
|
173
|
+
<Button size="small" icon={<DiffOutlined />} onClick={() => openCommitDetail(record)}>
|
|
174
|
+
Detail
|
|
175
|
+
</Button>
|
|
176
|
+
),
|
|
177
|
+
},
|
|
178
|
+
];
|
|
179
|
+
|
|
180
|
+
return (
|
|
181
|
+
<div>
|
|
182
|
+
<div style={{ marginBottom: 12, display: 'flex', alignItems: 'center', gap: 12 }}>
|
|
183
|
+
<BranchesOutlined />
|
|
184
|
+
<Select
|
|
185
|
+
size="small"
|
|
186
|
+
style={{ width: 200 }}
|
|
187
|
+
value={currentBranch}
|
|
188
|
+
options={branchList.map((b) => ({ label: b, value: b }))}
|
|
189
|
+
disabled
|
|
190
|
+
/>
|
|
191
|
+
<Input.Search
|
|
192
|
+
allowClear
|
|
193
|
+
size="small"
|
|
194
|
+
style={{ width: 280 }}
|
|
195
|
+
placeholder={t('Search commit title or message')}
|
|
196
|
+
value={searchKeyword}
|
|
197
|
+
onChange={(event) => setSearchKeyword(event.target.value)}
|
|
198
|
+
/>
|
|
199
|
+
<Text type="secondary">{filteredCommits.length} commits</Text>
|
|
200
|
+
</div>
|
|
201
|
+
|
|
202
|
+
{loading ? (
|
|
203
|
+
<Spin />
|
|
204
|
+
) : (
|
|
205
|
+
<Table
|
|
206
|
+
dataSource={filteredCommits}
|
|
207
|
+
columns={columns}
|
|
208
|
+
rowKey="hash"
|
|
209
|
+
size="small"
|
|
210
|
+
pagination={{ pageSize: 30, showSizeChanger: true }}
|
|
211
|
+
onRow={(record) => ({ style: { cursor: 'pointer' }, onClick: () => openCommitDetail(record) })}
|
|
212
|
+
/>
|
|
213
|
+
)}
|
|
214
|
+
|
|
215
|
+
<Drawer
|
|
216
|
+
title={
|
|
217
|
+
selectedCommit ? (
|
|
218
|
+
<div>
|
|
219
|
+
<Text strong>{selectedCommit.message}</Text>
|
|
220
|
+
<div>
|
|
221
|
+
<Text type="secondary" style={{ fontSize: 12 }}>
|
|
222
|
+
{selectedCommit.hash?.substring(0, 7)} · {selectedCommit.author_name} ·{' '}
|
|
223
|
+
{formatDate(selectedCommit.date)}
|
|
224
|
+
</Text>
|
|
225
|
+
</div>
|
|
226
|
+
</div>
|
|
227
|
+
) : (
|
|
228
|
+
'Commit Detail'
|
|
229
|
+
)
|
|
230
|
+
}
|
|
231
|
+
open={!!selectedCommit}
|
|
232
|
+
onClose={() => {
|
|
233
|
+
setSelectedCommit(null);
|
|
234
|
+
setCommitDetail(null);
|
|
235
|
+
setDiffContent(null);
|
|
236
|
+
setDiffFile(null);
|
|
237
|
+
}}
|
|
238
|
+
width={800}
|
|
239
|
+
extra={
|
|
240
|
+
selectedCommit && selectedRepo ? (
|
|
241
|
+
<RunReviewButton
|
|
242
|
+
target={{
|
|
243
|
+
type: 'commit',
|
|
244
|
+
repositoryId: selectedRepo.id,
|
|
245
|
+
commitSha: selectedCommit.hash,
|
|
246
|
+
title: selectedCommit.message,
|
|
247
|
+
}}
|
|
248
|
+
size="small"
|
|
249
|
+
/>
|
|
250
|
+
) : null
|
|
251
|
+
}
|
|
252
|
+
>
|
|
253
|
+
{detailLoading ? (
|
|
254
|
+
<Spin />
|
|
255
|
+
) : commitDetail ? (
|
|
256
|
+
<div>
|
|
257
|
+
<Text strong>Changed Files ({commitDetail.files?.length || 0})</Text>
|
|
258
|
+
<List
|
|
259
|
+
size="small"
|
|
260
|
+
style={{ marginTop: 8 }}
|
|
261
|
+
dataSource={commitDetail.files || []}
|
|
262
|
+
renderItem={(item: any) => {
|
|
263
|
+
const info = STATUS_COLORS[item.status] || STATUS_COLORS.M;
|
|
264
|
+
const isActive = diffFile === item.file;
|
|
265
|
+
return (
|
|
266
|
+
<List.Item
|
|
267
|
+
style={{
|
|
268
|
+
cursor: 'pointer',
|
|
269
|
+
background: isActive ? token.colorPrimaryBg : undefined,
|
|
270
|
+
padding: '6px 12px',
|
|
271
|
+
borderRadius: 4,
|
|
272
|
+
}}
|
|
273
|
+
onClick={() => loadFileDiff(selectedCommit.hash, item.file)}
|
|
274
|
+
>
|
|
275
|
+
<Space>
|
|
276
|
+
<Tag color={info.color} style={{ minWidth: 70, textAlign: 'center' }}>
|
|
277
|
+
{info.icon} {info.label}
|
|
278
|
+
</Tag>
|
|
279
|
+
<Text style={{ fontSize: 13 }}>{item.file}</Text>
|
|
280
|
+
</Space>
|
|
281
|
+
</List.Item>
|
|
282
|
+
);
|
|
283
|
+
}}
|
|
284
|
+
/>
|
|
285
|
+
|
|
286
|
+
{diffContent !== null && (
|
|
287
|
+
<div style={{ marginTop: 16 }}>
|
|
288
|
+
<Text strong style={{ display: 'block', marginBottom: 8 }}>
|
|
289
|
+
<FileTextOutlined /> {diffFile}
|
|
290
|
+
</Text>
|
|
291
|
+
<DiffViewer content={diffContent} />
|
|
292
|
+
</div>
|
|
293
|
+
)}
|
|
294
|
+
</div>
|
|
295
|
+
) : null}
|
|
296
|
+
</Drawer>
|
|
297
|
+
</div>
|
|
298
|
+
);
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
const DiffViewer: React.FC<{ content: string }> = memo(({ content }) => {
|
|
302
|
+
const { token } = useToken();
|
|
303
|
+
const lines = content.split('\n');
|
|
304
|
+
|
|
305
|
+
return (
|
|
306
|
+
<div
|
|
307
|
+
style={{
|
|
308
|
+
fontFamily: "'JetBrains Mono', 'Fira Code', Consolas, monospace",
|
|
309
|
+
fontSize: 12,
|
|
310
|
+
lineHeight: 1.5,
|
|
311
|
+
border: `1px solid ${token.colorBorderSecondary}`,
|
|
312
|
+
borderRadius: 6,
|
|
313
|
+
overflow: 'auto',
|
|
314
|
+
maxHeight: 500,
|
|
315
|
+
}}
|
|
316
|
+
>
|
|
317
|
+
{lines.map((line, i) => {
|
|
318
|
+
let bg = 'transparent';
|
|
319
|
+
let color = token.colorText;
|
|
320
|
+
if (line.startsWith('+') && !line.startsWith('+++')) {
|
|
321
|
+
bg = 'rgba(46, 160, 67, 0.12)';
|
|
322
|
+
color = '#2ea043';
|
|
323
|
+
} else if (line.startsWith('-') && !line.startsWith('---')) {
|
|
324
|
+
bg = 'rgba(248, 81, 73, 0.12)';
|
|
325
|
+
color = '#f85149';
|
|
326
|
+
} else if (line.startsWith('@@')) {
|
|
327
|
+
bg = 'rgba(56, 139, 253, 0.08)';
|
|
328
|
+
color = '#388bfd';
|
|
329
|
+
} else if (line.startsWith('diff') || line.startsWith('index')) {
|
|
330
|
+
color = token.colorTextSecondary;
|
|
331
|
+
}
|
|
332
|
+
return (
|
|
333
|
+
<div
|
|
334
|
+
key={i}
|
|
335
|
+
style={{
|
|
336
|
+
padding: '0 12px',
|
|
337
|
+
background: bg,
|
|
338
|
+
color,
|
|
339
|
+
whiteSpace: 'pre',
|
|
340
|
+
minHeight: 20,
|
|
341
|
+
}}
|
|
342
|
+
>
|
|
343
|
+
<span
|
|
344
|
+
style={{
|
|
345
|
+
display: 'inline-block',
|
|
346
|
+
width: 40,
|
|
347
|
+
color: token.colorTextQuaternary,
|
|
348
|
+
userSelect: 'none',
|
|
349
|
+
textAlign: 'right',
|
|
350
|
+
marginRight: 12,
|
|
351
|
+
}}
|
|
352
|
+
>
|
|
353
|
+
{i + 1}
|
|
354
|
+
</span>
|
|
355
|
+
{line}
|
|
356
|
+
</div>
|
|
357
|
+
);
|
|
358
|
+
})}
|
|
359
|
+
</div>
|
|
360
|
+
);
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
function formatDate(dateStr: string): string {
|
|
364
|
+
if (!dateStr) return '';
|
|
365
|
+
const d = new Date(dateStr);
|
|
366
|
+
const now = new Date();
|
|
367
|
+
const diffMs = now.getTime() - d.getTime();
|
|
368
|
+
const diffHours = diffMs / (1000 * 60 * 60);
|
|
369
|
+
|
|
370
|
+
if (diffHours < 1) return `${Math.round(diffMs / 60000)}m ago`;
|
|
371
|
+
if (diffHours < 24) return `${Math.round(diffHours)}h ago`;
|
|
372
|
+
if (diffHours < 168) return `${Math.round(diffHours / 24)}d ago`;
|
|
373
|
+
return d.toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' });
|
|
374
|
+
}
|