plugin-git-manager 1.2.26 → 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 +23 -10
- 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 +33 -11
- 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
|
@@ -28,12 +28,14 @@ var registry_content_service_exports = {};
|
|
|
28
28
|
__export(registry_content_service_exports, {
|
|
29
29
|
REGISTRY_CONTENT_LIMIT_EXCEEDED: () => REGISTRY_CONTENT_LIMIT_EXCEEDED,
|
|
30
30
|
REGISTRY_EXPORT_NOT_GRANTED: () => REGISTRY_EXPORT_NOT_GRANTED,
|
|
31
|
+
REGISTRY_GIT_COMMAND_FAILED: () => REGISTRY_GIT_COMMAND_FAILED,
|
|
31
32
|
REGISTRY_GIT_CONTENT_CAPABILITIES: () => REGISTRY_GIT_CONTENT_CAPABILITIES,
|
|
32
33
|
REGISTRY_GIT_CONTENT_CONTRACT_VERSION: () => REGISTRY_GIT_CONTENT_CONTRACT_VERSION,
|
|
33
34
|
REGISTRY_GIT_FILE_NOT_FOUND: () => REGISTRY_GIT_FILE_NOT_FOUND,
|
|
34
35
|
REGISTRY_REPOSITORY_ACCESS_DENIED: () => REGISTRY_REPOSITORY_ACCESS_DENIED,
|
|
35
36
|
RegistryContentLimitError: () => RegistryContentLimitError,
|
|
36
37
|
RegistryExportNotGrantedError: () => RegistryExportNotGrantedError,
|
|
38
|
+
RegistryGitCommandError: () => RegistryGitCommandError,
|
|
37
39
|
RegistryGitContentService: () => RegistryGitContentService,
|
|
38
40
|
RegistryGitFileNotFoundError: () => RegistryGitFileNotFoundError,
|
|
39
41
|
RegistryRepositoryAccessDeniedError: () => RegistryRepositoryAccessDeniedError,
|
|
@@ -54,13 +56,13 @@ function positiveLimit(value, fallback, maximum = Number.MAX_SAFE_INTEGER) {
|
|
|
54
56
|
}
|
|
55
57
|
const DEFAULT_REGISTRY_GIT_CONTENT_LIMITS = {
|
|
56
58
|
get maxFileBytes() {
|
|
57
|
-
return positiveLimit(process.env.SKILL_REGISTRY_MAX_SOURCE_FILE_BYTES,
|
|
59
|
+
return positiveLimit(process.env.SKILL_REGISTRY_MAX_SOURCE_FILE_BYTES, 100 * 1024 * 1024);
|
|
58
60
|
},
|
|
59
61
|
get maxTreeEntries() {
|
|
60
|
-
return positiveLimit(process.env.SKILL_REGISTRY_MAX_SOURCE_TREE_ENTRIES,
|
|
62
|
+
return positiveLimit(process.env.SKILL_REGISTRY_MAX_SOURCE_TREE_ENTRIES, 5e4);
|
|
61
63
|
},
|
|
62
64
|
get maxTreeOutputBytes() {
|
|
63
|
-
return positiveLimit(process.env.SKILL_REGISTRY_MAX_SOURCE_TREE_OUTPUT_BYTES,
|
|
65
|
+
return positiveLimit(process.env.SKILL_REGISTRY_MAX_SOURCE_TREE_OUTPUT_BYTES, 64 * 1024 * 1024);
|
|
64
66
|
}
|
|
65
67
|
};
|
|
66
68
|
const REGISTRY_EXPORT_NOT_GRANTED = "REGISTRY_EXPORT_NOT_GRANTED";
|
|
@@ -71,7 +73,8 @@ const REGISTRY_GIT_FILE_NOT_FOUND = "REGISTRY_GIT_FILE_NOT_FOUND";
|
|
|
71
73
|
const REGISTRY_GIT_CONTENT_CONTRACT_VERSION = 2;
|
|
72
74
|
const REGISTRY_GIT_CONTENT_CAPABILITIES = [
|
|
73
75
|
"registry-content-with-actor",
|
|
74
|
-
"registry-content-authorize-source"
|
|
76
|
+
"registry-content-authorize-source",
|
|
77
|
+
"registry-content-tree-limits"
|
|
75
78
|
];
|
|
76
79
|
const SKILL_HUB_GIT_CONTENT_CONTRACT_VERSION = 2;
|
|
77
80
|
const SKILL_HUB_GIT_CONTENT_CAPABILITIES = ["skill-hub-content-with-actor"];
|
|
@@ -112,6 +115,14 @@ class RegistryGitFileNotFoundError extends Error {
|
|
|
112
115
|
this.name = "RegistryGitFileNotFoundError";
|
|
113
116
|
}
|
|
114
117
|
}
|
|
118
|
+
const REGISTRY_GIT_COMMAND_FAILED = "REGISTRY_GIT_COMMAND_FAILED";
|
|
119
|
+
class RegistryGitCommandError extends Error {
|
|
120
|
+
code = REGISTRY_GIT_COMMAND_FAILED;
|
|
121
|
+
constructor(message) {
|
|
122
|
+
super(message);
|
|
123
|
+
this.name = "RegistryGitCommandError";
|
|
124
|
+
}
|
|
125
|
+
}
|
|
115
126
|
const REGISTRY_CONTENT_ACCESS_POLICY = {
|
|
116
127
|
contractVersion: REGISTRY_GIT_CONTENT_CONTRACT_VERSION,
|
|
117
128
|
capabilities: REGISTRY_GIT_CONTENT_CAPABILITIES,
|
|
@@ -192,7 +203,7 @@ function runGitBuffer(localPath, args, maximumBytes, timeoutMs) {
|
|
|
192
203
|
reject(new RegistryGitFileNotFoundError());
|
|
193
204
|
return;
|
|
194
205
|
}
|
|
195
|
-
reject(new
|
|
206
|
+
reject(new RegistryGitCommandError(`git command failed: ${stderr.trim() || String(code)}`));
|
|
196
207
|
return;
|
|
197
208
|
}
|
|
198
209
|
resolve(Buffer.concat(chunks, outputBytes));
|
|
@@ -266,7 +277,7 @@ class GitContentService {
|
|
|
266
277
|
DEFAULT_GIT_TIMEOUT_MS
|
|
267
278
|
)).toString("utf8").trim();
|
|
268
279
|
if (!/^[a-f0-9]{40,64}$/i.test(result)) {
|
|
269
|
-
throw new
|
|
280
|
+
throw new RegistryGitCommandError("Git reference did not resolve to a commit SHA");
|
|
270
281
|
}
|
|
271
282
|
return result.toLowerCase();
|
|
272
283
|
}
|
|
@@ -282,11 +293,11 @@ class GitContentService {
|
|
|
282
293
|
const output = await runGitBuffer(
|
|
283
294
|
localPath,
|
|
284
295
|
["ls-tree", "-l", ...input.recursive ? ["-r"] : [], target],
|
|
285
|
-
this.limits.maxTreeOutputBytes,
|
|
296
|
+
boundedPositive(input.maxTreeOutputBytes, this.limits.maxTreeOutputBytes, this.limits.maxTreeOutputBytes),
|
|
286
297
|
DEFAULT_GIT_TIMEOUT_MS
|
|
287
298
|
);
|
|
288
299
|
const lines = output.toString("utf8").trim().split("\n").filter(Boolean);
|
|
289
|
-
if (lines.length > this.limits.maxTreeEntries) {
|
|
300
|
+
if (lines.length > boundedPositive(input.maxTreeEntries, this.limits.maxTreeEntries, this.limits.maxTreeEntries)) {
|
|
290
301
|
throw new RegistryContentLimitError("Git tree contains too many entries for registry export.");
|
|
291
302
|
}
|
|
292
303
|
return lines.map((line) => parseTreeLine(line, rootPath)).filter((entry) => entry !== null).sort((left, right) => left.path.localeCompare(right.path));
|
|
@@ -334,7 +345,7 @@ class GitContentService {
|
|
|
334
345
|
child.once("spawn", () => resolve(child.stdout));
|
|
335
346
|
child.once("close", (code) => {
|
|
336
347
|
if (code !== 0) {
|
|
337
|
-
child.stdout.destroy(new
|
|
348
|
+
child.stdout.destroy(new RegistryGitCommandError(`git archive failed: ${stderr.trim() || String(code)}`));
|
|
338
349
|
}
|
|
339
350
|
});
|
|
340
351
|
});
|
|
@@ -377,7 +388,7 @@ class GitContentService {
|
|
|
377
388
|
assertCommitSha(value) {
|
|
378
389
|
const normalized = (0, import_git_actions.validateRef)(value);
|
|
379
390
|
if (!/^[a-f0-9]{40,64}$/i.test(normalized)) {
|
|
380
|
-
throw new
|
|
391
|
+
throw new RegistryGitCommandError("Registry reads require a full commit SHA");
|
|
381
392
|
}
|
|
382
393
|
return normalized.toLowerCase();
|
|
383
394
|
}
|
|
@@ -396,12 +407,14 @@ class SkillHubGitContentService extends GitContentService {
|
|
|
396
407
|
0 && (module.exports = {
|
|
397
408
|
REGISTRY_CONTENT_LIMIT_EXCEEDED,
|
|
398
409
|
REGISTRY_EXPORT_NOT_GRANTED,
|
|
410
|
+
REGISTRY_GIT_COMMAND_FAILED,
|
|
399
411
|
REGISTRY_GIT_CONTENT_CAPABILITIES,
|
|
400
412
|
REGISTRY_GIT_CONTENT_CONTRACT_VERSION,
|
|
401
413
|
REGISTRY_GIT_FILE_NOT_FOUND,
|
|
402
414
|
REGISTRY_REPOSITORY_ACCESS_DENIED,
|
|
403
415
|
RegistryContentLimitError,
|
|
404
416
|
RegistryExportNotGrantedError,
|
|
417
|
+
RegistryGitCommandError,
|
|
405
418
|
RegistryGitContentService,
|
|
406
419
|
RegistryGitFileNotFoundError,
|
|
407
420
|
RegistryRepositoryAccessDeniedError,
|
|
@@ -38,12 +38,13 @@ async function getRepoAccount(db, repo) {
|
|
|
38
38
|
});
|
|
39
39
|
if (!account) return null;
|
|
40
40
|
const baseUrl = (account.get("baseUrl") || "").trim() || null;
|
|
41
|
-
|
|
41
|
+
const provider = (account.get("provider") || "gitlab").trim();
|
|
42
|
+
(0, import_url_security.assertAccountRepositoryUrl)(String(repo.get("repoUrl") || ""), baseUrl, provider);
|
|
42
43
|
return {
|
|
43
44
|
pat: (account.get("pat") || "").trim(),
|
|
44
45
|
username: (account.get("username") || "").trim(),
|
|
45
46
|
baseUrl,
|
|
46
|
-
provider
|
|
47
|
+
provider
|
|
47
48
|
};
|
|
48
49
|
}
|
|
49
50
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -27,6 +27,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
27
27
|
var url_security_exports = {};
|
|
28
28
|
__export(url_security_exports, {
|
|
29
29
|
URL_USERINFO_NOT_ALLOWED: () => URL_USERINFO_NOT_ALLOWED,
|
|
30
|
+
assertAccountRepositoryUrl: () => assertAccountRepositoryUrl,
|
|
30
31
|
assertUrlHasNoUserInfo: () => assertUrlHasNoUserInfo,
|
|
31
32
|
containsCredentialBearingUrlField: () => containsCredentialBearingUrlField,
|
|
32
33
|
hasUrlUserInfo: () => hasUrlUserInfo,
|
|
@@ -34,6 +35,28 @@ __export(url_security_exports, {
|
|
|
34
35
|
});
|
|
35
36
|
module.exports = __toCommonJS(url_security_exports);
|
|
36
37
|
const URL_USERINFO_NOT_ALLOWED = "Credential-bearing URLs are not allowed";
|
|
38
|
+
function assertAccountRepositoryUrl(repoUrl, baseUrl, provider) {
|
|
39
|
+
assertUrlHasNoUserInfo(repoUrl);
|
|
40
|
+
const trustedUrl = baseUrl || (provider === "github" ? "https://github.com" : "https://gitlab.com");
|
|
41
|
+
assertUrlHasNoUserInfo(trustedUrl);
|
|
42
|
+
let repository;
|
|
43
|
+
let account;
|
|
44
|
+
try {
|
|
45
|
+
repository = new URL(repoUrl);
|
|
46
|
+
account = new URL(trustedUrl);
|
|
47
|
+
} catch {
|
|
48
|
+
throw new Error("Invalid repository or account URL");
|
|
49
|
+
}
|
|
50
|
+
if (repository.protocol !== "https:" || account.protocol !== "https:") {
|
|
51
|
+
throw new Error("Only HTTPS repository and account URLs are allowed");
|
|
52
|
+
}
|
|
53
|
+
if (repository.origin !== account.origin) {
|
|
54
|
+
throw new Error("Repository URL must match the Git account origin");
|
|
55
|
+
}
|
|
56
|
+
if (provider === "github" && repository.origin !== "https://github.com") {
|
|
57
|
+
throw new Error("GitHub accounts currently require github.com");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
37
60
|
function pathSegments(value) {
|
|
38
61
|
return value.split(/[.[\],:/()=\s'"]+/);
|
|
39
62
|
}
|
|
@@ -102,6 +125,7 @@ function redactUrlUserInfo(value) {
|
|
|
102
125
|
// Annotate the CommonJS export names for ESM import in node:
|
|
103
126
|
0 && (module.exports = {
|
|
104
127
|
URL_USERINFO_NOT_ALLOWED,
|
|
128
|
+
assertAccountRepositoryUrl,
|
|
105
129
|
assertUrlHasNoUserInfo,
|
|
106
130
|
containsCredentialBearingUrlField,
|
|
107
131
|
hasUrlUserInfo,
|
package/package.json
CHANGED
|
@@ -1,43 +1,61 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "plugin-git-manager",
|
|
3
|
-
"displayName": "Git Manager",
|
|
4
|
-
"displayName.zh-CN": "Git 管理器",
|
|
5
|
-
"description": "Manage Git repositories with PAT authentication - pull, push, fetch, diff, file browsing",
|
|
6
|
-
"version": "1.2.
|
|
7
|
-
"license": "Apache-2.0",
|
|
8
|
-
"main": "dist/server/index.js",
|
|
9
|
-
"files": [
|
|
10
|
-
"dist",
|
|
11
|
-
"src",
|
|
12
|
-
"client.js",
|
|
13
|
-
"server.js",
|
|
14
|
-
"client.d.ts",
|
|
15
|
-
"server.d.ts",
|
|
16
|
-
"client-v2.js",
|
|
17
|
-
"client-v2.d.ts"
|
|
18
|
-
],
|
|
19
|
-
"nocobase": {
|
|
20
|
-
"supportedVersions": [
|
|
21
|
-
"2.x"
|
|
22
|
-
],
|
|
23
|
-
"editionLevel": 0
|
|
24
|
-
},
|
|
25
|
-
"peerDependencies": {
|
|
26
|
-
"@nocobase/client": "2.x",
|
|
27
|
-
"@nocobase/server": "2.x",
|
|
28
|
-
"@nocobase/database": "2.x",
|
|
29
|
-
"@nocobase/test": "2.x",
|
|
30
|
-
"@nocobase/client-v2": "2.x",
|
|
31
|
-
"@nocobase/flow-engine": "2.x"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"@nocobase/
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "plugin-git-manager",
|
|
3
|
+
"displayName": "Git Manager",
|
|
4
|
+
"displayName.zh-CN": "Git 管理器",
|
|
5
|
+
"description": "Manage Git repositories with PAT authentication - pull, push, fetch, diff, file browsing",
|
|
6
|
+
"version": "1.2.28",
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"main": "dist/server/index.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"src",
|
|
12
|
+
"client.js",
|
|
13
|
+
"server.js",
|
|
14
|
+
"client.d.ts",
|
|
15
|
+
"server.d.ts",
|
|
16
|
+
"client-v2.js",
|
|
17
|
+
"client-v2.d.ts"
|
|
18
|
+
],
|
|
19
|
+
"nocobase": {
|
|
20
|
+
"supportedVersions": [
|
|
21
|
+
"2.x"
|
|
22
|
+
],
|
|
23
|
+
"editionLevel": 0
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@nocobase/client": "2.x",
|
|
27
|
+
"@nocobase/server": "2.x",
|
|
28
|
+
"@nocobase/database": "2.x",
|
|
29
|
+
"@nocobase/test": "2.x",
|
|
30
|
+
"@nocobase/client-v2": "2.x",
|
|
31
|
+
"@nocobase/flow-engine": "2.x",
|
|
32
|
+
"@nocobase/ai": "2.x",
|
|
33
|
+
"@nocobase/plugin-ai": "2.x",
|
|
34
|
+
"@nocobase/plugin-field-markdown-vditor": "2.x"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"simple-git": "^3.27.0"
|
|
38
|
+
},
|
|
39
|
+
"keywords": "System management",
|
|
40
|
+
"peerDependenciesMeta": {
|
|
41
|
+
"@nocobase/ai": {
|
|
42
|
+
"optional": true
|
|
43
|
+
},
|
|
44
|
+
"@nocobase/plugin-ai": {
|
|
45
|
+
"optional": true
|
|
46
|
+
},
|
|
47
|
+
"@nocobase/plugin-field-markdown-vditor": {
|
|
48
|
+
"optional": true
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "git+https://github.com/OrgGem/nocobase-beta.git",
|
|
54
|
+
"directory": "packages/plugins/plugin-git-manager"
|
|
55
|
+
},
|
|
56
|
+
"gitHead": "4c1fe95b5f725713505c59944232259eb386bcf7",
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"access": "public",
|
|
59
|
+
"registry": "https://registry.npmjs.org/"
|
|
60
|
+
}
|
|
61
|
+
}
|
package/server.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './dist/server';
|
|
2
|
-
export { default } from './dist/server';
|
|
1
|
+
export * from './dist/server';
|
|
2
|
+
export { default } from './dist/server';
|
package/server.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = require('./dist/server/index.js');
|
|
1
|
+
module.exports = require('./dist/server/index.js');
|
|
@@ -0,0 +1,73 @@
|
|
|
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 from 'react';
|
|
11
|
+
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
12
|
+
import { RunReviewButton } from '../components/RunReviewButton';
|
|
13
|
+
|
|
14
|
+
const mocks = vi.hoisted(() => ({ request: vi.fn(), getPlugin: vi.fn(), triggerTask: vi.fn() }));
|
|
15
|
+
vi.mock('@nocobase/client-v2', () => ({
|
|
16
|
+
useApp: () => ({ apiClient: { request: mocks.request }, pm: { get: mocks.getPlugin } }),
|
|
17
|
+
}));
|
|
18
|
+
vi.mock('../locale', () => ({ useT: () => (key: string) => key }));
|
|
19
|
+
// Any accidental runtime import of the optional AI package must fail this suite.
|
|
20
|
+
vi.mock('@nocobase/plugin-ai', () => {
|
|
21
|
+
throw new Error('Unexpected legacy AI import');
|
|
22
|
+
});
|
|
23
|
+
vi.mock('@nocobase/plugin-ai/client-v2', () => {
|
|
24
|
+
throw new Error('Unexpected mandatory AI import');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('RunReviewButton optional AI integration', () => {
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
vi.clearAllMocks();
|
|
30
|
+
mocks.getPlugin.mockReturnValue(undefined);
|
|
31
|
+
mocks.request.mockImplementation(async ({ url }: { url: string }) => ({
|
|
32
|
+
data: {
|
|
33
|
+
data: url === 'gitReviewFlows:list' ? [{ id: 1, name: 'Security', aiEmployeeUsername: 'reviewer' }] : [],
|
|
34
|
+
},
|
|
35
|
+
}));
|
|
36
|
+
});
|
|
37
|
+
afterEach(cleanup);
|
|
38
|
+
|
|
39
|
+
it('renders Git review controls without the AI plugin and disables only chat', async () => {
|
|
40
|
+
render(<RunReviewButton target={{ type: 'branch', repositoryId: 7, branch: 'main' }} />);
|
|
41
|
+
fireEvent.click(screen.getByRole('button', { name: /Code Review/ }));
|
|
42
|
+
const chat = await screen.findByRole('menuitem', { name: /Ask AI Employee/ });
|
|
43
|
+
expect(chat.getAttribute('aria-disabled')).toBe('true');
|
|
44
|
+
expect(screen.getByRole('menuitem', { name: /Run automated review/ }).getAttribute('aria-disabled')).not.toBe(
|
|
45
|
+
'true',
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('opens a contextual task through the installed AI manager', async () => {
|
|
50
|
+
mocks.getPlugin.mockReturnValue({ aiManager: { triggerTask: mocks.triggerTask } });
|
|
51
|
+
render(<RunReviewButton target={{ type: 'mr', repositoryId: 7, mrIid: 42, title: 'Fix permissions' }} />);
|
|
52
|
+
fireEvent.click(screen.getByRole('button', { name: /Code Review/ }));
|
|
53
|
+
fireEvent.click(await screen.findByRole('menuitem', { name: /Ask AI Employee/ }));
|
|
54
|
+
await waitFor(() => expect(mocks.triggerTask).toHaveBeenCalledTimes(1));
|
|
55
|
+
expect(mocks.triggerTask).toHaveBeenCalledWith({
|
|
56
|
+
aiEmployee: 'reviewer',
|
|
57
|
+
tasks: [
|
|
58
|
+
expect.objectContaining({
|
|
59
|
+
autoSend: false,
|
|
60
|
+
message: expect.objectContaining({
|
|
61
|
+
workContext: [
|
|
62
|
+
expect.objectContaining({
|
|
63
|
+
type: 'git-merge-request',
|
|
64
|
+
content: { repositoryId: 7, mrIid: 42, title: 'Fix permissions' },
|
|
65
|
+
}),
|
|
66
|
+
],
|
|
67
|
+
}),
|
|
68
|
+
}),
|
|
69
|
+
],
|
|
70
|
+
});
|
|
71
|
+
expect(mocks.getPlugin).toHaveBeenCalledWith('ai');
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -1,114 +1,114 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Space } from 'antd';
|
|
3
|
-
import { BranchesOutlined, MergeOutlined, NodeIndexOutlined } from '@ant-design/icons';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* WorkContext options exported as plain objects so we can register them
|
|
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
|
-
};
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Space } from 'antd';
|
|
3
|
+
import { BranchesOutlined, MergeOutlined, NodeIndexOutlined } from '@ant-design/icons';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* WorkContext options exported as plain objects so we can register them
|
|
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
|
+
};
|