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
package/src/server/ai-tools.ts
CHANGED
|
@@ -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 { z } from 'zod';
|
|
11
4
|
import type { Application } from '@nocobase/server';
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
|
|
3
|
+
import type { Context } from '@nocobase/actions';
|
|
4
|
+
import { loadChatContext } from './actions/chat-context';
|
|
5
|
+
|
|
6
|
+
type GitContextType = 'git-repository' | 'git-merge-request' | 'git-commit';
|
|
7
|
+
type GitContextItem = { type: GitContextType; uid: string; title?: string };
|
|
8
|
+
type WorkContextHandler = {
|
|
9
|
+
registerStrategy: (
|
|
10
|
+
type: string,
|
|
11
|
+
strategy: { resolve: (ctx: Context, item: GitContextItem) => Promise<string> },
|
|
12
|
+
) => void;
|
|
13
|
+
};
|
|
14
|
+
type AIPlugin = {
|
|
15
|
+
workContextHandler?: WorkContextHandler;
|
|
16
|
+
aiConversationsManager?: {
|
|
17
|
+
getConversation: (options: { sessionId: string; userId: number | string }) => Promise<unknown>;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
type App = { pm: { get: (name: string) => unknown } };
|
|
21
|
+
|
|
22
|
+
const TYPES: GitContextType[] = ['git-repository', 'git-merge-request', 'git-commit'];
|
|
23
|
+
const registered = new WeakMap<WorkContextHandler, Set<GitContextType>>();
|
|
24
|
+
const admitted = new WeakMap<object, Map<string, Record<string, unknown>>>();
|
|
25
|
+
|
|
26
|
+
function gitContext(value: unknown): GitContextItem | null {
|
|
27
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
|
|
28
|
+
const item = value as Record<string, unknown>;
|
|
29
|
+
if (typeof item.type !== 'string' || !TYPES.includes(item.type as GitContextType)) return null;
|
|
30
|
+
return {
|
|
31
|
+
type: item.type as GitContextType,
|
|
32
|
+
uid: typeof item.uid === 'string' ? item.uid : '',
|
|
33
|
+
...(typeof item.title === 'string' ? { title: item.title } : {}),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function contextParams(ctx: Context, item: GitContextItem): Record<string, unknown> {
|
|
38
|
+
const kind = item.type.slice(4);
|
|
39
|
+
if (!item.uid || !item.uid.trim()) return ctx.throw(400, 'Invalid Git context');
|
|
40
|
+
if (kind === 'repository') return { kind, repositoryId: item.uid };
|
|
41
|
+
const separator = item.uid.indexOf(':');
|
|
42
|
+
if (separator <= 0 || separator === item.uid.length - 1) return ctx.throw(400, 'Invalid Git context');
|
|
43
|
+
const repositoryId = item.uid.slice(0, separator);
|
|
44
|
+
const target = item.uid.slice(separator + 1);
|
|
45
|
+
return kind === 'merge-request' ? { kind, repositoryId, mrIid: target } : { kind, repositoryId, commitHash: target };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function contextKey(item: GitContextItem): string {
|
|
49
|
+
return JSON.stringify([item.type, item.uid]);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function resolvedItem(item: GitContextItem, content: Record<string, unknown>) {
|
|
53
|
+
const name = typeof content.repositoryName === 'string' ? content.repositoryName : String(content.repositoryId || '');
|
|
54
|
+
let title: string;
|
|
55
|
+
if (item.type === 'git-repository') {
|
|
56
|
+
title = typeof content.name === 'string' ? content.name : String(content.repositoryId || '');
|
|
57
|
+
} else if (item.type === 'git-merge-request') {
|
|
58
|
+
title = [name, `!${content.mrIid}`, content.title].filter(Boolean).join(' · ');
|
|
59
|
+
} else {
|
|
60
|
+
title = [name, String(content.commitSha || '').slice(0, 7), content.subject].filter(Boolean).join(' · ');
|
|
61
|
+
}
|
|
62
|
+
return { type: item.type, uid: item.uid, title, content };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function aiPluginFor(app: App): AIPlugin | undefined {
|
|
66
|
+
try {
|
|
67
|
+
return (app.pm.get('ai') || app.pm.get('@nocobase/plugin-ai')) as AIPlugin | undefined;
|
|
68
|
+
} catch {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function registerGitChatContextStrategies(app: App): boolean {
|
|
74
|
+
const handler = aiPluginFor(app)?.workContextHandler;
|
|
75
|
+
if (!handler || typeof handler.registerStrategy !== 'function') return false;
|
|
76
|
+
const names = registered.get(handler) || new Set<GitContextType>();
|
|
77
|
+
registered.set(handler, names);
|
|
78
|
+
for (const type of TYPES) {
|
|
79
|
+
if (names.has(type)) continue;
|
|
80
|
+
handler.registerStrategy(type, {
|
|
81
|
+
resolve: async (ctx, source) => {
|
|
82
|
+
const item = gitContext(source);
|
|
83
|
+
if (!item) return '';
|
|
84
|
+
try {
|
|
85
|
+
const content =
|
|
86
|
+
admitted.get(ctx)?.get(contextKey(item)) || (await loadChatContext(ctx, contextParams(ctx, item)));
|
|
87
|
+
return JSON.stringify(resolvedItem(item, content));
|
|
88
|
+
} catch {
|
|
89
|
+
return JSON.stringify({ type, content: { unavailable: true } });
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
names.add(type);
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function admitContextItems(ctx: Context, values: unknown): Promise<void> {
|
|
99
|
+
if (!Array.isArray(values)) return;
|
|
100
|
+
for (let index = 0; index < values.length; index += 1) {
|
|
101
|
+
const item = gitContext(values[index]);
|
|
102
|
+
if (!item) continue;
|
|
103
|
+
try {
|
|
104
|
+
if (!registerGitChatContextStrategies(ctx.app)) throw new Error('Git context strategy is unavailable');
|
|
105
|
+
const content = await loadChatContext(ctx, contextParams(ctx, item));
|
|
106
|
+
let cache = admitted.get(ctx);
|
|
107
|
+
if (!cache) {
|
|
108
|
+
cache = new Map();
|
|
109
|
+
admitted.set(ctx, cache);
|
|
110
|
+
}
|
|
111
|
+
cache.set(contextKey(item), content);
|
|
112
|
+
values[index] = resolvedItem(item, content);
|
|
113
|
+
} catch {
|
|
114
|
+
ctx.throw(
|
|
115
|
+
403,
|
|
116
|
+
ctx.t('Git context is unavailable. Check your access and select it again.', { ns: 'plugin-git-manager' }),
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function recordValue(record: unknown, key: string): unknown {
|
|
123
|
+
if (!record || typeof record !== 'object') return undefined;
|
|
124
|
+
const object = record as { get?: (field: string) => unknown } & Record<string, unknown>;
|
|
125
|
+
return typeof object.get === 'function' ? object.get(key) : object[key];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function admitResentMessage(ctx: Context, values: Record<string, unknown>) {
|
|
129
|
+
const sessionId = typeof values.sessionId === 'string' ? values.sessionId : '';
|
|
130
|
+
const hasMessageId = Object.prototype.hasOwnProperty.call(values, 'messageId');
|
|
131
|
+
let messageId: string | number | undefined;
|
|
132
|
+
if (hasMessageId) {
|
|
133
|
+
const supplied = values.messageId;
|
|
134
|
+
if (typeof supplied === 'number' && Number.isSafeInteger(supplied) && supplied > 0) {
|
|
135
|
+
messageId = supplied;
|
|
136
|
+
} else if (typeof supplied === 'string' && /^\d+$/.test(supplied) && /[1-9]/.test(supplied)) {
|
|
137
|
+
messageId = supplied;
|
|
138
|
+
} else {
|
|
139
|
+
return ctx.throw(400, 'Invalid messageId');
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const userId = ctx.auth?.user?.id;
|
|
143
|
+
const plugin = aiPluginFor(ctx.app);
|
|
144
|
+
if (!sessionId || !userId || !plugin?.aiConversationsManager) return;
|
|
145
|
+
const conversation = await plugin.aiConversationsManager.getConversation({ sessionId, userId });
|
|
146
|
+
if (!conversation) return;
|
|
147
|
+
const repository = ctx.db.getRepository('aiConversations.messages', sessionId);
|
|
148
|
+
const target = hasMessageId
|
|
149
|
+
? await repository.findOne({ filter: { messageId } })
|
|
150
|
+
: await repository.findOne({ filter: { sessionId }, sort: ['-messageId'] });
|
|
151
|
+
if (!target) return;
|
|
152
|
+
const targetId = recordValue(target, 'messageId');
|
|
153
|
+
if ((typeof targetId !== 'string' && typeof targetId !== 'number') || !targetId) {
|
|
154
|
+
return ctx.throw(400, 'Invalid messageId');
|
|
155
|
+
}
|
|
156
|
+
const message =
|
|
157
|
+
recordValue(target, 'role') === 'user'
|
|
158
|
+
? target
|
|
159
|
+
: await repository.findOne({
|
|
160
|
+
filter: { sessionId, role: 'user', messageId: { $lt: targetId } },
|
|
161
|
+
sort: ['-messageId'],
|
|
162
|
+
});
|
|
163
|
+
await admitContextItems(ctx, recordValue(message, 'workContext'));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export async function enforceGitChatAdmission(ctx: Context, next: () => Promise<void>) {
|
|
167
|
+
if (ctx.action?.resourceName !== 'aiConversations') return next();
|
|
168
|
+
const action = ctx.action.actionName;
|
|
169
|
+
if (action !== 'sendMessages' && action !== 'resendMessages') return next();
|
|
170
|
+
const values = ctx.action.params?.values;
|
|
171
|
+
if (!values || typeof values !== 'object' || Array.isArray(values)) return next();
|
|
172
|
+
if (action === 'sendMessages' && Array.isArray(values.messages)) {
|
|
173
|
+
for (const message of values.messages) {
|
|
174
|
+
if (message && typeof message === 'object' && message.role === 'user') {
|
|
175
|
+
await admitContextItems(ctx, message.workContext);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
} else if (action === 'resendMessages') {
|
|
179
|
+
await admitResentMessage(ctx, values);
|
|
180
|
+
}
|
|
181
|
+
await next();
|
|
182
|
+
}
|
|
@@ -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 { defineCollection } from '@nocobase/database';
|
|
11
4
|
|
|
@@ -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 { defineCollection } from '@nocobase/database';
|
|
11
4
|
|
|
@@ -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 { defineCollection } from '@nocobase/database';
|
|
11
4
|
|
|
@@ -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 { defineCollection } from '@nocobase/database';
|
|
11
4
|
|
|
@@ -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 { defineCollection } from '@nocobase/database';
|
|
11
4
|
|
|
@@ -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 { defineCollection } from '@nocobase/database';
|
|
11
4
|
|
package/src/server/index.ts
CHANGED
|
@@ -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
|
export { default } from './plugin';
|
|
11
4
|
export { PluginGitManagerServer } from './plugin';
|
package/src/server/plugin.ts
CHANGED
|
@@ -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 { Plugin } from '@nocobase/server';
|
|
11
4
|
import type { Context } from '@nocobase/actions';
|
|
@@ -19,6 +12,7 @@ import * as reviewCutoverActions from './actions/review-cutover';
|
|
|
19
12
|
import * as pollerActions from './actions/poller';
|
|
20
13
|
import * as rolePermissionsActions from './actions/role-permissions';
|
|
21
14
|
import * as subtreeActions from './actions/subtree';
|
|
15
|
+
import * as chatContextActions from './actions/chat-context';
|
|
22
16
|
import { unregisterReviewQueue } from './actions/review';
|
|
23
17
|
import { registerGitReviewAiTools } from './ai-tools';
|
|
24
18
|
import { enforceGitRequestMethod } from './request-method-policy';
|
|
@@ -28,6 +22,7 @@ import { GitReviewService } from './services/review-service';
|
|
|
28
22
|
import { LegacyPostService } from './services/legacy-post-service';
|
|
29
23
|
import { enforceReviewControlAccess } from './review-control-access';
|
|
30
24
|
import { enforceRepositoryAccess, enforceRepositoryCollectionAccess } from './repository-access';
|
|
25
|
+
import { enforceGitChatAdmission, registerGitChatContextStrategies } from './chat-context-admission';
|
|
31
26
|
import { isGitManagerResourceResponse, redactCredentialFields } from './utils/redact';
|
|
32
27
|
import { containsCredentialBearingUrlField, URL_USERINFO_NOT_ALLOWED } from './utils/url-security';
|
|
33
28
|
|
|
@@ -118,6 +113,8 @@ export class PluginGitManagerServer extends Plugin {
|
|
|
118
113
|
mergeRequests: gitlabApi.mergeRequests,
|
|
119
114
|
mergeRequestDetail: gitlabApi.mergeRequestDetail,
|
|
120
115
|
mergeRequestNotes: gitlabApi.mergeRequestNotes,
|
|
116
|
+
chatContextOptions: chatContextActions.chatContextOptions,
|
|
117
|
+
chatContextContent: chatContextActions.chatContextContent,
|
|
121
118
|
triggerReview: reviewActions.triggerReview,
|
|
122
119
|
reviewApprovePost: reviewActions.reviewApprovePost,
|
|
123
120
|
reviewLegacyPostStatus: reviewActions.reviewLegacyPostStatus,
|
|
@@ -142,6 +139,10 @@ export class PluginGitManagerServer extends Plugin {
|
|
|
142
139
|
},
|
|
143
140
|
});
|
|
144
141
|
|
|
142
|
+
// These actions perform their own checks against the caller's existing Git and collection permissions.
|
|
143
|
+
this.app.acl.allow('gitManager', 'chatContextOptions', 'loggedIn');
|
|
144
|
+
this.app.acl.allow('gitManager', 'chatContextContent', 'loggedIn');
|
|
145
|
+
|
|
145
146
|
const legacyApprovalAction = this.app.acl.getAvailableAction('reviewApprovePost');
|
|
146
147
|
const priorAliases = legacyApprovalAction?.options?.aliases;
|
|
147
148
|
this.app.acl.setAvailableAction('reviewApprovePost', {
|
|
@@ -193,6 +194,7 @@ export class PluginGitManagerServer extends Plugin {
|
|
|
193
194
|
}
|
|
194
195
|
|
|
195
196
|
this.app.resourceManager.use(enforceGitRequestMethod);
|
|
197
|
+
this.app.resourceManager.use(enforceGitChatAdmission);
|
|
196
198
|
this.app.resourceManager.use(enforceReviewControlAccess);
|
|
197
199
|
(this as any).app.resourceManager.use(enforceRepositoryAccess);
|
|
198
200
|
(this as any).app.resourceManager.use(enforceRepositoryCollectionAccess);
|
|
@@ -218,6 +220,8 @@ export class PluginGitManagerServer extends Plugin {
|
|
|
218
220
|
|
|
219
221
|
registerGitReviewAiTools((this as any).app);
|
|
220
222
|
|
|
223
|
+
this.app.on('afterLoad', () => registerGitChatContextStrategies(this.app));
|
|
224
|
+
|
|
221
225
|
(this as any).app.on('afterStart', async () => {
|
|
222
226
|
await ensureAutoReviewFlowSchema((this as any).app).catch(
|
|
223
227
|
(err) => (this as any).app.log?.error?.('plugin-git-manager: ensure schema error', err),
|
package/src/server/poller.ts
CHANGED
|
@@ -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 type { Application } from '@nocobase/server';
|
|
11
4
|
import { triggerReviewInternal, branchMatches } from './actions/review';
|
|
@@ -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
|
const REPOSITORY_ID_ACTIONS = new Set([
|
|
11
4
|
'clone',
|
|
@@ -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 type { Context } from '@nocobase/actions';
|
|
11
4
|
|
|
@@ -20,6 +13,8 @@ const READ_ACTIONS = new Set([
|
|
|
20
13
|
'mergeRequests',
|
|
21
14
|
'mergeRequestDetail',
|
|
22
15
|
'mergeRequestNotes',
|
|
16
|
+
'chatContextOptions',
|
|
17
|
+
'chatContextContent',
|
|
23
18
|
'pollerStatus',
|
|
24
19
|
'rolePermissions',
|
|
25
20
|
'reviewCutoverStatus',
|
|
@@ -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 type { Context } from '@nocobase/actions';
|
|
11
4
|
|
|
@@ -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 { execFileSync } from 'child_process';
|
|
11
4
|
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'fs';
|
|
@@ -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 { execFileSync } from 'child_process';
|
|
11
4
|
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'fs';
|
|
@@ -223,4 +216,36 @@ describe('pinned Git review source', () => {
|
|
|
223
216
|
`https://gitlab.test/api/v4/projects/team%2Fproject/repository/compare?from=${projectBase}&to=${projectHead}`,
|
|
224
217
|
);
|
|
225
218
|
});
|
|
219
|
+
|
|
220
|
+
it('marks collapsed or binary merge-request patches as omitted instead of failing the review context', async () => {
|
|
221
|
+
const fetchMock = vi.fn(async (input: string | URL | Request) => {
|
|
222
|
+
const url = String(input);
|
|
223
|
+
const body = url.includes('/repository/compare')
|
|
224
|
+
? {
|
|
225
|
+
compare_timeout: false,
|
|
226
|
+
overflow: false,
|
|
227
|
+
diffs: [
|
|
228
|
+
{ old_path: 'src/action.ts', new_path: 'src/action.ts', diff: '@@ -1 +1 @@\n-old()\n+new()' },
|
|
229
|
+
{ old_path: 'yarn.lock', new_path: 'yarn.lock', collapsed: true, too_large: true, diff: '' },
|
|
230
|
+
],
|
|
231
|
+
}
|
|
232
|
+
: url.includes('/merge_requests/9')
|
|
233
|
+
? { sha: projectHead, diff_refs: { base_sha: projectBase }, source_branch: 'feature/review' }
|
|
234
|
+
: { id: 71, web_url: 'https://gitlab.test/team/project' };
|
|
235
|
+
return new Response(JSON.stringify(body), { status: 200, headers: { 'content-type': 'application/json' } });
|
|
236
|
+
});
|
|
237
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
238
|
+
const database = createDatabase();
|
|
239
|
+
const repository = createRepository(1, 'https://gitlab.test/team/project.git');
|
|
240
|
+
const source = await resolveReviewSource(database, repository, {
|
|
241
|
+
targetType: 'mr',
|
|
242
|
+
mrIid: 9,
|
|
243
|
+
headSha: projectHead,
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
const diff = await readPinnedReviewSource(database, repository, source);
|
|
247
|
+
|
|
248
|
+
expect(diff).toContain('+new()');
|
|
249
|
+
expect(diff).toContain('Binary files a/yarn.lock and b/yarn.lock differ (patch omitted by provider)');
|
|
250
|
+
});
|
|
226
251
|
});
|
|
@@ -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 { createHash, randomUUID } from 'crypto';
|
|
11
4
|
import type { Application } from '@nocobase/server';
|
|
@@ -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 { spawn } from 'child_process';
|
|
11
4
|
import { existsSync } from 'fs';
|
|
@@ -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 { createHash, randomUUID } from 'crypto';
|
|
11
4
|
import type { Application } from '@nocobase/server';
|
|
@@ -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 { createHash } from 'crypto';
|
|
11
4
|
import type { Database } from '@nocobase/database';
|
|
@@ -192,9 +185,11 @@ export async function readPinnedReviewSource(
|
|
|
192
185
|
content = files
|
|
193
186
|
.map((item) => {
|
|
194
187
|
const file = object(item);
|
|
195
|
-
if (typeof file.filename !== 'string'
|
|
196
|
-
throw new Error('GitHub comparison contains an unavailable patch');
|
|
188
|
+
if (typeof file.filename !== 'string') throw new Error('GitHub comparison contains an unavailable patch');
|
|
197
189
|
if (/[\r\n]/.test(file.filename)) throw new Error('GitHub comparison has an unsupported filename');
|
|
190
|
+
if (typeof file.patch !== 'string') {
|
|
191
|
+
return `Binary files a/${file.filename} and b/${file.filename} differ (patch omitted by provider)`;
|
|
192
|
+
}
|
|
198
193
|
return `--- a/${file.filename}\n+++ b/${file.filename}\n${file.patch}`;
|
|
199
194
|
})
|
|
200
195
|
.join('\n');
|
|
@@ -209,11 +204,12 @@ export async function readPinnedReviewSource(
|
|
|
209
204
|
content = comparison.diffs
|
|
210
205
|
.map((item) => {
|
|
211
206
|
const file = object(item);
|
|
212
|
-
if (file.too_large || file.collapsed || typeof file.diff !== 'string')
|
|
213
|
-
throw new Error('GitLab comparison contains an unavailable patch');
|
|
214
207
|
const oldPath = String(file.old_path || '');
|
|
215
208
|
const newPath = String(file.new_path || '');
|
|
216
209
|
if (/[\r\n]/.test(oldPath + newPath)) throw new Error('GitLab comparison has an unsupported filename');
|
|
210
|
+
if (file.too_large || file.collapsed || typeof file.diff !== 'string') {
|
|
211
|
+
return `Binary files a/${oldPath} and b/${newPath} differ (patch omitted by provider)`;
|
|
212
|
+
}
|
|
217
213
|
return `--- a/${oldPath}\n+++ b/${newPath}\n${file.diff}`;
|
|
218
214
|
})
|
|
219
215
|
.join('\n');
|
|
@@ -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 { assertAccountRepositoryUrl } from './url-security';
|
|
11
4
|
|
|
@@ -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
|
export const URL_USERINFO_NOT_ALLOWED = 'Credential-bearing URLs are not allowed';
|
|
11
4
|
|