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,11 +1,26 @@
|
|
|
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
12
|
import { RobotOutlined, MessageOutlined, ThunderboltOutlined, ReloadOutlined } from '@ant-design/icons';
|
|
4
13
|
import { useApp } from '@nocobase/client-v2';
|
|
5
|
-
import
|
|
14
|
+
import type PluginAIClientV2 from '@nocobase/plugin-ai/client-v2';
|
|
6
15
|
import { REVIEW_PROMPT_TEMPLATES } from '../promptTemplates';
|
|
7
16
|
import { useT } from '../locale';
|
|
8
17
|
|
|
18
|
+
interface ExistingReview {
|
|
19
|
+
status: string;
|
|
20
|
+
headSha?: string;
|
|
21
|
+
latestSha?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
9
24
|
interface ReviewFlow {
|
|
10
25
|
id: number;
|
|
11
26
|
name: string;
|
|
@@ -29,7 +44,7 @@ type Target =
|
|
|
29
44
|
* Button that lets the user kick off a code review for a given target.
|
|
30
45
|
* Two paths:
|
|
31
46
|
* - "Run review" → POST gitManager:triggerReview (server-side, async)
|
|
32
|
-
* - "Open chat" → call
|
|
47
|
+
* - "Open chat" → call the enabled AI plugin manager,
|
|
33
48
|
* so the user can chat with the AI employee using the same context.
|
|
34
49
|
*/
|
|
35
50
|
export const RunReviewButton: React.FC<{
|
|
@@ -39,20 +54,20 @@ export const RunReviewButton: React.FC<{
|
|
|
39
54
|
onTriggered?: (reviewId: number) => void;
|
|
40
55
|
}> = ({ target, size = 'small', type = 'default', onTriggered }) => {
|
|
41
56
|
const t = useT();
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
const
|
|
57
|
+
const app = useApp();
|
|
58
|
+
const api = app.apiClient;
|
|
59
|
+
const aiManager = app.pm.get<PluginAIClientV2>('ai')?.aiManager;
|
|
45
60
|
const [open, setOpen] = useState(false);
|
|
46
61
|
const [flows, setFlows] = useState<ReviewFlow[]>([]);
|
|
47
62
|
const [submitting, setSubmitting] = useState(false);
|
|
48
63
|
const [asking, setAsking] = useState(false);
|
|
49
|
-
const [existingReview, setExistingReview] = useState<
|
|
64
|
+
const [existingReview, setExistingReview] = useState<ExistingReview | null>(null);
|
|
50
65
|
const [templateKey, setTemplateKey] = useState<string | undefined>();
|
|
51
66
|
const [form] = Form.useForm();
|
|
52
67
|
|
|
53
68
|
const loadExistingReview = useCallback(() => {
|
|
54
69
|
let cancelled = false;
|
|
55
|
-
const filter:
|
|
70
|
+
const filter: Record<string, unknown> = {
|
|
56
71
|
repositoryId: target.repositoryId,
|
|
57
72
|
targetType: target.type,
|
|
58
73
|
};
|
|
@@ -132,7 +147,7 @@ export const RunReviewButton: React.FC<{
|
|
|
132
147
|
try {
|
|
133
148
|
const values = await form.validateFields();
|
|
134
149
|
setSubmitting(true);
|
|
135
|
-
const params:
|
|
150
|
+
const params: Record<string, unknown> = {
|
|
136
151
|
repositoryId: target.repositoryId,
|
|
137
152
|
targetType: target.type,
|
|
138
153
|
flowId: values.flowId,
|
|
@@ -156,9 +171,14 @@ export const RunReviewButton: React.FC<{
|
|
|
156
171
|
form.resetFields();
|
|
157
172
|
loadExistingReview();
|
|
158
173
|
onTriggered?.(reviewId);
|
|
159
|
-
} catch (err:
|
|
160
|
-
if (err
|
|
161
|
-
|
|
174
|
+
} catch (err: unknown) {
|
|
175
|
+
if (err && typeof err === 'object' && 'errorFields' in err) return;
|
|
176
|
+
const responseError = err as { response?: { data?: { errors?: Array<{ message?: string }> } } } | null;
|
|
177
|
+
message.error(
|
|
178
|
+
responseError?.response?.data?.errors?.[0]?.message ||
|
|
179
|
+
(err instanceof Error && err.message) ||
|
|
180
|
+
t('Failed to trigger review'),
|
|
181
|
+
);
|
|
162
182
|
} finally {
|
|
163
183
|
setSubmitting(false);
|
|
164
184
|
}
|
|
@@ -235,7 +255,7 @@ export const RunReviewButton: React.FC<{
|
|
|
235
255
|
};
|
|
236
256
|
|
|
237
257
|
const handleOpenChat = async () => {
|
|
238
|
-
if (!triggerTask
|
|
258
|
+
if (!aiManager?.triggerTask) {
|
|
239
259
|
message.warning(t('AI plugin is not available'));
|
|
240
260
|
return;
|
|
241
261
|
}
|
|
@@ -247,16 +267,8 @@ export const RunReviewButton: React.FC<{
|
|
|
247
267
|
message.warning(t('No matching flow available'));
|
|
248
268
|
return;
|
|
249
269
|
}
|
|
250
|
-
|
|
251
|
-
|
|
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,
|
|
270
|
+
aiManager.triggerTask({
|
|
271
|
+
aiEmployee: flow.aiEmployeeUsername,
|
|
260
272
|
tasks: [
|
|
261
273
|
{
|
|
262
274
|
title: `${flow.name}: ${buildContextHint()}`,
|
|
@@ -270,8 +282,8 @@ export const RunReviewButton: React.FC<{
|
|
|
270
282
|
},
|
|
271
283
|
],
|
|
272
284
|
});
|
|
273
|
-
} catch (err:
|
|
274
|
-
message.error(err
|
|
285
|
+
} catch (err: unknown) {
|
|
286
|
+
message.error((err instanceof Error && err.message) || t('Failed to open AI chat'));
|
|
275
287
|
} finally {
|
|
276
288
|
setAsking(false);
|
|
277
289
|
}
|
|
@@ -298,36 +310,33 @@ export const RunReviewButton: React.FC<{
|
|
|
298
310
|
: t('Code Review');
|
|
299
311
|
const ButtonIcon = isReReview ? ReloadOutlined : RobotOutlined;
|
|
300
312
|
|
|
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
|
-
},
|
|
313
|
+
const items = [
|
|
314
|
+
{
|
|
315
|
+
key: 'run',
|
|
316
|
+
icon: <ThunderboltOutlined />,
|
|
317
|
+
label: isReReview ? t('Re-run automated review') : t('Run automated review'),
|
|
318
|
+
onClick: () => setOpen(true),
|
|
319
|
+
},
|
|
320
|
+
...(existingReview
|
|
321
|
+
? [
|
|
322
|
+
{
|
|
323
|
+
key: 'view',
|
|
324
|
+
icon: <RobotOutlined />,
|
|
325
|
+
label: t(`Status: ${existingReview.status}`) + ' - ' + t('View in Review History tab'),
|
|
326
|
+
onClick: () => {
|
|
327
|
+
message.info(t('Please switch to the "Review History" tab to see the details.'));
|
|
318
328
|
},
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
);
|
|
329
|
+
},
|
|
330
|
+
]
|
|
331
|
+
: []),
|
|
332
|
+
{
|
|
333
|
+
key: 'chat',
|
|
334
|
+
icon: <MessageOutlined />,
|
|
335
|
+
label: t('Ask AI Employee'),
|
|
336
|
+
onClick: handleOpenChat,
|
|
337
|
+
disabled: asking || !aiManager?.triggerTask,
|
|
338
|
+
},
|
|
339
|
+
];
|
|
331
340
|
|
|
332
341
|
return (
|
|
333
342
|
<>
|
|
@@ -434,4 +443,3 @@ export const RunReviewButton: React.FC<{
|
|
|
434
443
|
</>
|
|
435
444
|
);
|
|
436
445
|
};
|
|
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;
|
package/src/client/locale.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { useApp } from '@nocobase/client-v2';
|
|
2
|
-
|
|
3
|
-
export const namespace = 'plugin-git-manager';
|
|
4
|
-
|
|
5
|
-
export function useT() {
|
|
6
|
-
const app = useApp();
|
|
7
|
-
return (str: string, options?: any): string =>
|
|
8
|
-
app.i18n.t(str, { ns: [namespace, 'client'], ...options }) as unknown as string;
|
|
9
|
-
}
|
|
1
|
+
import { useApp } from '@nocobase/client-v2';
|
|
2
|
+
|
|
3
|
+
export const namespace = 'plugin-git-manager';
|
|
4
|
+
|
|
5
|
+
export function useT() {
|
|
6
|
+
const app = useApp();
|
|
7
|
+
return (str: string, options?: any): string =>
|
|
8
|
+
app.i18n.t(str, { ns: [namespace, 'client'], ...options }) as unknown as string;
|
|
9
|
+
}
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
export interface ReviewPromptTemplate {
|
|
2
|
-
key: 'application' | 'workflow-config';
|
|
3
|
-
label: string;
|
|
4
|
-
text: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export const REVIEW_PROMPT_TEMPLATES: ReviewPromptTemplate[] = [
|
|
8
|
-
{
|
|
9
|
-
key: 'application',
|
|
10
|
-
label: 'Application code (C#, .NET, Java, JS/TS…)',
|
|
11
|
-
text: `Please review the code changes with a focus on:
|
|
12
|
-
1. Best Practices & Style:
|
|
13
|
-
- C#/VB.NET: Follow standard naming conventions (PascalCase for methods/properties, camelCase for fields). Ensure proper use of async/await (avoid .Result/.Wait()). Use LINQ efficiently.
|
|
14
|
-
- Java: Follow standard naming conventions. Check null-safety (Optional, null checks). Prefer try-with-resources for closeable resources and use streams/collections idiomatically.
|
|
15
|
-
- JS/TS: Use strict equality (===), prefer const/let. Ensure TypeScript types are explicit and avoid 'any'.
|
|
16
|
-
2. Performance: Watch out for N+1 queries, unnecessary loops, and memory leaks.
|
|
17
|
-
3. Security: Identify potential SQL injections, XSS vulnerabilities, and improper data validation.
|
|
18
|
-
4. Maintainability: Check for readability, SOLID principles, and DRY. Ensure meaningful naming.
|
|
19
|
-
5. Error Handling: Verify that exceptions are properly caught, handled, and logged.`,
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
key: 'workflow-config',
|
|
23
|
-
label: 'Workflow / Config (XML, XAML, YAML, JSON…)',
|
|
24
|
-
text: `Please review the workflow/configuration files (XML, XAML, YAML, JSON, ...) with a focus on:
|
|
25
|
-
1. Structure & Validity: Well-formed syntax, correct schema/namespace usage, no duplicate or conflicting keys, consistent indentation and encoding.
|
|
26
|
-
2. Workflow Logic: Unreachable or dead steps, missing error handling / retry / timeout settings, incorrect transitions or dependencies between steps, infinite loops.
|
|
27
|
-
3. Security: Hardcoded credentials, secrets, tokens or connection strings; insecure endpoints (http instead of https); overly broad permissions.
|
|
28
|
-
4. Environment & Portability: Hardcoded environment-specific values (paths, hosts, ports) that should be parameterized; missing default values.
|
|
29
|
-
5. Maintainability: Meaningful naming for steps/variables, duplicated blocks that should be shared, obsolete or unused entries.`,
|
|
30
|
-
},
|
|
31
|
-
];
|
|
1
|
+
export interface ReviewPromptTemplate {
|
|
2
|
+
key: 'application' | 'workflow-config';
|
|
3
|
+
label: string;
|
|
4
|
+
text: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const REVIEW_PROMPT_TEMPLATES: ReviewPromptTemplate[] = [
|
|
8
|
+
{
|
|
9
|
+
key: 'application',
|
|
10
|
+
label: 'Application code (C#, .NET, Java, JS/TS…)',
|
|
11
|
+
text: `Please review the code changes with a focus on:
|
|
12
|
+
1. Best Practices & Style:
|
|
13
|
+
- C#/VB.NET: Follow standard naming conventions (PascalCase for methods/properties, camelCase for fields). Ensure proper use of async/await (avoid .Result/.Wait()). Use LINQ efficiently.
|
|
14
|
+
- Java: Follow standard naming conventions. Check null-safety (Optional, null checks). Prefer try-with-resources for closeable resources and use streams/collections idiomatically.
|
|
15
|
+
- JS/TS: Use strict equality (===), prefer const/let. Ensure TypeScript types are explicit and avoid 'any'.
|
|
16
|
+
2. Performance: Watch out for N+1 queries, unnecessary loops, and memory leaks.
|
|
17
|
+
3. Security: Identify potential SQL injections, XSS vulnerabilities, and improper data validation.
|
|
18
|
+
4. Maintainability: Check for readability, SOLID principles, and DRY. Ensure meaningful naming.
|
|
19
|
+
5. Error Handling: Verify that exceptions are properly caught, handled, and logged.`,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
key: 'workflow-config',
|
|
23
|
+
label: 'Workflow / Config (XML, XAML, YAML, JSON…)',
|
|
24
|
+
text: `Please review the workflow/configuration files (XML, XAML, YAML, JSON, ...) with a focus on:
|
|
25
|
+
1. Structure & Validity: Well-formed syntax, correct schema/namespace usage, no duplicate or conflicting keys, consistent indentation and encoding.
|
|
26
|
+
2. Workflow Logic: Unreachable or dead steps, missing error handling / retry / timeout settings, incorrect transitions or dependencies between steps, infinite loops.
|
|
27
|
+
3. Security: Hardcoded credentials, secrets, tokens or connection strings; insecure endpoints (http instead of https); overly broad permissions.
|
|
28
|
+
4. Environment & Portability: Hardcoded environment-specific values (paths, hosts, ports) that should be parameterized; missing default values.
|
|
29
|
+
5. Maintainability: Meaningful naming for steps/variables, duplicated blocks that should be shared, obsolete or unused entries.`,
|
|
30
|
+
},
|
|
31
|
+
];
|