plugin-git-manager 1.3.2 → 1.4.0
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/LICENSE +201 -0
- package/dist/client/{156.c27c2392746e7866.js → 156.8e36af3e2cee173e.js} +1 -1
- package/dist/client/{317.17ed0018e3e7db00.js → 317.2d0d33871e24ee24.js} +1 -1
- package/dist/client/{434.b2eeaaef33aae6e0.js → 434.2401f7257495b66e.js} +1 -1
- package/dist/client/{453.d49fac0e20ea08d9.js → 453.58657b9ba0904477.js} +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client-v2/{434.19c7579c06b9077c.js → 434.32b0a07b821b9329.js} +1 -1
- package/dist/client-v2/{453.84c4387ba605dc27.js → 453.f9a0ec6d8e1bd1cc.js} +1 -1
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +10 -9
- package/dist/locale/en-US.json +27 -1
- package/dist/locale/vi-VN.json +27 -1
- package/dist/locale/zh-CN.json +30 -1
- package/dist/node_modules/simple-git/package.json +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/actions/chat-context.js +282 -0
- package/dist/server/actions/git-actions.js +99 -4
- package/dist/server/actions/gitlab-api.js +86 -7
- package/dist/server/chat-context-admission.js +187 -0
- package/dist/server/plugin.js +8 -0
- package/dist/server/request-method-policy.js +2 -0
- package/dist/server/services/review-source.js +7 -4
- package/package.json +2 -2
- package/src/client/__tests__/CommitHistory.test.tsx +1 -8
- package/src/client/__tests__/GitContextPicker.test.tsx +120 -0
- package/src/client/__tests__/ReviewHistory.test.tsx +1 -8
- package/src/client/__tests__/RunReviewButton.test.tsx +1 -8
- package/src/client/__tests__/ai-context.test.tsx +119 -0
- package/src/client/__tests__/workflowRoutes.test.ts +3 -10
- package/src/client/ai-context.tsx +3 -113
- package/src/client/components/CommitHistory.tsx +1 -8
- package/src/client/components/ReviewFlows.tsx +1 -8
- package/src/client/components/ReviewHistory.tsx +1 -8
- package/src/client/components/RunReviewButton.tsx +1 -8
- package/src/client/context/GitManagerContext.tsx +18 -2
- package/src/client/index.tsx +4 -13
- package/src/client/workflowRoutes.ts +3 -18
- package/src/client-v2/ai-context.tsx +135 -72
- package/src/client-v2/components/GitContextPicker.tsx +418 -0
- package/src/client-v2/git-context-api.ts +59 -0
- package/src/client-v2/plugin.tsx +2 -4
- package/src/locale/en-US.json +27 -1
- package/src/locale/vi-VN.json +27 -1
- package/src/locale/zh-CN.json +30 -1
- package/src/server/__tests__/chat-context-admission.test.ts +276 -0
- package/src/server/__tests__/chat-context-options.test.ts +144 -0
- package/src/server/__tests__/git-chat-context.test.ts +138 -0
- package/src/server/__tests__/git-security.test.ts +53 -8
- package/src/server/__tests__/poller-lifecycle.test.ts +1 -8
- package/src/server/__tests__/repository-access.test.ts +1 -8
- package/src/server/__tests__/review-service.integration.test.ts +1 -8
- package/src/server/__tests__/review.test.ts +1 -8
- package/src/server/__tests__/smoke.test.ts +201 -8
- package/src/server/actions/chat-context.ts +302 -0
- package/src/server/actions/git-actions.ts +120 -14
- package/src/server/actions/gitlab-api.ts +98 -12
- package/src/server/actions/poller.ts +1 -8
- package/src/server/actions/review-cutover.ts +1 -8
- package/src/server/actions/review.ts +1 -8
- package/src/server/actions/role-permissions.ts +1 -8
- package/src/server/ai-tools.ts +1 -8
- package/src/server/chat-context-admission.ts +182 -0
- package/src/server/collections/gitCodeReviews.ts +1 -8
- package/src/server/collections/gitReviewCutover.ts +1 -8
- package/src/server/collections/gitReviewFlows.ts +1 -8
- package/src/server/collections/gitReviewInbox.ts +1 -8
- package/src/server/collections/gitReviewProjects.ts +1 -8
- package/src/server/collections/gitReviewRequests.ts +1 -8
- package/src/server/index.ts +1 -8
- package/src/server/plugin.ts +12 -8
- package/src/server/poller.ts +1 -8
- package/src/server/repository-access.ts +1 -8
- package/src/server/request-method-policy.ts +3 -8
- package/src/server/review-control-access.ts +1 -8
- package/src/server/services/__tests__/registry-content-service.test.ts +1 -8
- package/src/server/services/__tests__/review-source.test.ts +33 -8
- package/src/server/services/legacy-post-service.ts +1 -8
- package/src/server/services/registry-content-service.ts +1 -8
- package/src/server/services/review-service.ts +1 -8
- package/src/server/services/review-source.ts +8 -12
- package/src/server/utils/get-repo-account.ts +1 -8
- package/src/server/utils/url-security.ts +1 -8
|
@@ -0,0 +1,120 @@
|
|
|
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 type { GitContextApp } from '../../client-v2/git-context-api';
|
|
6
|
+
import { GitContextPicker } from '../../client-v2/components/GitContextPicker';
|
|
7
|
+
import { setCurrentGitRepository } from '../../client-v2/git-context-api';
|
|
8
|
+
|
|
9
|
+
const mocks = vi.hoisted(() => ({ t: (key: string) => key }));
|
|
10
|
+
|
|
11
|
+
vi.mock('react-i18next', () => ({
|
|
12
|
+
useTranslation: () => ({ t: mocks.t }),
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
const actionResponse = (data: unknown, extra: Record<string, unknown> = {}) => ({
|
|
16
|
+
data: { data: { success: true, data, ...extra } },
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe('GitContextPicker', () => {
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
cleanup();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('preselects an authorized repository and rechecks a selected commit before attaching only its uid and title', async () => {
|
|
25
|
+
const commitHash = 'a'.repeat(40);
|
|
26
|
+
const repository = { id: 7, name: 'backend', defaultBranch: 'main', status: 'connected' };
|
|
27
|
+
const request = vi.fn(async ({ url, params }: { url: string; params?: Record<string, unknown> }) => {
|
|
28
|
+
if (url === 'gitManager:chatContextOptions') {
|
|
29
|
+
return actionResponse({ items: [repository], hasMore: false });
|
|
30
|
+
}
|
|
31
|
+
if (url === 'gitManager:branches') {
|
|
32
|
+
return actionResponse({ all: ['main', 'release'], current: 'release', detached: false });
|
|
33
|
+
}
|
|
34
|
+
if (url === 'gitManager:log') {
|
|
35
|
+
return actionResponse({
|
|
36
|
+
all: [{ hash: commitHash, subject: 'Fix access checks', author_name: 'Maya', date: '2026-10-20T10:00:00Z' }],
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
if (url === 'gitManager:chatContextContent') {
|
|
40
|
+
return actionResponse({ type: 'git-commit', repositoryId: 7, commitSha: commitHash, diff: '+secure' });
|
|
41
|
+
}
|
|
42
|
+
throw new Error(`Unexpected API request ${url} ${JSON.stringify(params)}`);
|
|
43
|
+
});
|
|
44
|
+
const app = { apiClient: { request }, eventBus: new EventTarget() } as GitContextApp;
|
|
45
|
+
const onAdd = vi.fn();
|
|
46
|
+
const onClose = vi.fn();
|
|
47
|
+
setCurrentGitRepository(app, repository.id);
|
|
48
|
+
|
|
49
|
+
render(<GitContextPicker app={app} kind="commit" onAdd={onAdd} onClose={onClose} />);
|
|
50
|
+
|
|
51
|
+
await waitFor(() =>
|
|
52
|
+
expect(request).toHaveBeenCalledWith(
|
|
53
|
+
expect.objectContaining({
|
|
54
|
+
url: 'gitManager:chatContextOptions',
|
|
55
|
+
params: { kind: 'commit', repositoryId: 7, page: 1, pageSize: 1 },
|
|
56
|
+
}),
|
|
57
|
+
),
|
|
58
|
+
);
|
|
59
|
+
await waitFor(() =>
|
|
60
|
+
expect(request).toHaveBeenCalledWith(
|
|
61
|
+
expect.objectContaining({
|
|
62
|
+
url: 'gitManager:log',
|
|
63
|
+
params: { repositoryId: 7, branch: 'release', skip: 0, maxCount: 30 },
|
|
64
|
+
}),
|
|
65
|
+
),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
fireEvent.mouseDown(await screen.findByRole('combobox', { name: 'Commit' }));
|
|
69
|
+
fireEvent.click(await screen.findByText(/aaaaaaa · Fix access checks · Maya/));
|
|
70
|
+
fireEvent.click(screen.getByRole('button', { name: 'Attach to chat' }));
|
|
71
|
+
|
|
72
|
+
await waitFor(() =>
|
|
73
|
+
expect(onAdd).toHaveBeenCalledWith({
|
|
74
|
+
uid: `7:${commitHash}`,
|
|
75
|
+
title: 'backend · aaaaaaa · Fix access checks',
|
|
76
|
+
}),
|
|
77
|
+
);
|
|
78
|
+
expect(request).toHaveBeenCalledWith(
|
|
79
|
+
expect.objectContaining({
|
|
80
|
+
url: 'gitManager:chatContextContent',
|
|
81
|
+
params: { kind: 'commit', repositoryId: '7', commitHash },
|
|
82
|
+
}),
|
|
83
|
+
);
|
|
84
|
+
const contentRequestIndex = request.mock.calls.findIndex(
|
|
85
|
+
([config]) => config.url === 'gitManager:chatContextContent',
|
|
86
|
+
);
|
|
87
|
+
expect(request.mock.invocationCallOrder[contentRequestIndex]).toBeLessThan(onAdd.mock.invocationCallOrder[0]);
|
|
88
|
+
expect(onClose).toHaveBeenCalledTimes(1);
|
|
89
|
+
expect(JSON.stringify(onAdd.mock.calls[0][0])).not.toContain('diff');
|
|
90
|
+
setCurrentGitRepository(app);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('keeps an empty GitHub merged page loadable when the server reports a next page', async () => {
|
|
94
|
+
const repository = { id: 9, name: 'frontend', defaultBranch: 'main', status: 'connected' };
|
|
95
|
+
const request = vi.fn(async ({ url }: { url: string }) => {
|
|
96
|
+
if (url === 'gitManager:chatContextOptions') return actionResponse({ items: [repository], hasMore: false });
|
|
97
|
+
if (url === 'gitManager:mergeRequests') {
|
|
98
|
+
return actionResponse([], { pagination: { totalPages: null, hasMore: true } });
|
|
99
|
+
}
|
|
100
|
+
throw new Error(`Unexpected API request ${url}`);
|
|
101
|
+
});
|
|
102
|
+
const app = { apiClient: { request }, eventBus: new EventTarget() } as GitContextApp;
|
|
103
|
+
setCurrentGitRepository(app, repository.id);
|
|
104
|
+
|
|
105
|
+
render(<GitContextPicker app={app} kind="merge-request" onAdd={vi.fn()} onClose={vi.fn()} />);
|
|
106
|
+
|
|
107
|
+
const loadMore = await screen.findByRole('button', { name: 'Load more results' });
|
|
108
|
+
fireEvent.click(loadMore);
|
|
109
|
+
|
|
110
|
+
await waitFor(() => {
|
|
111
|
+
expect(request).toHaveBeenCalledWith(
|
|
112
|
+
expect.objectContaining({
|
|
113
|
+
url: 'gitManager:mergeRequests',
|
|
114
|
+
params: { repositoryId: 9, state: 'opened', page: 2, perPage: 30 },
|
|
115
|
+
}),
|
|
116
|
+
);
|
|
117
|
+
});
|
|
118
|
+
setCurrentGitRepository(app);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import React from 'react';
|
|
11
4
|
import { cleanup, configure, fireEvent, render, screen, waitFor, within } from '@testing-library/react';
|
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import React from 'react';
|
|
11
4
|
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
|
|
3
|
+
import { Registry } from '@nocobase/utils/client';
|
|
4
|
+
import { waitFor } from '@testing-library/react';
|
|
5
|
+
import type { AIManager } from '@nocobase/plugin-ai/client-v2';
|
|
6
|
+
import { actionData, fetchGitContext, type GitContextApp } from '../../client-v2/git-context-api';
|
|
7
|
+
import { registerGitWorkContexts } from '../../client-v2/ai-context';
|
|
8
|
+
|
|
9
|
+
type WorkContextRecord = {
|
|
10
|
+
name?: string;
|
|
11
|
+
menu?: { onClick?: unknown };
|
|
12
|
+
getContent?: (app: unknown, item: { uid: string }) => Promise<unknown>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
function createManager() {
|
|
16
|
+
const manager = {
|
|
17
|
+
workContext: new Registry<WorkContextRecord>(),
|
|
18
|
+
getWorkContext(name: string) {
|
|
19
|
+
return this.workContext.get(name);
|
|
20
|
+
},
|
|
21
|
+
registerWorkContext(name: string, options: WorkContextRecord) {
|
|
22
|
+
this.workContext.register(name, { ...options, name });
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
return manager as unknown as AIManager & { workContext: Registry<WorkContextRecord> };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function actionResponse(data: unknown) {
|
|
29
|
+
return { data: { data: { success: true, data } } };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe('Git chat work contexts', () => {
|
|
33
|
+
it('keeps menus hidden until capabilities load and updates them after authentication and role changes', async () => {
|
|
34
|
+
const eventBus = new EventTarget();
|
|
35
|
+
const responseHandlers: Array<(response: { config?: { url?: string } }) => unknown> = [];
|
|
36
|
+
const pendingRequest = vi.fn();
|
|
37
|
+
const app = {
|
|
38
|
+
eventBus,
|
|
39
|
+
apiClient: {
|
|
40
|
+
auth: { token: 'test-token' },
|
|
41
|
+
axios: {
|
|
42
|
+
interceptors: {
|
|
43
|
+
response: {
|
|
44
|
+
use: (handler: (response: { config?: { url?: string } }) => unknown) => {
|
|
45
|
+
responseHandlers.push(handler);
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
request: pendingRequest,
|
|
51
|
+
},
|
|
52
|
+
} as unknown as GitContextApp;
|
|
53
|
+
const manager = createManager();
|
|
54
|
+
let resolveInitial: ((value: unknown) => void) | undefined;
|
|
55
|
+
pendingRequest.mockImplementationOnce(
|
|
56
|
+
() =>
|
|
57
|
+
new Promise((resolve) => {
|
|
58
|
+
resolveInitial = resolve;
|
|
59
|
+
}),
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const registration = registerGitWorkContexts(app, manager);
|
|
63
|
+
expect([...manager.workContext.getValues()].every((context) => !context.menu)).toBe(true);
|
|
64
|
+
expect(registerGitWorkContexts(app, manager)).toBe(registration);
|
|
65
|
+
expect(pendingRequest).toHaveBeenCalledWith({
|
|
66
|
+
url: 'gitManager:chatContextOptions',
|
|
67
|
+
skipNotify: true,
|
|
68
|
+
timeout: 5000,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
resolveInitial?.(actionResponse({ capabilities: { repository: true, 'merge-request': false, commit: false } }));
|
|
72
|
+
await registration;
|
|
73
|
+
expect(manager.workContext.get('git-repository')?.menu).toBeDefined();
|
|
74
|
+
expect(manager.workContext.get('git-merge-request')?.menu).toBeUndefined();
|
|
75
|
+
expect(manager.workContext.get('git-commit')?.menu).toBeUndefined();
|
|
76
|
+
|
|
77
|
+
pendingRequest.mockResolvedValueOnce(
|
|
78
|
+
actionResponse({ capabilities: { repository: false, 'merge-request': false, commit: true } }),
|
|
79
|
+
);
|
|
80
|
+
const roleCheck = responseHandlers[0]({ config: { url: '/api/roles:check' } });
|
|
81
|
+
expect(roleCheck).toEqual({ config: { url: '/api/roles:check' } });
|
|
82
|
+
await waitFor(() => {
|
|
83
|
+
expect(manager.workContext.get('git-repository')?.menu).toBeUndefined();
|
|
84
|
+
expect(manager.workContext.get('git-commit')?.menu).toBeDefined();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
if (!app.apiClient.auth) throw new Error('Expected the authenticated API client');
|
|
88
|
+
app.apiClient.auth.token = null;
|
|
89
|
+
eventBus.dispatchEvent(new Event('auth:tokenChanged'));
|
|
90
|
+
expect(manager.workContext.get('git-commit')?.menu).toBeUndefined();
|
|
91
|
+
expect(pendingRequest).toHaveBeenCalledTimes(2);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('unwraps an action response and refetches attached context by its stable uid', async () => {
|
|
95
|
+
const contextData = { type: 'git-commit', repositoryId: 7, commitSha: 'a'.repeat(40), diff: '+value' };
|
|
96
|
+
const request = vi
|
|
97
|
+
.fn()
|
|
98
|
+
.mockResolvedValueOnce(
|
|
99
|
+
actionResponse({ capabilities: { repository: false, 'merge-request': false, commit: true } }),
|
|
100
|
+
)
|
|
101
|
+
.mockResolvedValue(actionResponse(contextData));
|
|
102
|
+
const app = { apiClient: { request }, eventBus: new EventTarget() } as GitContextApp;
|
|
103
|
+
const manager = createManager();
|
|
104
|
+
await registerGitWorkContexts(app, manager);
|
|
105
|
+
|
|
106
|
+
expect(actionData(actionResponse(contextData))).toEqual(contextData);
|
|
107
|
+
const reader = manager.workContext.get('git-commit')?.getContent;
|
|
108
|
+
await expect(
|
|
109
|
+
reader?.(app, { uid: `7:${'a'.repeat(40)}`, content: { type: 'git-commit', diff: 'stale content' } }),
|
|
110
|
+
).resolves.toEqual(contextData);
|
|
111
|
+
await expect(fetchGitContext(app, 'commit', `7:${'a'.repeat(40)}`)).resolves.toEqual(contextData);
|
|
112
|
+
expect(request).toHaveBeenCalledWith({
|
|
113
|
+
url: 'gitManager:chatContextContent',
|
|
114
|
+
params: { kind: 'commit', repositoryId: '7', commitHash: 'a'.repeat(40) },
|
|
115
|
+
skipNotify: true,
|
|
116
|
+
});
|
|
117
|
+
expect(request).toHaveBeenCalledTimes(3);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import { reviewApprovalHref, workflowHref } from '../workflowRoutes';
|
|
11
4
|
|
|
@@ -40,7 +33,7 @@ describe('Git review workflow route resolution', () => {
|
|
|
40
33
|
else routeWindow.__nocobase_modern_client_prefix__ = originalModernPrefix;
|
|
41
34
|
});
|
|
42
35
|
|
|
43
|
-
it('keeps workflow links in the legacy shell
|
|
36
|
+
it('keeps workflow and approval task links in the legacy shell without forcing a modern prefix', () => {
|
|
44
37
|
routeWindow.__nocobase_modern_client_prefix__ = 'v3-custom';
|
|
45
38
|
routeWindow.__nocobase_public_path__ = '/tenant/app/v3-custom/';
|
|
46
39
|
window.history.replaceState({}, '', '/tenant/app/admin/settings/workflow');
|
|
@@ -48,7 +41,7 @@ describe('Git review workflow route resolution', () => {
|
|
|
48
41
|
|
|
49
42
|
expect(workflowHref(app, 'workflow', 'flow/42')).toBe('/tenant/app/admin/settings/workflow/workflows/flow%2F42');
|
|
50
43
|
expect(workflowHref(app, 'execution', 73)).toBe('/tenant/app/admin/settings/workflow/executions/73');
|
|
51
|
-
expect(reviewApprovalHref(app)).toBe('/tenant/app/
|
|
44
|
+
expect(reviewApprovalHref(app)).toBe('/tenant/app/admin/workflow/tasks/git-review-approval/pending');
|
|
52
45
|
});
|
|
53
46
|
|
|
54
47
|
it('uses the effective modern basename and custom modern prefix for v2 workflow links', () => {
|
|
@@ -1,114 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { Space } from 'antd';
|
|
3
|
-
import { BranchesOutlined, MergeOutlined, NodeIndexOutlined } from '@ant-design/icons';
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
* regardless of whether plugin-ai is installed at compile time. The plugin
|
|
8
|
-
* checks `app.aiManager` at runtime before registering.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
export const GitRepositoryWorkContext: any = {
|
|
12
|
-
name: 'git-repository',
|
|
13
|
-
menu: {
|
|
14
|
-
icon: <BranchesOutlined />,
|
|
15
|
-
Component: () => <span>Git Repository</span>,
|
|
16
|
-
},
|
|
17
|
-
tag: {
|
|
18
|
-
Component: ({ item }: any) => (
|
|
19
|
-
<Space size={4}>
|
|
20
|
-
<BranchesOutlined />
|
|
21
|
-
<span>{item?.title || `Repo #${item?.uid}`}</span>
|
|
22
|
-
</Space>
|
|
23
|
-
),
|
|
24
|
-
},
|
|
25
|
-
getContent: async (app: any, { uid }: any) => {
|
|
26
|
-
const response = await app.apiClient.request({
|
|
27
|
-
url: 'gitRepositories:get',
|
|
28
|
-
params: { filterByTk: uid },
|
|
29
|
-
});
|
|
30
|
-
const repo = response?.data?.data;
|
|
31
|
-
if (!repo) return null;
|
|
32
|
-
return {
|
|
33
|
-
type: 'git-repository',
|
|
34
|
-
repositoryId: repo.id,
|
|
35
|
-
name: repo.name,
|
|
36
|
-
repoUrl: repo.repoUrl,
|
|
37
|
-
defaultBranch: repo.defaultBranch,
|
|
38
|
-
status: repo.status,
|
|
39
|
-
};
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export const GitMergeRequestWorkContext: any = {
|
|
44
|
-
name: 'git-merge-request',
|
|
45
|
-
menu: {
|
|
46
|
-
icon: <MergeOutlined />,
|
|
47
|
-
Component: () => <span>Git Merge Request</span>,
|
|
48
|
-
},
|
|
49
|
-
tag: {
|
|
50
|
-
Component: ({ item }: any) => (
|
|
51
|
-
<Space size={4}>
|
|
52
|
-
<MergeOutlined />
|
|
53
|
-
<span>{item?.title || `MR ${item?.uid}`}</span>
|
|
54
|
-
</Space>
|
|
55
|
-
),
|
|
56
|
-
},
|
|
57
|
-
getContent: async (app: any, { uid }: any) => {
|
|
58
|
-
// uid format: "<repositoryId>:<mrIid>"
|
|
59
|
-
const [repoIdStr, mrIidStr] = String(uid || '').split(':');
|
|
60
|
-
const repositoryId = Number(repoIdStr);
|
|
61
|
-
const mrIid = Number(mrIidStr);
|
|
62
|
-
if (!repositoryId || !mrIid) return null;
|
|
63
|
-
const response = await app.apiClient.request({
|
|
64
|
-
url: 'gitManager:mergeRequestDetail',
|
|
65
|
-
params: { repositoryId, mrIid },
|
|
66
|
-
});
|
|
67
|
-
const data = response?.data?.data;
|
|
68
|
-
return {
|
|
69
|
-
type: 'git-merge-request',
|
|
70
|
-
repositoryId,
|
|
71
|
-
mrIid,
|
|
72
|
-
title: data?.title,
|
|
73
|
-
sourceBranch: data?.sourceBranch,
|
|
74
|
-
targetBranch: data?.targetBranch,
|
|
75
|
-
author: data?.author,
|
|
76
|
-
changes: data?.changes,
|
|
77
|
-
description: data?.description,
|
|
78
|
-
webUrl: data?.webUrl,
|
|
79
|
-
};
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
export const GitCommitWorkContext: any = {
|
|
84
|
-
name: 'git-commit',
|
|
85
|
-
menu: {
|
|
86
|
-
icon: <NodeIndexOutlined />,
|
|
87
|
-
Component: () => <span>Git Commit</span>,
|
|
88
|
-
},
|
|
89
|
-
tag: {
|
|
90
|
-
Component: ({ item }: any) => (
|
|
91
|
-
<Space size={4}>
|
|
92
|
-
<NodeIndexOutlined />
|
|
93
|
-
<span>{item?.title || `Commit ${item?.uid}`}</span>
|
|
94
|
-
</Space>
|
|
95
|
-
),
|
|
96
|
-
},
|
|
97
|
-
getContent: async (app: any, { uid }: any) => {
|
|
98
|
-
// uid format: "<repositoryId>:<commitSha>"
|
|
99
|
-
const [repoIdStr, commitSha] = String(uid || '').split(':');
|
|
100
|
-
const repositoryId = Number(repoIdStr);
|
|
101
|
-
if (!repositoryId || !commitSha) return null;
|
|
102
|
-
const response = await app.apiClient.request({
|
|
103
|
-
url: 'gitManager:commitDetail',
|
|
104
|
-
params: { repositoryId, commitHash: commitSha },
|
|
105
|
-
});
|
|
106
|
-
const data = response?.data?.data;
|
|
107
|
-
return {
|
|
108
|
-
type: 'git-commit',
|
|
109
|
-
repositoryId,
|
|
110
|
-
commitSha,
|
|
111
|
-
...data,
|
|
112
|
-
};
|
|
113
|
-
},
|
|
114
|
-
};
|
|
3
|
+
// The legacy client can use the v2 AI chat and its work-context contract.
|
|
4
|
+
export * from '../client-v2/ai-context';
|
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import React, { useEffect, useState, useCallback, memo } from 'react';
|
|
11
4
|
import { Table, Empty, Spin, Typography, Tag, Drawer, List, Button, Space, Select, Input, theme } from 'antd';
|
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import React, { useCallback, useEffect, useState } from 'react';
|
|
11
4
|
import {
|
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
11
4
|
import {
|
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import React, { useCallback, useEffect, useState } from 'react';
|
|
11
4
|
import { Button, Dropdown, Modal, Form, Select, Input, message, Space, Tooltip, Tag, Alert } from 'antd';
|
|
@@ -1,5 +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, { createContext, useContext, useState, useCallback, useRef, useEffect } from 'react';
|
|
2
11
|
import { useApp } from '@nocobase/client-v2';
|
|
12
|
+
import { setCurrentGitRepository } from '../../client-v2/git-context-api';
|
|
3
13
|
|
|
4
14
|
interface Repository {
|
|
5
15
|
id: number;
|
|
@@ -34,7 +44,8 @@ export function useGitManager() {
|
|
|
34
44
|
}
|
|
35
45
|
|
|
36
46
|
export const GitManagerProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
|
37
|
-
const
|
|
47
|
+
const app = useApp();
|
|
48
|
+
const api = app.apiClient;
|
|
38
49
|
const [repos, setRepos] = useState<Repository[]>([]);
|
|
39
50
|
const [selectedRepo, setSelectedRepo] = useState<Repository | null>(null);
|
|
40
51
|
const [loading, setLoading] = useState(false);
|
|
@@ -43,6 +54,11 @@ export const GitManagerProvider: React.FC<{ children: React.ReactNode }> = ({ ch
|
|
|
43
54
|
const selectedRepoRef = useRef(selectedRepo);
|
|
44
55
|
selectedRepoRef.current = selectedRepo;
|
|
45
56
|
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
setCurrentGitRepository(app, selectedRepo?.id);
|
|
59
|
+
return () => setCurrentGitRepository(app);
|
|
60
|
+
}, [app, selectedRepo?.id]);
|
|
61
|
+
|
|
46
62
|
const refreshBranches = useCallback(async () => {
|
|
47
63
|
const repo = selectedRepoRef.current;
|
|
48
64
|
if (!repo || repo.status !== 'connected') {
|
package/src/client/index.tsx
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import { Plugin } from '@nocobase/client';
|
|
11
4
|
import type PluginAIClientV2 from '@nocobase/plugin-ai/client-v2';
|
|
12
5
|
import React from 'react';
|
|
13
|
-
import {
|
|
6
|
+
import { registerGitWorkContexts } from './ai-context';
|
|
14
7
|
|
|
15
8
|
const GitManagerSettings = React.lazy(() =>
|
|
16
9
|
import('./components/GitManagerSettings').then((m) => ({ default: m.GitManagerSettings })),
|
|
@@ -77,10 +70,8 @@ export class PluginGitManagerClient extends Plugin {
|
|
|
77
70
|
});
|
|
78
71
|
|
|
79
72
|
const aiManager = this.app.pm.get<PluginAIClientV2>('ai')?.aiManager;
|
|
80
|
-
if (aiManager
|
|
81
|
-
|
|
82
|
-
aiManager.registerWorkContext('git-merge-request', GitMergeRequestWorkContext);
|
|
83
|
-
aiManager.registerWorkContext('git-commit', GitCommitWorkContext);
|
|
73
|
+
if (aiManager) {
|
|
74
|
+
await registerGitWorkContexts(this.app, aiManager);
|
|
84
75
|
}
|
|
85
76
|
|
|
86
77
|
const aclPlugin = this.app.pm.get<PluginACLClient>('acl');
|
|
@@ -1,18 +1,6 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
|
-
import {
|
|
11
|
-
getModernClientPrefix,
|
|
12
|
-
getRouteRuntimeVersion,
|
|
13
|
-
getV2EffectiveBasePath,
|
|
14
|
-
stripModernClientPrefix,
|
|
15
|
-
} from '@nocobase/client-v2';
|
|
3
|
+
import { getRouteRuntimeVersion, getV2EffectiveBasePath, stripModernClientPrefix } from '@nocobase/client-v2';
|
|
16
4
|
|
|
17
5
|
type App = Parameters<typeof getV2EffectiveBasePath>[0];
|
|
18
6
|
|
|
@@ -34,9 +22,6 @@ export function workflowHref(app: App, type: 'workflow' | 'execution', id: strin
|
|
|
34
22
|
}
|
|
35
23
|
|
|
36
24
|
export function reviewApprovalHref(app: App) {
|
|
37
|
-
const base =
|
|
38
|
-
getRouteRuntimeVersion() === 'modern'
|
|
39
|
-
? getV2EffectiveBasePath(app)
|
|
40
|
-
: join(legacyBase(app), getModernClientPrefix());
|
|
25
|
+
const base = getRouteRuntimeVersion() === 'modern' ? getV2EffectiveBasePath(app) : legacyBase(app);
|
|
41
26
|
return join(base, '/admin/workflow/tasks/git-review-approval/pending');
|
|
42
27
|
}
|