plugin-git-manager 1.2.27 → 1.3.1
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 +151 -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/941.1793e67472872992.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/928.bba701b5a1ece58e.js +10 -0
- package/dist/client-v2/941.b0d55429cd053f32.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +9 -8
- package/dist/locale/en-US.json +396 -297
- package/dist/locale/vi-VN.json +384 -292
- package/dist/locale/zh-CN.json +150 -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-cutover.js +137 -0
- package/dist/server/actions/review.js +150 -51
- package/dist/server/actions/role-permissions.js +1 -0
- package/dist/server/ai-tools.js +8 -9
- package/dist/server/collections/gitCodeReviews.js +10 -0
- package/dist/server/collections/gitReviewCutover.js +44 -0
- package/dist/server/collections/gitReviewFlows.js +3 -0
- package/dist/server/collections/gitReviewInbox.js +51 -0
- package/dist/server/collections/gitReviewProjects.js +43 -0
- package/dist/server/collections/gitReviewRequests.js +56 -0
- package/dist/server/index.js +8 -2
- package/dist/server/plugin.js +57 -20
- package/dist/server/poller.js +95 -74
- package/dist/server/repository-access.js +23 -5
- package/dist/server/request-method-policy.js +76 -0
- package/dist/server/review-control-access.js +79 -0
- package/dist/server/services/legacy-post-service.js +412 -0
- package/dist/server/services/registry-content-service.js +4 -3
- package/dist/server/services/review-service.js +1451 -0
- package/dist/server/services/review-source.js +325 -0
- 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__/CommitHistory.test.tsx +79 -0
- package/src/client/__tests__/ReviewHistory.test.tsx +126 -0
- package/src/client/__tests__/RunReviewButton.test.tsx +84 -0
- package/src/client/__tests__/workflowRoutes.test.ts +65 -0
- package/src/client/ai-context.tsx +114 -114
- package/src/client/components/AIEmployeeSelect.tsx +63 -63
- package/src/client/components/CommitHistory.tsx +429 -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 +352 -303
- package/src/client/components/ReviewHistory.tsx +796 -566
- package/src/client/components/RunReviewButton.tsx +57 -173
- 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/workflowRoutes.ts +42 -0
- 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 +396 -297
- package/src/locale/vi-VN.json +384 -292
- package/src/locale/zh-CN.json +150 -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 +760 -752
- package/src/server/__tests__/review-service.integration.test.ts +1263 -0
- package/src/server/__tests__/review.test.ts +76 -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-cutover.ts +121 -0
- package/src/server/actions/review.ts +1498 -1369
- package/src/server/actions/role-permissions.ts +331 -321
- package/src/server/actions/subtree.ts +508 -508
- package/src/server/ai-tools.ts +334 -319
- package/src/server/collections/gitAccounts.ts +56 -56
- package/src/server/collections/gitCodeReviews.ts +218 -199
- package/src/server/collections/gitRepositories.ts +87 -87
- package/src/server/collections/gitReviewCutover.ts +23 -0
- package/src/server/collections/gitReviewFlows.ts +120 -108
- package/src/server/collections/gitReviewInbox.ts +30 -0
- package/src/server/collections/gitReviewProjects.ts +22 -0
- package/src/server/collections/gitReviewRequests.ts +35 -0
- package/src/server/collections/gitSubtreeConfigs.ts +38 -38
- package/src/server/collections/gitSubtreeRuns.ts +30 -30
- package/src/server/index.ts +14 -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 +409 -361
- package/src/server/poller.ts +365 -352
- package/src/server/repository-access.ts +803 -773
- package/src/server/request-method-policy.ts +56 -0
- package/src/server/review-control-access.ts +71 -0
- package/src/server/services/__tests__/registry-content-service.test.ts +359 -345
- package/src/server/services/__tests__/review-source.test.ts +226 -0
- package/src/server/services/legacy-post-service.ts +550 -0
- package/src/server/services/registry-content-service.ts +495 -484
- package/src/server/services/review-service.ts +1899 -0
- package/src/server/services/review-source.ts +359 -0
- 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,11 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
2
11
|
import { Button, Dropdown, Modal, Form, Select, Input, message, Space, Tooltip, Tag, Alert } from 'antd';
|
|
3
|
-
import { RobotOutlined,
|
|
12
|
+
import { RobotOutlined, ThunderboltOutlined, ReloadOutlined } from '@ant-design/icons';
|
|
4
13
|
import { useApp } from '@nocobase/client-v2';
|
|
5
|
-
import * as aiClient from "@nocobase/plugin-ai";
|
|
6
14
|
import { REVIEW_PROMPT_TEMPLATES } from '../promptTemplates';
|
|
7
15
|
import { useT } from '../locale';
|
|
8
16
|
|
|
17
|
+
interface ExistingReview {
|
|
18
|
+
status: string;
|
|
19
|
+
headSha?: string;
|
|
20
|
+
latestSha?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
9
23
|
interface ReviewFlow {
|
|
10
24
|
id: number;
|
|
11
25
|
name: string;
|
|
@@ -27,32 +41,27 @@ type Target =
|
|
|
27
41
|
|
|
28
42
|
/**
|
|
29
43
|
* Button that lets the user kick off a code review for a given target.
|
|
30
|
-
*
|
|
31
|
-
* - "Run review" → POST gitManager:triggerReview (server-side, async)
|
|
32
|
-
* - "Open chat" → call (aiClient as any).useChatBoxActions?.() || {}.triggerTask if plugin-ai is loaded,
|
|
33
|
-
* so the user can chat with the AI employee using the same context.
|
|
44
|
+
* Submits review requests through the project-scoped admission service.
|
|
34
45
|
*/
|
|
35
46
|
export const RunReviewButton: React.FC<{
|
|
36
47
|
target: Target;
|
|
48
|
+
label?: string;
|
|
37
49
|
size?: 'small' | 'middle' | 'large';
|
|
38
50
|
type?: 'default' | 'primary' | 'link';
|
|
39
51
|
onTriggered?: (reviewId: number) => void;
|
|
40
|
-
}> = ({ target, size = 'small', type = 'default', onTriggered }) => {
|
|
52
|
+
}> = ({ target, label, size = 'small', type = 'default', onTriggered }) => {
|
|
41
53
|
const t = useT();
|
|
42
54
|
const api = useApp().apiClient;
|
|
43
|
-
const aiConfigRepository = (aiClient as any).useAIConfigRepository?.() || {};
|
|
44
|
-
const { triggerTask } = (aiClient as any).useChatBoxActions?.() || {};
|
|
45
55
|
const [open, setOpen] = useState(false);
|
|
46
56
|
const [flows, setFlows] = useState<ReviewFlow[]>([]);
|
|
47
57
|
const [submitting, setSubmitting] = useState(false);
|
|
48
|
-
const [
|
|
49
|
-
const [existingReview, setExistingReview] = useState<any | null>(null);
|
|
58
|
+
const [existingReview, setExistingReview] = useState<ExistingReview | null>(null);
|
|
50
59
|
const [templateKey, setTemplateKey] = useState<string | undefined>();
|
|
51
60
|
const [form] = Form.useForm();
|
|
52
61
|
|
|
53
62
|
const loadExistingReview = useCallback(() => {
|
|
54
63
|
let cancelled = false;
|
|
55
|
-
const filter:
|
|
64
|
+
const filter: Record<string, unknown> = {
|
|
56
65
|
repositoryId: target.repositoryId,
|
|
57
66
|
targetType: target.type,
|
|
58
67
|
};
|
|
@@ -132,7 +141,7 @@ export const RunReviewButton: React.FC<{
|
|
|
132
141
|
try {
|
|
133
142
|
const values = await form.validateFields();
|
|
134
143
|
setSubmitting(true);
|
|
135
|
-
const params:
|
|
144
|
+
const params: Record<string, unknown> = {
|
|
136
145
|
repositoryId: target.repositoryId,
|
|
137
146
|
targetType: target.type,
|
|
138
147
|
flowId: values.flowId,
|
|
@@ -151,137 +160,29 @@ export const RunReviewButton: React.FC<{
|
|
|
151
160
|
data: params,
|
|
152
161
|
});
|
|
153
162
|
const reviewId = res?.data?.data?.reviewId;
|
|
154
|
-
message.success(t('Review
|
|
163
|
+
message.success(t('Review queued'));
|
|
155
164
|
setOpen(false);
|
|
156
165
|
form.resetFields();
|
|
157
166
|
loadExistingReview();
|
|
158
167
|
onTriggered?.(reviewId);
|
|
159
|
-
} catch (err:
|
|
160
|
-
if (err
|
|
161
|
-
|
|
168
|
+
} catch (err: unknown) {
|
|
169
|
+
if (err && typeof err === 'object' && 'errorFields' in err) return;
|
|
170
|
+
const responseError = err as { response?: { data?: { errors?: Array<{ message?: string }> } } } | null;
|
|
171
|
+
message.error(
|
|
172
|
+
responseError?.response?.data?.errors?.[0]?.message ||
|
|
173
|
+
(err instanceof Error && err.message) ||
|
|
174
|
+
t('Failed to trigger review'),
|
|
175
|
+
);
|
|
162
176
|
} finally {
|
|
163
177
|
setSubmitting(false);
|
|
164
178
|
}
|
|
165
179
|
};
|
|
166
180
|
|
|
167
|
-
const buildWorkContext = () => {
|
|
168
|
-
const title = target.title || buildContextHint();
|
|
169
|
-
if (target.type === 'mr') {
|
|
170
|
-
return {
|
|
171
|
-
type: 'git-merge-request',
|
|
172
|
-
uid: `${target.repositoryId}:${target.mrIid}`,
|
|
173
|
-
title,
|
|
174
|
-
content: {
|
|
175
|
-
repositoryId: target.repositoryId,
|
|
176
|
-
mrIid: target.mrIid,
|
|
177
|
-
title,
|
|
178
|
-
},
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
if (target.type === 'commit') {
|
|
182
|
-
return {
|
|
183
|
-
type: 'git-commit',
|
|
184
|
-
uid: `${target.repositoryId}:${target.commitSha}`,
|
|
185
|
-
title,
|
|
186
|
-
content: {
|
|
187
|
-
repositoryId: target.repositoryId,
|
|
188
|
-
commitSha: target.commitSha,
|
|
189
|
-
title,
|
|
190
|
-
},
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
if (target.type === 'folder') {
|
|
194
|
-
return {
|
|
195
|
-
type: 'git-repository',
|
|
196
|
-
uid: `${target.repositoryId}:folder:${target.folderPath}`,
|
|
197
|
-
title,
|
|
198
|
-
content: {
|
|
199
|
-
repositoryId: target.repositoryId,
|
|
200
|
-
folderPath: target.folderPath,
|
|
201
|
-
ref: target.ref,
|
|
202
|
-
title,
|
|
203
|
-
},
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
return {
|
|
207
|
-
type: 'git-repository',
|
|
208
|
-
uid: String(target.repositoryId),
|
|
209
|
-
title,
|
|
210
|
-
content: {
|
|
211
|
-
repositoryId: target.repositoryId,
|
|
212
|
-
branch: target.branch,
|
|
213
|
-
title,
|
|
214
|
-
},
|
|
215
|
-
};
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
const buildChatPrompt = () => {
|
|
219
|
-
if (target.type === 'mr') {
|
|
220
|
-
return `Please review merge request !${target.mrIid} (${
|
|
221
|
-
target.title || 'untitled'
|
|
222
|
-
}). Use the attached Git merge request context and the available git tools when you need more detail.`;
|
|
223
|
-
}
|
|
224
|
-
if (target.type === 'commit') {
|
|
225
|
-
return `Please review commit ${target.commitSha} (${
|
|
226
|
-
target.title || 'untitled'
|
|
227
|
-
}). Use the attached Git commit context and the available git tools when you need more detail.`;
|
|
228
|
-
}
|
|
229
|
-
if (target.type === 'folder') {
|
|
230
|
-
return `Please review the full code inside folder "${target.folderPath || '/'}" at ref ${
|
|
231
|
-
target.ref || 'HEAD'
|
|
232
|
-
}. Use git_list_files (recursive=true) to enumerate the files, then git_get_file_content to read them.`;
|
|
233
|
-
}
|
|
234
|
-
return `Please help me inspect branch ${target.branch}. Use the attached Git repository context and the available git tools when you need more detail.`;
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
const handleOpenChat = async () => {
|
|
238
|
-
if (!triggerTask || !aiConfigRepository?.getAIEmployees) {
|
|
239
|
-
message.warning(t('AI plugin is not available'));
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
setAsking(true);
|
|
243
|
-
try {
|
|
244
|
-
const list = flows.length ? flows : await loadFlows();
|
|
245
|
-
const flow = pickFlow(list);
|
|
246
|
-
if (!flow?.aiEmployeeUsername) {
|
|
247
|
-
message.warning(t('No matching flow available'));
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
const employees: any[] = aiConfigRepository.aiEmployees?.length
|
|
251
|
-
? aiConfigRepository.aiEmployees
|
|
252
|
-
: await aiConfigRepository.getAIEmployees();
|
|
253
|
-
const aiEmployee = employees.find((item) => item.username === flow.aiEmployeeUsername);
|
|
254
|
-
if (!aiEmployee) {
|
|
255
|
-
message.warning(t('AI employee not found'));
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
await triggerTask({
|
|
259
|
-
aiEmployee,
|
|
260
|
-
tasks: [
|
|
261
|
-
{
|
|
262
|
-
title: `${flow.name}: ${buildContextHint()}`,
|
|
263
|
-
message: {
|
|
264
|
-
user: buildChatPrompt(),
|
|
265
|
-
system: flow.instructions || undefined,
|
|
266
|
-
workContext: [buildWorkContext()],
|
|
267
|
-
},
|
|
268
|
-
model: flow.llmService && flow.model ? { llmService: flow.llmService, model: flow.model } : null,
|
|
269
|
-
autoSend: false,
|
|
270
|
-
},
|
|
271
|
-
],
|
|
272
|
-
});
|
|
273
|
-
} catch (err: any) {
|
|
274
|
-
message.error(err?.message || t('Failed to open AI chat'));
|
|
275
|
-
} finally {
|
|
276
|
-
setAsking(false);
|
|
277
|
-
}
|
|
278
|
-
};
|
|
279
|
-
|
|
280
181
|
const buildContextHint = () => {
|
|
281
182
|
if (target.type === 'mr') return `MR !${target.mrIid}`;
|
|
282
183
|
if (target.type === 'commit') return `Commit ${String(target.commitSha).slice(0, 7)}`;
|
|
283
184
|
if (target.type === 'folder') return `${t('Folder')} ${target.folderPath || '/'}`;
|
|
284
|
-
return
|
|
185
|
+
return `${t('Branch')} ${target.branch}`;
|
|
285
186
|
};
|
|
286
187
|
|
|
287
188
|
// Derive re-run state for MR targets
|
|
@@ -290,7 +191,7 @@ export const RunReviewButton: React.FC<{
|
|
|
290
191
|
existingReview.headSha &&
|
|
291
192
|
existingReview.latestSha &&
|
|
292
193
|
existingReview.headSha !== existingReview.latestSha;
|
|
293
|
-
const isReReview = !!existingReview
|
|
194
|
+
const isReReview = !!existingReview;
|
|
294
195
|
const buttonLabel = isReReview
|
|
295
196
|
? hasNewCommits
|
|
296
197
|
? t('Re-review (new commits)')
|
|
@@ -298,48 +199,32 @@ export const RunReviewButton: React.FC<{
|
|
|
298
199
|
: t('Code Review');
|
|
299
200
|
const ButtonIcon = isReReview ? ReloadOutlined : RobotOutlined;
|
|
300
201
|
|
|
301
|
-
const items =
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
message.info(t('Please switch to the "Review History" tab to see the details.'));
|
|
317
|
-
},
|
|
202
|
+
const items = [
|
|
203
|
+
{
|
|
204
|
+
key: 'run',
|
|
205
|
+
icon: <ThunderboltOutlined />,
|
|
206
|
+
label: isReReview ? t('Re-run automated review') : t('Run automated review'),
|
|
207
|
+
onClick: () => setOpen(true),
|
|
208
|
+
},
|
|
209
|
+
...(existingReview
|
|
210
|
+
? [
|
|
211
|
+
{
|
|
212
|
+
key: 'view',
|
|
213
|
+
icon: <RobotOutlined />,
|
|
214
|
+
label: t(`Status: ${existingReview.status}`) + ' - ' + t('View in Review History tab'),
|
|
215
|
+
onClick: () => {
|
|
216
|
+
message.info(t('Please switch to the "Review History" tab to see the details.'));
|
|
318
217
|
},
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
icon: <MessageOutlined />,
|
|
324
|
-
label: t('Ask AI Employee'),
|
|
325
|
-
onClick: handleOpenChat,
|
|
326
|
-
disabled: asking,
|
|
327
|
-
},
|
|
328
|
-
],
|
|
329
|
-
[isReReview, existingReview, asking, handleOpenChat, t],
|
|
330
|
-
);
|
|
218
|
+
},
|
|
219
|
+
]
|
|
220
|
+
: []),
|
|
221
|
+
];
|
|
331
222
|
|
|
332
223
|
return (
|
|
333
224
|
<>
|
|
334
225
|
<Dropdown menu={{ items }} placement="bottomRight" trigger={['click']}>
|
|
335
|
-
<Button
|
|
336
|
-
|
|
337
|
-
type={hasNewCommits ? 'primary' : type}
|
|
338
|
-
icon={<ButtonIcon />}
|
|
339
|
-
danger={!!hasNewCommits}
|
|
340
|
-
loading={asking}
|
|
341
|
-
>
|
|
342
|
-
{buttonLabel}
|
|
226
|
+
<Button size={size} type={hasNewCommits ? 'primary' : type} icon={<ButtonIcon />} danger={!!hasNewCommits}>
|
|
227
|
+
{label ?? buttonLabel}
|
|
343
228
|
</Button>
|
|
344
229
|
</Dropdown>
|
|
345
230
|
<Modal
|
|
@@ -364,8 +249,8 @@ export const RunReviewButton: React.FC<{
|
|
|
364
249
|
style={{ marginBottom: 12 }}
|
|
365
250
|
message={
|
|
366
251
|
hasNewCommits
|
|
367
|
-
? t('New commits detected
|
|
368
|
-
: t('A review
|
|
252
|
+
? t('New commits detected. A new review will be queued.')
|
|
253
|
+
: t('A new review will be queued and existing history will be kept.')
|
|
369
254
|
}
|
|
370
255
|
description={
|
|
371
256
|
<Space size={8} wrap style={{ fontSize: 12 }}>
|
|
@@ -434,4 +319,3 @@ export const RunReviewButton: React.FC<{
|
|
|
434
319
|
</>
|
|
435
320
|
);
|
|
436
321
|
};
|
|
437
|
-
|
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
import React, { createContext, useContext, useState, useCallback, useRef } from 'react';
|
|
2
|
-
import { useApp } from '@nocobase/client-v2';
|
|
3
|
-
|
|
4
|
-
interface Repository {
|
|
5
|
-
id: number;
|
|
6
|
-
name: string;
|
|
7
|
-
repoUrl: string;
|
|
8
|
-
localPath: string;
|
|
9
|
-
defaultBranch: string;
|
|
10
|
-
status: string;
|
|
11
|
-
autoReview?: boolean;
|
|
12
|
-
autoReviewFlowId?: number | null;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
interface GitManagerContextType {
|
|
16
|
-
repos: Repository[];
|
|
17
|
-
selectedRepo: Repository | null;
|
|
18
|
-
loading: boolean;
|
|
19
|
-
branches: string[];
|
|
20
|
-
currentBranch: string;
|
|
21
|
-
setSelectedRepo: (repo: Repository | null) => void;
|
|
22
|
-
refreshRepos: () => Promise<void>;
|
|
23
|
-
refreshBranches: () => Promise<void>;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const GitManagerContext = createContext<GitManagerContextType | null>(null);
|
|
27
|
-
|
|
28
|
-
export function useGitManager() {
|
|
29
|
-
const context = useContext(GitManagerContext);
|
|
30
|
-
if (!context) {
|
|
31
|
-
throw new Error('useGitManager must be used within GitManagerProvider');
|
|
32
|
-
}
|
|
33
|
-
return context;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export const GitManagerProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
|
37
|
-
const api = useApp().apiClient;
|
|
38
|
-
const [repos, setRepos] = useState<Repository[]>([]);
|
|
39
|
-
const [selectedRepo, setSelectedRepo] = useState<Repository | null>(null);
|
|
40
|
-
const [loading, setLoading] = useState(false);
|
|
41
|
-
const [branches, setBranches] = useState<string[]>([]);
|
|
42
|
-
const [currentBranch, setCurrentBranch] = useState('');
|
|
43
|
-
const selectedRepoRef = useRef(selectedRepo);
|
|
44
|
-
selectedRepoRef.current = selectedRepo;
|
|
45
|
-
|
|
46
|
-
const refreshBranches = useCallback(async () => {
|
|
47
|
-
const repo = selectedRepoRef.current;
|
|
48
|
-
if (!repo || repo.status !== 'connected') {
|
|
49
|
-
setBranches([]);
|
|
50
|
-
setCurrentBranch('');
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
try {
|
|
54
|
-
const { data } = await api.request({
|
|
55
|
-
url: 'gitManager:branches',
|
|
56
|
-
params: { repositoryId: repo.id },
|
|
57
|
-
});
|
|
58
|
-
const responseData = data?.data?.data || data?.data;
|
|
59
|
-
if (responseData) {
|
|
60
|
-
setBranches(responseData.all || []);
|
|
61
|
-
setCurrentBranch(responseData.current || '');
|
|
62
|
-
}
|
|
63
|
-
} catch {
|
|
64
|
-
setBranches([]);
|
|
65
|
-
setCurrentBranch('');
|
|
66
|
-
}
|
|
67
|
-
}, [api]);
|
|
68
|
-
|
|
69
|
-
const refreshRepos = useCallback(async () => {
|
|
70
|
-
setLoading(true);
|
|
71
|
-
try {
|
|
72
|
-
const { data } = await api.request({ url: 'gitRepositories:list', params: { pageSize: 100 } });
|
|
73
|
-
const list = data?.data || [];
|
|
74
|
-
setRepos(list);
|
|
75
|
-
const current = selectedRepoRef.current;
|
|
76
|
-
if (current) {
|
|
77
|
-
const updated = list.find((r: Repository) => r.id === current.id);
|
|
78
|
-
if (updated) setSelectedRepo(updated);
|
|
79
|
-
}
|
|
80
|
-
} finally {
|
|
81
|
-
setLoading(false);
|
|
82
|
-
}
|
|
83
|
-
}, [api]);
|
|
84
|
-
|
|
85
|
-
return (
|
|
86
|
-
<GitManagerContext.Provider
|
|
87
|
-
value={{ repos, selectedRepo, loading, branches, currentBranch, setSelectedRepo, refreshRepos, refreshBranches }}
|
|
88
|
-
>
|
|
89
|
-
{children}
|
|
90
|
-
</GitManagerContext.Provider>
|
|
91
|
-
);
|
|
92
|
-
};
|
|
1
|
+
import React, { createContext, useContext, useState, useCallback, useRef } from 'react';
|
|
2
|
+
import { useApp } from '@nocobase/client-v2';
|
|
3
|
+
|
|
4
|
+
interface Repository {
|
|
5
|
+
id: number;
|
|
6
|
+
name: string;
|
|
7
|
+
repoUrl: string;
|
|
8
|
+
localPath: string;
|
|
9
|
+
defaultBranch: string;
|
|
10
|
+
status: string;
|
|
11
|
+
autoReview?: boolean;
|
|
12
|
+
autoReviewFlowId?: number | null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface GitManagerContextType {
|
|
16
|
+
repos: Repository[];
|
|
17
|
+
selectedRepo: Repository | null;
|
|
18
|
+
loading: boolean;
|
|
19
|
+
branches: string[];
|
|
20
|
+
currentBranch: string;
|
|
21
|
+
setSelectedRepo: (repo: Repository | null) => void;
|
|
22
|
+
refreshRepos: () => Promise<void>;
|
|
23
|
+
refreshBranches: () => Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const GitManagerContext = createContext<GitManagerContextType | null>(null);
|
|
27
|
+
|
|
28
|
+
export function useGitManager() {
|
|
29
|
+
const context = useContext(GitManagerContext);
|
|
30
|
+
if (!context) {
|
|
31
|
+
throw new Error('useGitManager must be used within GitManagerProvider');
|
|
32
|
+
}
|
|
33
|
+
return context;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const GitManagerProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
|
37
|
+
const api = useApp().apiClient;
|
|
38
|
+
const [repos, setRepos] = useState<Repository[]>([]);
|
|
39
|
+
const [selectedRepo, setSelectedRepo] = useState<Repository | null>(null);
|
|
40
|
+
const [loading, setLoading] = useState(false);
|
|
41
|
+
const [branches, setBranches] = useState<string[]>([]);
|
|
42
|
+
const [currentBranch, setCurrentBranch] = useState('');
|
|
43
|
+
const selectedRepoRef = useRef(selectedRepo);
|
|
44
|
+
selectedRepoRef.current = selectedRepo;
|
|
45
|
+
|
|
46
|
+
const refreshBranches = useCallback(async () => {
|
|
47
|
+
const repo = selectedRepoRef.current;
|
|
48
|
+
if (!repo || repo.status !== 'connected') {
|
|
49
|
+
setBranches([]);
|
|
50
|
+
setCurrentBranch('');
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const { data } = await api.request({
|
|
55
|
+
url: 'gitManager:branches',
|
|
56
|
+
params: { repositoryId: repo.id },
|
|
57
|
+
});
|
|
58
|
+
const responseData = data?.data?.data || data?.data;
|
|
59
|
+
if (responseData) {
|
|
60
|
+
setBranches(responseData.all || []);
|
|
61
|
+
setCurrentBranch(responseData.current || '');
|
|
62
|
+
}
|
|
63
|
+
} catch {
|
|
64
|
+
setBranches([]);
|
|
65
|
+
setCurrentBranch('');
|
|
66
|
+
}
|
|
67
|
+
}, [api]);
|
|
68
|
+
|
|
69
|
+
const refreshRepos = useCallback(async () => {
|
|
70
|
+
setLoading(true);
|
|
71
|
+
try {
|
|
72
|
+
const { data } = await api.request({ url: 'gitRepositories:list', params: { pageSize: 100 } });
|
|
73
|
+
const list = data?.data || [];
|
|
74
|
+
setRepos(list);
|
|
75
|
+
const current = selectedRepoRef.current;
|
|
76
|
+
if (current) {
|
|
77
|
+
const updated = list.find((r: Repository) => r.id === current.id);
|
|
78
|
+
if (updated) setSelectedRepo(updated);
|
|
79
|
+
}
|
|
80
|
+
} finally {
|
|
81
|
+
setLoading(false);
|
|
82
|
+
}
|
|
83
|
+
}, [api]);
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<GitManagerContext.Provider
|
|
87
|
+
value={{ repos, selectedRepo, loading, branches, currentBranch, setSelectedRepo, refreshRepos, refreshBranches }}
|
|
88
|
+
>
|
|
89
|
+
{children}
|
|
90
|
+
</GitManagerContext.Provider>
|
|
91
|
+
);
|
|
92
|
+
};
|
package/src/client/index.tsx
CHANGED
|
@@ -1,83 +1,92 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const RepositoryConfig = React.lazy(() =>
|
|
10
|
-
import('./components/RepositoryConfig').then((m) => ({ default: m.RepositoryConfigSettings })),
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
const GitAccounts = React.lazy(() =>
|
|
14
|
-
import('./components/GitAccounts').then((m) => ({ default: m.GitAccountsSettings })),
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
// The settings center can still be rendered by the legacy client runtime.
|
|
18
|
-
// Reuse the v2 subtree UI here so the feature is available in both runtimes.
|
|
19
|
-
const SubtreeSplits = React.lazy(() => import('../client-v2/components/SubtreeSplits'));
|
|
20
|
-
|
|
21
|
-
import PluginACLClient from "@nocobase/plugin-acl";
|
|
22
|
-
import { RepositoryPermissions } from './components/RepositoryPermissions';
|
|
23
|
-
|
|
24
|
-
export class PluginGitManagerClient extends Plugin {
|
|
25
|
-
async load() {
|
|
26
|
-
// Parent group with no direct component — acts as a category in settings
|
|
27
|
-
this.app.pluginSettingsManager.add('git-manager', {
|
|
28
|
-
title: (this as any).t('Git Manager'),
|
|
29
|
-
icon: 'BranchesOutlined',
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
// Repositories config — separate group for ACL-granular access
|
|
33
|
-
this.app.pluginSettingsManager.add('git-manager.repositories', {
|
|
34
|
-
title: (this as any).t('Repositories'),
|
|
35
|
-
Component: RepositoryConfig,
|
|
36
|
-
aclSnippet: `pm.plugin-git-manager.repositories`,
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
// Git Accounts — separate group for managing shared credentials
|
|
40
|
-
this.app.pluginSettingsManager.add('git-manager.accounts', {
|
|
41
|
-
title: (this as any).t('Git Accounts'),
|
|
42
|
-
Component: GitAccounts,
|
|
43
|
-
aclSnippet: `pm.plugin-git-manager.repositories`,
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
this.app.pluginSettingsManager.add('git-manager.subtree-splits', {
|
|
47
|
-
title: (this as any).t('Subtree Splits'),
|
|
48
|
-
Component: SubtreeSplits,
|
|
49
|
-
aclSnippet: `pm.plugin-git-manager.write`,
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
// Full management — requires full plugin permission
|
|
53
|
-
this.app.pluginSettingsManager.add('git-manager.manage', {
|
|
54
|
-
title: (this as any).t('Manage'),
|
|
55
|
-
Component: GitManagerSettings,
|
|
56
|
-
aclSnippet: `pm.plugin-git-manager.manage`,
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
const aiManager = ((this as any).app as any).aiManager;
|
|
60
|
-
if (aiManager?.registerWorkContext) {
|
|
61
|
-
aiManager.registerWorkContext('git-repository', GitRepositoryWorkContext);
|
|
62
|
-
aiManager.registerWorkContext('git-merge-request', GitMergeRequestWorkContext);
|
|
63
|
-
aiManager.registerWorkContext('git-commit', GitCommitWorkContext);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const aclPlugin = this.app.pm.get(PluginACLClient);
|
|
67
|
-
if (aclPlugin) {
|
|
68
|
-
aclPlugin.settingsUI.addPermissionsTab(({ t, TabLayout, activeRole }) => ({
|
|
69
|
-
key: 'git-manager',
|
|
70
|
-
label: 'Git Manager',
|
|
71
|
-
sort: 25,
|
|
72
|
-
children: (
|
|
73
|
-
<TabLayout>
|
|
74
|
-
<RepositoryPermissions activeRole={activeRole} />
|
|
75
|
-
</TabLayout>
|
|
76
|
-
),
|
|
77
|
-
}));
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export default PluginGitManagerClient;
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
83
9
|
|
|
10
|
+
import { Plugin } from '@nocobase/client';
|
|
11
|
+
import type PluginAIClientV2 from '@nocobase/plugin-ai/client-v2';
|
|
12
|
+
import React from 'react';
|
|
13
|
+
import { GitRepositoryWorkContext, GitMergeRequestWorkContext, GitCommitWorkContext } from './ai-context';
|
|
14
|
+
|
|
15
|
+
const GitManagerSettings = React.lazy(() =>
|
|
16
|
+
import('./components/GitManagerSettings').then((m) => ({ default: m.GitManagerSettings })),
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const RepositoryConfig = React.lazy(() =>
|
|
20
|
+
import('./components/RepositoryConfig').then((m) => ({ default: m.RepositoryConfigSettings })),
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const GitAccounts = React.lazy(() =>
|
|
24
|
+
import('./components/GitAccounts').then((m) => ({ default: m.GitAccountsSettings })),
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
// The settings center can still be rendered by the legacy client runtime.
|
|
28
|
+
// Reuse the v2 subtree UI here so the feature is available in both runtimes.
|
|
29
|
+
const SubtreeSplits = React.lazy(() => import('../client-v2/components/SubtreeSplits'));
|
|
30
|
+
|
|
31
|
+
import type PluginACLClient from '@nocobase/plugin-acl/client';
|
|
32
|
+
import { RepositoryPermissions } from './components/RepositoryPermissions';
|
|
33
|
+
|
|
34
|
+
export class PluginGitManagerClient extends Plugin {
|
|
35
|
+
async load() {
|
|
36
|
+
// Parent group with no direct component — acts as a category in settings
|
|
37
|
+
this.app.pluginSettingsManager.add('git-manager', {
|
|
38
|
+
title: (this as any).t('Git Manager'),
|
|
39
|
+
icon: 'BranchesOutlined',
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// Repositories config — separate group for ACL-granular access
|
|
43
|
+
this.app.pluginSettingsManager.add('git-manager.repositories', {
|
|
44
|
+
title: (this as any).t('Repositories'),
|
|
45
|
+
Component: RepositoryConfig,
|
|
46
|
+
aclSnippet: `pm.plugin-git-manager.repositories`,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// Git Accounts — separate group for managing shared credentials
|
|
50
|
+
this.app.pluginSettingsManager.add('git-manager.accounts', {
|
|
51
|
+
title: (this as any).t('Git Accounts'),
|
|
52
|
+
Component: GitAccounts,
|
|
53
|
+
aclSnippet: `pm.plugin-git-manager.repositories`,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
this.app.pluginSettingsManager.add('git-manager.subtree-splits', {
|
|
57
|
+
title: (this as any).t('Subtree Splits'),
|
|
58
|
+
Component: SubtreeSplits,
|
|
59
|
+
aclSnippet: `pm.plugin-git-manager.write`,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Full management — requires full plugin permission
|
|
63
|
+
this.app.pluginSettingsManager.add('git-manager.manage', {
|
|
64
|
+
title: (this as any).t('Manage'),
|
|
65
|
+
Component: GitManagerSettings,
|
|
66
|
+
aclSnippet: `pm.plugin-git-manager.manage`,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const aiManager = this.app.pm.get<PluginAIClientV2>('ai')?.aiManager;
|
|
70
|
+
if (aiManager?.registerWorkContext) {
|
|
71
|
+
aiManager.registerWorkContext('git-repository', GitRepositoryWorkContext);
|
|
72
|
+
aiManager.registerWorkContext('git-merge-request', GitMergeRequestWorkContext);
|
|
73
|
+
aiManager.registerWorkContext('git-commit', GitCommitWorkContext);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const aclPlugin = this.app.pm.get<PluginACLClient>('acl');
|
|
77
|
+
if (aclPlugin) {
|
|
78
|
+
aclPlugin.settingsUI.addPermissionsTab(({ t, TabLayout, activeRole }) => ({
|
|
79
|
+
key: 'git-manager',
|
|
80
|
+
label: 'Git Manager',
|
|
81
|
+
sort: 25,
|
|
82
|
+
children: (
|
|
83
|
+
<TabLayout>
|
|
84
|
+
<RepositoryPermissions activeRole={activeRole} />
|
|
85
|
+
</TabLayout>
|
|
86
|
+
),
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export default PluginGitManagerClient;
|