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.
- 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 +4 -3
- 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 +495 -484
- 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,335 +1,335 @@
|
|
|
1
|
-
import React, { useCallback, useEffect, useState } from 'react';
|
|
2
|
-
import { Table, Button, Modal, Form, Input, Space, Tag, Popconfirm, Switch, Tooltip, Select, message } from 'antd';
|
|
3
|
-
import { PlusOutlined, DeleteOutlined, LinkOutlined, RobotOutlined } from '@ant-design/icons';
|
|
4
|
-
import { useApp } from '@nocobase/client-v2';
|
|
5
|
-
import { GitManagerProvider, useGitManager } from '../context/GitManagerContext';
|
|
6
|
-
import { useT } from '../locale';
|
|
7
|
-
|
|
8
|
-
export const RepositoryConfig: React.FC = () => {
|
|
9
|
-
const t = useT();
|
|
10
|
-
const api = useApp().apiClient;
|
|
11
|
-
const { repos, refreshRepos, selectedRepo, setSelectedRepo } = useGitManager();
|
|
12
|
-
const [modalOpen, setModalOpen] = useState(false);
|
|
13
|
-
const [editingRepo, setEditingRepo] = useState<any>(null);
|
|
14
|
-
const [form] = Form.useForm();
|
|
15
|
-
const [actionLoading, setActionLoading] = useState<string | null>(null);
|
|
16
|
-
const [reviewFlows, setReviewFlows] = useState<any[]>([]);
|
|
17
|
-
const [gitAccounts, setGitAccounts] = useState<any[]>([]);
|
|
18
|
-
|
|
19
|
-
const loadReviewFlows = useCallback(async () => {
|
|
20
|
-
const { data } = await api.request({
|
|
21
|
-
url: 'gitReviewFlows:list',
|
|
22
|
-
params: {
|
|
23
|
-
pageSize: 100,
|
|
24
|
-
filter: {
|
|
25
|
-
enabled: true,
|
|
26
|
-
triggerMode: { $in: ['onMergeRequestCreated', 'both'] },
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
setReviewFlows(data?.data || []);
|
|
31
|
-
}, [api]);
|
|
32
|
-
|
|
33
|
-
const loadGitAccounts = useCallback(async () => {
|
|
34
|
-
const { data } = await api.request({ url: 'gitAccounts:list', params: { pageSize: 100 } });
|
|
35
|
-
setGitAccounts(data?.data || []);
|
|
36
|
-
}, [api]);
|
|
37
|
-
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
loadReviewFlows().catch(() => undefined);
|
|
40
|
-
loadGitAccounts().catch(() => undefined);
|
|
41
|
-
}, [loadReviewFlows, loadGitAccounts]);
|
|
42
|
-
|
|
43
|
-
useEffect(() => {
|
|
44
|
-
refreshRepos().catch(() => undefined);
|
|
45
|
-
}, [refreshRepos]);
|
|
46
|
-
|
|
47
|
-
const getAutoFlowOptions = (repoId: number) =>
|
|
48
|
-
reviewFlows
|
|
49
|
-
.filter((flow) => flow.repositoryId === repoId || flow.repositoryId == null)
|
|
50
|
-
.map((flow) => ({
|
|
51
|
-
value: flow.id,
|
|
52
|
-
label: `${flow.name}${flow.repositoryId == null ? ` (${t('global')})` : ''}`,
|
|
53
|
-
}));
|
|
54
|
-
|
|
55
|
-
const handleSave = async () => {
|
|
56
|
-
const values = await form.validateFields();
|
|
57
|
-
try {
|
|
58
|
-
if (editingRepo) {
|
|
59
|
-
await api.request({
|
|
60
|
-
url: 'gitRepositories:update',
|
|
61
|
-
method: 'post',
|
|
62
|
-
params: { filterByTk: editingRepo.id },
|
|
63
|
-
data: values,
|
|
64
|
-
});
|
|
65
|
-
message.success(t('Repository updated'));
|
|
66
|
-
} else {
|
|
67
|
-
await api.request({
|
|
68
|
-
url: 'gitRepositories:create',
|
|
69
|
-
method: 'post',
|
|
70
|
-
data: values,
|
|
71
|
-
});
|
|
72
|
-
message.success(t('Repository added'));
|
|
73
|
-
}
|
|
74
|
-
setModalOpen(false);
|
|
75
|
-
setEditingRepo(null);
|
|
76
|
-
form.resetFields();
|
|
77
|
-
await refreshRepos();
|
|
78
|
-
} catch (err) {
|
|
79
|
-
message.error(err?.message || t('Failed to save'));
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const handleDelete = async (id: number) => {
|
|
84
|
-
await api.request({ url: 'gitRepositories:destroy', method: 'post', params: { filterByTk: id } });
|
|
85
|
-
if (selectedRepo?.id === id) setSelectedRepo(null);
|
|
86
|
-
message.success(t('Deleted'));
|
|
87
|
-
await refreshRepos();
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const handleClone = async (repo: any) => {
|
|
91
|
-
setActionLoading(`clone-${repo.id}`);
|
|
92
|
-
try {
|
|
93
|
-
await api.request({
|
|
94
|
-
url: 'gitManager:clone',
|
|
95
|
-
method: 'post',
|
|
96
|
-
params: { repositoryId: repo.id },
|
|
97
|
-
});
|
|
98
|
-
message.success(t('Clone successful'));
|
|
99
|
-
await refreshRepos();
|
|
100
|
-
} catch (err) {
|
|
101
|
-
message.error(err?.response?.data?.errors?.[0]?.message || t('Clone failed'));
|
|
102
|
-
} finally {
|
|
103
|
-
setActionLoading(null);
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
const columns = [
|
|
108
|
-
{
|
|
109
|
-
title: t('Repository Name'),
|
|
110
|
-
dataIndex: 'name',
|
|
111
|
-
key: 'name',
|
|
112
|
-
render: (text: string, record: any) => <a onClick={() => setSelectedRepo(record)}>{text}</a>,
|
|
113
|
-
},
|
|
114
|
-
{ title: t('Repository URL'), dataIndex: 'repoUrl', key: 'repoUrl', ellipsis: true },
|
|
115
|
-
{
|
|
116
|
-
title: t('Git Account'),
|
|
117
|
-
dataIndex: 'gitAccountId',
|
|
118
|
-
key: 'gitAccountId',
|
|
119
|
-
width: 160,
|
|
120
|
-
render: (gitAccountId: number | null) => {
|
|
121
|
-
if (!gitAccountId) return <Tag>{t('None')}</Tag>;
|
|
122
|
-
const account = gitAccounts.find((acc) => acc.id === gitAccountId);
|
|
123
|
-
return account ? account.name : <Tag>{t('None')}</Tag>;
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
{ title: t('Local Path'), dataIndex: 'localPath', key: 'localPath', ellipsis: true },
|
|
127
|
-
{ title: t('Default Branch'), dataIndex: 'defaultBranch', key: 'defaultBranch', width: 120 },
|
|
128
|
-
{
|
|
129
|
-
title: (
|
|
130
|
-
<Tooltip title={t('Auto-poll new merge requests every 5 minutes')}>
|
|
131
|
-
<Space size={4}>
|
|
132
|
-
<RobotOutlined />
|
|
133
|
-
{t('Auto Review')}
|
|
134
|
-
</Space>
|
|
135
|
-
</Tooltip>
|
|
136
|
-
),
|
|
137
|
-
dataIndex: 'autoReview',
|
|
138
|
-
key: 'autoReview',
|
|
139
|
-
width: 110,
|
|
140
|
-
render: (v: boolean, record: any) => (
|
|
141
|
-
<Switch
|
|
142
|
-
size="small"
|
|
143
|
-
checked={!!v}
|
|
144
|
-
onChange={async (checked) => {
|
|
145
|
-
try {
|
|
146
|
-
const options = getAutoFlowOptions(record.id);
|
|
147
|
-
await api.request({
|
|
148
|
-
url: 'gitRepositories:update',
|
|
149
|
-
method: 'post',
|
|
150
|
-
params: { filterByTk: record.id },
|
|
151
|
-
data: {
|
|
152
|
-
autoReview: checked,
|
|
153
|
-
autoReviewFlowId:
|
|
154
|
-
checked && !record.autoReviewFlowId ? options[0]?.value ?? null : record.autoReviewFlowId,
|
|
155
|
-
},
|
|
156
|
-
});
|
|
157
|
-
await refreshRepos();
|
|
158
|
-
} catch (err: any) {
|
|
159
|
-
message.error(err?.message || t('Failed to save'));
|
|
160
|
-
}
|
|
161
|
-
}}
|
|
162
|
-
/>
|
|
163
|
-
),
|
|
164
|
-
},
|
|
165
|
-
{
|
|
166
|
-
title: t('Primary Auto Flow'),
|
|
167
|
-
dataIndex: 'autoReviewFlowId',
|
|
168
|
-
key: 'autoReviewFlowId',
|
|
169
|
-
width: 220,
|
|
170
|
-
render: (value: number | null, record: any) => {
|
|
171
|
-
const options = getAutoFlowOptions(record.id);
|
|
172
|
-
return (
|
|
173
|
-
<Select
|
|
174
|
-
allowClear
|
|
175
|
-
size="small"
|
|
176
|
-
style={{ width: '100%' }}
|
|
177
|
-
disabled={!record.autoReview}
|
|
178
|
-
placeholder={t('Select a flow')}
|
|
179
|
-
value={value || undefined}
|
|
180
|
-
options={options}
|
|
181
|
-
notFoundContent={t('No matching flow available')}
|
|
182
|
-
onChange={async (flowId) => {
|
|
183
|
-
try {
|
|
184
|
-
await api.request({
|
|
185
|
-
url: 'gitRepositories:update',
|
|
186
|
-
method: 'post',
|
|
187
|
-
params: { filterByTk: record.id },
|
|
188
|
-
data: { autoReviewFlowId: flowId || null },
|
|
189
|
-
});
|
|
190
|
-
await refreshRepos();
|
|
191
|
-
} catch (err: any) {
|
|
192
|
-
message.error(err?.message || t('Failed to save'));
|
|
193
|
-
}
|
|
194
|
-
}}
|
|
195
|
-
/>
|
|
196
|
-
);
|
|
197
|
-
},
|
|
198
|
-
},
|
|
199
|
-
{
|
|
200
|
-
title: t('Status'),
|
|
201
|
-
dataIndex: 'status',
|
|
202
|
-
key: 'status',
|
|
203
|
-
width: 120,
|
|
204
|
-
render: (status: string) => {
|
|
205
|
-
const statusMap: Record<string, { color: string; label: string }> = {
|
|
206
|
-
connected: { color: 'green', label: t('Connected') },
|
|
207
|
-
error: { color: 'red', label: t('Error') },
|
|
208
|
-
};
|
|
209
|
-
const info = statusMap[status] || { color: 'default', label: t('Disconnected') };
|
|
210
|
-
return <Tag color={info.color}>{info.label}</Tag>;
|
|
211
|
-
},
|
|
212
|
-
},
|
|
213
|
-
{
|
|
214
|
-
title: '',
|
|
215
|
-
key: 'actions',
|
|
216
|
-
width: 200,
|
|
217
|
-
render: (_: any, record: any) => (
|
|
218
|
-
<Space size="small">
|
|
219
|
-
{record.status !== 'connected' && (
|
|
220
|
-
<Button
|
|
221
|
-
size="small"
|
|
222
|
-
icon={<LinkOutlined />}
|
|
223
|
-
loading={actionLoading === `clone-${record.id}`}
|
|
224
|
-
onClick={() => handleClone(record)}
|
|
225
|
-
>
|
|
226
|
-
{t('Clone')}
|
|
227
|
-
</Button>
|
|
228
|
-
)}
|
|
229
|
-
<Button
|
|
230
|
-
size="small"
|
|
231
|
-
onClick={() => {
|
|
232
|
-
setEditingRepo(record);
|
|
233
|
-
form.setFieldsValue(record);
|
|
234
|
-
setModalOpen(true);
|
|
235
|
-
}}
|
|
236
|
-
>
|
|
237
|
-
{t('Edit')}
|
|
238
|
-
</Button>
|
|
239
|
-
<Popconfirm title={t('Delete this repository?')} onConfirm={() => handleDelete(record.id)}>
|
|
240
|
-
<Button size="small" danger icon={<DeleteOutlined />} />
|
|
241
|
-
</Popconfirm>
|
|
242
|
-
</Space>
|
|
243
|
-
),
|
|
244
|
-
},
|
|
245
|
-
];
|
|
246
|
-
|
|
247
|
-
return (
|
|
248
|
-
<div>
|
|
249
|
-
<div style={{ marginBottom: 16 }}>
|
|
250
|
-
<Button
|
|
251
|
-
type="primary"
|
|
252
|
-
icon={<PlusOutlined />}
|
|
253
|
-
onClick={() => {
|
|
254
|
-
setEditingRepo(null);
|
|
255
|
-
form.resetFields();
|
|
256
|
-
setModalOpen(true);
|
|
257
|
-
}}
|
|
258
|
-
>
|
|
259
|
-
{t('Add Repository')}
|
|
260
|
-
</Button>
|
|
261
|
-
</div>
|
|
262
|
-
|
|
263
|
-
<Table
|
|
264
|
-
dataSource={repos}
|
|
265
|
-
columns={columns}
|
|
266
|
-
rowKey="id"
|
|
267
|
-
size="small"
|
|
268
|
-
pagination={false}
|
|
269
|
-
rowClassName={(record) => (selectedRepo?.id === record.id ? 'ant-table-row-selected' : '')}
|
|
270
|
-
/>
|
|
271
|
-
|
|
272
|
-
<Modal
|
|
273
|
-
title={editingRepo ? t('Edit Repository') : t('Add Repository')}
|
|
274
|
-
open={modalOpen}
|
|
275
|
-
onOk={handleSave}
|
|
276
|
-
onCancel={() => {
|
|
277
|
-
setModalOpen(false);
|
|
278
|
-
setEditingRepo(null);
|
|
279
|
-
}}
|
|
280
|
-
width={520}
|
|
281
|
-
>
|
|
282
|
-
<Form form={form} layout="vertical" initialValues={{ defaultBranch: 'main', registryExportEnabled: false }}>
|
|
283
|
-
<Form.Item name="name" label={t('Repository Name')} rules={[{ required: true }]}>
|
|
284
|
-
<Input placeholder="my-project" />
|
|
285
|
-
</Form.Item>
|
|
286
|
-
<Form.Item name="repoUrl" label={t('Repository URL')} rules={[{ required: true }]}>
|
|
287
|
-
<Input placeholder="https://gitlab.com/user/repo.git" />
|
|
288
|
-
</Form.Item>
|
|
289
|
-
<Form.Item
|
|
290
|
-
name="gitAccountId"
|
|
291
|
-
label={t('Git Account')}
|
|
292
|
-
rules={[{ required: true, message: t('Please select a Git account') }]}
|
|
293
|
-
extra={t('Select the GitLab or GitHub account to use for this repository')}
|
|
294
|
-
>
|
|
295
|
-
<Select
|
|
296
|
-
placeholder={t('Select an account')}
|
|
297
|
-
options={gitAccounts.map((acc) => ({
|
|
298
|
-
value: acc.id,
|
|
299
|
-
label: `${acc.name} (${acc.username})`,
|
|
300
|
-
}))}
|
|
301
|
-
notFoundContent={t('No accounts configured. Add one in the Git Accounts tab.')}
|
|
302
|
-
/>
|
|
303
|
-
</Form.Item>
|
|
304
|
-
<Form.Item name="localPath" label={t('Local Path')} rules={[{ required: true }]}>
|
|
305
|
-
<Input placeholder="my-project" />
|
|
306
|
-
</Form.Item>
|
|
307
|
-
<Form.Item name="defaultBranch" label={t('Default Branch')}>
|
|
308
|
-
<Input placeholder="main" />
|
|
309
|
-
</Form.Item>
|
|
310
|
-
<Form.Item name="registryExportEnabled" label={t('Allow Skill Registry export')} valuePropName="checked">
|
|
311
|
-
<Switch />
|
|
312
|
-
</Form.Item>
|
|
313
|
-
<Form.Item
|
|
314
|
-
name="autoReviewFlowId"
|
|
315
|
-
label={t('Primary Auto Review Flow')}
|
|
316
|
-
extra={t('Only flows with automatic trigger modes are shown')}
|
|
317
|
-
>
|
|
318
|
-
<Select
|
|
319
|
-
allowClear
|
|
320
|
-
placeholder={t('Select a flow')}
|
|
321
|
-
options={getAutoFlowOptions(editingRepo?.id)}
|
|
322
|
-
notFoundContent={t('No matching flow available')}
|
|
323
|
-
/>
|
|
324
|
-
</Form.Item>
|
|
325
|
-
</Form>
|
|
326
|
-
</Modal>
|
|
327
|
-
</div>
|
|
328
|
-
);
|
|
329
|
-
};
|
|
330
|
-
|
|
331
|
-
export const RepositoryConfigSettings: React.FC = () => (
|
|
332
|
-
<GitManagerProvider>
|
|
333
|
-
<RepositoryConfig />
|
|
334
|
-
</GitManagerProvider>
|
|
335
|
-
);
|
|
1
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import { Table, Button, Modal, Form, Input, Space, Tag, Popconfirm, Switch, Tooltip, Select, message } from 'antd';
|
|
3
|
+
import { PlusOutlined, DeleteOutlined, LinkOutlined, RobotOutlined } from '@ant-design/icons';
|
|
4
|
+
import { useApp } from '@nocobase/client-v2';
|
|
5
|
+
import { GitManagerProvider, useGitManager } from '../context/GitManagerContext';
|
|
6
|
+
import { useT } from '../locale';
|
|
7
|
+
|
|
8
|
+
export const RepositoryConfig: React.FC = () => {
|
|
9
|
+
const t = useT();
|
|
10
|
+
const api = useApp().apiClient;
|
|
11
|
+
const { repos, refreshRepos, selectedRepo, setSelectedRepo } = useGitManager();
|
|
12
|
+
const [modalOpen, setModalOpen] = useState(false);
|
|
13
|
+
const [editingRepo, setEditingRepo] = useState<any>(null);
|
|
14
|
+
const [form] = Form.useForm();
|
|
15
|
+
const [actionLoading, setActionLoading] = useState<string | null>(null);
|
|
16
|
+
const [reviewFlows, setReviewFlows] = useState<any[]>([]);
|
|
17
|
+
const [gitAccounts, setGitAccounts] = useState<any[]>([]);
|
|
18
|
+
|
|
19
|
+
const loadReviewFlows = useCallback(async () => {
|
|
20
|
+
const { data } = await api.request({
|
|
21
|
+
url: 'gitReviewFlows:list',
|
|
22
|
+
params: {
|
|
23
|
+
pageSize: 100,
|
|
24
|
+
filter: {
|
|
25
|
+
enabled: true,
|
|
26
|
+
triggerMode: { $in: ['onMergeRequestCreated', 'both'] },
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
setReviewFlows(data?.data || []);
|
|
31
|
+
}, [api]);
|
|
32
|
+
|
|
33
|
+
const loadGitAccounts = useCallback(async () => {
|
|
34
|
+
const { data } = await api.request({ url: 'gitAccounts:list', params: { pageSize: 100 } });
|
|
35
|
+
setGitAccounts(data?.data || []);
|
|
36
|
+
}, [api]);
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
loadReviewFlows().catch(() => undefined);
|
|
40
|
+
loadGitAccounts().catch(() => undefined);
|
|
41
|
+
}, [loadReviewFlows, loadGitAccounts]);
|
|
42
|
+
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
refreshRepos().catch(() => undefined);
|
|
45
|
+
}, [refreshRepos]);
|
|
46
|
+
|
|
47
|
+
const getAutoFlowOptions = (repoId: number) =>
|
|
48
|
+
reviewFlows
|
|
49
|
+
.filter((flow) => flow.repositoryId === repoId || flow.repositoryId == null)
|
|
50
|
+
.map((flow) => ({
|
|
51
|
+
value: flow.id,
|
|
52
|
+
label: `${flow.name}${flow.repositoryId == null ? ` (${t('global')})` : ''}`,
|
|
53
|
+
}));
|
|
54
|
+
|
|
55
|
+
const handleSave = async () => {
|
|
56
|
+
const values = await form.validateFields();
|
|
57
|
+
try {
|
|
58
|
+
if (editingRepo) {
|
|
59
|
+
await api.request({
|
|
60
|
+
url: 'gitRepositories:update',
|
|
61
|
+
method: 'post',
|
|
62
|
+
params: { filterByTk: editingRepo.id },
|
|
63
|
+
data: values,
|
|
64
|
+
});
|
|
65
|
+
message.success(t('Repository updated'));
|
|
66
|
+
} else {
|
|
67
|
+
await api.request({
|
|
68
|
+
url: 'gitRepositories:create',
|
|
69
|
+
method: 'post',
|
|
70
|
+
data: values,
|
|
71
|
+
});
|
|
72
|
+
message.success(t('Repository added'));
|
|
73
|
+
}
|
|
74
|
+
setModalOpen(false);
|
|
75
|
+
setEditingRepo(null);
|
|
76
|
+
form.resetFields();
|
|
77
|
+
await refreshRepos();
|
|
78
|
+
} catch (err) {
|
|
79
|
+
message.error(err?.message || t('Failed to save'));
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const handleDelete = async (id: number) => {
|
|
84
|
+
await api.request({ url: 'gitRepositories:destroy', method: 'post', params: { filterByTk: id } });
|
|
85
|
+
if (selectedRepo?.id === id) setSelectedRepo(null);
|
|
86
|
+
message.success(t('Deleted'));
|
|
87
|
+
await refreshRepos();
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const handleClone = async (repo: any) => {
|
|
91
|
+
setActionLoading(`clone-${repo.id}`);
|
|
92
|
+
try {
|
|
93
|
+
await api.request({
|
|
94
|
+
url: 'gitManager:clone',
|
|
95
|
+
method: 'post',
|
|
96
|
+
params: { repositoryId: repo.id },
|
|
97
|
+
});
|
|
98
|
+
message.success(t('Clone successful'));
|
|
99
|
+
await refreshRepos();
|
|
100
|
+
} catch (err) {
|
|
101
|
+
message.error(err?.response?.data?.errors?.[0]?.message || t('Clone failed'));
|
|
102
|
+
} finally {
|
|
103
|
+
setActionLoading(null);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const columns = [
|
|
108
|
+
{
|
|
109
|
+
title: t('Repository Name'),
|
|
110
|
+
dataIndex: 'name',
|
|
111
|
+
key: 'name',
|
|
112
|
+
render: (text: string, record: any) => <a onClick={() => setSelectedRepo(record)}>{text}</a>,
|
|
113
|
+
},
|
|
114
|
+
{ title: t('Repository URL'), dataIndex: 'repoUrl', key: 'repoUrl', ellipsis: true },
|
|
115
|
+
{
|
|
116
|
+
title: t('Git Account'),
|
|
117
|
+
dataIndex: 'gitAccountId',
|
|
118
|
+
key: 'gitAccountId',
|
|
119
|
+
width: 160,
|
|
120
|
+
render: (gitAccountId: number | null) => {
|
|
121
|
+
if (!gitAccountId) return <Tag>{t('None')}</Tag>;
|
|
122
|
+
const account = gitAccounts.find((acc) => acc.id === gitAccountId);
|
|
123
|
+
return account ? account.name : <Tag>{t('None')}</Tag>;
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
{ title: t('Local Path'), dataIndex: 'localPath', key: 'localPath', ellipsis: true },
|
|
127
|
+
{ title: t('Default Branch'), dataIndex: 'defaultBranch', key: 'defaultBranch', width: 120 },
|
|
128
|
+
{
|
|
129
|
+
title: (
|
|
130
|
+
<Tooltip title={t('Auto-poll new merge requests every 5 minutes')}>
|
|
131
|
+
<Space size={4}>
|
|
132
|
+
<RobotOutlined />
|
|
133
|
+
{t('Auto Review')}
|
|
134
|
+
</Space>
|
|
135
|
+
</Tooltip>
|
|
136
|
+
),
|
|
137
|
+
dataIndex: 'autoReview',
|
|
138
|
+
key: 'autoReview',
|
|
139
|
+
width: 110,
|
|
140
|
+
render: (v: boolean, record: any) => (
|
|
141
|
+
<Switch
|
|
142
|
+
size="small"
|
|
143
|
+
checked={!!v}
|
|
144
|
+
onChange={async (checked) => {
|
|
145
|
+
try {
|
|
146
|
+
const options = getAutoFlowOptions(record.id);
|
|
147
|
+
await api.request({
|
|
148
|
+
url: 'gitRepositories:update',
|
|
149
|
+
method: 'post',
|
|
150
|
+
params: { filterByTk: record.id },
|
|
151
|
+
data: {
|
|
152
|
+
autoReview: checked,
|
|
153
|
+
autoReviewFlowId:
|
|
154
|
+
checked && !record.autoReviewFlowId ? options[0]?.value ?? null : record.autoReviewFlowId,
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
await refreshRepos();
|
|
158
|
+
} catch (err: any) {
|
|
159
|
+
message.error(err?.message || t('Failed to save'));
|
|
160
|
+
}
|
|
161
|
+
}}
|
|
162
|
+
/>
|
|
163
|
+
),
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
title: t('Primary Auto Flow'),
|
|
167
|
+
dataIndex: 'autoReviewFlowId',
|
|
168
|
+
key: 'autoReviewFlowId',
|
|
169
|
+
width: 220,
|
|
170
|
+
render: (value: number | null, record: any) => {
|
|
171
|
+
const options = getAutoFlowOptions(record.id);
|
|
172
|
+
return (
|
|
173
|
+
<Select
|
|
174
|
+
allowClear
|
|
175
|
+
size="small"
|
|
176
|
+
style={{ width: '100%' }}
|
|
177
|
+
disabled={!record.autoReview}
|
|
178
|
+
placeholder={t('Select a flow')}
|
|
179
|
+
value={value || undefined}
|
|
180
|
+
options={options}
|
|
181
|
+
notFoundContent={t('No matching flow available')}
|
|
182
|
+
onChange={async (flowId) => {
|
|
183
|
+
try {
|
|
184
|
+
await api.request({
|
|
185
|
+
url: 'gitRepositories:update',
|
|
186
|
+
method: 'post',
|
|
187
|
+
params: { filterByTk: record.id },
|
|
188
|
+
data: { autoReviewFlowId: flowId || null },
|
|
189
|
+
});
|
|
190
|
+
await refreshRepos();
|
|
191
|
+
} catch (err: any) {
|
|
192
|
+
message.error(err?.message || t('Failed to save'));
|
|
193
|
+
}
|
|
194
|
+
}}
|
|
195
|
+
/>
|
|
196
|
+
);
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
title: t('Status'),
|
|
201
|
+
dataIndex: 'status',
|
|
202
|
+
key: 'status',
|
|
203
|
+
width: 120,
|
|
204
|
+
render: (status: string) => {
|
|
205
|
+
const statusMap: Record<string, { color: string; label: string }> = {
|
|
206
|
+
connected: { color: 'green', label: t('Connected') },
|
|
207
|
+
error: { color: 'red', label: t('Error') },
|
|
208
|
+
};
|
|
209
|
+
const info = statusMap[status] || { color: 'default', label: t('Disconnected') };
|
|
210
|
+
return <Tag color={info.color}>{info.label}</Tag>;
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
title: '',
|
|
215
|
+
key: 'actions',
|
|
216
|
+
width: 200,
|
|
217
|
+
render: (_: any, record: any) => (
|
|
218
|
+
<Space size="small">
|
|
219
|
+
{record.status !== 'connected' && (
|
|
220
|
+
<Button
|
|
221
|
+
size="small"
|
|
222
|
+
icon={<LinkOutlined />}
|
|
223
|
+
loading={actionLoading === `clone-${record.id}`}
|
|
224
|
+
onClick={() => handleClone(record)}
|
|
225
|
+
>
|
|
226
|
+
{t('Clone')}
|
|
227
|
+
</Button>
|
|
228
|
+
)}
|
|
229
|
+
<Button
|
|
230
|
+
size="small"
|
|
231
|
+
onClick={() => {
|
|
232
|
+
setEditingRepo(record);
|
|
233
|
+
form.setFieldsValue(record);
|
|
234
|
+
setModalOpen(true);
|
|
235
|
+
}}
|
|
236
|
+
>
|
|
237
|
+
{t('Edit')}
|
|
238
|
+
</Button>
|
|
239
|
+
<Popconfirm title={t('Delete this repository?')} onConfirm={() => handleDelete(record.id)}>
|
|
240
|
+
<Button size="small" danger icon={<DeleteOutlined />} />
|
|
241
|
+
</Popconfirm>
|
|
242
|
+
</Space>
|
|
243
|
+
),
|
|
244
|
+
},
|
|
245
|
+
];
|
|
246
|
+
|
|
247
|
+
return (
|
|
248
|
+
<div>
|
|
249
|
+
<div style={{ marginBottom: 16 }}>
|
|
250
|
+
<Button
|
|
251
|
+
type="primary"
|
|
252
|
+
icon={<PlusOutlined />}
|
|
253
|
+
onClick={() => {
|
|
254
|
+
setEditingRepo(null);
|
|
255
|
+
form.resetFields();
|
|
256
|
+
setModalOpen(true);
|
|
257
|
+
}}
|
|
258
|
+
>
|
|
259
|
+
{t('Add Repository')}
|
|
260
|
+
</Button>
|
|
261
|
+
</div>
|
|
262
|
+
|
|
263
|
+
<Table
|
|
264
|
+
dataSource={repos}
|
|
265
|
+
columns={columns}
|
|
266
|
+
rowKey="id"
|
|
267
|
+
size="small"
|
|
268
|
+
pagination={false}
|
|
269
|
+
rowClassName={(record) => (selectedRepo?.id === record.id ? 'ant-table-row-selected' : '')}
|
|
270
|
+
/>
|
|
271
|
+
|
|
272
|
+
<Modal
|
|
273
|
+
title={editingRepo ? t('Edit Repository') : t('Add Repository')}
|
|
274
|
+
open={modalOpen}
|
|
275
|
+
onOk={handleSave}
|
|
276
|
+
onCancel={() => {
|
|
277
|
+
setModalOpen(false);
|
|
278
|
+
setEditingRepo(null);
|
|
279
|
+
}}
|
|
280
|
+
width={520}
|
|
281
|
+
>
|
|
282
|
+
<Form form={form} layout="vertical" initialValues={{ defaultBranch: 'main', registryExportEnabled: false }}>
|
|
283
|
+
<Form.Item name="name" label={t('Repository Name')} rules={[{ required: true }]}>
|
|
284
|
+
<Input placeholder="my-project" />
|
|
285
|
+
</Form.Item>
|
|
286
|
+
<Form.Item name="repoUrl" label={t('Repository URL')} rules={[{ required: true }]}>
|
|
287
|
+
<Input placeholder="https://gitlab.com/user/repo.git" />
|
|
288
|
+
</Form.Item>
|
|
289
|
+
<Form.Item
|
|
290
|
+
name="gitAccountId"
|
|
291
|
+
label={t('Git Account')}
|
|
292
|
+
rules={[{ required: true, message: t('Please select a Git account') }]}
|
|
293
|
+
extra={t('Select the GitLab or GitHub account to use for this repository')}
|
|
294
|
+
>
|
|
295
|
+
<Select
|
|
296
|
+
placeholder={t('Select an account')}
|
|
297
|
+
options={gitAccounts.map((acc) => ({
|
|
298
|
+
value: acc.id,
|
|
299
|
+
label: `${acc.name} (${acc.username})`,
|
|
300
|
+
}))}
|
|
301
|
+
notFoundContent={t('No accounts configured. Add one in the Git Accounts tab.')}
|
|
302
|
+
/>
|
|
303
|
+
</Form.Item>
|
|
304
|
+
<Form.Item name="localPath" label={t('Local Path')} rules={[{ required: true }]}>
|
|
305
|
+
<Input placeholder="my-project" />
|
|
306
|
+
</Form.Item>
|
|
307
|
+
<Form.Item name="defaultBranch" label={t('Default Branch')}>
|
|
308
|
+
<Input placeholder="main" />
|
|
309
|
+
</Form.Item>
|
|
310
|
+
<Form.Item name="registryExportEnabled" label={t('Allow Skill Registry export')} valuePropName="checked">
|
|
311
|
+
<Switch />
|
|
312
|
+
</Form.Item>
|
|
313
|
+
<Form.Item
|
|
314
|
+
name="autoReviewFlowId"
|
|
315
|
+
label={t('Primary Auto Review Flow')}
|
|
316
|
+
extra={t('Only flows with automatic trigger modes are shown')}
|
|
317
|
+
>
|
|
318
|
+
<Select
|
|
319
|
+
allowClear
|
|
320
|
+
placeholder={t('Select a flow')}
|
|
321
|
+
options={getAutoFlowOptions(editingRepo?.id)}
|
|
322
|
+
notFoundContent={t('No matching flow available')}
|
|
323
|
+
/>
|
|
324
|
+
</Form.Item>
|
|
325
|
+
</Form>
|
|
326
|
+
</Modal>
|
|
327
|
+
</div>
|
|
328
|
+
);
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
export const RepositoryConfigSettings: React.FC = () => (
|
|
332
|
+
<GitManagerProvider>
|
|
333
|
+
<RepositoryConfig />
|
|
334
|
+
</GitManagerProvider>
|
|
335
|
+
);
|