plugin-git-manager 1.4.0 → 1.4.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/dist/client/317.e7b1d59371812c30.js +10 -0
- package/dist/client/434.05d0ba2b821105dc.js +10 -0
- package/dist/client/453.cdcba6d2d0c9522b.js +10 -0
- package/dist/client/454.625da741a7e1161f.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/317.4e116f84ed9081b6.js +10 -0
- package/dist/client-v2/434.764113d20743a45b.js +10 -0
- package/dist/client-v2/453.5ab80c06d8e61a7e.js +10 -0
- package/dist/client-v2/454.b885b1d35ef7ff72.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/locale/en-US.json +12 -1
- package/dist/locale/vi-VN.json +12 -1
- package/dist/locale/zh-CN.json +12 -1
- package/dist/node_modules/simple-git/package.json +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/actions/git-actions.js +299 -87
- package/dist/server/actions/gitlab-api.js +19 -12
- package/dist/server/actions/subtree.js +20 -10
- package/dist/server/plugin.js +134 -10
- package/dist/server/repository-access.js +2 -2
- package/dist/server/request-method-policy.js +2 -1
- package/dist/server/services/review-source.js +2 -1
- package/dist/server/utils/cluster-git.js +181 -0
- package/package.json +2 -2
- package/src/client/__tests__/FileExplorerAndManage.test.tsx +236 -0
- package/src/client/__tests__/workflowRoutes.test.ts +3 -1
- package/src/client/components/CommitHistory.tsx +19 -7
- package/src/client/components/FileExplorer.tsx +80 -34
- package/src/client/components/GitManagerSettings.tsx +21 -5
- package/src/client/components/GitOperations.tsx +25 -4
- package/src/client/components/GitRuntimeBanner.tsx +97 -0
- package/src/client/components/RepositoryConfig.tsx +28 -6
- package/src/client/context/GitManagerContext.tsx +156 -13
- package/src/client/workflowRoutes.ts +11 -0
- package/src/locale/en-US.json +12 -1
- package/src/locale/vi-VN.json +12 -1
- package/src/locale/zh-CN.json +12 -1
- package/src/server/__tests__/git-actions.test.ts +329 -4
- package/src/server/__tests__/smoke.test.ts +32 -1
- package/src/server/actions/git-actions.ts +322 -96
- package/src/server/actions/gitlab-api.ts +20 -14
- package/src/server/actions/subtree.ts +23 -6
- package/src/server/plugin.ts +152 -3
- package/src/server/repository-access.ts +2 -2
- package/src/server/request-method-policy.ts +1 -0
- package/src/server/services/review-source.ts +3 -2
- package/src/server/utils/cluster-git.ts +209 -0
- package/dist/client/317.2d0d33871e24ee24.js +0 -10
- package/dist/client/434.2401f7257495b66e.js +0 -10
- package/dist/client/453.58657b9ba0904477.js +0 -10
- package/dist/client-v2/317.d2466574d00f94d0.js +0 -10
- package/dist/client-v2/434.32b0a07b821b9329.js +0 -10
- package/dist/client-v2/453.f9a0ec6d8e1bd1cc.js +0 -10
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
6
|
+
import { GitManagerSettings } from '../components/GitManagerSettings';
|
|
7
|
+
import { RepositoryConfigSettings } from '../components/RepositoryConfig';
|
|
8
|
+
|
|
9
|
+
const mocks = vi.hoisted(() => {
|
|
10
|
+
const request = vi.fn();
|
|
11
|
+
const t = (key: string) => key;
|
|
12
|
+
return {
|
|
13
|
+
request,
|
|
14
|
+
t,
|
|
15
|
+
app: {
|
|
16
|
+
apiClient: { request },
|
|
17
|
+
getPublicPath: () => '/',
|
|
18
|
+
router: { getBasename: () => '/' },
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
vi.mock('@nocobase/client-v2', () => ({
|
|
24
|
+
useApp: () => mocks.app,
|
|
25
|
+
getRouteRuntimeVersion: () => 'legacy',
|
|
26
|
+
getV2EffectiveBasePath: () => '/',
|
|
27
|
+
stripModernClientPrefix: (p: string) => p,
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
vi.mock('../../client-v2/git-context-api', () => ({
|
|
31
|
+
setCurrentGitRepository: vi.fn(),
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
vi.mock('../locale', () => ({
|
|
35
|
+
useT: () => mocks.t,
|
|
36
|
+
}));
|
|
37
|
+
|
|
38
|
+
vi.mock('../components/RunReviewButton', () => ({
|
|
39
|
+
RunReviewButton: () => <button type="button">Run review</button>,
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
describe('Git Manager UI — Cluster Manager compatibility, branch reset, and Manage navigation', () => {
|
|
43
|
+
const originalPath = window.location.pathname + window.location.search;
|
|
44
|
+
|
|
45
|
+
beforeEach(() => {
|
|
46
|
+
vi.clearAllMocks();
|
|
47
|
+
window.history.replaceState({}, '', '/admin/settings/git-manager/manage?repositoryId=1');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
afterEach(() => {
|
|
51
|
+
cleanup();
|
|
52
|
+
window.history.replaceState({}, '', originalPath || '/');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('shows Cluster Manager install banner without firing fileTree when git is missing, then unlocks once installed', async () => {
|
|
56
|
+
let gitReady = false;
|
|
57
|
+
mocks.request.mockImplementation(async ({ url }: { url: string }) => {
|
|
58
|
+
if (url === 'gitRepositories:list') {
|
|
59
|
+
return {
|
|
60
|
+
data: {
|
|
61
|
+
data: [
|
|
62
|
+
{
|
|
63
|
+
id: 1,
|
|
64
|
+
name: 'test-pretext',
|
|
65
|
+
repoUrl: 'https://github.com/gemvn90/pretext',
|
|
66
|
+
localPath: 'my-project-main',
|
|
67
|
+
defaultBranch: 'main',
|
|
68
|
+
status: 'connected',
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (url === 'gitManager:runtimeStatus') {
|
|
75
|
+
return {
|
|
76
|
+
data: {
|
|
77
|
+
data: {
|
|
78
|
+
gitAvailable: gitReady,
|
|
79
|
+
gitBinary: 'git',
|
|
80
|
+
clusterManager: {
|
|
81
|
+
available: true,
|
|
82
|
+
gitConfigured: true,
|
|
83
|
+
status: 'idle',
|
|
84
|
+
progressPercent: 0,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
if (url === 'gitManager:installGit') {
|
|
91
|
+
gitReady = true;
|
|
92
|
+
return { data: { data: { dispatched: true } } };
|
|
93
|
+
}
|
|
94
|
+
if (url === 'gitManager:branches') {
|
|
95
|
+
return { data: { data: { current: 'main', all: ['main'] } } };
|
|
96
|
+
}
|
|
97
|
+
if (url === 'gitManager:fileTree') {
|
|
98
|
+
return {
|
|
99
|
+
data: {
|
|
100
|
+
data: [{ mode: '100644', type: 'blob', hash: 'abc1234', size: 120, name: 'README.md', path: 'README.md' }],
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return { data: { data: [] } };
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
render(<GitManagerSettings />);
|
|
108
|
+
|
|
109
|
+
const installBtn = await screen.findByRole('button', { name: /Install Git via Cluster Manager/i });
|
|
110
|
+
expect(installBtn).toBeInTheDocument();
|
|
111
|
+
expect(mocks.request).not.toHaveBeenCalledWith(expect.objectContaining({ url: 'gitManager:fileTree' }));
|
|
112
|
+
|
|
113
|
+
fireEvent.click(installBtn);
|
|
114
|
+
|
|
115
|
+
expect(await screen.findByText('README.md')).toBeInTheDocument();
|
|
116
|
+
const fileTreeCalls = mocks.request.mock.calls.filter(([arg]) => arg.url === 'gitManager:fileTree');
|
|
117
|
+
expect(fileTreeCalls).toHaveLength(1);
|
|
118
|
+
expect(fileTreeCalls[0][0]).toMatchObject({
|
|
119
|
+
url: 'gitManager:fileTree',
|
|
120
|
+
params: { repositoryId: 1, ref: 'main', treePath: '' },
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('resets branch ref when switching between repositories with different default branches', async () => {
|
|
125
|
+
window.history.replaceState({}, '', '/admin/settings/git-manager/manage?repositoryId=1');
|
|
126
|
+
mocks.request.mockImplementation(async ({ url, params }: { url: string; params?: { repositoryId?: number } }) => {
|
|
127
|
+
if (url === 'gitRepositories:list') {
|
|
128
|
+
return {
|
|
129
|
+
data: {
|
|
130
|
+
data: [
|
|
131
|
+
{
|
|
132
|
+
id: 1,
|
|
133
|
+
name: 'repo-develop',
|
|
134
|
+
repoUrl: 'https://github.com/org/repo-a',
|
|
135
|
+
localPath: 'repo-a',
|
|
136
|
+
defaultBranch: 'develop',
|
|
137
|
+
status: 'connected',
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
id: 2,
|
|
141
|
+
name: 'repo-main',
|
|
142
|
+
repoUrl: 'https://github.com/org/repo-b',
|
|
143
|
+
localPath: 'repo-b',
|
|
144
|
+
defaultBranch: 'main',
|
|
145
|
+
status: 'connected',
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
if (url === 'gitManager:runtimeStatus') {
|
|
152
|
+
return {
|
|
153
|
+
data: {
|
|
154
|
+
data: {
|
|
155
|
+
gitAvailable: true,
|
|
156
|
+
gitBinary: '/usr/bin/git',
|
|
157
|
+
clusterManager: { available: true, gitConfigured: true, status: 'succeeded', progressPercent: 100 },
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
if (url === 'gitManager:branches') {
|
|
163
|
+
return params?.repositoryId === 1
|
|
164
|
+
? { data: { data: { current: 'develop', all: ['develop'] } } }
|
|
165
|
+
: { data: { data: { current: 'main', all: ['main'] } } };
|
|
166
|
+
}
|
|
167
|
+
if (url === 'gitManager:fileTree') {
|
|
168
|
+
return { data: { data: [] } };
|
|
169
|
+
}
|
|
170
|
+
return { data: { data: [] } };
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
render(<GitManagerSettings />);
|
|
174
|
+
|
|
175
|
+
await waitFor(() => {
|
|
176
|
+
expect(mocks.request).toHaveBeenCalledWith({
|
|
177
|
+
url: 'gitManager:fileTree',
|
|
178
|
+
params: { repositoryId: 1, ref: 'develop', treePath: '' },
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
const comboboxes = screen.getAllByRole('combobox');
|
|
183
|
+
fireEvent.mouseDown(comboboxes[0]);
|
|
184
|
+
fireEvent.click(await screen.findByText('repo-main'));
|
|
185
|
+
|
|
186
|
+
await waitFor(() => {
|
|
187
|
+
expect(mocks.request).toHaveBeenCalledWith({
|
|
188
|
+
url: 'gitManager:fileTree',
|
|
189
|
+
params: { repositoryId: 2, ref: 'main', treePath: '' },
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
expect(mocks.request).not.toHaveBeenCalledWith({
|
|
193
|
+
url: 'gitManager:fileTree',
|
|
194
|
+
params: { repositoryId: 2, ref: 'develop', treePath: '' },
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('renders accessible Manage links in RepositoryConfig table', async () => {
|
|
199
|
+
window.history.replaceState({}, '', '/admin/settings/git-manager/repositories');
|
|
200
|
+
mocks.request.mockImplementation(async ({ url }: { url: string }) => {
|
|
201
|
+
if (url === 'gitRepositories:list') {
|
|
202
|
+
return {
|
|
203
|
+
data: {
|
|
204
|
+
data: [
|
|
205
|
+
{
|
|
206
|
+
id: 1,
|
|
207
|
+
name: 'test-pretext',
|
|
208
|
+
repoUrl: 'https://github.com/gemvn90/pretext',
|
|
209
|
+
localPath: 'my-project-main',
|
|
210
|
+
defaultBranch: 'main',
|
|
211
|
+
status: 'connected',
|
|
212
|
+
},
|
|
213
|
+
],
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
if (url === 'gitManager:runtimeStatus') {
|
|
218
|
+
return {
|
|
219
|
+
data: {
|
|
220
|
+
data: {
|
|
221
|
+
gitAvailable: true,
|
|
222
|
+
gitBinary: '/usr/bin/git',
|
|
223
|
+
clusterManager: { available: true, gitConfigured: true, status: 'succeeded', progressPercent: 100 },
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
return { data: { data: [] } };
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
render(<RepositoryConfigSettings />);
|
|
232
|
+
|
|
233
|
+
const link = await screen.findByRole('link', { name: 'test-pretext' });
|
|
234
|
+
expect(link).toHaveAttribute('href', '/admin/settings/git-manager/manage?repositoryId=1');
|
|
235
|
+
});
|
|
236
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
|
|
3
|
-
import { reviewApprovalHref, workflowHref } from '../workflowRoutes';
|
|
3
|
+
import { clusterPackageInstallerHref, gitManagerManageHref, reviewApprovalHref, workflowHref } from '../workflowRoutes';
|
|
4
4
|
|
|
5
5
|
type RouteWindow = Window & {
|
|
6
6
|
__nocobase_modern_client_prefix__?: string;
|
|
@@ -42,6 +42,8 @@ describe('Git review workflow route resolution', () => {
|
|
|
42
42
|
expect(workflowHref(app, 'workflow', 'flow/42')).toBe('/tenant/app/admin/settings/workflow/workflows/flow%2F42');
|
|
43
43
|
expect(workflowHref(app, 'execution', 73)).toBe('/tenant/app/admin/settings/workflow/executions/73');
|
|
44
44
|
expect(reviewApprovalHref(app)).toBe('/tenant/app/admin/workflow/tasks/git-review-approval/pending');
|
|
45
|
+
expect(gitManagerManageHref(app, 9)).toBe('/tenant/app/admin/settings/git-manager/manage?repositoryId=9');
|
|
46
|
+
expect(clusterPackageInstallerHref(app)).toBe('/tenant/app/admin/settings/plugin-cluster-manager');
|
|
45
47
|
});
|
|
46
48
|
|
|
47
49
|
it('uses the effective modern basename and custom modern prefix for v2 workflow links', () => {
|
|
@@ -31,7 +31,8 @@ export const CommitHistory: React.FC = () => {
|
|
|
31
31
|
const t = useT();
|
|
32
32
|
const { token } = useToken();
|
|
33
33
|
const api = useApp().apiClient;
|
|
34
|
-
const { selectedRepo } = useGitManager();
|
|
34
|
+
const { selectedRepo, gitRuntime } = useGitManager();
|
|
35
|
+
const gitAvailable = gitRuntime?.gitAvailable !== false;
|
|
35
36
|
const repositoryId = selectedRepo?.id;
|
|
36
37
|
const [branchSnapshot, setBranchSnapshot] = useState<{
|
|
37
38
|
repositoryId: number;
|
|
@@ -51,7 +52,7 @@ export const CommitHistory: React.FC = () => {
|
|
|
51
52
|
let cancelled = false;
|
|
52
53
|
const repositoryId = selectedRepo?.id;
|
|
53
54
|
setBranchSnapshot(null);
|
|
54
|
-
if (!repositoryId || selectedRepo.status !== 'connected')
|
|
55
|
+
if (!repositoryId || selectedRepo.status !== 'connected' || !gitAvailable)
|
|
55
56
|
return () => {
|
|
56
57
|
cancelled = true;
|
|
57
58
|
};
|
|
@@ -74,10 +75,10 @@ export const CommitHistory: React.FC = () => {
|
|
|
74
75
|
return () => {
|
|
75
76
|
cancelled = true;
|
|
76
77
|
};
|
|
77
|
-
}, [api, selectedRepo?.id, selectedRepo?.status]);
|
|
78
|
+
}, [api, selectedRepo?.id, selectedRepo?.status, gitAvailable]);
|
|
78
79
|
|
|
79
80
|
const loadHistory = useCallback(async () => {
|
|
80
|
-
if (!selectedRepo) return;
|
|
81
|
+
if (!selectedRepo || !gitAvailable) return;
|
|
81
82
|
setLoading(true);
|
|
82
83
|
try {
|
|
83
84
|
const { data } = await api.request({
|
|
@@ -92,15 +93,15 @@ export const CommitHistory: React.FC = () => {
|
|
|
92
93
|
} finally {
|
|
93
94
|
setLoading(false);
|
|
94
95
|
}
|
|
95
|
-
}, [api, selectedRepo]);
|
|
96
|
+
}, [api, selectedRepo, gitAvailable]);
|
|
96
97
|
|
|
97
98
|
useEffect(() => {
|
|
98
|
-
if (selectedRepo?.status === 'connected') {
|
|
99
|
+
if (selectedRepo?.status === 'connected' && gitAvailable) {
|
|
99
100
|
loadHistory();
|
|
100
101
|
} else {
|
|
101
102
|
setCommits([]);
|
|
102
103
|
}
|
|
103
|
-
}, [selectedRepo, loadHistory]);
|
|
104
|
+
}, [selectedRepo, gitAvailable, loadHistory]);
|
|
104
105
|
|
|
105
106
|
const filteredCommits = commits.filter((commit) => {
|
|
106
107
|
const keyword = searchKeyword.trim().toLowerCase();
|
|
@@ -151,6 +152,17 @@ export const CommitHistory: React.FC = () => {
|
|
|
151
152
|
if (selectedRepo.status !== 'connected') {
|
|
152
153
|
return <Empty description={t('Repository not cloned yet')} />;
|
|
153
154
|
}
|
|
155
|
+
if (!gitAvailable) {
|
|
156
|
+
return (
|
|
157
|
+
<Empty
|
|
158
|
+
description={t(
|
|
159
|
+
gitRuntime?.clusterManager.status === 'running'
|
|
160
|
+
? 'Installing Git via Cluster Manager...'
|
|
161
|
+
: 'Git CLI is not installed on this node yet',
|
|
162
|
+
)}
|
|
163
|
+
/>
|
|
164
|
+
);
|
|
165
|
+
}
|
|
154
166
|
|
|
155
167
|
const currentBranch = branchSnapshot?.repositoryId === selectedRepo.id ? branchSnapshot : null;
|
|
156
168
|
|
|
@@ -1,3 +1,12 @@
|
|
|
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
|
+
|
|
1
10
|
import React, { useEffect, useState, useCallback, useMemo, useRef } from 'react';
|
|
2
11
|
import { Tree, Empty, Spin, Typography, Select, Space, Breadcrumb, Input, theme } from 'antd';
|
|
3
12
|
import {
|
|
@@ -78,24 +87,30 @@ export const FileExplorer: React.FC = () => {
|
|
|
78
87
|
const t = useT();
|
|
79
88
|
const { token } = useToken();
|
|
80
89
|
const api = useApp().apiClient;
|
|
81
|
-
const { selectedRepo, branches: branchList,
|
|
90
|
+
const { selectedRepo, branches: branchList, refreshBranches, gitRuntime, refreshRuntimeStatus } = useGitManager();
|
|
91
|
+
const selectedRepoId = selectedRepo?.id;
|
|
92
|
+
const selectedRepoStatus = selectedRepo?.status;
|
|
93
|
+
const gitAvailable = gitRuntime?.gitAvailable !== false;
|
|
82
94
|
const [treeData, setTreeData] = useState<TreeNode[]>([]);
|
|
83
95
|
const [loading, setLoading] = useState(false);
|
|
84
96
|
const [fileContent, setFileContent] = useState<string | null>(null);
|
|
85
97
|
const [selectedFile, setSelectedFile] = useState<string | null>(null);
|
|
86
98
|
const [selectedFolder, setSelectedFolder] = useState<string | null>(null);
|
|
87
99
|
const [currentRef, setCurrentRef] = useState('HEAD');
|
|
100
|
+
const currentRefRef = useRef(currentRef);
|
|
101
|
+
currentRefRef.current = currentRef;
|
|
88
102
|
const [searchText, setSearchText] = useState('');
|
|
89
103
|
const [debouncedSearch, setDebouncedSearch] = useState('');
|
|
90
104
|
const [contentLoading, setContentLoading] = useState(false);
|
|
91
105
|
|
|
92
106
|
const loadTree = useCallback(
|
|
93
|
-
async (treePath = '', ref
|
|
94
|
-
|
|
107
|
+
async (treePath = '', ref?: string) => {
|
|
108
|
+
const effectiveRef = ref ?? currentRefRef.current;
|
|
109
|
+
if (!selectedRepoId || !gitAvailable) return [];
|
|
95
110
|
try {
|
|
96
111
|
const { data } = await api.request({
|
|
97
112
|
url: 'gitManager:fileTree',
|
|
98
|
-
params: { repositoryId:
|
|
113
|
+
params: { repositoryId: selectedRepoId, ref: effectiveRef, treePath },
|
|
99
114
|
});
|
|
100
115
|
const responseData = data?.data || data || [];
|
|
101
116
|
const list = Array.isArray(responseData)
|
|
@@ -104,7 +119,7 @@ export const FileExplorer: React.FC = () => {
|
|
|
104
119
|
? responseData.data
|
|
105
120
|
: [];
|
|
106
121
|
|
|
107
|
-
return list.map((item:
|
|
122
|
+
return list.map((item: { path: string; name: string; type: string; size: number }) => ({
|
|
108
123
|
key: item.path,
|
|
109
124
|
title: (
|
|
110
125
|
<Text style={{ fontSize: 13 }}>
|
|
@@ -123,47 +138,65 @@ export const FileExplorer: React.FC = () => {
|
|
|
123
138
|
}));
|
|
124
139
|
} catch (error) {
|
|
125
140
|
console.warn('Failed to load file tree:', error);
|
|
141
|
+
refreshRuntimeStatus?.();
|
|
126
142
|
return [];
|
|
127
143
|
}
|
|
128
144
|
},
|
|
129
|
-
[api,
|
|
145
|
+
[api, selectedRepoId, gitAvailable, refreshRuntimeStatus],
|
|
130
146
|
);
|
|
131
147
|
|
|
132
|
-
const loadRoot = useCallback(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
148
|
+
const loadRoot = useCallback(
|
|
149
|
+
async (refToLoad: string) => {
|
|
150
|
+
setLoading(true);
|
|
151
|
+
try {
|
|
152
|
+
const nodes = await loadTree('', refToLoad);
|
|
153
|
+
setTreeData(nodes);
|
|
154
|
+
} finally {
|
|
155
|
+
setLoading(false);
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
[loadTree],
|
|
159
|
+
);
|
|
141
160
|
|
|
142
161
|
useEffect(() => {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
162
|
+
let cancelled = false;
|
|
163
|
+
setFileContent(null);
|
|
164
|
+
setSelectedFile(null);
|
|
165
|
+
setSelectedFolder(null);
|
|
166
|
+
setCurrentRef('HEAD');
|
|
167
|
+
|
|
168
|
+
if (!selectedRepoId || selectedRepoStatus !== 'connected' || !gitAvailable) {
|
|
149
169
|
setTreeData([]);
|
|
170
|
+
return () => {
|
|
171
|
+
cancelled = true;
|
|
172
|
+
};
|
|
150
173
|
}
|
|
151
|
-
}, [selectedRepo]);
|
|
152
174
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
175
|
+
const initializeRepositoryView = async () => {
|
|
176
|
+
setLoading(true);
|
|
177
|
+
try {
|
|
178
|
+
const resolvedBranch = await refreshBranches();
|
|
179
|
+
if (cancelled) return;
|
|
180
|
+
const nextRef = resolvedBranch || 'HEAD';
|
|
181
|
+
setCurrentRef(nextRef);
|
|
182
|
+
const nodes = await loadTree('', nextRef);
|
|
183
|
+
if (!cancelled) {
|
|
184
|
+
setTreeData(nodes);
|
|
185
|
+
}
|
|
186
|
+
} finally {
|
|
187
|
+
if (!cancelled) {
|
|
188
|
+
setLoading(false);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
};
|
|
159
192
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
}, [
|
|
193
|
+
initializeRepositoryView();
|
|
194
|
+
return () => {
|
|
195
|
+
cancelled = true;
|
|
196
|
+
};
|
|
197
|
+
}, [selectedRepoId, selectedRepoStatus, gitAvailable, refreshBranches, loadTree]);
|
|
165
198
|
|
|
166
|
-
const onLoadData = async (node:
|
|
199
|
+
const onLoadData = async (node: TreeNode) => {
|
|
167
200
|
if (node.children) return;
|
|
168
201
|
const children = await loadTree(node.filePath, currentRef);
|
|
169
202
|
setTreeData((prev) => updateTreeData(prev, node.key, children));
|
|
@@ -217,6 +250,18 @@ export const FileExplorer: React.FC = () => {
|
|
|
217
250
|
return <Empty description={t('Repository not cloned yet')} />;
|
|
218
251
|
}
|
|
219
252
|
|
|
253
|
+
if (!gitAvailable) {
|
|
254
|
+
return (
|
|
255
|
+
<Empty
|
|
256
|
+
description={t(
|
|
257
|
+
gitRuntime?.clusterManager.status === 'running'
|
|
258
|
+
? 'Installing Git via Cluster Manager...'
|
|
259
|
+
: 'Git CLI is not installed on this node yet',
|
|
260
|
+
)}
|
|
261
|
+
/>
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
|
|
220
265
|
const filteredTree = debouncedSearch ? filterTree(treeData, debouncedSearch.toLowerCase()) : treeData;
|
|
221
266
|
|
|
222
267
|
return (
|
|
@@ -243,6 +288,7 @@ export const FileExplorer: React.FC = () => {
|
|
|
243
288
|
setFileContent(null);
|
|
244
289
|
setSelectedFile(null);
|
|
245
290
|
setSelectedFolder(null);
|
|
291
|
+
loadRoot(val);
|
|
246
292
|
}}
|
|
247
293
|
options={branchList.map((b) => ({ label: b, value: b }))}
|
|
248
294
|
placeholder="Branch"
|
|
@@ -1,7 +1,15 @@
|
|
|
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, { useEffect, useId } from 'react';
|
|
2
11
|
import { Tabs, Select, Space, Typography, Tag, theme } from 'antd';
|
|
3
12
|
import {
|
|
4
|
-
BranchesOutlined,
|
|
5
13
|
FolderOutlined,
|
|
6
14
|
HistoryOutlined,
|
|
7
15
|
ToolOutlined,
|
|
@@ -19,6 +27,7 @@ import { GitOperations } from './GitOperations';
|
|
|
19
27
|
import { ReviewFlows } from './ReviewFlows';
|
|
20
28
|
import { ReviewHistory } from './ReviewHistory';
|
|
21
29
|
import { PollingStatus } from './PollingStatus';
|
|
30
|
+
import { GitRuntimeBanner } from './GitRuntimeBanner';
|
|
22
31
|
import { useT } from '../locale';
|
|
23
32
|
|
|
24
33
|
const { Text } = Typography;
|
|
@@ -27,14 +36,17 @@ const { useToken } = theme;
|
|
|
27
36
|
const GitManagerContent: React.FC = () => {
|
|
28
37
|
const t = useT();
|
|
29
38
|
const { token } = useToken();
|
|
39
|
+
const repoLabelId = useId();
|
|
40
|
+
const repoSelectId = useId();
|
|
30
41
|
const { repos, selectedRepo, setSelectedRepo, refreshRepos } = useGitManager();
|
|
31
42
|
|
|
32
43
|
useEffect(() => {
|
|
33
44
|
refreshRepos();
|
|
34
|
-
}, []);
|
|
45
|
+
}, [refreshRepos]);
|
|
35
46
|
|
|
36
47
|
return (
|
|
37
48
|
<div style={{ height: '100%' }}>
|
|
49
|
+
<GitRuntimeBanner />
|
|
38
50
|
{/* Repository selector bar */}
|
|
39
51
|
<div
|
|
40
52
|
style={{
|
|
@@ -46,9 +58,13 @@ const GitManagerContent: React.FC = () => {
|
|
|
46
58
|
borderBottom: `1px solid ${token.colorBorderSecondary}`,
|
|
47
59
|
}}
|
|
48
60
|
>
|
|
49
|
-
<DatabaseOutlined style={{ fontSize: 16 }} />
|
|
50
|
-
<
|
|
61
|
+
<DatabaseOutlined aria-hidden="true" style={{ fontSize: 16 }} />
|
|
62
|
+
<label id={repoLabelId} htmlFor={repoSelectId}>
|
|
63
|
+
<Text strong>{t('Repository')}:</Text>
|
|
64
|
+
</label>
|
|
51
65
|
<Select
|
|
66
|
+
id={repoSelectId}
|
|
67
|
+
aria-labelledby={repoLabelId}
|
|
52
68
|
style={{ minWidth: 250 }}
|
|
53
69
|
placeholder={t('Select a repository')}
|
|
54
70
|
value={selectedRepo?.id}
|
|
@@ -1,3 +1,12 @@
|
|
|
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
|
+
|
|
1
10
|
import React, { useState, useCallback, useEffect } from 'react';
|
|
2
11
|
import { Button, Space, Card, Typography, Tag, Empty, message, Spin, Descriptions, List, Badge, theme } from 'antd';
|
|
3
12
|
import {
|
|
@@ -31,13 +40,14 @@ export const GitOperations: React.FC = () => {
|
|
|
31
40
|
const t = useT();
|
|
32
41
|
const { token } = useToken();
|
|
33
42
|
const api = useApp().apiClient;
|
|
34
|
-
const { selectedRepo, refreshRepos } = useGitManager();
|
|
43
|
+
const { selectedRepo, refreshRepos, gitRuntime } = useGitManager();
|
|
44
|
+
const gitAvailable = gitRuntime?.gitAvailable !== false;
|
|
35
45
|
const [actionLoading, setActionLoading] = useState<string | null>(null);
|
|
36
46
|
const [statusData, setStatusData] = useState<any>(null);
|
|
37
47
|
const [lastResult, setLastResult] = useState<{ action: string; success: boolean; message: string } | null>(null);
|
|
38
48
|
|
|
39
49
|
const loadStatus = useCallback(async () => {
|
|
40
|
-
if (!selectedRepo || selectedRepo.status !== 'connected') {
|
|
50
|
+
if (!selectedRepo || selectedRepo.status !== 'connected' || !gitAvailable) {
|
|
41
51
|
setStatusData(null);
|
|
42
52
|
return;
|
|
43
53
|
}
|
|
@@ -56,7 +66,7 @@ export const GitOperations: React.FC = () => {
|
|
|
56
66
|
} finally {
|
|
57
67
|
setActionLoading(null);
|
|
58
68
|
}
|
|
59
|
-
}, [api, selectedRepo]);
|
|
69
|
+
}, [api, selectedRepo, gitAvailable]);
|
|
60
70
|
|
|
61
71
|
useEffect(() => {
|
|
62
72
|
loadStatus();
|
|
@@ -87,7 +97,7 @@ export const GitOperations: React.FC = () => {
|
|
|
87
97
|
setActionLoading(null);
|
|
88
98
|
}
|
|
89
99
|
},
|
|
90
|
-
[api, selectedRepo, refreshRepos, loadStatus],
|
|
100
|
+
[api, selectedRepo, refreshRepos, loadStatus, t],
|
|
91
101
|
);
|
|
92
102
|
|
|
93
103
|
if (!selectedRepo) {
|
|
@@ -96,6 +106,17 @@ export const GitOperations: React.FC = () => {
|
|
|
96
106
|
if (selectedRepo.status !== 'connected') {
|
|
97
107
|
return <Empty description={t('Repository not cloned yet')} />;
|
|
98
108
|
}
|
|
109
|
+
if (!gitAvailable) {
|
|
110
|
+
return (
|
|
111
|
+
<Empty
|
|
112
|
+
description={t(
|
|
113
|
+
gitRuntime?.clusterManager.status === 'running'
|
|
114
|
+
? 'Installing Git via Cluster Manager...'
|
|
115
|
+
: 'Git CLI is not installed on this node yet',
|
|
116
|
+
)}
|
|
117
|
+
/>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
99
120
|
|
|
100
121
|
const allChangedFiles = statusData
|
|
101
122
|
? [
|