plugin-git-manager 1.3.3 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/{156.c27c2392746e7866.js → 156.8e36af3e2cee173e.js} +1 -1
- package/dist/client/317.e7b1d59371812c30.js +10 -0
- package/dist/client/434.05d0ba2b821105dc.js +10 -0
- package/dist/client/453.cdcba6d2d0c9522b.js +10 -0
- package/dist/client/454.625da741a7e1161f.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/317.4e116f84ed9081b6.js +10 -0
- package/dist/client-v2/434.764113d20743a45b.js +10 -0
- package/dist/client-v2/453.5ab80c06d8e61a7e.js +10 -0
- package/dist/client-v2/454.b885b1d35ef7ff72.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +10 -9
- package/dist/locale/en-US.json +38 -1
- package/dist/locale/vi-VN.json +38 -1
- package/dist/locale/zh-CN.json +41 -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 +387 -80
- package/dist/server/actions/gitlab-api.js +101 -15
- package/dist/server/actions/subtree.js +20 -10
- package/dist/server/chat-context-admission.js +187 -0
- package/dist/server/plugin.js +142 -10
- package/dist/server/repository-access.js +2 -2
- package/dist/server/request-method-policy.js +4 -1
- package/dist/server/services/review-source.js +2 -1
- package/dist/server/utils/cluster-git.js +181 -0
- package/package.json +2 -2
- package/src/client/__tests__/FileExplorerAndManage.test.tsx +236 -0
- package/src/client/__tests__/GitContextPicker.test.tsx +120 -0
- package/src/client/__tests__/ai-context.test.tsx +119 -0
- package/src/client/__tests__/workflowRoutes.test.ts +3 -1
- package/src/client/ai-context.tsx +3 -113
- package/src/client/components/CommitHistory.tsx +19 -7
- package/src/client/components/FileExplorer.tsx +80 -34
- package/src/client/components/GitManagerSettings.tsx +21 -5
- package/src/client/components/GitOperations.tsx +25 -4
- package/src/client/components/GitRuntimeBanner.tsx +97 -0
- package/src/client/components/RepositoryConfig.tsx +28 -6
- package/src/client/context/GitManagerContext.tsx +174 -15
- package/src/client/index.tsx +3 -5
- package/src/client/workflowRoutes.ts +11 -0
- 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 +38 -1
- package/src/locale/vi-VN.json +38 -1
- package/src/locale/zh-CN.json +41 -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-actions.test.ts +329 -4
- package/src/server/__tests__/git-chat-context.test.ts +138 -0
- package/src/server/__tests__/git-security.test.ts +52 -0
- package/src/server/__tests__/smoke.test.ts +232 -1
- package/src/server/actions/chat-context.ts +302 -0
- package/src/server/actions/git-actions.ts +428 -89
- package/src/server/actions/gitlab-api.ts +113 -14
- package/src/server/actions/subtree.ts +23 -6
- package/src/server/chat-context-admission.ts +182 -0
- package/src/server/plugin.ts +163 -3
- package/src/server/repository-access.ts +2 -2
- package/src/server/request-method-policy.ts +3 -0
- package/src/server/services/review-source.ts +3 -2
- package/src/server/utils/cluster-git.ts +209 -0
- package/dist/client/317.17ed0018e3e7db00.js +0 -10
- package/dist/client/434.b2eeaaef33aae6e0.js +0 -10
- package/dist/client/453.fc3042c9740d8fab.js +0 -10
- package/dist/client-v2/317.d2466574d00f94d0.js +0 -10
- package/dist/client-v2/434.19c7579c06b9077c.js +0 -10
- package/dist/client-v2/453.5e507c94c59277b1.js +0 -10
package/dist/server/plugin.js
CHANGED
|
@@ -43,6 +43,7 @@ __export(plugin_exports, {
|
|
|
43
43
|
});
|
|
44
44
|
module.exports = __toCommonJS(plugin_exports);
|
|
45
45
|
var import_server = require("@nocobase/server");
|
|
46
|
+
var fs = __toESM(require("fs"));
|
|
46
47
|
var import_path = require("path");
|
|
47
48
|
var import_sequelize = require("sequelize");
|
|
48
49
|
var gitActions = __toESM(require("./actions/git-actions"));
|
|
@@ -52,6 +53,7 @@ var reviewCutoverActions = __toESM(require("./actions/review-cutover"));
|
|
|
52
53
|
var pollerActions = __toESM(require("./actions/poller"));
|
|
53
54
|
var rolePermissionsActions = __toESM(require("./actions/role-permissions"));
|
|
54
55
|
var subtreeActions = __toESM(require("./actions/subtree"));
|
|
56
|
+
var chatContextActions = __toESM(require("./actions/chat-context"));
|
|
55
57
|
var import_review = require("./actions/review");
|
|
56
58
|
var import_ai_tools = require("./ai-tools");
|
|
57
59
|
var import_request_method_policy = require("./request-method-policy");
|
|
@@ -61,8 +63,10 @@ var import_review_service = require("./services/review-service");
|
|
|
61
63
|
var import_legacy_post_service = require("./services/legacy-post-service");
|
|
62
64
|
var import_review_control_access = require("./review-control-access");
|
|
63
65
|
var import_repository_access = require("./repository-access");
|
|
66
|
+
var import_chat_context_admission = require("./chat-context-admission");
|
|
64
67
|
var import_redact = require("./utils/redact");
|
|
65
68
|
var import_url_security = require("./utils/url-security");
|
|
69
|
+
var import_cluster_git = require("./utils/cluster-git");
|
|
66
70
|
const GIT_CONFIGURATION_URL_FIELDS = /* @__PURE__ */ new Set(["repoUrl", "baseUrl"]);
|
|
67
71
|
function isConcurrentSchemaChange(error) {
|
|
68
72
|
var _a, _b, _c;
|
|
@@ -81,6 +85,13 @@ class PluginGitManagerServer extends import_server.Plugin {
|
|
|
81
85
|
skillHubContentService;
|
|
82
86
|
reviewService;
|
|
83
87
|
legacyPostService;
|
|
88
|
+
gitAutoRestoreTimer = null;
|
|
89
|
+
stopGitAutoRestore() {
|
|
90
|
+
if (this.gitAutoRestoreTimer) {
|
|
91
|
+
clearTimeout(this.gitAutoRestoreTimer);
|
|
92
|
+
this.gitAutoRestoreTimer = null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
84
95
|
async afterAdd() {
|
|
85
96
|
this.reviewService = new import_review_service.GitReviewService(this.app);
|
|
86
97
|
this.legacyPostService = new import_legacy_post_service.LegacyPostService(this.app);
|
|
@@ -130,6 +141,8 @@ class PluginGitManagerServer extends import_server.Plugin {
|
|
|
130
141
|
mergeRequests: gitlabApi.mergeRequests,
|
|
131
142
|
mergeRequestDetail: gitlabApi.mergeRequestDetail,
|
|
132
143
|
mergeRequestNotes: gitlabApi.mergeRequestNotes,
|
|
144
|
+
chatContextOptions: chatContextActions.chatContextOptions,
|
|
145
|
+
chatContextContent: chatContextActions.chatContextContent,
|
|
133
146
|
triggerReview: reviewActions.triggerReview,
|
|
134
147
|
reviewApprovePost: reviewActions.reviewApprovePost,
|
|
135
148
|
reviewLegacyPostStatus: reviewActions.reviewLegacyPostStatus,
|
|
@@ -150,9 +163,13 @@ class PluginGitManagerServer extends import_server.Plugin {
|
|
|
150
163
|
subtreePreview: subtreeActions.subtreePreview,
|
|
151
164
|
subtreeOptions: subtreeActions.subtreeOptions,
|
|
152
165
|
subtreeRun: subtreeActions.subtreeRunOnAppProcess,
|
|
153
|
-
subtreeReplace: subtreeActions.subtreeRunOnAppProcess
|
|
166
|
+
subtreeReplace: subtreeActions.subtreeRunOnAppProcess,
|
|
167
|
+
runtimeStatus: gitActions.runtimeStatus,
|
|
168
|
+
installGit: gitActions.installGit
|
|
154
169
|
}
|
|
155
170
|
});
|
|
171
|
+
this.app.acl.allow("gitManager", "chatContextOptions", "loggedIn");
|
|
172
|
+
this.app.acl.allow("gitManager", "chatContextContent", "loggedIn");
|
|
156
173
|
const legacyApprovalAction = this.app.acl.getAvailableAction("reviewApprovePost");
|
|
157
174
|
const priorAliases = (_a = legacyApprovalAction == null ? void 0 : legacyApprovalAction.options) == null ? void 0 : _a.aliases;
|
|
158
175
|
this.app.acl.setAvailableAction("reviewApprovePost", {
|
|
@@ -164,7 +181,7 @@ class PluginGitManagerServer extends import_server.Plugin {
|
|
|
164
181
|
]
|
|
165
182
|
});
|
|
166
183
|
for (const [action, aliases] of [
|
|
167
|
-
["fileContent", ["reviewCutoverStatus"]],
|
|
184
|
+
["fileContent", ["reviewCutoverStatus", "runtimeStatus"]],
|
|
168
185
|
[
|
|
169
186
|
"triggerReview",
|
|
170
187
|
[
|
|
@@ -201,6 +218,7 @@ class PluginGitManagerServer extends import_server.Plugin {
|
|
|
201
218
|
});
|
|
202
219
|
}
|
|
203
220
|
this.app.resourceManager.use(import_request_method_policy.enforceGitRequestMethod);
|
|
221
|
+
this.app.resourceManager.use(import_chat_context_admission.enforceGitChatAdmission);
|
|
204
222
|
this.app.resourceManager.use(import_review_control_access.enforceReviewControlAccess);
|
|
205
223
|
this.app.resourceManager.use(import_repository_access.enforceRepositoryAccess);
|
|
206
224
|
this.app.resourceManager.use(import_repository_access.enforceRepositoryCollectionAccess);
|
|
@@ -217,32 +235,52 @@ class PluginGitManagerServer extends import_server.Plugin {
|
|
|
217
235
|
return next();
|
|
218
236
|
});
|
|
219
237
|
(0, import_ai_tools.registerGitReviewAiTools)(this.app);
|
|
238
|
+
this.app.on("afterLoad", () => (0, import_chat_context_admission.registerGitChatContextStrategies)(this.app));
|
|
220
239
|
this.app.on("afterStart", async () => {
|
|
240
|
+
var _a2;
|
|
221
241
|
await ensureAutoReviewFlowSchema(this.app).catch(
|
|
222
242
|
(err) => {
|
|
223
|
-
var
|
|
224
|
-
return (_b2 = (
|
|
243
|
+
var _a3, _b2;
|
|
244
|
+
return (_b2 = (_a3 = this.app.log) == null ? void 0 : _a3.error) == null ? void 0 : _b2.call(_a3, "plugin-git-manager: ensure schema error", err);
|
|
225
245
|
}
|
|
226
246
|
);
|
|
227
247
|
await this.ensureReviewSchema().catch(
|
|
228
248
|
(error) => {
|
|
229
|
-
var
|
|
230
|
-
return (_b2 = (
|
|
249
|
+
var _a3, _b2;
|
|
250
|
+
return (_b2 = (_a3 = this.app.log) == null ? void 0 : _a3.error) == null ? void 0 : _b2.call(_a3, "plugin-git-manager: review schema error", error);
|
|
231
251
|
}
|
|
232
252
|
);
|
|
233
253
|
this.reviewService.start();
|
|
234
254
|
subtreeActions.recoverStuckSubtreeRuns(this.app).catch((err) => {
|
|
235
|
-
var
|
|
236
|
-
return (_b2 = (
|
|
255
|
+
var _a3, _b2;
|
|
256
|
+
return (_b2 = (_a3 = this.app.log) == null ? void 0 : _a3.error) == null ? void 0 : _b2.call(_a3, "plugin-git-manager: recover subtree runs error", err);
|
|
237
257
|
});
|
|
238
258
|
(0, import_poller.startPoller)(this.app);
|
|
259
|
+
this.stopGitAutoRestore();
|
|
260
|
+
const restoreTimer = setTimeout(async () => {
|
|
261
|
+
this.gitAutoRestoreTimer = null;
|
|
262
|
+
if (gitActions.isGitAvailable()) return;
|
|
263
|
+
const clusterStatus = await (0, import_cluster_git.readClusterGitStatus)(this.app).catch(() => void 0);
|
|
264
|
+
if ((clusterStatus == null ? void 0 : clusterStatus.available) && clusterStatus.gitConfigured && clusterStatus.previouslyInitialized) {
|
|
265
|
+
await (0, import_cluster_git.dispatchClusterGitInstall)(this.app).catch(
|
|
266
|
+
(err) => {
|
|
267
|
+
var _a3, _b2;
|
|
268
|
+
return (_b2 = (_a3 = this.app.log) == null ? void 0 : _a3.warn) == null ? void 0 : _b2.call(_a3, "plugin-git-manager: startup git restore via Cluster Manager failed", err);
|
|
269
|
+
}
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
}, 5e3);
|
|
273
|
+
(_a2 = restoreTimer.unref) == null ? void 0 : _a2.call(restoreTimer);
|
|
274
|
+
this.gitAutoRestoreTimer = restoreTimer;
|
|
239
275
|
});
|
|
240
276
|
this.app.on("beforeStop", () => {
|
|
277
|
+
this.stopGitAutoRestore();
|
|
241
278
|
(0, import_review.unregisterReviewQueue)(this.app);
|
|
242
279
|
this.reviewService.stop();
|
|
243
280
|
(0, import_poller.stopPoller)(this.app);
|
|
244
281
|
});
|
|
245
282
|
this.app.on("beforeDestroy", () => {
|
|
283
|
+
this.stopGitAutoRestore();
|
|
246
284
|
(0, import_review.unregisterReviewQueue)(this.app);
|
|
247
285
|
this.reviewService.stop();
|
|
248
286
|
(0, import_poller.stopPoller)(this.app);
|
|
@@ -276,6 +314,7 @@ class PluginGitManagerServer extends import_server.Plugin {
|
|
|
276
314
|
"gitManager:subtreePreview",
|
|
277
315
|
"gitManager:subtreeOptions",
|
|
278
316
|
"gitManager:reviewCutoverStatus",
|
|
317
|
+
"gitManager:runtimeStatus",
|
|
279
318
|
"workflowGitReview:status"
|
|
280
319
|
]
|
|
281
320
|
});
|
|
@@ -313,6 +352,7 @@ class PluginGitManagerServer extends import_server.Plugin {
|
|
|
313
352
|
"gitManager:reviewResetPostClaim",
|
|
314
353
|
"gitManager:reviewCancelQueued",
|
|
315
354
|
"gitManager:reviewLegacyReleaseHold",
|
|
355
|
+
"gitManager:installGit",
|
|
316
356
|
"workflowGitReview:setup",
|
|
317
357
|
"workflowGitReview:repair"
|
|
318
358
|
]
|
|
@@ -323,7 +363,7 @@ class PluginGitManagerServer extends import_server.Plugin {
|
|
|
323
363
|
});
|
|
324
364
|
this.app.acl.registerSnippet({
|
|
325
365
|
name: `pm.${this.name}.repositories`,
|
|
326
|
-
actions: ["gitRepositories:*", "gitAccounts:*"]
|
|
366
|
+
actions: ["gitRepositories:*", "gitAccounts:*", "gitManager:runtimeStatus", "gitManager:installGit"]
|
|
327
367
|
});
|
|
328
368
|
this.app.acl.registerSnippet({
|
|
329
369
|
name: `pm.${this.name}.manage`,
|
|
@@ -340,7 +380,7 @@ class PluginGitManagerServer extends import_server.Plugin {
|
|
|
340
380
|
]
|
|
341
381
|
});
|
|
342
382
|
this.app.resourceManager.use(async (ctx, next) => {
|
|
343
|
-
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
383
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
344
384
|
const resource = (_a2 = ctx.action) == null ? void 0 : _a2.resourceName;
|
|
345
385
|
if (resource === "gitSubtreeConfigs" && ["create", "update"].includes((_b2 = ctx.action) == null ? void 0 : _b2.actionName) && ((_c = ctx.action.params) == null ? void 0 : _c.values)) {
|
|
346
386
|
try {
|
|
@@ -395,6 +435,96 @@ class PluginGitManagerServer extends import_server.Plugin {
|
|
|
395
435
|
if (((_m = ctx.request.body) == null ? void 0 : _m.pat) === "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022") {
|
|
396
436
|
delete ctx.request.body.pat;
|
|
397
437
|
}
|
|
438
|
+
const mergedValues = {
|
|
439
|
+
...requestBody && typeof requestBody === "object" && !Array.isArray(requestBody) ? requestBody : {},
|
|
440
|
+
...(requestBody == null ? void 0 : requestBody.values) && typeof requestBody.values === "object" && !Array.isArray(requestBody.values) ? requestBody.values : {},
|
|
441
|
+
...(actionParams == null ? void 0 : actionParams.values) && typeof actionParams.values === "object" && !Array.isArray(actionParams.values) ? actionParams.values : {}
|
|
442
|
+
};
|
|
443
|
+
try {
|
|
444
|
+
if (resource === "gitAccounts") {
|
|
445
|
+
let existingAccount = null;
|
|
446
|
+
if (((_n = ctx.action) == null ? void 0 : _n.actionName) === "update" && (actionParams == null ? void 0 : actionParams.filterByTk) != null) {
|
|
447
|
+
existingAccount = await ctx.db.getRepository("gitAccounts").findOne({ filterByTk: actionParams.filterByTk });
|
|
448
|
+
}
|
|
449
|
+
const provider = String(mergedValues.provider ?? (existingAccount == null ? void 0 : existingAccount.get("provider")) ?? "gitlab").trim();
|
|
450
|
+
const rawBaseUrl = mergedValues.baseUrl !== void 0 ? mergedValues.baseUrl : existingAccount == null ? void 0 : existingAccount.get("baseUrl");
|
|
451
|
+
const baseUrl = typeof rawBaseUrl === "string" && rawBaseUrl.trim() ? rawBaseUrl.trim() : null;
|
|
452
|
+
if (baseUrl) {
|
|
453
|
+
(0, import_url_security.assertUrlHasNoUserInfo)(baseUrl);
|
|
454
|
+
let parsedBase;
|
|
455
|
+
try {
|
|
456
|
+
parsedBase = new URL(baseUrl);
|
|
457
|
+
} catch {
|
|
458
|
+
throw new Error("Invalid repository or account URL");
|
|
459
|
+
}
|
|
460
|
+
if (parsedBase.protocol !== "https:") {
|
|
461
|
+
throw new Error("Only HTTPS repository and account URLs are allowed");
|
|
462
|
+
}
|
|
463
|
+
if (provider === "github" && parsedBase.origin !== "https://github.com") {
|
|
464
|
+
throw new Error("GitHub accounts currently require github.com");
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
if (resource === "gitRepositories") {
|
|
469
|
+
if (mergedValues.localPath !== void 0) {
|
|
470
|
+
gitActions.validateLocalPath(String(mergedValues.localPath));
|
|
471
|
+
}
|
|
472
|
+
if (mergedValues.repoUrl !== void 0) {
|
|
473
|
+
gitActions.validateRepoUrl(String(mergedValues.repoUrl).trim());
|
|
474
|
+
}
|
|
475
|
+
if (mergedValues.defaultBranch !== void 0 && String(mergedValues.defaultBranch).trim()) {
|
|
476
|
+
gitActions.validateBranch(String(mergedValues.defaultBranch).trim());
|
|
477
|
+
}
|
|
478
|
+
if (mergedValues.repoUrl !== void 0 || mergedValues.gitAccountId !== void 0) {
|
|
479
|
+
let existingRepo = null;
|
|
480
|
+
if (((_o = ctx.action) == null ? void 0 : _o.actionName) === "update" && (actionParams == null ? void 0 : actionParams.filterByTk) != null) {
|
|
481
|
+
existingRepo = await ctx.db.getRepository("gitRepositories").findOne({ filterByTk: actionParams.filterByTk });
|
|
482
|
+
}
|
|
483
|
+
const effectiveRepoUrl = String(
|
|
484
|
+
mergedValues.repoUrl !== void 0 ? mergedValues.repoUrl : (existingRepo == null ? void 0 : existingRepo.get("repoUrl")) || ""
|
|
485
|
+
).trim();
|
|
486
|
+
const effectiveAccountId = mergedValues.gitAccountId !== void 0 ? mergedValues.gitAccountId : existingRepo == null ? void 0 : existingRepo.get("gitAccountId");
|
|
487
|
+
if (effectiveRepoUrl && (typeof effectiveAccountId === "number" || typeof effectiveAccountId === "string") && String(effectiveAccountId).trim()) {
|
|
488
|
+
const account = await ctx.db.getRepository("gitAccounts").findOne({ filterByTk: effectiveAccountId });
|
|
489
|
+
if (account) {
|
|
490
|
+
const baseUrl = String(account.get("baseUrl") || "").trim() || null;
|
|
491
|
+
const provider = String(account.get("provider") || "gitlab").trim();
|
|
492
|
+
(0, import_url_security.assertAccountRepositoryUrl)(effectiveRepoUrl, baseUrl, provider);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
} catch (error) {
|
|
498
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
499
|
+
ctx.throw(400, ctx.t(message, { ns: this.name }));
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
if (resource === "gitRepositories" && ((_p = ctx.action) == null ? void 0 : _p.actionName) === "destroy") {
|
|
503
|
+
const targetRepos = await ctx.db.getRepository("gitRepositories").find({
|
|
504
|
+
filterByTk: (_q = ctx.action.params) == null ? void 0 : _q.filterByTk,
|
|
505
|
+
filter: (_r = ctx.action.params) == null ? void 0 : _r.filter,
|
|
506
|
+
fields: ["id", "localPath"]
|
|
507
|
+
});
|
|
508
|
+
const localPaths = Array.from(
|
|
509
|
+
new Set(
|
|
510
|
+
targetRepos.map((item) => item.get("localPath")).filter((value) => typeof value === "string" && Boolean(value.trim()))
|
|
511
|
+
)
|
|
512
|
+
);
|
|
513
|
+
await next();
|
|
514
|
+
for (const rawLocalPath of localPaths) {
|
|
515
|
+
const remainingCount = await ctx.db.getRepository("gitRepositories").count({
|
|
516
|
+
filter: { localPath: rawLocalPath }
|
|
517
|
+
});
|
|
518
|
+
if (remainingCount > 0) continue;
|
|
519
|
+
try {
|
|
520
|
+
const resolvedPath = gitActions.validateLocalPath(rawLocalPath);
|
|
521
|
+
if (fs.existsSync(resolvedPath)) {
|
|
522
|
+
fs.rmSync(resolvedPath, { recursive: true, force: true });
|
|
523
|
+
}
|
|
524
|
+
} catch {
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
return;
|
|
398
528
|
}
|
|
399
529
|
return next();
|
|
400
530
|
});
|
|
@@ -439,11 +569,13 @@ class PluginGitManagerServer extends import_server.Plugin {
|
|
|
439
569
|
}, 3e5);
|
|
440
570
|
}
|
|
441
571
|
async beforeDisable() {
|
|
572
|
+
this.stopGitAutoRestore();
|
|
442
573
|
(0, import_review.unregisterReviewQueue)(this.app);
|
|
443
574
|
this.reviewService.stop();
|
|
444
575
|
(0, import_poller.stopPoller)(this.app);
|
|
445
576
|
}
|
|
446
577
|
async beforeUnload() {
|
|
578
|
+
this.stopGitAutoRestore();
|
|
447
579
|
(0, import_review.unregisterReviewQueue)(this.app);
|
|
448
580
|
this.reviewService.stop();
|
|
449
581
|
(0, import_poller.stopPoller)(this.app);
|
|
@@ -589,8 +589,8 @@ async function enforceRepositoryAccess(ctx, next) {
|
|
|
589
589
|
const reviewId = asRepositoryId(params.reviewId);
|
|
590
590
|
if (reviewId == null) return ctx.throw(400, "reviewId is required");
|
|
591
591
|
repositoryId = await repositoryIdFromReview(ctx, reviewId);
|
|
592
|
-
} else if (actionName === "pollNow") {
|
|
593
|
-
repositoryId = asRepositoryId(params.repositoryId);
|
|
592
|
+
} else if (actionName === "pollNow" || actionName === "installGit") {
|
|
593
|
+
repositoryId = actionName === "pollNow" ? asRepositoryId(params.repositoryId) : void 0;
|
|
594
594
|
if (repositoryId == null) {
|
|
595
595
|
const allowed2 = await hasUnrestrictedRepositoryAccess({
|
|
596
596
|
acl: ctx.app.acl,
|
|
@@ -40,9 +40,12 @@ const READ_ACTIONS = /* @__PURE__ */ new Set([
|
|
|
40
40
|
"mergeRequests",
|
|
41
41
|
"mergeRequestDetail",
|
|
42
42
|
"mergeRequestNotes",
|
|
43
|
+
"chatContextOptions",
|
|
44
|
+
"chatContextContent",
|
|
43
45
|
"pollerStatus",
|
|
44
46
|
"rolePermissions",
|
|
45
|
-
"reviewCutoverStatus"
|
|
47
|
+
"reviewCutoverStatus",
|
|
48
|
+
"runtimeStatus"
|
|
46
49
|
]);
|
|
47
50
|
async function enforceGitRequestMethod(ctx, next) {
|
|
48
51
|
var _a, _b;
|
|
@@ -97,7 +97,8 @@ async function resolveReviewProjectKey(db, repo) {
|
|
|
97
97
|
return (await provider(db, repo)).projectKey;
|
|
98
98
|
}
|
|
99
99
|
async function validateCheckoutProject(db, repo, expectedProjectKey) {
|
|
100
|
-
const
|
|
100
|
+
const localPath = (0, import_git_actions.validateLocalPath)(String(repo.get("localPath") || ""));
|
|
101
|
+
const git = await (0, import_git_actions.assertLocalGitReady)(localPath);
|
|
101
102
|
let origin;
|
|
102
103
|
try {
|
|
103
104
|
origin = (await git.raw(["remote", "get-url", "origin"])).trim();
|
|
@@ -0,0 +1,181 @@
|
|
|
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
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var cluster_git_exports = {};
|
|
28
|
+
__export(cluster_git_exports, {
|
|
29
|
+
dispatchClusterGitInstall: () => dispatchClusterGitInstall,
|
|
30
|
+
readClusterGitStatus: () => readClusterGitStatus,
|
|
31
|
+
resetClusterGitDispatchCooldownForTests: () => resetClusterGitDispatchCooldownForTests
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(cluster_git_exports);
|
|
34
|
+
const CLUSTER_INSTALL_CHANNEL = "cluster-manager.install-packages";
|
|
35
|
+
const AUTO_RESTORE_LOCK_KEY = "git-manager:cluster-git-install";
|
|
36
|
+
const AUTO_RESTORE_COOLDOWN_MS = 45e3;
|
|
37
|
+
let lastDispatchAt = 0;
|
|
38
|
+
function parseAptPackages(raw) {
|
|
39
|
+
if (typeof raw !== "string" || !raw.trim()) return [];
|
|
40
|
+
return Array.from(
|
|
41
|
+
new Set(
|
|
42
|
+
raw.split(/[\r\n,]+/).map((item) => item.trim()).filter(Boolean)
|
|
43
|
+
)
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
function hasGitInWhitelist(raw) {
|
|
47
|
+
if (!raw) return false;
|
|
48
|
+
try {
|
|
49
|
+
const parsed = typeof raw === "string" ? JSON.parse(raw) : raw;
|
|
50
|
+
return Array.isArray(parsed == null ? void 0 : parsed.apt) && parsed.apt.includes("git");
|
|
51
|
+
} catch {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function normalizeStatus(raw) {
|
|
56
|
+
if (raw === "running" || raw === "succeeded" || raw === "failed") return raw;
|
|
57
|
+
return "idle";
|
|
58
|
+
}
|
|
59
|
+
function isClusterManagerEnabled(app) {
|
|
60
|
+
var _a, _b, _c;
|
|
61
|
+
if (!((_b = (_a = app == null ? void 0 : app.db) == null ? void 0 : _a.getCollection) == null ? void 0 : _b.call(_a, "workerPackagesConfigs"))) return false;
|
|
62
|
+
if (!((_c = app.pm) == null ? void 0 : _c.get)) return true;
|
|
63
|
+
return Boolean(app.pm.get("plugin-cluster-manager") || app.pm.get("cluster-manager"));
|
|
64
|
+
}
|
|
65
|
+
async function readClusterGitStatus(app) {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
if (!isClusterManagerEnabled(app)) {
|
|
68
|
+
return {
|
|
69
|
+
available: false,
|
|
70
|
+
gitConfigured: false,
|
|
71
|
+
previouslyInitialized: false,
|
|
72
|
+
status: "idle",
|
|
73
|
+
progressPercent: 0
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const repo = (_b = (_a = app == null ? void 0 : app.db) == null ? void 0 : _a.getRepository) == null ? void 0 : _b.call(_a, "workerPackagesConfigs");
|
|
77
|
+
if (!repo) {
|
|
78
|
+
return {
|
|
79
|
+
available: false,
|
|
80
|
+
gitConfigured: false,
|
|
81
|
+
previouslyInitialized: false,
|
|
82
|
+
status: "idle",
|
|
83
|
+
progressPercent: 0
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const config = await repo.findOne();
|
|
87
|
+
if (!config) {
|
|
88
|
+
return {
|
|
89
|
+
available: true,
|
|
90
|
+
gitConfigured: false,
|
|
91
|
+
previouslyInitialized: false,
|
|
92
|
+
status: "idle",
|
|
93
|
+
progressPercent: 0
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
const aptPackages = parseAptPackages(config.get("aptPackages"));
|
|
97
|
+
const whitelisted = hasGitInWhitelist(config.get("packageWhitelist"));
|
|
98
|
+
const status = normalizeStatus(config.get("initStatus"));
|
|
99
|
+
const rawPercent = Number(config.get("initProgressPercent") ?? 0);
|
|
100
|
+
return {
|
|
101
|
+
available: true,
|
|
102
|
+
gitConfigured: aptPackages.includes("git") || whitelisted,
|
|
103
|
+
previouslyInitialized: Boolean(config.get("lastInitAt") || whitelisted || status === "succeeded"),
|
|
104
|
+
status,
|
|
105
|
+
progressPercent: Number.isFinite(rawPercent) ? Math.min(Math.max(rawPercent, 0), 100) : 0
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
async function dispatchClusterGitInstall(app, options = {}) {
|
|
109
|
+
var _a, _b, _c;
|
|
110
|
+
if (!isClusterManagerEnabled(app)) {
|
|
111
|
+
return { dispatched: false, reason: "Cluster Manager plugin is not enabled" };
|
|
112
|
+
}
|
|
113
|
+
const pubSub = app == null ? void 0 : app.pubSubManager;
|
|
114
|
+
const connected = pubSub ? pubSub.isConnected ? await pubSub.isConnected() : true : false;
|
|
115
|
+
if (!pubSub || !connected) {
|
|
116
|
+
return { dispatched: false, reason: "Cluster PubSub is not connected" };
|
|
117
|
+
}
|
|
118
|
+
const repo = (_b = (_a = app == null ? void 0 : app.db) == null ? void 0 : _a.getRepository) == null ? void 0 : _b.call(_a, "workerPackagesConfigs");
|
|
119
|
+
if (!repo) {
|
|
120
|
+
return { dispatched: false, reason: "Cluster package configuration repository is unavailable" };
|
|
121
|
+
}
|
|
122
|
+
const runDispatch = async () => {
|
|
123
|
+
var _a2, _b2;
|
|
124
|
+
const now = Date.now();
|
|
125
|
+
if (!options.force && now - lastDispatchAt < AUTO_RESTORE_COOLDOWN_MS) {
|
|
126
|
+
return { dispatched: false, reason: "Recent install dispatch still in cooldown" };
|
|
127
|
+
}
|
|
128
|
+
let config = await repo.findOne();
|
|
129
|
+
if (!config) {
|
|
130
|
+
if (!options.ensureGitInConfig) {
|
|
131
|
+
return { dispatched: false, reason: "Cluster package configuration has not been initialized" };
|
|
132
|
+
}
|
|
133
|
+
config = await repo.create({ values: { aptPackages: "git" } });
|
|
134
|
+
}
|
|
135
|
+
const currentStatus = normalizeStatus(config.get("initStatus"));
|
|
136
|
+
if (!options.force && currentStatus === "running") {
|
|
137
|
+
return { dispatched: false, reason: "Cluster package installation is already running" };
|
|
138
|
+
}
|
|
139
|
+
const aptPackages = parseAptPackages(config.get("aptPackages"));
|
|
140
|
+
if (!aptPackages.includes("git")) {
|
|
141
|
+
if (!options.ensureGitInConfig && !hasGitInWhitelist(config.get("packageWhitelist"))) {
|
|
142
|
+
return { dispatched: false, reason: "git is not configured in Cluster Manager packages" };
|
|
143
|
+
}
|
|
144
|
+
if (options.ensureGitInConfig) {
|
|
145
|
+
aptPackages.push("git");
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const aptMirrorUrl = String(config.get("aptMirrorUrl") || process.env.APT_MIRROR_URL || "").trim() || void 0;
|
|
149
|
+
await repo.update({
|
|
150
|
+
filterByTk: config.get("id"),
|
|
151
|
+
values: {
|
|
152
|
+
...options.ensureGitInConfig ? { aptPackages: aptPackages.join("\n") } : {},
|
|
153
|
+
initStatus: "running",
|
|
154
|
+
lastInitAt: /* @__PURE__ */ new Date(),
|
|
155
|
+
initProgressPercent: 5,
|
|
156
|
+
initProgressLog: "Installing git on app/worker nodes via Cluster Manager..."
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
await pubSub.publish(CLUSTER_INSTALL_CHANNEL, {
|
|
160
|
+
targetRole: "all",
|
|
161
|
+
packages: { apt: ["git"] },
|
|
162
|
+
registryConfig: { aptMirrorUrl }
|
|
163
|
+
});
|
|
164
|
+
lastDispatchAt = Date.now();
|
|
165
|
+
(_b2 = (_a2 = app == null ? void 0 : app.log) == null ? void 0 : _a2.info) == null ? void 0 : _b2.call(_a2, "plugin-git-manager: dispatched git installation via Cluster Manager");
|
|
166
|
+
return { dispatched: true };
|
|
167
|
+
};
|
|
168
|
+
if ((_c = app == null ? void 0 : app.lockManager) == null ? void 0 : _c.runExclusive) {
|
|
169
|
+
return app.lockManager.runExclusive(AUTO_RESTORE_LOCK_KEY, runDispatch, 3e4);
|
|
170
|
+
}
|
|
171
|
+
return runDispatch();
|
|
172
|
+
}
|
|
173
|
+
function resetClusterGitDispatchCooldownForTests() {
|
|
174
|
+
lastDispatchAt = 0;
|
|
175
|
+
}
|
|
176
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
177
|
+
0 && (module.exports = {
|
|
178
|
+
dispatchClusterGitInstall,
|
|
179
|
+
readClusterGitStatus,
|
|
180
|
+
resetClusterGitDispatchCooldownForTests
|
|
181
|
+
});
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"displayName": "Git Manager",
|
|
4
4
|
"displayName.zh-CN": "Git 管理器",
|
|
5
5
|
"description": "Manage Git repositories with PAT authentication - pull, push, fetch, diff, file browsing",
|
|
6
|
-
"version": "1.
|
|
6
|
+
"version": "1.4.1",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"main": "dist/server/index.js",
|
|
9
9
|
"files": [
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"url": "git+https://github.com/OrgGem/nocobase-beta.git",
|
|
54
54
|
"directory": "packages/plugins/plugin-git-manager"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "14cdd027ade7f31b9cc416cfbd338ed0e1b70ccb",
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public",
|
|
59
59
|
"registry": "https://registry.npmjs.org/"
|