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,303 +1,303 @@
|
|
|
1
|
-
import React, { useCallback, useEffect, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
Table,
|
|
4
|
-
Button,
|
|
5
|
-
Space,
|
|
6
|
-
Modal,
|
|
7
|
-
Form,
|
|
8
|
-
Input,
|
|
9
|
-
Select,
|
|
10
|
-
Switch,
|
|
11
|
-
Tag,
|
|
12
|
-
Popconfirm,
|
|
13
|
-
message,
|
|
14
|
-
Empty,
|
|
15
|
-
Tooltip,
|
|
16
|
-
} from 'antd';
|
|
17
|
-
import { PlusOutlined, EditOutlined, DeleteOutlined, BranchesOutlined } from '@ant-design/icons';
|
|
18
|
-
import { useApp } from '@nocobase/client-v2';
|
|
19
|
-
import { useGitManager } from '../context/GitManagerContext';
|
|
20
|
-
import { AIEmployeeSelect } from './AIEmployeeSelect';
|
|
21
|
-
import { LLMServiceSelect } from './LLMServiceSelect';
|
|
22
|
-
import { LLMModelSelect } from './LLMModelSelect';
|
|
23
|
-
import { REVIEW_PROMPT_TEMPLATES } from '../promptTemplates';
|
|
24
|
-
import { useT } from '../locale';
|
|
25
|
-
|
|
26
|
-
const TRIGGER_LABELS: Record<string, string> = {
|
|
27
|
-
manual: 'Manual',
|
|
28
|
-
onMergeRequestCreated: 'On MR Created',
|
|
29
|
-
both: 'Both',
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const POST_LABELS: Record<string, string> = {
|
|
33
|
-
auto: 'Auto',
|
|
34
|
-
manual: 'Manual',
|
|
35
|
-
disabled: 'Disabled',
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export const ReviewFlows: React.FC = () => {
|
|
39
|
-
const t = useT();
|
|
40
|
-
const api = useApp().apiClient;
|
|
41
|
-
const { repos } = useGitManager();
|
|
42
|
-
const [flows, setFlows] = useState<any[]>([]);
|
|
43
|
-
const [loading, setLoading] = useState(false);
|
|
44
|
-
const [editing, setEditing] = useState<any | null>(null);
|
|
45
|
-
const [open, setOpen] = useState(false);
|
|
46
|
-
const [templateKey, setTemplateKey] = useState<string | undefined>();
|
|
47
|
-
const [form] = Form.useForm();
|
|
48
|
-
|
|
49
|
-
const load = useCallback(async () => {
|
|
50
|
-
setLoading(true);
|
|
51
|
-
try {
|
|
52
|
-
const { data } = await api.request({ url: 'gitReviewFlows:list', params: { pageSize: 100 } });
|
|
53
|
-
setFlows(data?.data || []);
|
|
54
|
-
} finally {
|
|
55
|
-
setLoading(false);
|
|
56
|
-
}
|
|
57
|
-
}, [api]);
|
|
58
|
-
|
|
59
|
-
useEffect(() => {
|
|
60
|
-
load();
|
|
61
|
-
}, [load]);
|
|
62
|
-
|
|
63
|
-
const handleSave = async () => {
|
|
64
|
-
try {
|
|
65
|
-
const values = await form.validateFields();
|
|
66
|
-
// Normalize empty string to null for repositoryId
|
|
67
|
-
if (values.repositoryId === undefined || values.repositoryId === '') {
|
|
68
|
-
values.repositoryId = null;
|
|
69
|
-
}
|
|
70
|
-
if (editing?.id) {
|
|
71
|
-
await api.request({
|
|
72
|
-
url: 'gitReviewFlows:update',
|
|
73
|
-
method: 'post',
|
|
74
|
-
params: { filterByTk: editing.id },
|
|
75
|
-
data: values,
|
|
76
|
-
});
|
|
77
|
-
message.success(t('Flow updated'));
|
|
78
|
-
} else {
|
|
79
|
-
await api.request({ url: 'gitReviewFlows:create', method: 'post', data: values });
|
|
80
|
-
message.success(t('Flow created'));
|
|
81
|
-
}
|
|
82
|
-
setOpen(false);
|
|
83
|
-
setEditing(null);
|
|
84
|
-
setTemplateKey(undefined);
|
|
85
|
-
form.resetFields();
|
|
86
|
-
load();
|
|
87
|
-
} catch (err: any) {
|
|
88
|
-
if (err?.errorFields) return;
|
|
89
|
-
message.error(err?.response?.data?.errors?.[0]?.message || err?.message || t('Failed to save'));
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const handleDelete = async (id: number) => {
|
|
94
|
-
try {
|
|
95
|
-
await api.request({ url: 'gitReviewFlows:destroy', method: 'post', params: { filterByTk: id } });
|
|
96
|
-
message.success(t('Flow deleted'));
|
|
97
|
-
load();
|
|
98
|
-
} catch (err: any) {
|
|
99
|
-
message.error(err?.message || t('Failed to delete'));
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const openCreate = () => {
|
|
104
|
-
setEditing(null);
|
|
105
|
-
form.resetFields();
|
|
106
|
-
setTemplateKey('application');
|
|
107
|
-
form.setFieldsValue({
|
|
108
|
-
enabled: true,
|
|
109
|
-
triggerMode: 'manual',
|
|
110
|
-
postMode: 'manual',
|
|
111
|
-
instructions: REVIEW_PROMPT_TEMPLATES.find((tpl) => tpl.key === 'application')?.text,
|
|
112
|
-
});
|
|
113
|
-
setOpen(true);
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
const openEdit = (record: any) => {
|
|
117
|
-
setEditing(record);
|
|
118
|
-
setTemplateKey(undefined);
|
|
119
|
-
form.setFieldsValue(record);
|
|
120
|
-
setOpen(true);
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
const columns = [
|
|
124
|
-
{
|
|
125
|
-
title: t('Name'),
|
|
126
|
-
dataIndex: 'name',
|
|
127
|
-
render: (v: string, r: any) => (
|
|
128
|
-
<Space>
|
|
129
|
-
<span style={{ fontWeight: 500 }}>{v}</span>
|
|
130
|
-
{!r.enabled && <Tag color="default">{t('Disabled')}</Tag>}
|
|
131
|
-
</Space>
|
|
132
|
-
),
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
title: t('Repository'),
|
|
136
|
-
dataIndex: 'repositoryId',
|
|
137
|
-
render: (v: number | null) => {
|
|
138
|
-
if (v == null) return <Tag color="purple">{t('Global')}</Tag>;
|
|
139
|
-
const repo = repos.find((r: any) => r.id === v);
|
|
140
|
-
return repo ? (
|
|
141
|
-
<Space size={4}>
|
|
142
|
-
<BranchesOutlined />
|
|
143
|
-
{repo.name}
|
|
144
|
-
</Space>
|
|
145
|
-
) : (
|
|
146
|
-
`#${v}`
|
|
147
|
-
);
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
title: t('AI Employee'),
|
|
152
|
-
dataIndex: 'aiEmployeeUsername',
|
|
153
|
-
render: (v: string) => (v ? <Tag color="blue">@{v}</Tag> : <span style={{ color: '#999' }}>—</span>),
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
title: t('Trigger'),
|
|
157
|
-
dataIndex: 'triggerMode',
|
|
158
|
-
render: (v: string) => <Tag>{t(TRIGGER_LABELS[v] || v)}</Tag>,
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
title: t('Post'),
|
|
162
|
-
dataIndex: 'postMode',
|
|
163
|
-
render: (v: string) => {
|
|
164
|
-
const color = v === 'auto' ? 'green' : v === 'manual' ? 'orange' : 'default';
|
|
165
|
-
return <Tag color={color}>{t(POST_LABELS[v] || v)}</Tag>;
|
|
166
|
-
},
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
title: '',
|
|
170
|
-
key: 'actions',
|
|
171
|
-
width: 100,
|
|
172
|
-
render: (_: any, record: any) => (
|
|
173
|
-
<Space>
|
|
174
|
-
<Tooltip title={t('Edit')}>
|
|
175
|
-
<Button size="small" icon={<EditOutlined />} onClick={() => openEdit(record)} />
|
|
176
|
-
</Tooltip>
|
|
177
|
-
<Popconfirm title={t('Delete this flow?')} onConfirm={() => handleDelete(record.id)}>
|
|
178
|
-
<Button size="small" danger icon={<DeleteOutlined />} />
|
|
179
|
-
</Popconfirm>
|
|
180
|
-
</Space>
|
|
181
|
-
),
|
|
182
|
-
},
|
|
183
|
-
];
|
|
184
|
-
|
|
185
|
-
return (
|
|
186
|
-
<div>
|
|
187
|
-
<div style={{ marginBottom: 12, display: 'flex', justifyContent: 'space-between' }}>
|
|
188
|
-
<Button type="primary" icon={<PlusOutlined />} onClick={openCreate}>
|
|
189
|
-
{t('Add Review Flow')}
|
|
190
|
-
</Button>
|
|
191
|
-
<Button onClick={load} loading={loading}>
|
|
192
|
-
{t('Refresh')}
|
|
193
|
-
</Button>
|
|
194
|
-
</div>
|
|
195
|
-
<Table
|
|
196
|
-
size="small"
|
|
197
|
-
rowKey="id"
|
|
198
|
-
loading={loading}
|
|
199
|
-
dataSource={flows}
|
|
200
|
-
columns={columns}
|
|
201
|
-
locale={{ emptyText: <Empty description={t('No review flows yet')} /> }}
|
|
202
|
-
pagination={{ pageSize: 20 }}
|
|
203
|
-
/>
|
|
204
|
-
|
|
205
|
-
<Modal
|
|
206
|
-
title={editing?.id ? t('Edit Review Flow') : t('Add Review Flow')}
|
|
207
|
-
open={open}
|
|
208
|
-
onCancel={() => {
|
|
209
|
-
setOpen(false);
|
|
210
|
-
setEditing(null);
|
|
211
|
-
setTemplateKey(undefined);
|
|
212
|
-
form.resetFields();
|
|
213
|
-
}}
|
|
214
|
-
onOk={handleSave}
|
|
215
|
-
width={640}
|
|
216
|
-
destroyOnClose
|
|
217
|
-
>
|
|
218
|
-
<Form form={form} layout="vertical">
|
|
219
|
-
<Form.Item name="name" label={t('Name')} rules={[{ required: true }]}>
|
|
220
|
-
<Input placeholder={t('e.g. Default review flow')} />
|
|
221
|
-
</Form.Item>
|
|
222
|
-
<Form.Item name="repositoryId" label={t('Repository')} extra={t('Leave empty to apply to all repositories')}>
|
|
223
|
-
<Select
|
|
224
|
-
allowClear
|
|
225
|
-
placeholder={t('All repositories (global)')}
|
|
226
|
-
options={repos.map((r: any) => ({ value: r.id, label: r.name }))}
|
|
227
|
-
/>
|
|
228
|
-
</Form.Item>
|
|
229
|
-
<Form.Item name="aiEmployeeUsername" label={t('AI Employee')} rules={[{ required: true }]}>
|
|
230
|
-
<AIEmployeeSelect placeholder={t('Select an AI employee')} />
|
|
231
|
-
</Form.Item>
|
|
232
|
-
<Space.Compact style={{ width: '100%' }}>
|
|
233
|
-
<Form.Item name="llmService" label={t('LLM Service (optional)')} style={{ flex: 1, marginRight: 8 }}>
|
|
234
|
-
<LLMServiceSelect placeholder={t('Override flow LLM service')} />
|
|
235
|
-
</Form.Item>
|
|
236
|
-
<Form.Item
|
|
237
|
-
noStyle
|
|
238
|
-
shouldUpdate={(prevValues, currentValues) => prevValues.llmService !== currentValues.llmService}
|
|
239
|
-
>
|
|
240
|
-
{({ getFieldValue }) => {
|
|
241
|
-
const llmService = getFieldValue('llmService');
|
|
242
|
-
return (
|
|
243
|
-
<Form.Item name="model" label={t('Model (optional)')} style={{ flex: 1 }}>
|
|
244
|
-
{llmService ? (
|
|
245
|
-
<LLMModelSelect llmService={llmService} placeholder={t('Override LLM model')} />
|
|
246
|
-
) : (
|
|
247
|
-
<Input placeholder={t('Select an LLM service first')} disabled />
|
|
248
|
-
)}
|
|
249
|
-
</Form.Item>
|
|
250
|
-
);
|
|
251
|
-
}}
|
|
252
|
-
</Form.Item>
|
|
253
|
-
</Space.Compact>
|
|
254
|
-
<Form.Item
|
|
255
|
-
name="triggerMode"
|
|
256
|
-
label={t('Trigger Mode')}
|
|
257
|
-
rules={[{ required: true }]}
|
|
258
|
-
extra={t('Auto modes require enabling Auto Review on the repository')}
|
|
259
|
-
>
|
|
260
|
-
<Select
|
|
261
|
-
options={[
|
|
262
|
-
{ value: 'manual', label: t('Manual') },
|
|
263
|
-
{ value: 'onMergeRequestCreated', label: t('On Merge Request Created') },
|
|
264
|
-
{ value: 'both', label: t('Both') },
|
|
265
|
-
]}
|
|
266
|
-
/>
|
|
267
|
-
</Form.Item>
|
|
268
|
-
<Form.Item name="postMode" label={t('Post Mode')} rules={[{ required: true }]}>
|
|
269
|
-
<Select
|
|
270
|
-
options={[
|
|
271
|
-
{ value: 'auto', label: t('Auto post to MR') },
|
|
272
|
-
{ value: 'manual', label: t('Manual approval before posting') },
|
|
273
|
-
{ value: 'disabled', label: t('Do not post') },
|
|
274
|
-
]}
|
|
275
|
-
/>
|
|
276
|
-
</Form.Item>
|
|
277
|
-
<Form.Item name="branchFilter" label={t('Branch Filter (regex, optional)')}>
|
|
278
|
-
<Input placeholder="^(feature|hotfix)/.*$" />
|
|
279
|
-
</Form.Item>
|
|
280
|
-
<Form.Item label={t('Prompt template')} extra={t('Selecting a template replaces the instructions text')}>
|
|
281
|
-
<Select
|
|
282
|
-
allowClear
|
|
283
|
-
value={templateKey}
|
|
284
|
-
placeholder={t('Load a default prompt by code type')}
|
|
285
|
-
options={REVIEW_PROMPT_TEMPLATES.map((tpl) => ({ value: tpl.key, label: t(tpl.label) }))}
|
|
286
|
-
onChange={(key) => {
|
|
287
|
-
setTemplateKey(key);
|
|
288
|
-
const tpl = REVIEW_PROMPT_TEMPLATES.find((item) => item.key === key);
|
|
289
|
-
if (tpl) form.setFieldsValue({ instructions: tpl.text });
|
|
290
|
-
}}
|
|
291
|
-
/>
|
|
292
|
-
</Form.Item>
|
|
293
|
-
<Form.Item name="instructions" label={t('Additional Instructions (optional)')}>
|
|
294
|
-
<Input.TextArea rows={8} placeholder={t('Extra guidance appended to every review prompt')} />
|
|
295
|
-
</Form.Item>
|
|
296
|
-
<Form.Item name="enabled" label={t('Enabled')} valuePropName="checked">
|
|
297
|
-
<Switch />
|
|
298
|
-
</Form.Item>
|
|
299
|
-
</Form>
|
|
300
|
-
</Modal>
|
|
301
|
-
</div>
|
|
302
|
-
);
|
|
303
|
-
};
|
|
1
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Table,
|
|
4
|
+
Button,
|
|
5
|
+
Space,
|
|
6
|
+
Modal,
|
|
7
|
+
Form,
|
|
8
|
+
Input,
|
|
9
|
+
Select,
|
|
10
|
+
Switch,
|
|
11
|
+
Tag,
|
|
12
|
+
Popconfirm,
|
|
13
|
+
message,
|
|
14
|
+
Empty,
|
|
15
|
+
Tooltip,
|
|
16
|
+
} from 'antd';
|
|
17
|
+
import { PlusOutlined, EditOutlined, DeleteOutlined, BranchesOutlined } from '@ant-design/icons';
|
|
18
|
+
import { useApp } from '@nocobase/client-v2';
|
|
19
|
+
import { useGitManager } from '../context/GitManagerContext';
|
|
20
|
+
import { AIEmployeeSelect } from './AIEmployeeSelect';
|
|
21
|
+
import { LLMServiceSelect } from './LLMServiceSelect';
|
|
22
|
+
import { LLMModelSelect } from './LLMModelSelect';
|
|
23
|
+
import { REVIEW_PROMPT_TEMPLATES } from '../promptTemplates';
|
|
24
|
+
import { useT } from '../locale';
|
|
25
|
+
|
|
26
|
+
const TRIGGER_LABELS: Record<string, string> = {
|
|
27
|
+
manual: 'Manual',
|
|
28
|
+
onMergeRequestCreated: 'On MR Created',
|
|
29
|
+
both: 'Both',
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const POST_LABELS: Record<string, string> = {
|
|
33
|
+
auto: 'Auto',
|
|
34
|
+
manual: 'Manual',
|
|
35
|
+
disabled: 'Disabled',
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const ReviewFlows: React.FC = () => {
|
|
39
|
+
const t = useT();
|
|
40
|
+
const api = useApp().apiClient;
|
|
41
|
+
const { repos } = useGitManager();
|
|
42
|
+
const [flows, setFlows] = useState<any[]>([]);
|
|
43
|
+
const [loading, setLoading] = useState(false);
|
|
44
|
+
const [editing, setEditing] = useState<any | null>(null);
|
|
45
|
+
const [open, setOpen] = useState(false);
|
|
46
|
+
const [templateKey, setTemplateKey] = useState<string | undefined>();
|
|
47
|
+
const [form] = Form.useForm();
|
|
48
|
+
|
|
49
|
+
const load = useCallback(async () => {
|
|
50
|
+
setLoading(true);
|
|
51
|
+
try {
|
|
52
|
+
const { data } = await api.request({ url: 'gitReviewFlows:list', params: { pageSize: 100 } });
|
|
53
|
+
setFlows(data?.data || []);
|
|
54
|
+
} finally {
|
|
55
|
+
setLoading(false);
|
|
56
|
+
}
|
|
57
|
+
}, [api]);
|
|
58
|
+
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
load();
|
|
61
|
+
}, [load]);
|
|
62
|
+
|
|
63
|
+
const handleSave = async () => {
|
|
64
|
+
try {
|
|
65
|
+
const values = await form.validateFields();
|
|
66
|
+
// Normalize empty string to null for repositoryId
|
|
67
|
+
if (values.repositoryId === undefined || values.repositoryId === '') {
|
|
68
|
+
values.repositoryId = null;
|
|
69
|
+
}
|
|
70
|
+
if (editing?.id) {
|
|
71
|
+
await api.request({
|
|
72
|
+
url: 'gitReviewFlows:update',
|
|
73
|
+
method: 'post',
|
|
74
|
+
params: { filterByTk: editing.id },
|
|
75
|
+
data: values,
|
|
76
|
+
});
|
|
77
|
+
message.success(t('Flow updated'));
|
|
78
|
+
} else {
|
|
79
|
+
await api.request({ url: 'gitReviewFlows:create', method: 'post', data: values });
|
|
80
|
+
message.success(t('Flow created'));
|
|
81
|
+
}
|
|
82
|
+
setOpen(false);
|
|
83
|
+
setEditing(null);
|
|
84
|
+
setTemplateKey(undefined);
|
|
85
|
+
form.resetFields();
|
|
86
|
+
load();
|
|
87
|
+
} catch (err: any) {
|
|
88
|
+
if (err?.errorFields) return;
|
|
89
|
+
message.error(err?.response?.data?.errors?.[0]?.message || err?.message || t('Failed to save'));
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const handleDelete = async (id: number) => {
|
|
94
|
+
try {
|
|
95
|
+
await api.request({ url: 'gitReviewFlows:destroy', method: 'post', params: { filterByTk: id } });
|
|
96
|
+
message.success(t('Flow deleted'));
|
|
97
|
+
load();
|
|
98
|
+
} catch (err: any) {
|
|
99
|
+
message.error(err?.message || t('Failed to delete'));
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const openCreate = () => {
|
|
104
|
+
setEditing(null);
|
|
105
|
+
form.resetFields();
|
|
106
|
+
setTemplateKey('application');
|
|
107
|
+
form.setFieldsValue({
|
|
108
|
+
enabled: true,
|
|
109
|
+
triggerMode: 'manual',
|
|
110
|
+
postMode: 'manual',
|
|
111
|
+
instructions: REVIEW_PROMPT_TEMPLATES.find((tpl) => tpl.key === 'application')?.text,
|
|
112
|
+
});
|
|
113
|
+
setOpen(true);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const openEdit = (record: any) => {
|
|
117
|
+
setEditing(record);
|
|
118
|
+
setTemplateKey(undefined);
|
|
119
|
+
form.setFieldsValue(record);
|
|
120
|
+
setOpen(true);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const columns = [
|
|
124
|
+
{
|
|
125
|
+
title: t('Name'),
|
|
126
|
+
dataIndex: 'name',
|
|
127
|
+
render: (v: string, r: any) => (
|
|
128
|
+
<Space>
|
|
129
|
+
<span style={{ fontWeight: 500 }}>{v}</span>
|
|
130
|
+
{!r.enabled && <Tag color="default">{t('Disabled')}</Tag>}
|
|
131
|
+
</Space>
|
|
132
|
+
),
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
title: t('Repository'),
|
|
136
|
+
dataIndex: 'repositoryId',
|
|
137
|
+
render: (v: number | null) => {
|
|
138
|
+
if (v == null) return <Tag color="purple">{t('Global')}</Tag>;
|
|
139
|
+
const repo = repos.find((r: any) => r.id === v);
|
|
140
|
+
return repo ? (
|
|
141
|
+
<Space size={4}>
|
|
142
|
+
<BranchesOutlined />
|
|
143
|
+
{repo.name}
|
|
144
|
+
</Space>
|
|
145
|
+
) : (
|
|
146
|
+
`#${v}`
|
|
147
|
+
);
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
title: t('AI Employee'),
|
|
152
|
+
dataIndex: 'aiEmployeeUsername',
|
|
153
|
+
render: (v: string) => (v ? <Tag color="blue">@{v}</Tag> : <span style={{ color: '#999' }}>—</span>),
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
title: t('Trigger'),
|
|
157
|
+
dataIndex: 'triggerMode',
|
|
158
|
+
render: (v: string) => <Tag>{t(TRIGGER_LABELS[v] || v)}</Tag>,
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
title: t('Post'),
|
|
162
|
+
dataIndex: 'postMode',
|
|
163
|
+
render: (v: string) => {
|
|
164
|
+
const color = v === 'auto' ? 'green' : v === 'manual' ? 'orange' : 'default';
|
|
165
|
+
return <Tag color={color}>{t(POST_LABELS[v] || v)}</Tag>;
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
title: '',
|
|
170
|
+
key: 'actions',
|
|
171
|
+
width: 100,
|
|
172
|
+
render: (_: any, record: any) => (
|
|
173
|
+
<Space>
|
|
174
|
+
<Tooltip title={t('Edit')}>
|
|
175
|
+
<Button size="small" icon={<EditOutlined />} onClick={() => openEdit(record)} />
|
|
176
|
+
</Tooltip>
|
|
177
|
+
<Popconfirm title={t('Delete this flow?')} onConfirm={() => handleDelete(record.id)}>
|
|
178
|
+
<Button size="small" danger icon={<DeleteOutlined />} />
|
|
179
|
+
</Popconfirm>
|
|
180
|
+
</Space>
|
|
181
|
+
),
|
|
182
|
+
},
|
|
183
|
+
];
|
|
184
|
+
|
|
185
|
+
return (
|
|
186
|
+
<div>
|
|
187
|
+
<div style={{ marginBottom: 12, display: 'flex', justifyContent: 'space-between' }}>
|
|
188
|
+
<Button type="primary" icon={<PlusOutlined />} onClick={openCreate}>
|
|
189
|
+
{t('Add Review Flow')}
|
|
190
|
+
</Button>
|
|
191
|
+
<Button onClick={load} loading={loading}>
|
|
192
|
+
{t('Refresh')}
|
|
193
|
+
</Button>
|
|
194
|
+
</div>
|
|
195
|
+
<Table
|
|
196
|
+
size="small"
|
|
197
|
+
rowKey="id"
|
|
198
|
+
loading={loading}
|
|
199
|
+
dataSource={flows}
|
|
200
|
+
columns={columns}
|
|
201
|
+
locale={{ emptyText: <Empty description={t('No review flows yet')} /> }}
|
|
202
|
+
pagination={{ pageSize: 20 }}
|
|
203
|
+
/>
|
|
204
|
+
|
|
205
|
+
<Modal
|
|
206
|
+
title={editing?.id ? t('Edit Review Flow') : t('Add Review Flow')}
|
|
207
|
+
open={open}
|
|
208
|
+
onCancel={() => {
|
|
209
|
+
setOpen(false);
|
|
210
|
+
setEditing(null);
|
|
211
|
+
setTemplateKey(undefined);
|
|
212
|
+
form.resetFields();
|
|
213
|
+
}}
|
|
214
|
+
onOk={handleSave}
|
|
215
|
+
width={640}
|
|
216
|
+
destroyOnClose
|
|
217
|
+
>
|
|
218
|
+
<Form form={form} layout="vertical">
|
|
219
|
+
<Form.Item name="name" label={t('Name')} rules={[{ required: true }]}>
|
|
220
|
+
<Input placeholder={t('e.g. Default review flow')} />
|
|
221
|
+
</Form.Item>
|
|
222
|
+
<Form.Item name="repositoryId" label={t('Repository')} extra={t('Leave empty to apply to all repositories')}>
|
|
223
|
+
<Select
|
|
224
|
+
allowClear
|
|
225
|
+
placeholder={t('All repositories (global)')}
|
|
226
|
+
options={repos.map((r: any) => ({ value: r.id, label: r.name }))}
|
|
227
|
+
/>
|
|
228
|
+
</Form.Item>
|
|
229
|
+
<Form.Item name="aiEmployeeUsername" label={t('AI Employee')} rules={[{ required: true }]}>
|
|
230
|
+
<AIEmployeeSelect placeholder={t('Select an AI employee')} />
|
|
231
|
+
</Form.Item>
|
|
232
|
+
<Space.Compact style={{ width: '100%' }}>
|
|
233
|
+
<Form.Item name="llmService" label={t('LLM Service (optional)')} style={{ flex: 1, marginRight: 8 }}>
|
|
234
|
+
<LLMServiceSelect placeholder={t('Override flow LLM service')} />
|
|
235
|
+
</Form.Item>
|
|
236
|
+
<Form.Item
|
|
237
|
+
noStyle
|
|
238
|
+
shouldUpdate={(prevValues, currentValues) => prevValues.llmService !== currentValues.llmService}
|
|
239
|
+
>
|
|
240
|
+
{({ getFieldValue }) => {
|
|
241
|
+
const llmService = getFieldValue('llmService');
|
|
242
|
+
return (
|
|
243
|
+
<Form.Item name="model" label={t('Model (optional)')} style={{ flex: 1 }}>
|
|
244
|
+
{llmService ? (
|
|
245
|
+
<LLMModelSelect llmService={llmService} placeholder={t('Override LLM model')} />
|
|
246
|
+
) : (
|
|
247
|
+
<Input placeholder={t('Select an LLM service first')} disabled />
|
|
248
|
+
)}
|
|
249
|
+
</Form.Item>
|
|
250
|
+
);
|
|
251
|
+
}}
|
|
252
|
+
</Form.Item>
|
|
253
|
+
</Space.Compact>
|
|
254
|
+
<Form.Item
|
|
255
|
+
name="triggerMode"
|
|
256
|
+
label={t('Trigger Mode')}
|
|
257
|
+
rules={[{ required: true }]}
|
|
258
|
+
extra={t('Auto modes require enabling Auto Review on the repository')}
|
|
259
|
+
>
|
|
260
|
+
<Select
|
|
261
|
+
options={[
|
|
262
|
+
{ value: 'manual', label: t('Manual') },
|
|
263
|
+
{ value: 'onMergeRequestCreated', label: t('On Merge Request Created') },
|
|
264
|
+
{ value: 'both', label: t('Both') },
|
|
265
|
+
]}
|
|
266
|
+
/>
|
|
267
|
+
</Form.Item>
|
|
268
|
+
<Form.Item name="postMode" label={t('Post Mode')} rules={[{ required: true }]}>
|
|
269
|
+
<Select
|
|
270
|
+
options={[
|
|
271
|
+
{ value: 'auto', label: t('Auto post to MR') },
|
|
272
|
+
{ value: 'manual', label: t('Manual approval before posting') },
|
|
273
|
+
{ value: 'disabled', label: t('Do not post') },
|
|
274
|
+
]}
|
|
275
|
+
/>
|
|
276
|
+
</Form.Item>
|
|
277
|
+
<Form.Item name="branchFilter" label={t('Branch Filter (regex, optional)')}>
|
|
278
|
+
<Input placeholder="^(feature|hotfix)/.*$" />
|
|
279
|
+
</Form.Item>
|
|
280
|
+
<Form.Item label={t('Prompt template')} extra={t('Selecting a template replaces the instructions text')}>
|
|
281
|
+
<Select
|
|
282
|
+
allowClear
|
|
283
|
+
value={templateKey}
|
|
284
|
+
placeholder={t('Load a default prompt by code type')}
|
|
285
|
+
options={REVIEW_PROMPT_TEMPLATES.map((tpl) => ({ value: tpl.key, label: t(tpl.label) }))}
|
|
286
|
+
onChange={(key) => {
|
|
287
|
+
setTemplateKey(key);
|
|
288
|
+
const tpl = REVIEW_PROMPT_TEMPLATES.find((item) => item.key === key);
|
|
289
|
+
if (tpl) form.setFieldsValue({ instructions: tpl.text });
|
|
290
|
+
}}
|
|
291
|
+
/>
|
|
292
|
+
</Form.Item>
|
|
293
|
+
<Form.Item name="instructions" label={t('Additional Instructions (optional)')}>
|
|
294
|
+
<Input.TextArea rows={8} placeholder={t('Extra guidance appended to every review prompt')} />
|
|
295
|
+
</Form.Item>
|
|
296
|
+
<Form.Item name="enabled" label={t('Enabled')} valuePropName="checked">
|
|
297
|
+
<Switch />
|
|
298
|
+
</Form.Item>
|
|
299
|
+
</Form>
|
|
300
|
+
</Modal>
|
|
301
|
+
</div>
|
|
302
|
+
);
|
|
303
|
+
};
|