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,547 +1,547 @@
|
|
|
1
|
-
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
Alert,
|
|
4
|
-
AutoComplete,
|
|
5
|
-
Button,
|
|
6
|
-
Card,
|
|
7
|
-
Descriptions,
|
|
8
|
-
Form,
|
|
9
|
-
Input,
|
|
10
|
-
Modal,
|
|
11
|
-
Popconfirm,
|
|
12
|
-
Radio,
|
|
13
|
-
Select,
|
|
14
|
-
Space,
|
|
15
|
-
Switch,
|
|
16
|
-
Table,
|
|
17
|
-
Tag,
|
|
18
|
-
Typography,
|
|
19
|
-
message,
|
|
20
|
-
} from 'antd';
|
|
21
|
-
import { DeleteOutlined, EditOutlined, HistoryOutlined, PlayCircleOutlined, PlusOutlined } from '@ant-design/icons';
|
|
22
|
-
import { useFlowContext } from '@nocobase/flow-engine';
|
|
23
|
-
import { useT } from '../locale';
|
|
24
|
-
|
|
25
|
-
type SubtreePolicy = 'fastForward' | 'replace' | 'merge';
|
|
26
|
-
|
|
27
|
-
interface RepositoryItem {
|
|
28
|
-
id: number;
|
|
29
|
-
name: string;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
interface SubtreeConfig {
|
|
33
|
-
id: number;
|
|
34
|
-
name: string;
|
|
35
|
-
repositoryId: number;
|
|
36
|
-
sourceBranch: string;
|
|
37
|
-
sourcePrefix: string;
|
|
38
|
-
sourcePrefixes?: string[];
|
|
39
|
-
targetBranch: string;
|
|
40
|
-
remoteName: string;
|
|
41
|
-
defaultPolicy: SubtreePolicy;
|
|
42
|
-
pushAfterRun: boolean;
|
|
43
|
-
enabled: boolean;
|
|
44
|
-
lastStatus?: string;
|
|
45
|
-
lastRunAt?: string;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
type ConfigFormValues = Omit<SubtreeConfig, 'id' | 'lastStatus' | 'lastRunAt'>;
|
|
49
|
-
|
|
50
|
-
type SearchOption = { label?: React.ReactNode; value?: string | number };
|
|
51
|
-
|
|
52
|
-
function optionText(option?: SearchOption): string {
|
|
53
|
-
return String(option?.label ?? option?.value ?? '').toLocaleLowerCase();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function filterOption(input: string, option?: SearchOption): boolean {
|
|
57
|
-
return optionText(option).includes(input.trim().toLocaleLowerCase());
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function filterSort(optionA: SearchOption, optionB: SearchOption, info: { searchValue: string }): number {
|
|
61
|
-
const search = info.searchValue.trim().toLocaleLowerCase();
|
|
62
|
-
const a = optionText(optionA);
|
|
63
|
-
const b = optionText(optionB);
|
|
64
|
-
const aStarts = a.startsWith(search);
|
|
65
|
-
const bStarts = b.startsWith(search);
|
|
66
|
-
if (aStarts !== bStarts) return aStarts ? -1 : 1;
|
|
67
|
-
return a.localeCompare(b);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
interface PreviewResult {
|
|
71
|
-
sourceSha: string;
|
|
72
|
-
splitSha: string;
|
|
73
|
-
targetExists: boolean;
|
|
74
|
-
targetSha: string | null;
|
|
75
|
-
relationship: 'target-missing' | 'already-up-to-date' | 'fast-forward' | 'diverged';
|
|
76
|
-
recommendedPolicy: SubtreePolicy;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
interface OptionsResult {
|
|
80
|
-
branches: string[];
|
|
81
|
-
folders: string[];
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
interface SubtreeRun {
|
|
85
|
-
id: number;
|
|
86
|
-
policy: SubtreePolicy;
|
|
87
|
-
executionMode: 'app';
|
|
88
|
-
status: string;
|
|
89
|
-
sourceSha?: string;
|
|
90
|
-
splitSha?: string;
|
|
91
|
-
targetBeforeSha?: string;
|
|
92
|
-
targetAfterSha?: string;
|
|
93
|
-
startedAt: string;
|
|
94
|
-
finishedAt?: string;
|
|
95
|
-
error?: string;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function errorMessage(error: unknown): string {
|
|
99
|
-
if (error && typeof error === 'object') {
|
|
100
|
-
const response = 'response' in error ? error.response : undefined;
|
|
101
|
-
if (response && typeof response === 'object' && 'data' in response) {
|
|
102
|
-
const data = response.data;
|
|
103
|
-
if (data && typeof data === 'object' && 'errors' in data && Array.isArray(data.errors)) {
|
|
104
|
-
const first = data.errors[0];
|
|
105
|
-
if (first && typeof first === 'object' && 'message' in first && typeof first.message === 'string') {
|
|
106
|
-
return first.message;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
if ('message' in error && typeof error.message === 'string') return error.message;
|
|
111
|
-
}
|
|
112
|
-
return String(error);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export default function SubtreeSplits() {
|
|
116
|
-
const ctx = useFlowContext();
|
|
117
|
-
const t = useT();
|
|
118
|
-
const [form] = Form.useForm<ConfigFormValues>();
|
|
119
|
-
const [configs, setConfigs] = useState<SubtreeConfig[]>([]);
|
|
120
|
-
const [repositories, setRepositories] = useState<RepositoryItem[]>([]);
|
|
121
|
-
const [branches, setBranches] = useState<string[]>([]);
|
|
122
|
-
const [folders, setFolders] = useState<string[]>([]);
|
|
123
|
-
const [loading, setLoading] = useState(false);
|
|
124
|
-
const [saving, setSaving] = useState(false);
|
|
125
|
-
const [configOpen, setConfigOpen] = useState(false);
|
|
126
|
-
const [editing, setEditing] = useState<SubtreeConfig | null>(null);
|
|
127
|
-
const [runningConfig, setRunningConfig] = useState<SubtreeConfig | null>(null);
|
|
128
|
-
const [policy, setPolicy] = useState<SubtreePolicy>('fastForward');
|
|
129
|
-
const [pushAfterRun, setPushAfterRun] = useState(true);
|
|
130
|
-
const [preview, setPreview] = useState<PreviewResult | null>(null);
|
|
131
|
-
const [previewing, setPreviewing] = useState(false);
|
|
132
|
-
const [running, setRunning] = useState(false);
|
|
133
|
-
const [replaceConfirmation, setReplaceConfirmation] = useState('');
|
|
134
|
-
const [historyConfig, setHistoryConfig] = useState<SubtreeConfig | null>(null);
|
|
135
|
-
const [historyRuns, setHistoryRuns] = useState<SubtreeRun[]>([]);
|
|
136
|
-
const [historyLoading, setHistoryLoading] = useState(false);
|
|
137
|
-
|
|
138
|
-
const repositoryName = useMemo(
|
|
139
|
-
() => new Map(repositories.map((repository) => [repository.id, repository.name])),
|
|
140
|
-
[repositories],
|
|
141
|
-
);
|
|
142
|
-
|
|
143
|
-
const loadData = useCallback(async () => {
|
|
144
|
-
setLoading(true);
|
|
145
|
-
try {
|
|
146
|
-
const [configResponse, repositoryResponse] = await Promise.all([
|
|
147
|
-
ctx.api.request({ url: 'gitSubtreeConfigs:list', params: { pageSize: 200, sort: ['name'] } }),
|
|
148
|
-
ctx.api.request({ url: 'gitRepositories:list', params: { pageSize: 200, sort: ['name'] } }),
|
|
149
|
-
]);
|
|
150
|
-
setConfigs((configResponse.data?.data || []) as SubtreeConfig[]);
|
|
151
|
-
setRepositories((repositoryResponse.data?.data || []) as RepositoryItem[]);
|
|
152
|
-
} catch (error) {
|
|
153
|
-
message.error(errorMessage(error));
|
|
154
|
-
} finally {
|
|
155
|
-
setLoading(false);
|
|
156
|
-
}
|
|
157
|
-
}, [ctx.api]);
|
|
158
|
-
|
|
159
|
-
useEffect(() => {
|
|
160
|
-
loadData();
|
|
161
|
-
}, [loadData]);
|
|
162
|
-
|
|
163
|
-
const loadOptions = async (repositoryId: number, sourceBranch?: string, remoteName = 'origin') => {
|
|
164
|
-
const response = await ctx.api.request({
|
|
165
|
-
url: 'gitManager:subtreeOptions',
|
|
166
|
-
method: 'post',
|
|
167
|
-
params: { repositoryId, sourceBranch, remoteName },
|
|
168
|
-
});
|
|
169
|
-
// v1 and v2 requesters can wrap the action payload differently.
|
|
170
|
-
// Normalize both `{ data: { branches } }` and `{ data: { data: { branches } } }`.
|
|
171
|
-
const data = (response.data?.data?.data || response.data?.data) as OptionsResult;
|
|
172
|
-
setBranches(data?.branches || []);
|
|
173
|
-
setFolders(data?.folders || []);
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
const openCreate = () => {
|
|
177
|
-
setEditing(null);
|
|
178
|
-
setBranches([]);
|
|
179
|
-
setFolders([]);
|
|
180
|
-
form.resetFields();
|
|
181
|
-
form.setFieldsValue({ remoteName: 'origin', defaultPolicy: 'fastForward', pushAfterRun: true, enabled: true });
|
|
182
|
-
setConfigOpen(true);
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
const openEdit = async (config: SubtreeConfig) => {
|
|
186
|
-
setEditing(config);
|
|
187
|
-
form.setFieldsValue({
|
|
188
|
-
...config,
|
|
189
|
-
sourcePrefixes: config.sourcePrefixes?.length ? config.sourcePrefixes : [config.sourcePrefix],
|
|
190
|
-
});
|
|
191
|
-
setConfigOpen(true);
|
|
192
|
-
try {
|
|
193
|
-
await loadOptions(config.repositoryId, config.sourceBranch, config.remoteName);
|
|
194
|
-
} catch (error) {
|
|
195
|
-
message.error(errorMessage(error));
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
const saveConfig = async () => {
|
|
200
|
-
const values = await form.validateFields();
|
|
201
|
-
const sourcePrefixes = values.sourcePrefixes || [];
|
|
202
|
-
setSaving(true);
|
|
203
|
-
try {
|
|
204
|
-
await ctx.api.request({
|
|
205
|
-
url: editing ? 'gitSubtreeConfigs:update' : 'gitSubtreeConfigs:create',
|
|
206
|
-
method: 'post',
|
|
207
|
-
params: editing ? { filterByTk: editing.id } : undefined,
|
|
208
|
-
data: { ...values, sourcePrefix: sourcePrefixes[0], sourcePrefixes },
|
|
209
|
-
});
|
|
210
|
-
message.success(t(editing ? 'Subtree configuration updated' : 'Subtree configuration created'));
|
|
211
|
-
setConfigOpen(false);
|
|
212
|
-
await loadData();
|
|
213
|
-
} catch (error) {
|
|
214
|
-
message.error(errorMessage(error));
|
|
215
|
-
} finally {
|
|
216
|
-
setSaving(false);
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
const deleteConfig = async (id: number) => {
|
|
221
|
-
try {
|
|
222
|
-
await ctx.api.request({ url: 'gitSubtreeConfigs:destroy', method: 'post', params: { filterByTk: id } });
|
|
223
|
-
message.success(t('Deleted'));
|
|
224
|
-
await loadData();
|
|
225
|
-
} catch (error) {
|
|
226
|
-
message.error(errorMessage(error));
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
const openRun = (config: SubtreeConfig) => {
|
|
231
|
-
setRunningConfig(config);
|
|
232
|
-
setPolicy(config.defaultPolicy || 'fastForward');
|
|
233
|
-
setPushAfterRun(config.pushAfterRun !== false);
|
|
234
|
-
setPreview(null);
|
|
235
|
-
setReplaceConfirmation('');
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
const openHistory = async (config: SubtreeConfig) => {
|
|
239
|
-
setHistoryConfig(config);
|
|
240
|
-
setHistoryLoading(true);
|
|
241
|
-
try {
|
|
242
|
-
const response = await ctx.api.request({
|
|
243
|
-
url: 'gitSubtreeRuns:list',
|
|
244
|
-
params: { filter: { configId: config.id }, pageSize: 100, sort: ['-startedAt'] },
|
|
245
|
-
});
|
|
246
|
-
setHistoryRuns((response.data?.data || []) as SubtreeRun[]);
|
|
247
|
-
} catch (error) {
|
|
248
|
-
message.error(errorMessage(error));
|
|
249
|
-
} finally {
|
|
250
|
-
setHistoryLoading(false);
|
|
251
|
-
}
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
const previewRun = async () => {
|
|
255
|
-
if (!runningConfig) return;
|
|
256
|
-
setPreviewing(true);
|
|
257
|
-
try {
|
|
258
|
-
const response = await ctx.api.request({
|
|
259
|
-
url: 'gitManager:subtreePreview',
|
|
260
|
-
method: 'post',
|
|
261
|
-
data: { configId: runningConfig.id },
|
|
262
|
-
});
|
|
263
|
-
const data = response.data?.data as PreviewResult;
|
|
264
|
-
setPreview(data);
|
|
265
|
-
setPolicy(data.recommendedPolicy);
|
|
266
|
-
} catch (error) {
|
|
267
|
-
message.error(errorMessage(error));
|
|
268
|
-
} finally {
|
|
269
|
-
setPreviewing(false);
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
const runSubtree = async () => {
|
|
274
|
-
if (!runningConfig || !preview) return;
|
|
275
|
-
if (policy === 'replace' && replaceConfirmation !== runningConfig.targetBranch) return;
|
|
276
|
-
setRunning(true);
|
|
277
|
-
try {
|
|
278
|
-
await ctx.api.request({
|
|
279
|
-
url: policy === 'replace' ? 'gitManager:subtreeReplace' : 'gitManager:subtreeRun',
|
|
280
|
-
method: 'post',
|
|
281
|
-
data: {
|
|
282
|
-
configId: runningConfig.id,
|
|
283
|
-
policy,
|
|
284
|
-
push: pushAfterRun,
|
|
285
|
-
expectedTargetSha: preview.targetSha,
|
|
286
|
-
},
|
|
287
|
-
});
|
|
288
|
-
message.success(t('Subtree split completed'));
|
|
289
|
-
setRunningConfig(null);
|
|
290
|
-
await loadData();
|
|
291
|
-
} catch (error) {
|
|
292
|
-
message.error(errorMessage(error));
|
|
293
|
-
} finally {
|
|
294
|
-
setRunning(false);
|
|
295
|
-
}
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
const columns = [
|
|
299
|
-
{ title: t('Name'), dataIndex: 'name', key: 'name' },
|
|
300
|
-
{
|
|
301
|
-
title: t('Repository'),
|
|
302
|
-
dataIndex: 'repositoryId',
|
|
303
|
-
key: 'repositoryId',
|
|
304
|
-
render: (repositoryId: number) => repositoryName.get(repositoryId) || repositoryId,
|
|
305
|
-
},
|
|
306
|
-
{
|
|
307
|
-
title: t('Source'),
|
|
308
|
-
key: 'source',
|
|
309
|
-
render: (_: unknown, config: SubtreeConfig) =>
|
|
310
|
-
`${config.sourceBranch}:${(config.sourcePrefixes?.length ? config.sourcePrefixes : [config.sourcePrefix]).join(
|
|
311
|
-
', ',
|
|
312
|
-
)}`,
|
|
313
|
-
},
|
|
314
|
-
{ title: t('Target branch'), dataIndex: 'targetBranch', key: 'targetBranch' },
|
|
315
|
-
{
|
|
316
|
-
title: t('Last status'),
|
|
317
|
-
dataIndex: 'lastStatus',
|
|
318
|
-
key: 'lastStatus',
|
|
319
|
-
render: (status?: string) =>
|
|
320
|
-
status ? (
|
|
321
|
-
<Tag color={status === 'success' ? 'green' : status === 'conflict' ? 'orange' : 'red'}>{status}</Tag>
|
|
322
|
-
) : (
|
|
323
|
-
'—'
|
|
324
|
-
),
|
|
325
|
-
},
|
|
326
|
-
{
|
|
327
|
-
title: t('Actions'),
|
|
328
|
-
key: 'actions',
|
|
329
|
-
render: (_: unknown, config: SubtreeConfig) => (
|
|
330
|
-
<Space>
|
|
331
|
-
<Button icon={<PlayCircleOutlined />} size="small" disabled={!config.enabled} onClick={() => openRun(config)}>
|
|
332
|
-
{t('Run')}
|
|
333
|
-
</Button>
|
|
334
|
-
<Button icon={<EditOutlined />} size="small" onClick={() => openEdit(config)} aria-label={t('Edit')} />
|
|
335
|
-
<Button
|
|
336
|
-
icon={<HistoryOutlined />}
|
|
337
|
-
size="small"
|
|
338
|
-
onClick={() => openHistory(config)}
|
|
339
|
-
aria-label={t('Run history')}
|
|
340
|
-
/>
|
|
341
|
-
<Popconfirm title={t('Delete this subtree configuration?')} onConfirm={() => deleteConfig(config.id)}>
|
|
342
|
-
<Button icon={<DeleteOutlined />} size="small" danger aria-label={t('Delete')} />
|
|
343
|
-
</Popconfirm>
|
|
344
|
-
</Space>
|
|
345
|
-
),
|
|
346
|
-
},
|
|
347
|
-
];
|
|
348
|
-
|
|
349
|
-
return (
|
|
350
|
-
<Card
|
|
351
|
-
title={t('Subtree Splits')}
|
|
352
|
-
extra={
|
|
353
|
-
<Button type="primary" icon={<PlusOutlined />} onClick={openCreate}>
|
|
354
|
-
{t('Add subtree configuration')}
|
|
355
|
-
</Button>
|
|
356
|
-
}
|
|
357
|
-
>
|
|
358
|
-
<Table rowKey="id" dataSource={configs} columns={columns} loading={loading} pagination={{ pageSize: 20 }} />
|
|
359
|
-
|
|
360
|
-
<Modal
|
|
361
|
-
title={editing ? t('Edit subtree configuration') : t('Add subtree configuration')}
|
|
362
|
-
open={configOpen}
|
|
363
|
-
onCancel={() => setConfigOpen(false)}
|
|
364
|
-
onOk={saveConfig}
|
|
365
|
-
confirmLoading={saving}
|
|
366
|
-
width={680}
|
|
367
|
-
destroyOnClose
|
|
368
|
-
>
|
|
369
|
-
<Form form={form} layout="vertical">
|
|
370
|
-
<Form.Item name="name" label={t('Name')} rules={[{ required: true }]}>
|
|
371
|
-
<Input />
|
|
372
|
-
</Form.Item>
|
|
373
|
-
<Form.Item name="repositoryId" label={t('Repository')} rules={[{ required: true }]}>
|
|
374
|
-
<Select
|
|
375
|
-
showSearch
|
|
376
|
-
filterOption={filterOption}
|
|
377
|
-
filterSort={filterSort}
|
|
378
|
-
options={repositories.map((repository) => ({ value: repository.id, label: repository.name }))}
|
|
379
|
-
onChange={async (repositoryId: number) => {
|
|
380
|
-
form.setFieldsValue({ sourceBranch: undefined, sourcePrefix: undefined, sourcePrefixes: undefined });
|
|
381
|
-
setFolders([]);
|
|
382
|
-
try {
|
|
383
|
-
await loadOptions(repositoryId, undefined, form.getFieldValue('remoteName'));
|
|
384
|
-
} catch (error) {
|
|
385
|
-
message.error(errorMessage(error));
|
|
386
|
-
}
|
|
387
|
-
}}
|
|
388
|
-
/>
|
|
389
|
-
</Form.Item>
|
|
390
|
-
<Form.Item name="remoteName" label={t('Remote name')} rules={[{ required: true }]}>
|
|
391
|
-
<Input placeholder="origin" />
|
|
392
|
-
</Form.Item>
|
|
393
|
-
<Form.Item name="sourceBranch" label={t('Source branch')} rules={[{ required: true }]}>
|
|
394
|
-
<Select
|
|
395
|
-
showSearch
|
|
396
|
-
filterOption={filterOption}
|
|
397
|
-
filterSort={filterSort}
|
|
398
|
-
options={branches.map((branch) => ({ value: branch, label: branch }))}
|
|
399
|
-
onChange={async (sourceBranch: string) => {
|
|
400
|
-
form.setFieldsValue({ sourcePrefix: undefined, sourcePrefixes: undefined });
|
|
401
|
-
const repositoryId = form.getFieldValue('repositoryId');
|
|
402
|
-
if (!repositoryId) return;
|
|
403
|
-
try {
|
|
404
|
-
await loadOptions(repositoryId, sourceBranch, form.getFieldValue('remoteName'));
|
|
405
|
-
} catch (error) {
|
|
406
|
-
message.error(errorMessage(error));
|
|
407
|
-
}
|
|
408
|
-
}}
|
|
409
|
-
/>
|
|
410
|
-
</Form.Item>
|
|
411
|
-
<Form.Item name="sourcePrefixes" label={t('Source folder')} rules={[{ required: true }]}>
|
|
412
|
-
<Select
|
|
413
|
-
mode="multiple"
|
|
414
|
-
showSearch
|
|
415
|
-
filterOption={filterOption}
|
|
416
|
-
filterSort={filterSort}
|
|
417
|
-
options={folders.map((folder) => ({ value: folder, label: folder }))}
|
|
418
|
-
/>
|
|
419
|
-
</Form.Item>
|
|
420
|
-
<Form.Item name="targetBranch" label={t('Target branch')} rules={[{ required: true }]}>
|
|
421
|
-
<AutoComplete
|
|
422
|
-
filterOption={filterOption}
|
|
423
|
-
filterSort={filterSort}
|
|
424
|
-
options={branches.map((branch) => ({ value: branch, label: branch }))}
|
|
425
|
-
/>
|
|
426
|
-
</Form.Item>
|
|
427
|
-
<Form.Item name="defaultPolicy" label={t('Default policy')} rules={[{ required: true }]}>
|
|
428
|
-
<Select
|
|
429
|
-
options={[
|
|
430
|
-
{ value: 'fastForward', label: t('Fast-forward only') },
|
|
431
|
-
{ value: 'replace', label: t('Replace target') },
|
|
432
|
-
{ value: 'merge', label: t('Merge histories') },
|
|
433
|
-
]}
|
|
434
|
-
/>
|
|
435
|
-
</Form.Item>
|
|
436
|
-
<Form.Item name="pushAfterRun" label={t('Push after run')} valuePropName="checked">
|
|
437
|
-
<Switch />
|
|
438
|
-
</Form.Item>
|
|
439
|
-
<Form.Item name="enabled" label={t('Enabled')} valuePropName="checked">
|
|
440
|
-
<Switch />
|
|
441
|
-
</Form.Item>
|
|
442
|
-
</Form>
|
|
443
|
-
</Modal>
|
|
444
|
-
|
|
445
|
-
<Modal
|
|
446
|
-
title={t('Run subtree split')}
|
|
447
|
-
open={!!runningConfig}
|
|
448
|
-
onCancel={() => setRunningConfig(null)}
|
|
449
|
-
onOk={runSubtree}
|
|
450
|
-
okText={t('Run')}
|
|
451
|
-
okButtonProps={{
|
|
452
|
-
disabled: !preview || (policy === 'replace' && replaceConfirmation !== runningConfig?.targetBranch),
|
|
453
|
-
}}
|
|
454
|
-
confirmLoading={running}
|
|
455
|
-
width={720}
|
|
456
|
-
>
|
|
457
|
-
{runningConfig && (
|
|
458
|
-
<Space direction="vertical" size="middle" style={{ width: '100%' }}>
|
|
459
|
-
<Descriptions size="small" bordered column={1}>
|
|
460
|
-
<Descriptions.Item label={t('Source')}>
|
|
461
|
-
{runningConfig.sourceBranch}:
|
|
462
|
-
{(runningConfig.sourcePrefixes?.length
|
|
463
|
-
? runningConfig.sourcePrefixes
|
|
464
|
-
: [runningConfig.sourcePrefix]
|
|
465
|
-
).join(', ')}
|
|
466
|
-
</Descriptions.Item>
|
|
467
|
-
<Descriptions.Item label={t('Target branch')}>{runningConfig.targetBranch}</Descriptions.Item>
|
|
468
|
-
</Descriptions>
|
|
469
|
-
<Button onClick={previewRun} loading={previewing}>
|
|
470
|
-
{t('Preview')}
|
|
471
|
-
</Button>
|
|
472
|
-
{preview && (
|
|
473
|
-
<Alert
|
|
474
|
-
type={preview.relationship === 'diverged' ? 'warning' : 'info'}
|
|
475
|
-
showIcon
|
|
476
|
-
message={t(`Subtree relationship: ${preview.relationship}`)}
|
|
477
|
-
description={`${preview.targetSha || t('Target branch does not exist')} → ${preview.splitSha}`}
|
|
478
|
-
/>
|
|
479
|
-
)}
|
|
480
|
-
<Radio.Group value={policy} onChange={(event) => setPolicy(event.target.value as SubtreePolicy)}>
|
|
481
|
-
<Space direction="vertical">
|
|
482
|
-
<Radio value="fastForward">{t('Fast-forward only')}</Radio>
|
|
483
|
-
<Radio value="replace">{t('Replace target')}</Radio>
|
|
484
|
-
<Radio value="merge">{t('Merge histories')}</Radio>
|
|
485
|
-
</Space>
|
|
486
|
-
</Radio.Group>
|
|
487
|
-
{policy === 'replace' && (
|
|
488
|
-
<Alert
|
|
489
|
-
type="error"
|
|
490
|
-
showIcon
|
|
491
|
-
message={t('Replace target may discard target-only commits')}
|
|
492
|
-
description={
|
|
493
|
-
<Space direction="vertical" style={{ width: '100%' }}>
|
|
494
|
-
<Typography.Text>{t('Type the target branch name to confirm')}</Typography.Text>
|
|
495
|
-
<Input
|
|
496
|
-
value={replaceConfirmation}
|
|
497
|
-
onChange={(event) => setReplaceConfirmation(event.target.value)}
|
|
498
|
-
/>
|
|
499
|
-
</Space>
|
|
500
|
-
}
|
|
501
|
-
/>
|
|
502
|
-
)}
|
|
503
|
-
<Space>
|
|
504
|
-
<Switch checked={pushAfterRun} onChange={setPushAfterRun} />
|
|
505
|
-
<Typography.Text>{t('Push target branch after success')}</Typography.Text>
|
|
506
|
-
</Space>
|
|
507
|
-
</Space>
|
|
508
|
-
)}
|
|
509
|
-
</Modal>
|
|
510
|
-
|
|
511
|
-
<Modal
|
|
512
|
-
title={`${t('Run history')}: ${historyConfig?.name || ''}`}
|
|
513
|
-
open={!!historyConfig}
|
|
514
|
-
onCancel={() => setHistoryConfig(null)}
|
|
515
|
-
footer={null}
|
|
516
|
-
width={1000}
|
|
517
|
-
>
|
|
518
|
-
<Table
|
|
519
|
-
rowKey="id"
|
|
520
|
-
loading={historyLoading}
|
|
521
|
-
dataSource={historyRuns}
|
|
522
|
-
pagination={{ pageSize: 10 }}
|
|
523
|
-
columns={[
|
|
524
|
-
{
|
|
525
|
-
title: t('Started at'),
|
|
526
|
-
dataIndex: 'startedAt',
|
|
527
|
-
render: (value: string) => new Date(value).toLocaleString(),
|
|
528
|
-
},
|
|
529
|
-
{ title: t('Policy'), dataIndex: 'policy' },
|
|
530
|
-
{ title: t('Execution mode'), dataIndex: 'executionMode', render: () => t('App process') },
|
|
531
|
-
{
|
|
532
|
-
title: t('Status'),
|
|
533
|
-
dataIndex: 'status',
|
|
534
|
-
render: (value: string) => (
|
|
535
|
-
<Tag color={value === 'success' ? 'green' : value === 'conflict' ? 'orange' : 'red'}>{value}</Tag>
|
|
536
|
-
),
|
|
537
|
-
},
|
|
538
|
-
{ title: t('Split SHA'), dataIndex: 'splitSha', ellipsis: true },
|
|
539
|
-
{ title: t('Target before'), dataIndex: 'targetBeforeSha', ellipsis: true },
|
|
540
|
-
{ title: t('Target after'), dataIndex: 'targetAfterSha', ellipsis: true },
|
|
541
|
-
{ title: t('Error'), dataIndex: 'error', ellipsis: true },
|
|
542
|
-
]}
|
|
543
|
-
/>
|
|
544
|
-
</Modal>
|
|
545
|
-
</Card>
|
|
546
|
-
);
|
|
547
|
-
}
|
|
1
|
+
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Alert,
|
|
4
|
+
AutoComplete,
|
|
5
|
+
Button,
|
|
6
|
+
Card,
|
|
7
|
+
Descriptions,
|
|
8
|
+
Form,
|
|
9
|
+
Input,
|
|
10
|
+
Modal,
|
|
11
|
+
Popconfirm,
|
|
12
|
+
Radio,
|
|
13
|
+
Select,
|
|
14
|
+
Space,
|
|
15
|
+
Switch,
|
|
16
|
+
Table,
|
|
17
|
+
Tag,
|
|
18
|
+
Typography,
|
|
19
|
+
message,
|
|
20
|
+
} from 'antd';
|
|
21
|
+
import { DeleteOutlined, EditOutlined, HistoryOutlined, PlayCircleOutlined, PlusOutlined } from '@ant-design/icons';
|
|
22
|
+
import { useFlowContext } from '@nocobase/flow-engine';
|
|
23
|
+
import { useT } from '../locale';
|
|
24
|
+
|
|
25
|
+
type SubtreePolicy = 'fastForward' | 'replace' | 'merge';
|
|
26
|
+
|
|
27
|
+
interface RepositoryItem {
|
|
28
|
+
id: number;
|
|
29
|
+
name: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface SubtreeConfig {
|
|
33
|
+
id: number;
|
|
34
|
+
name: string;
|
|
35
|
+
repositoryId: number;
|
|
36
|
+
sourceBranch: string;
|
|
37
|
+
sourcePrefix: string;
|
|
38
|
+
sourcePrefixes?: string[];
|
|
39
|
+
targetBranch: string;
|
|
40
|
+
remoteName: string;
|
|
41
|
+
defaultPolicy: SubtreePolicy;
|
|
42
|
+
pushAfterRun: boolean;
|
|
43
|
+
enabled: boolean;
|
|
44
|
+
lastStatus?: string;
|
|
45
|
+
lastRunAt?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
type ConfigFormValues = Omit<SubtreeConfig, 'id' | 'lastStatus' | 'lastRunAt'>;
|
|
49
|
+
|
|
50
|
+
type SearchOption = { label?: React.ReactNode; value?: string | number };
|
|
51
|
+
|
|
52
|
+
function optionText(option?: SearchOption): string {
|
|
53
|
+
return String(option?.label ?? option?.value ?? '').toLocaleLowerCase();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function filterOption(input: string, option?: SearchOption): boolean {
|
|
57
|
+
return optionText(option).includes(input.trim().toLocaleLowerCase());
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function filterSort(optionA: SearchOption, optionB: SearchOption, info: { searchValue: string }): number {
|
|
61
|
+
const search = info.searchValue.trim().toLocaleLowerCase();
|
|
62
|
+
const a = optionText(optionA);
|
|
63
|
+
const b = optionText(optionB);
|
|
64
|
+
const aStarts = a.startsWith(search);
|
|
65
|
+
const bStarts = b.startsWith(search);
|
|
66
|
+
if (aStarts !== bStarts) return aStarts ? -1 : 1;
|
|
67
|
+
return a.localeCompare(b);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface PreviewResult {
|
|
71
|
+
sourceSha: string;
|
|
72
|
+
splitSha: string;
|
|
73
|
+
targetExists: boolean;
|
|
74
|
+
targetSha: string | null;
|
|
75
|
+
relationship: 'target-missing' | 'already-up-to-date' | 'fast-forward' | 'diverged';
|
|
76
|
+
recommendedPolicy: SubtreePolicy;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
interface OptionsResult {
|
|
80
|
+
branches: string[];
|
|
81
|
+
folders: string[];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
interface SubtreeRun {
|
|
85
|
+
id: number;
|
|
86
|
+
policy: SubtreePolicy;
|
|
87
|
+
executionMode: 'app';
|
|
88
|
+
status: string;
|
|
89
|
+
sourceSha?: string;
|
|
90
|
+
splitSha?: string;
|
|
91
|
+
targetBeforeSha?: string;
|
|
92
|
+
targetAfterSha?: string;
|
|
93
|
+
startedAt: string;
|
|
94
|
+
finishedAt?: string;
|
|
95
|
+
error?: string;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function errorMessage(error: unknown): string {
|
|
99
|
+
if (error && typeof error === 'object') {
|
|
100
|
+
const response = 'response' in error ? error.response : undefined;
|
|
101
|
+
if (response && typeof response === 'object' && 'data' in response) {
|
|
102
|
+
const data = response.data;
|
|
103
|
+
if (data && typeof data === 'object' && 'errors' in data && Array.isArray(data.errors)) {
|
|
104
|
+
const first = data.errors[0];
|
|
105
|
+
if (first && typeof first === 'object' && 'message' in first && typeof first.message === 'string') {
|
|
106
|
+
return first.message;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if ('message' in error && typeof error.message === 'string') return error.message;
|
|
111
|
+
}
|
|
112
|
+
return String(error);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export default function SubtreeSplits() {
|
|
116
|
+
const ctx = useFlowContext();
|
|
117
|
+
const t = useT();
|
|
118
|
+
const [form] = Form.useForm<ConfigFormValues>();
|
|
119
|
+
const [configs, setConfigs] = useState<SubtreeConfig[]>([]);
|
|
120
|
+
const [repositories, setRepositories] = useState<RepositoryItem[]>([]);
|
|
121
|
+
const [branches, setBranches] = useState<string[]>([]);
|
|
122
|
+
const [folders, setFolders] = useState<string[]>([]);
|
|
123
|
+
const [loading, setLoading] = useState(false);
|
|
124
|
+
const [saving, setSaving] = useState(false);
|
|
125
|
+
const [configOpen, setConfigOpen] = useState(false);
|
|
126
|
+
const [editing, setEditing] = useState<SubtreeConfig | null>(null);
|
|
127
|
+
const [runningConfig, setRunningConfig] = useState<SubtreeConfig | null>(null);
|
|
128
|
+
const [policy, setPolicy] = useState<SubtreePolicy>('fastForward');
|
|
129
|
+
const [pushAfterRun, setPushAfterRun] = useState(true);
|
|
130
|
+
const [preview, setPreview] = useState<PreviewResult | null>(null);
|
|
131
|
+
const [previewing, setPreviewing] = useState(false);
|
|
132
|
+
const [running, setRunning] = useState(false);
|
|
133
|
+
const [replaceConfirmation, setReplaceConfirmation] = useState('');
|
|
134
|
+
const [historyConfig, setHistoryConfig] = useState<SubtreeConfig | null>(null);
|
|
135
|
+
const [historyRuns, setHistoryRuns] = useState<SubtreeRun[]>([]);
|
|
136
|
+
const [historyLoading, setHistoryLoading] = useState(false);
|
|
137
|
+
|
|
138
|
+
const repositoryName = useMemo(
|
|
139
|
+
() => new Map(repositories.map((repository) => [repository.id, repository.name])),
|
|
140
|
+
[repositories],
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const loadData = useCallback(async () => {
|
|
144
|
+
setLoading(true);
|
|
145
|
+
try {
|
|
146
|
+
const [configResponse, repositoryResponse] = await Promise.all([
|
|
147
|
+
ctx.api.request({ url: 'gitSubtreeConfigs:list', params: { pageSize: 200, sort: ['name'] } }),
|
|
148
|
+
ctx.api.request({ url: 'gitRepositories:list', params: { pageSize: 200, sort: ['name'] } }),
|
|
149
|
+
]);
|
|
150
|
+
setConfigs((configResponse.data?.data || []) as SubtreeConfig[]);
|
|
151
|
+
setRepositories((repositoryResponse.data?.data || []) as RepositoryItem[]);
|
|
152
|
+
} catch (error) {
|
|
153
|
+
message.error(errorMessage(error));
|
|
154
|
+
} finally {
|
|
155
|
+
setLoading(false);
|
|
156
|
+
}
|
|
157
|
+
}, [ctx.api]);
|
|
158
|
+
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
loadData();
|
|
161
|
+
}, [loadData]);
|
|
162
|
+
|
|
163
|
+
const loadOptions = async (repositoryId: number, sourceBranch?: string, remoteName = 'origin') => {
|
|
164
|
+
const response = await ctx.api.request({
|
|
165
|
+
url: 'gitManager:subtreeOptions',
|
|
166
|
+
method: 'post',
|
|
167
|
+
params: { repositoryId, sourceBranch, remoteName },
|
|
168
|
+
});
|
|
169
|
+
// v1 and v2 requesters can wrap the action payload differently.
|
|
170
|
+
// Normalize both `{ data: { branches } }` and `{ data: { data: { branches } } }`.
|
|
171
|
+
const data = (response.data?.data?.data || response.data?.data) as OptionsResult;
|
|
172
|
+
setBranches(data?.branches || []);
|
|
173
|
+
setFolders(data?.folders || []);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const openCreate = () => {
|
|
177
|
+
setEditing(null);
|
|
178
|
+
setBranches([]);
|
|
179
|
+
setFolders([]);
|
|
180
|
+
form.resetFields();
|
|
181
|
+
form.setFieldsValue({ remoteName: 'origin', defaultPolicy: 'fastForward', pushAfterRun: true, enabled: true });
|
|
182
|
+
setConfigOpen(true);
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const openEdit = async (config: SubtreeConfig) => {
|
|
186
|
+
setEditing(config);
|
|
187
|
+
form.setFieldsValue({
|
|
188
|
+
...config,
|
|
189
|
+
sourcePrefixes: config.sourcePrefixes?.length ? config.sourcePrefixes : [config.sourcePrefix],
|
|
190
|
+
});
|
|
191
|
+
setConfigOpen(true);
|
|
192
|
+
try {
|
|
193
|
+
await loadOptions(config.repositoryId, config.sourceBranch, config.remoteName);
|
|
194
|
+
} catch (error) {
|
|
195
|
+
message.error(errorMessage(error));
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const saveConfig = async () => {
|
|
200
|
+
const values = await form.validateFields();
|
|
201
|
+
const sourcePrefixes = values.sourcePrefixes || [];
|
|
202
|
+
setSaving(true);
|
|
203
|
+
try {
|
|
204
|
+
await ctx.api.request({
|
|
205
|
+
url: editing ? 'gitSubtreeConfigs:update' : 'gitSubtreeConfigs:create',
|
|
206
|
+
method: 'post',
|
|
207
|
+
params: editing ? { filterByTk: editing.id } : undefined,
|
|
208
|
+
data: { ...values, sourcePrefix: sourcePrefixes[0], sourcePrefixes },
|
|
209
|
+
});
|
|
210
|
+
message.success(t(editing ? 'Subtree configuration updated' : 'Subtree configuration created'));
|
|
211
|
+
setConfigOpen(false);
|
|
212
|
+
await loadData();
|
|
213
|
+
} catch (error) {
|
|
214
|
+
message.error(errorMessage(error));
|
|
215
|
+
} finally {
|
|
216
|
+
setSaving(false);
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const deleteConfig = async (id: number) => {
|
|
221
|
+
try {
|
|
222
|
+
await ctx.api.request({ url: 'gitSubtreeConfigs:destroy', method: 'post', params: { filterByTk: id } });
|
|
223
|
+
message.success(t('Deleted'));
|
|
224
|
+
await loadData();
|
|
225
|
+
} catch (error) {
|
|
226
|
+
message.error(errorMessage(error));
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const openRun = (config: SubtreeConfig) => {
|
|
231
|
+
setRunningConfig(config);
|
|
232
|
+
setPolicy(config.defaultPolicy || 'fastForward');
|
|
233
|
+
setPushAfterRun(config.pushAfterRun !== false);
|
|
234
|
+
setPreview(null);
|
|
235
|
+
setReplaceConfirmation('');
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
const openHistory = async (config: SubtreeConfig) => {
|
|
239
|
+
setHistoryConfig(config);
|
|
240
|
+
setHistoryLoading(true);
|
|
241
|
+
try {
|
|
242
|
+
const response = await ctx.api.request({
|
|
243
|
+
url: 'gitSubtreeRuns:list',
|
|
244
|
+
params: { filter: { configId: config.id }, pageSize: 100, sort: ['-startedAt'] },
|
|
245
|
+
});
|
|
246
|
+
setHistoryRuns((response.data?.data || []) as SubtreeRun[]);
|
|
247
|
+
} catch (error) {
|
|
248
|
+
message.error(errorMessage(error));
|
|
249
|
+
} finally {
|
|
250
|
+
setHistoryLoading(false);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
const previewRun = async () => {
|
|
255
|
+
if (!runningConfig) return;
|
|
256
|
+
setPreviewing(true);
|
|
257
|
+
try {
|
|
258
|
+
const response = await ctx.api.request({
|
|
259
|
+
url: 'gitManager:subtreePreview',
|
|
260
|
+
method: 'post',
|
|
261
|
+
data: { configId: runningConfig.id },
|
|
262
|
+
});
|
|
263
|
+
const data = response.data?.data as PreviewResult;
|
|
264
|
+
setPreview(data);
|
|
265
|
+
setPolicy(data.recommendedPolicy);
|
|
266
|
+
} catch (error) {
|
|
267
|
+
message.error(errorMessage(error));
|
|
268
|
+
} finally {
|
|
269
|
+
setPreviewing(false);
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
const runSubtree = async () => {
|
|
274
|
+
if (!runningConfig || !preview) return;
|
|
275
|
+
if (policy === 'replace' && replaceConfirmation !== runningConfig.targetBranch) return;
|
|
276
|
+
setRunning(true);
|
|
277
|
+
try {
|
|
278
|
+
await ctx.api.request({
|
|
279
|
+
url: policy === 'replace' ? 'gitManager:subtreeReplace' : 'gitManager:subtreeRun',
|
|
280
|
+
method: 'post',
|
|
281
|
+
data: {
|
|
282
|
+
configId: runningConfig.id,
|
|
283
|
+
policy,
|
|
284
|
+
push: pushAfterRun,
|
|
285
|
+
expectedTargetSha: preview.targetSha,
|
|
286
|
+
},
|
|
287
|
+
});
|
|
288
|
+
message.success(t('Subtree split completed'));
|
|
289
|
+
setRunningConfig(null);
|
|
290
|
+
await loadData();
|
|
291
|
+
} catch (error) {
|
|
292
|
+
message.error(errorMessage(error));
|
|
293
|
+
} finally {
|
|
294
|
+
setRunning(false);
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
const columns = [
|
|
299
|
+
{ title: t('Name'), dataIndex: 'name', key: 'name' },
|
|
300
|
+
{
|
|
301
|
+
title: t('Repository'),
|
|
302
|
+
dataIndex: 'repositoryId',
|
|
303
|
+
key: 'repositoryId',
|
|
304
|
+
render: (repositoryId: number) => repositoryName.get(repositoryId) || repositoryId,
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
title: t('Source'),
|
|
308
|
+
key: 'source',
|
|
309
|
+
render: (_: unknown, config: SubtreeConfig) =>
|
|
310
|
+
`${config.sourceBranch}:${(config.sourcePrefixes?.length ? config.sourcePrefixes : [config.sourcePrefix]).join(
|
|
311
|
+
', ',
|
|
312
|
+
)}`,
|
|
313
|
+
},
|
|
314
|
+
{ title: t('Target branch'), dataIndex: 'targetBranch', key: 'targetBranch' },
|
|
315
|
+
{
|
|
316
|
+
title: t('Last status'),
|
|
317
|
+
dataIndex: 'lastStatus',
|
|
318
|
+
key: 'lastStatus',
|
|
319
|
+
render: (status?: string) =>
|
|
320
|
+
status ? (
|
|
321
|
+
<Tag color={status === 'success' ? 'green' : status === 'conflict' ? 'orange' : 'red'}>{status}</Tag>
|
|
322
|
+
) : (
|
|
323
|
+
'—'
|
|
324
|
+
),
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
title: t('Actions'),
|
|
328
|
+
key: 'actions',
|
|
329
|
+
render: (_: unknown, config: SubtreeConfig) => (
|
|
330
|
+
<Space>
|
|
331
|
+
<Button icon={<PlayCircleOutlined />} size="small" disabled={!config.enabled} onClick={() => openRun(config)}>
|
|
332
|
+
{t('Run')}
|
|
333
|
+
</Button>
|
|
334
|
+
<Button icon={<EditOutlined />} size="small" onClick={() => openEdit(config)} aria-label={t('Edit')} />
|
|
335
|
+
<Button
|
|
336
|
+
icon={<HistoryOutlined />}
|
|
337
|
+
size="small"
|
|
338
|
+
onClick={() => openHistory(config)}
|
|
339
|
+
aria-label={t('Run history')}
|
|
340
|
+
/>
|
|
341
|
+
<Popconfirm title={t('Delete this subtree configuration?')} onConfirm={() => deleteConfig(config.id)}>
|
|
342
|
+
<Button icon={<DeleteOutlined />} size="small" danger aria-label={t('Delete')} />
|
|
343
|
+
</Popconfirm>
|
|
344
|
+
</Space>
|
|
345
|
+
),
|
|
346
|
+
},
|
|
347
|
+
];
|
|
348
|
+
|
|
349
|
+
return (
|
|
350
|
+
<Card
|
|
351
|
+
title={t('Subtree Splits')}
|
|
352
|
+
extra={
|
|
353
|
+
<Button type="primary" icon={<PlusOutlined />} onClick={openCreate}>
|
|
354
|
+
{t('Add subtree configuration')}
|
|
355
|
+
</Button>
|
|
356
|
+
}
|
|
357
|
+
>
|
|
358
|
+
<Table rowKey="id" dataSource={configs} columns={columns} loading={loading} pagination={{ pageSize: 20 }} />
|
|
359
|
+
|
|
360
|
+
<Modal
|
|
361
|
+
title={editing ? t('Edit subtree configuration') : t('Add subtree configuration')}
|
|
362
|
+
open={configOpen}
|
|
363
|
+
onCancel={() => setConfigOpen(false)}
|
|
364
|
+
onOk={saveConfig}
|
|
365
|
+
confirmLoading={saving}
|
|
366
|
+
width={680}
|
|
367
|
+
destroyOnClose
|
|
368
|
+
>
|
|
369
|
+
<Form form={form} layout="vertical">
|
|
370
|
+
<Form.Item name="name" label={t('Name')} rules={[{ required: true }]}>
|
|
371
|
+
<Input />
|
|
372
|
+
</Form.Item>
|
|
373
|
+
<Form.Item name="repositoryId" label={t('Repository')} rules={[{ required: true }]}>
|
|
374
|
+
<Select
|
|
375
|
+
showSearch
|
|
376
|
+
filterOption={filterOption}
|
|
377
|
+
filterSort={filterSort}
|
|
378
|
+
options={repositories.map((repository) => ({ value: repository.id, label: repository.name }))}
|
|
379
|
+
onChange={async (repositoryId: number) => {
|
|
380
|
+
form.setFieldsValue({ sourceBranch: undefined, sourcePrefix: undefined, sourcePrefixes: undefined });
|
|
381
|
+
setFolders([]);
|
|
382
|
+
try {
|
|
383
|
+
await loadOptions(repositoryId, undefined, form.getFieldValue('remoteName'));
|
|
384
|
+
} catch (error) {
|
|
385
|
+
message.error(errorMessage(error));
|
|
386
|
+
}
|
|
387
|
+
}}
|
|
388
|
+
/>
|
|
389
|
+
</Form.Item>
|
|
390
|
+
<Form.Item name="remoteName" label={t('Remote name')} rules={[{ required: true }]}>
|
|
391
|
+
<Input placeholder="origin" />
|
|
392
|
+
</Form.Item>
|
|
393
|
+
<Form.Item name="sourceBranch" label={t('Source branch')} rules={[{ required: true }]}>
|
|
394
|
+
<Select
|
|
395
|
+
showSearch
|
|
396
|
+
filterOption={filterOption}
|
|
397
|
+
filterSort={filterSort}
|
|
398
|
+
options={branches.map((branch) => ({ value: branch, label: branch }))}
|
|
399
|
+
onChange={async (sourceBranch: string) => {
|
|
400
|
+
form.setFieldsValue({ sourcePrefix: undefined, sourcePrefixes: undefined });
|
|
401
|
+
const repositoryId = form.getFieldValue('repositoryId');
|
|
402
|
+
if (!repositoryId) return;
|
|
403
|
+
try {
|
|
404
|
+
await loadOptions(repositoryId, sourceBranch, form.getFieldValue('remoteName'));
|
|
405
|
+
} catch (error) {
|
|
406
|
+
message.error(errorMessage(error));
|
|
407
|
+
}
|
|
408
|
+
}}
|
|
409
|
+
/>
|
|
410
|
+
</Form.Item>
|
|
411
|
+
<Form.Item name="sourcePrefixes" label={t('Source folder')} rules={[{ required: true }]}>
|
|
412
|
+
<Select
|
|
413
|
+
mode="multiple"
|
|
414
|
+
showSearch
|
|
415
|
+
filterOption={filterOption}
|
|
416
|
+
filterSort={filterSort}
|
|
417
|
+
options={folders.map((folder) => ({ value: folder, label: folder }))}
|
|
418
|
+
/>
|
|
419
|
+
</Form.Item>
|
|
420
|
+
<Form.Item name="targetBranch" label={t('Target branch')} rules={[{ required: true }]}>
|
|
421
|
+
<AutoComplete
|
|
422
|
+
filterOption={filterOption}
|
|
423
|
+
filterSort={filterSort}
|
|
424
|
+
options={branches.map((branch) => ({ value: branch, label: branch }))}
|
|
425
|
+
/>
|
|
426
|
+
</Form.Item>
|
|
427
|
+
<Form.Item name="defaultPolicy" label={t('Default policy')} rules={[{ required: true }]}>
|
|
428
|
+
<Select
|
|
429
|
+
options={[
|
|
430
|
+
{ value: 'fastForward', label: t('Fast-forward only') },
|
|
431
|
+
{ value: 'replace', label: t('Replace target') },
|
|
432
|
+
{ value: 'merge', label: t('Merge histories') },
|
|
433
|
+
]}
|
|
434
|
+
/>
|
|
435
|
+
</Form.Item>
|
|
436
|
+
<Form.Item name="pushAfterRun" label={t('Push after run')} valuePropName="checked">
|
|
437
|
+
<Switch />
|
|
438
|
+
</Form.Item>
|
|
439
|
+
<Form.Item name="enabled" label={t('Enabled')} valuePropName="checked">
|
|
440
|
+
<Switch />
|
|
441
|
+
</Form.Item>
|
|
442
|
+
</Form>
|
|
443
|
+
</Modal>
|
|
444
|
+
|
|
445
|
+
<Modal
|
|
446
|
+
title={t('Run subtree split')}
|
|
447
|
+
open={!!runningConfig}
|
|
448
|
+
onCancel={() => setRunningConfig(null)}
|
|
449
|
+
onOk={runSubtree}
|
|
450
|
+
okText={t('Run')}
|
|
451
|
+
okButtonProps={{
|
|
452
|
+
disabled: !preview || (policy === 'replace' && replaceConfirmation !== runningConfig?.targetBranch),
|
|
453
|
+
}}
|
|
454
|
+
confirmLoading={running}
|
|
455
|
+
width={720}
|
|
456
|
+
>
|
|
457
|
+
{runningConfig && (
|
|
458
|
+
<Space direction="vertical" size="middle" style={{ width: '100%' }}>
|
|
459
|
+
<Descriptions size="small" bordered column={1}>
|
|
460
|
+
<Descriptions.Item label={t('Source')}>
|
|
461
|
+
{runningConfig.sourceBranch}:
|
|
462
|
+
{(runningConfig.sourcePrefixes?.length
|
|
463
|
+
? runningConfig.sourcePrefixes
|
|
464
|
+
: [runningConfig.sourcePrefix]
|
|
465
|
+
).join(', ')}
|
|
466
|
+
</Descriptions.Item>
|
|
467
|
+
<Descriptions.Item label={t('Target branch')}>{runningConfig.targetBranch}</Descriptions.Item>
|
|
468
|
+
</Descriptions>
|
|
469
|
+
<Button onClick={previewRun} loading={previewing}>
|
|
470
|
+
{t('Preview')}
|
|
471
|
+
</Button>
|
|
472
|
+
{preview && (
|
|
473
|
+
<Alert
|
|
474
|
+
type={preview.relationship === 'diverged' ? 'warning' : 'info'}
|
|
475
|
+
showIcon
|
|
476
|
+
message={t(`Subtree relationship: ${preview.relationship}`)}
|
|
477
|
+
description={`${preview.targetSha || t('Target branch does not exist')} → ${preview.splitSha}`}
|
|
478
|
+
/>
|
|
479
|
+
)}
|
|
480
|
+
<Radio.Group value={policy} onChange={(event) => setPolicy(event.target.value as SubtreePolicy)}>
|
|
481
|
+
<Space direction="vertical">
|
|
482
|
+
<Radio value="fastForward">{t('Fast-forward only')}</Radio>
|
|
483
|
+
<Radio value="replace">{t('Replace target')}</Radio>
|
|
484
|
+
<Radio value="merge">{t('Merge histories')}</Radio>
|
|
485
|
+
</Space>
|
|
486
|
+
</Radio.Group>
|
|
487
|
+
{policy === 'replace' && (
|
|
488
|
+
<Alert
|
|
489
|
+
type="error"
|
|
490
|
+
showIcon
|
|
491
|
+
message={t('Replace target may discard target-only commits')}
|
|
492
|
+
description={
|
|
493
|
+
<Space direction="vertical" style={{ width: '100%' }}>
|
|
494
|
+
<Typography.Text>{t('Type the target branch name to confirm')}</Typography.Text>
|
|
495
|
+
<Input
|
|
496
|
+
value={replaceConfirmation}
|
|
497
|
+
onChange={(event) => setReplaceConfirmation(event.target.value)}
|
|
498
|
+
/>
|
|
499
|
+
</Space>
|
|
500
|
+
}
|
|
501
|
+
/>
|
|
502
|
+
)}
|
|
503
|
+
<Space>
|
|
504
|
+
<Switch checked={pushAfterRun} onChange={setPushAfterRun} />
|
|
505
|
+
<Typography.Text>{t('Push target branch after success')}</Typography.Text>
|
|
506
|
+
</Space>
|
|
507
|
+
</Space>
|
|
508
|
+
)}
|
|
509
|
+
</Modal>
|
|
510
|
+
|
|
511
|
+
<Modal
|
|
512
|
+
title={`${t('Run history')}: ${historyConfig?.name || ''}`}
|
|
513
|
+
open={!!historyConfig}
|
|
514
|
+
onCancel={() => setHistoryConfig(null)}
|
|
515
|
+
footer={null}
|
|
516
|
+
width={1000}
|
|
517
|
+
>
|
|
518
|
+
<Table
|
|
519
|
+
rowKey="id"
|
|
520
|
+
loading={historyLoading}
|
|
521
|
+
dataSource={historyRuns}
|
|
522
|
+
pagination={{ pageSize: 10 }}
|
|
523
|
+
columns={[
|
|
524
|
+
{
|
|
525
|
+
title: t('Started at'),
|
|
526
|
+
dataIndex: 'startedAt',
|
|
527
|
+
render: (value: string) => new Date(value).toLocaleString(),
|
|
528
|
+
},
|
|
529
|
+
{ title: t('Policy'), dataIndex: 'policy' },
|
|
530
|
+
{ title: t('Execution mode'), dataIndex: 'executionMode', render: () => t('App process') },
|
|
531
|
+
{
|
|
532
|
+
title: t('Status'),
|
|
533
|
+
dataIndex: 'status',
|
|
534
|
+
render: (value: string) => (
|
|
535
|
+
<Tag color={value === 'success' ? 'green' : value === 'conflict' ? 'orange' : 'red'}>{value}</Tag>
|
|
536
|
+
),
|
|
537
|
+
},
|
|
538
|
+
{ title: t('Split SHA'), dataIndex: 'splitSha', ellipsis: true },
|
|
539
|
+
{ title: t('Target before'), dataIndex: 'targetBeforeSha', ellipsis: true },
|
|
540
|
+
{ title: t('Target after'), dataIndex: 'targetAfterSha', ellipsis: true },
|
|
541
|
+
{ title: t('Error'), dataIndex: 'error', ellipsis: true },
|
|
542
|
+
]}
|
|
543
|
+
/>
|
|
544
|
+
</Modal>
|
|
545
|
+
</Card>
|
|
546
|
+
);
|
|
547
|
+
}
|