plugin-git-manager 1.2.14 → 1.2.16
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 +10 -0
- package/dist/client/434.1d19d4d6acc114f1.js +10 -0
- package/dist/client/900.ee2fa037aff389e2.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/356.11ed4f8d56a6c08a.js +10 -0
- package/dist/client-v2/434.f8836ea116648de1.js +10 -0
- package/dist/client-v2/900.bef1c41d267e50c5.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +8 -7
- package/dist/locale/en-US.json +73 -2
- package/dist/locale/vi-VN.json +72 -1
- package/dist/locale/zh-CN.json +49 -0
- package/dist/server/actions/git-actions.js +31 -15
- package/dist/server/actions/gitlab-api.js +46 -20
- package/dist/server/actions/review.js +13 -10
- package/dist/server/actions/subtree.js +430 -0
- package/dist/server/collections/gitAccounts.js +86 -0
- package/dist/server/collections/gitRepositories.js +11 -10
- package/dist/server/collections/gitSubtreeConfigs.js +67 -0
- package/dist/server/collections/gitSubtreeRuns.js +60 -0
- package/dist/server/migrations/20260712000000-add-git-accounts.js +186 -0
- package/dist/server/plugin.js +76 -12
- package/dist/server/poller.js +12 -24
- package/dist/server/utils/get-repo-account.js +49 -0
- package/package.json +1 -1
- package/src/client/components/CommitHistory.tsx +21 -5
- package/src/client/components/GitAccounts.tsx +179 -0
- package/src/client/components/GitManagerSettings.tsx +10 -6
- package/src/client/components/GitOperations.tsx +27 -18
- package/src/client/components/LLMModelSelect.tsx +2 -2
- package/src/client/components/MarkdownView.tsx +1 -4
- package/src/client/components/MergeRequests.tsx +238 -129
- package/src/client/components/PollingStatus.tsx +10 -5
- package/src/client/components/RepositoryConfig.tsx +32 -14
- package/src/client/components/RepositoryPermissions.tsx +1 -8
- package/src/client/index.tsx +11 -0
- package/src/client-v2/components/SubtreeSplits.tsx +503 -0
- package/src/client-v2/locale.ts +8 -0
- package/src/client-v2/plugin.tsx +12 -5
- package/src/locale/en-US.json +73 -2
- package/src/locale/vi-VN.json +72 -1
- package/src/locale/zh-CN.json +49 -0
- package/src/server/__tests__/smoke.test.ts +1 -1
- package/src/server/__tests__/subtree.test.ts +73 -0
- package/src/server/actions/git-actions.ts +40 -19
- package/src/server/actions/gitlab-api.ts +59 -28
- package/src/server/actions/review.ts +13 -10
- package/src/server/actions/role-permissions.ts +2 -1
- package/src/server/actions/subtree.ts +460 -0
- package/src/server/collections/gitAccounts.ts +56 -0
- package/src/server/collections/gitRepositories.ts +11 -10
- package/src/server/collections/gitSubtreeConfigs.ts +37 -0
- package/src/server/collections/gitSubtreeRuns.ts +30 -0
- package/src/server/migrations/20260712000000-add-git-accounts.ts +198 -0
- package/src/server/plugin.ts +79 -5
- package/src/server/poller.ts +31 -32
- package/src/server/utils/get-repo-account.ts +23 -0
- package/dist/client/434.f82454801cf84906.js +0 -10
- package/dist/client/900.ec1fa7f16eb8cce6.js +0 -10
- package/dist/client-v2/434.c2f944f911a56da0.js +0 -10
- package/dist/client-v2/900.7a5e80bf21feda66.js +0 -10
|
@@ -0,0 +1,430 @@
|
|
|
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 __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __export = (target, all) => {
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(from))
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
+
mod
|
|
35
|
+
));
|
|
36
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
+
var subtree_exports = {};
|
|
38
|
+
__export(subtree_exports, {
|
|
39
|
+
SUBTREE_EXECUTION_MODE: () => SUBTREE_EXECUTION_MODE,
|
|
40
|
+
recoverStuckSubtreeRuns: () => recoverStuckSubtreeRuns,
|
|
41
|
+
subtreeOptions: () => subtreeOptions,
|
|
42
|
+
subtreePreview: () => subtreePreview,
|
|
43
|
+
subtreeRunOnAppProcess: () => subtreeRunOnAppProcess,
|
|
44
|
+
validateRemoteName: () => validateRemoteName,
|
|
45
|
+
validateRunAgainstPreview: () => validateRunAgainstPreview,
|
|
46
|
+
validateSubtreeConfigInput: () => validateSubtreeConfigInput,
|
|
47
|
+
validateSubtreePolicy: () => validateSubtreePolicy,
|
|
48
|
+
validateSubtreePrefix: () => validateSubtreePrefix
|
|
49
|
+
});
|
|
50
|
+
module.exports = __toCommonJS(subtree_exports);
|
|
51
|
+
var fs = __toESM(require("fs"));
|
|
52
|
+
var os = __toESM(require("os"));
|
|
53
|
+
var path = __toESM(require("path"));
|
|
54
|
+
var import_git_actions = require("./git-actions");
|
|
55
|
+
var import_get_repo_account = require("../utils/get-repo-account");
|
|
56
|
+
var import_redact = require("../utils/redact");
|
|
57
|
+
const SUBTREE_EXECUTION_MODE = "app";
|
|
58
|
+
function getActionParams(ctx) {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
const requestBody = ((_a = ctx.request) == null ? void 0 : _a.body) || {};
|
|
61
|
+
return { ...ctx.action.params, ...(_b = ctx.action.params) == null ? void 0 : _b.values, ...requestBody };
|
|
62
|
+
}
|
|
63
|
+
function stringValue(value, fallback = "") {
|
|
64
|
+
return typeof value === "string" ? value.trim() : fallback;
|
|
65
|
+
}
|
|
66
|
+
function booleanValue(value, fallback) {
|
|
67
|
+
return typeof value === "boolean" ? value : fallback;
|
|
68
|
+
}
|
|
69
|
+
function recordToConfig(record) {
|
|
70
|
+
return {
|
|
71
|
+
id: record.get("id"),
|
|
72
|
+
repositoryId: record.get("repositoryId"),
|
|
73
|
+
sourceBranch: stringValue(record.get("sourceBranch")),
|
|
74
|
+
sourcePrefix: stringValue(record.get("sourcePrefix")),
|
|
75
|
+
targetBranch: stringValue(record.get("targetBranch")),
|
|
76
|
+
remoteName: stringValue(record.get("remoteName"), "origin") || "origin",
|
|
77
|
+
enabled: record.get("enabled") !== false
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function validateSubtreePrefix(prefix) {
|
|
81
|
+
const normalized = prefix.replace(/\\/g, "/").replace(/^\.\//, "").replace(/\/$/, "");
|
|
82
|
+
if (!normalized || path.posix.isAbsolute(normalized) || /^[a-zA-Z]:\//.test(normalized)) {
|
|
83
|
+
throw new Error("Source folder must be a non-empty relative path");
|
|
84
|
+
}
|
|
85
|
+
if (normalized.split("/").some((segment) => !segment || segment === "." || segment === "..")) {
|
|
86
|
+
throw new Error("Source folder contains an invalid path segment");
|
|
87
|
+
}
|
|
88
|
+
return normalized;
|
|
89
|
+
}
|
|
90
|
+
function validateRemoteName(remoteName) {
|
|
91
|
+
if (!/^(?!-)[a-zA-Z0-9._-]+$/.test(remoteName)) {
|
|
92
|
+
throw new Error("Invalid Git remote name");
|
|
93
|
+
}
|
|
94
|
+
return remoteName;
|
|
95
|
+
}
|
|
96
|
+
function validateSubtreePolicy(policy) {
|
|
97
|
+
if (policy === "fastForward" || policy === "replace" || policy === "merge") return policy;
|
|
98
|
+
throw new Error("Invalid subtree update policy");
|
|
99
|
+
}
|
|
100
|
+
function validateSubtreeConfigInput(values) {
|
|
101
|
+
const sourceBranch = stringValue(values.sourceBranch);
|
|
102
|
+
const targetBranch = stringValue(values.targetBranch);
|
|
103
|
+
if (sourceBranch) (0, import_git_actions.validateBranch)(sourceBranch);
|
|
104
|
+
if (targetBranch) (0, import_git_actions.validateBranch)(targetBranch);
|
|
105
|
+
if (sourceBranch && targetBranch && sourceBranch === targetBranch) {
|
|
106
|
+
throw new Error("Source branch and target branch must be different");
|
|
107
|
+
}
|
|
108
|
+
if (values.sourcePrefix !== void 0) validateSubtreePrefix(stringValue(values.sourcePrefix));
|
|
109
|
+
if (values.remoteName !== void 0) validateRemoteName(stringValue(values.remoteName));
|
|
110
|
+
if (values.defaultPolicy !== void 0) validateSubtreePolicy(values.defaultPolicy);
|
|
111
|
+
}
|
|
112
|
+
function validateRunAgainstPreview(policy, preview, expectedTargetSha) {
|
|
113
|
+
if (policy === "fastForward" && preview.relationship === "diverged") {
|
|
114
|
+
throw new Error("Target branch cannot be fast-forwarded to the new subtree commit");
|
|
115
|
+
}
|
|
116
|
+
if (policy === "replace" && preview.targetSha) {
|
|
117
|
+
if (!expectedTargetSha) throw new Error("Replace policy requires the preview target SHA");
|
|
118
|
+
if (expectedTargetSha !== preview.targetSha) {
|
|
119
|
+
throw new Error("Target branch changed after preview; run preview again");
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async function recoverStuckSubtreeRuns(app) {
|
|
124
|
+
const finishedAt = /* @__PURE__ */ new Date();
|
|
125
|
+
const staleBefore = new Date(finishedAt.getTime() - 60 * 60 * 1e3);
|
|
126
|
+
await app.db.getRepository("gitSubtreeRuns").update({
|
|
127
|
+
filter: { status: "running", startedAt: { $lt: staleBefore } },
|
|
128
|
+
values: { status: "failed", finishedAt, error: "Subtree run was interrupted by a server restart" }
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
async function resolveOptionalRef(git, ref) {
|
|
132
|
+
try {
|
|
133
|
+
return (await git.revparse(["--verify", ref])).trim();
|
|
134
|
+
} catch {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async function isAncestor(git, ancestor, descendant) {
|
|
139
|
+
try {
|
|
140
|
+
await git.raw(["merge-base", "--is-ancestor", ancestor, descendant]);
|
|
141
|
+
return true;
|
|
142
|
+
} catch {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
async function assertCleanWorkingTree(git) {
|
|
147
|
+
const status = await git.status();
|
|
148
|
+
if (!status.isClean()) throw new Error("Repository working tree must be clean before running a subtree split");
|
|
149
|
+
}
|
|
150
|
+
async function assertGitBranchFormat(git, branch) {
|
|
151
|
+
try {
|
|
152
|
+
await git.raw(["check-ref-format", "--branch", branch]);
|
|
153
|
+
} catch {
|
|
154
|
+
throw new Error(`Invalid branch name: ${branch}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
async function createPreview(git, config) {
|
|
158
|
+
(0, import_git_actions.validateBranch)(config.sourceBranch);
|
|
159
|
+
(0, import_git_actions.validateBranch)(config.targetBranch);
|
|
160
|
+
if (config.sourceBranch === config.targetBranch) {
|
|
161
|
+
throw new Error("Source branch and target branch must be different");
|
|
162
|
+
}
|
|
163
|
+
const prefix = validateSubtreePrefix(config.sourcePrefix);
|
|
164
|
+
const remoteName = validateRemoteName(config.remoteName);
|
|
165
|
+
const sourceRef = `refs/remotes/${remoteName}/${config.sourceBranch}`;
|
|
166
|
+
const targetRef = `refs/remotes/${remoteName}/${config.targetBranch}`;
|
|
167
|
+
await assertCleanWorkingTree(git);
|
|
168
|
+
await assertGitBranchFormat(git, config.sourceBranch);
|
|
169
|
+
await assertGitBranchFormat(git, config.targetBranch);
|
|
170
|
+
await git.fetch(remoteName, ["--prune"]);
|
|
171
|
+
const sourceSha = await resolveOptionalRef(git, sourceRef);
|
|
172
|
+
if (!sourceSha) throw new Error("Source branch was not found on the configured remote");
|
|
173
|
+
let objectType = "";
|
|
174
|
+
try {
|
|
175
|
+
objectType = (await git.raw(["cat-file", "-t", `${sourceSha}:${prefix}`])).trim();
|
|
176
|
+
} catch {
|
|
177
|
+
throw new Error("Source folder was not found in the selected source branch");
|
|
178
|
+
}
|
|
179
|
+
if (objectType !== "tree") throw new Error("Selected source path is not a folder");
|
|
180
|
+
const splitSha = (await git.raw(["subtree", "split", "--prefix", prefix, sourceSha])).trim();
|
|
181
|
+
if (!/^[a-f0-9]{40,64}$/i.test(splitSha)) throw new Error("Git subtree split did not return a valid commit");
|
|
182
|
+
const targetSha = await resolveOptionalRef(git, targetRef);
|
|
183
|
+
let relationship = "target-missing";
|
|
184
|
+
if (targetSha === splitSha) relationship = "already-up-to-date";
|
|
185
|
+
else if (targetSha) relationship = await isAncestor(git, targetSha, splitSha) ? "fast-forward" : "diverged";
|
|
186
|
+
return {
|
|
187
|
+
sourceSha,
|
|
188
|
+
splitSha,
|
|
189
|
+
targetExists: !!targetSha,
|
|
190
|
+
targetSha,
|
|
191
|
+
relationship,
|
|
192
|
+
recommendedPolicy: relationship === "diverged" ? "merge" : "fastForward",
|
|
193
|
+
availablePolicies: ["fastForward", "replace", "merge"]
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
async function updateTargetRef(git, config, sha) {
|
|
197
|
+
await git.raw(["branch", "-f", config.targetBranch, sha]);
|
|
198
|
+
}
|
|
199
|
+
async function pushTarget(git, config, sha, forceWithLeaseSha) {
|
|
200
|
+
const args = ["push"];
|
|
201
|
+
if (forceWithLeaseSha) {
|
|
202
|
+
args.push(`--force-with-lease=refs/heads/${config.targetBranch}:${forceWithLeaseSha}`);
|
|
203
|
+
}
|
|
204
|
+
args.push(config.remoteName, `${sha}:refs/heads/${config.targetBranch}`);
|
|
205
|
+
await git.raw(args);
|
|
206
|
+
}
|
|
207
|
+
async function mergeTarget(git, config, preview) {
|
|
208
|
+
if (!preview.targetSha) return preview.splitSha;
|
|
209
|
+
const temporaryRoot = fs.mkdtempSync(path.join(os.tmpdir(), "nocobase-git-subtree-"));
|
|
210
|
+
const worktreePath = path.join(temporaryRoot, "worktree");
|
|
211
|
+
try {
|
|
212
|
+
await git.raw(["worktree", "add", "--detach", worktreePath, preview.targetSha]);
|
|
213
|
+
const worktreeGit = (0, import_git_actions.createGit)(worktreePath);
|
|
214
|
+
try {
|
|
215
|
+
await worktreeGit.raw([
|
|
216
|
+
"-c",
|
|
217
|
+
"user.name=NocoBase Git Manager",
|
|
218
|
+
"-c",
|
|
219
|
+
"user.email=git-manager@nocobase.local",
|
|
220
|
+
"merge",
|
|
221
|
+
preview.splitSha,
|
|
222
|
+
"--allow-unrelated-histories",
|
|
223
|
+
"--no-edit"
|
|
224
|
+
]);
|
|
225
|
+
} catch (error) {
|
|
226
|
+
await worktreeGit.raw(["merge", "--abort"]).catch(() => void 0);
|
|
227
|
+
throw new Error(`Subtree merge has conflicts: ${(0, import_redact.redactPat)((0, import_redact.redactError)(error).message)}`);
|
|
228
|
+
}
|
|
229
|
+
return (await worktreeGit.revparse(["HEAD"])).trim();
|
|
230
|
+
} finally {
|
|
231
|
+
await git.raw(["worktree", "remove", "--force", worktreePath]).catch(() => void 0);
|
|
232
|
+
fs.rmSync(temporaryRoot, { recursive: true, force: true });
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
async function loadConfigAndRepository(ctx, configId) {
|
|
236
|
+
const configRecord = await ctx.db.getRepository("gitSubtreeConfigs").findOne({ filterByTk: configId });
|
|
237
|
+
if (!configRecord) ctx.throw(404, "Subtree configuration not found");
|
|
238
|
+
const config = recordToConfig(configRecord);
|
|
239
|
+
if (!config.enabled) ctx.throw(400, "Subtree configuration is disabled");
|
|
240
|
+
const repo = await ctx.db.getRepository("gitRepositories").findOne({ filterByTk: config.repositoryId });
|
|
241
|
+
if (!repo) ctx.throw(404, "Repository not found");
|
|
242
|
+
const account = await (0, import_get_repo_account.getRepoAccount)(ctx.db, repo);
|
|
243
|
+
if (!account) ctx.throw(400, "Repository has no Git account configured");
|
|
244
|
+
return { configRecord, config, repo, account };
|
|
245
|
+
}
|
|
246
|
+
async function subtreeOptions(ctx, next) {
|
|
247
|
+
const params = getActionParams(ctx);
|
|
248
|
+
const repositoryId = params.repositoryId;
|
|
249
|
+
if (!repositoryId) ctx.throw(400, "repositoryId is required");
|
|
250
|
+
const remoteName = validateRemoteName(stringValue(params.remoteName, "origin") || "origin");
|
|
251
|
+
const sourceBranch = stringValue(params.sourceBranch);
|
|
252
|
+
if (sourceBranch) (0, import_git_actions.validateBranch)(sourceBranch);
|
|
253
|
+
const repo = await ctx.db.getRepository("gitRepositories").findOne({ filterByTk: repositoryId });
|
|
254
|
+
if (!repo) ctx.throw(404, "Repository not found");
|
|
255
|
+
const account = await (0, import_get_repo_account.getRepoAccount)(ctx.db, repo);
|
|
256
|
+
if (!account) ctx.throw(400, "Repository has no Git account configured");
|
|
257
|
+
const localPath = (0, import_git_actions.validateLocalPath)(stringValue(repo.get("localPath")));
|
|
258
|
+
const repoUrl = stringValue(repo.get("repoUrl"));
|
|
259
|
+
const git = (0, import_git_actions.createGit)(localPath);
|
|
260
|
+
try {
|
|
261
|
+
const data = await (0, import_git_actions.withAuth)(
|
|
262
|
+
git,
|
|
263
|
+
localPath,
|
|
264
|
+
repoUrl,
|
|
265
|
+
account.pat,
|
|
266
|
+
async () => {
|
|
267
|
+
if (sourceBranch) await assertGitBranchFormat(git, sourceBranch);
|
|
268
|
+
await git.fetch(remoteName, ["--prune"]);
|
|
269
|
+
const branchOutput = await git.raw([
|
|
270
|
+
"for-each-ref",
|
|
271
|
+
"--format=%(refname:strip=3)",
|
|
272
|
+
`refs/remotes/${remoteName}`
|
|
273
|
+
]);
|
|
274
|
+
const branches = branchOutput.split("\n").map((branch) => branch.trim()).filter((branch) => branch && branch !== "HEAD");
|
|
275
|
+
let folders = [];
|
|
276
|
+
if (sourceBranch) {
|
|
277
|
+
const sourceRef = `refs/remotes/${remoteName}/${sourceBranch}`;
|
|
278
|
+
if (!await resolveOptionalRef(git, sourceRef)) {
|
|
279
|
+
throw new Error("Source branch was not found on the configured remote");
|
|
280
|
+
}
|
|
281
|
+
const folderOutput = await git.raw(["ls-tree", "-d", "-r", "--name-only", sourceRef]);
|
|
282
|
+
folders = folderOutput.split("\n").map((folder) => folder.trim()).filter(Boolean);
|
|
283
|
+
}
|
|
284
|
+
return { branches: Array.from(new Set(branches)).sort(), folders };
|
|
285
|
+
},
|
|
286
|
+
account.username,
|
|
287
|
+
remoteName
|
|
288
|
+
);
|
|
289
|
+
ctx.body = { success: true, data };
|
|
290
|
+
} catch (error) {
|
|
291
|
+
const safeError = (0, import_redact.redactError)(error);
|
|
292
|
+
ctx.throw(400, ctx.t(safeError.message, { ns: "plugin-git-manager" }));
|
|
293
|
+
}
|
|
294
|
+
await next();
|
|
295
|
+
}
|
|
296
|
+
async function subtreePreview(ctx, next) {
|
|
297
|
+
const params = getActionParams(ctx);
|
|
298
|
+
const configId = params.configId;
|
|
299
|
+
if (!configId) ctx.throw(400, "configId is required");
|
|
300
|
+
const { config, repo, account } = await loadConfigAndRepository(ctx, configId);
|
|
301
|
+
const localPath = (0, import_git_actions.validateLocalPath)(stringValue(repo.get("localPath")));
|
|
302
|
+
const repoUrl = stringValue(repo.get("repoUrl"));
|
|
303
|
+
const git = (0, import_git_actions.createGit)(localPath);
|
|
304
|
+
try {
|
|
305
|
+
const preview = await (0, import_git_actions.withAuth)(
|
|
306
|
+
git,
|
|
307
|
+
localPath,
|
|
308
|
+
repoUrl,
|
|
309
|
+
account.pat,
|
|
310
|
+
() => createPreview(git, config),
|
|
311
|
+
account.username,
|
|
312
|
+
config.remoteName
|
|
313
|
+
);
|
|
314
|
+
ctx.body = { success: true, data: preview };
|
|
315
|
+
} catch (error) {
|
|
316
|
+
const safeError = (0, import_redact.redactError)(error);
|
|
317
|
+
ctx.throw(400, ctx.t(safeError.message, { ns: "plugin-git-manager" }));
|
|
318
|
+
}
|
|
319
|
+
await next();
|
|
320
|
+
}
|
|
321
|
+
async function subtreeRunOnAppProcess(ctx, next) {
|
|
322
|
+
var _a, _b;
|
|
323
|
+
const params = getActionParams(ctx);
|
|
324
|
+
const runParams = {
|
|
325
|
+
configId: params.configId,
|
|
326
|
+
policy: validateSubtreePolicy(params.policy),
|
|
327
|
+
push: booleanValue(params.push, true),
|
|
328
|
+
expectedTargetSha: stringValue(params.expectedTargetSha) || void 0
|
|
329
|
+
};
|
|
330
|
+
if (!runParams.configId) ctx.throw(400, "configId is required");
|
|
331
|
+
if (runParams.policy === "replace" && ctx.action.actionName !== "subtreeReplace") {
|
|
332
|
+
ctx.throw(403, "Replace policy requires the destructive subtree permission");
|
|
333
|
+
}
|
|
334
|
+
const { config, repo, account } = await loadConfigAndRepository(ctx, runParams.configId);
|
|
335
|
+
const localPath = (0, import_git_actions.validateLocalPath)(stringValue(repo.get("localPath")));
|
|
336
|
+
const repoUrl = stringValue(repo.get("repoUrl"));
|
|
337
|
+
const git = (0, import_git_actions.createGit)(localPath);
|
|
338
|
+
const runsRepository = ctx.db.getRepository("gitSubtreeRuns");
|
|
339
|
+
const startedAt = /* @__PURE__ */ new Date();
|
|
340
|
+
const run = await runsRepository.create({
|
|
341
|
+
values: {
|
|
342
|
+
configId: config.id,
|
|
343
|
+
policy: runParams.policy,
|
|
344
|
+
executionMode: SUBTREE_EXECUTION_MODE,
|
|
345
|
+
status: "running",
|
|
346
|
+
startedAt,
|
|
347
|
+
triggeredById: (_b = (_a = ctx.state) == null ? void 0 : _a.currentUser) == null ? void 0 : _b.id
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
try {
|
|
351
|
+
const result = await (0, import_git_actions.withAuth)(
|
|
352
|
+
git,
|
|
353
|
+
localPath,
|
|
354
|
+
repoUrl,
|
|
355
|
+
account.pat,
|
|
356
|
+
async () => {
|
|
357
|
+
const preview = await createPreview(git, config);
|
|
358
|
+
let targetAfterSha = preview.splitSha;
|
|
359
|
+
validateRunAgainstPreview(runParams.policy, preview, runParams.expectedTargetSha);
|
|
360
|
+
if (runParams.policy === "merge") targetAfterSha = await mergeTarget(git, config, preview);
|
|
361
|
+
if (runParams.push) {
|
|
362
|
+
await pushTarget(
|
|
363
|
+
git,
|
|
364
|
+
config,
|
|
365
|
+
targetAfterSha,
|
|
366
|
+
runParams.policy === "replace" && preview.targetSha ? preview.targetSha : void 0
|
|
367
|
+
);
|
|
368
|
+
} else {
|
|
369
|
+
await updateTargetRef(git, config, targetAfterSha);
|
|
370
|
+
}
|
|
371
|
+
return { preview, targetAfterSha };
|
|
372
|
+
},
|
|
373
|
+
account.username,
|
|
374
|
+
config.remoteName
|
|
375
|
+
);
|
|
376
|
+
const finishedAt = /* @__PURE__ */ new Date();
|
|
377
|
+
await runsRepository.update({
|
|
378
|
+
filterByTk: run.get("id"),
|
|
379
|
+
values: {
|
|
380
|
+
sourceSha: result.preview.sourceSha,
|
|
381
|
+
splitSha: result.preview.splitSha,
|
|
382
|
+
targetBeforeSha: result.preview.targetSha,
|
|
383
|
+
targetAfterSha: result.targetAfterSha,
|
|
384
|
+
status: "success",
|
|
385
|
+
finishedAt,
|
|
386
|
+
output: `Updated ${config.targetBranch} using ${runParams.policy}`
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
await ctx.db.getRepository("gitSubtreeConfigs").update({
|
|
390
|
+
filterByTk: config.id,
|
|
391
|
+
values: {
|
|
392
|
+
lastRunAt: finishedAt,
|
|
393
|
+
lastSplitSha: result.preview.splitSha,
|
|
394
|
+
lastStatus: "success",
|
|
395
|
+
lastError: null
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
ctx.body = {
|
|
399
|
+
success: true,
|
|
400
|
+
data: { runId: run.get("id"), executionMode: SUBTREE_EXECUTION_MODE, ...result }
|
|
401
|
+
};
|
|
402
|
+
} catch (error) {
|
|
403
|
+
const safeError = (0, import_redact.redactError)(error);
|
|
404
|
+
const status = /conflict/i.test(safeError.message) ? "conflict" : "failed";
|
|
405
|
+
const finishedAt = /* @__PURE__ */ new Date();
|
|
406
|
+
await runsRepository.update({
|
|
407
|
+
filterByTk: run.get("id"),
|
|
408
|
+
values: { status, finishedAt, error: safeError.message }
|
|
409
|
+
});
|
|
410
|
+
await ctx.db.getRepository("gitSubtreeConfigs").update({
|
|
411
|
+
filterByTk: config.id,
|
|
412
|
+
values: { lastRunAt: finishedAt, lastStatus: status, lastError: safeError.message }
|
|
413
|
+
});
|
|
414
|
+
ctx.throw(status === "conflict" ? 409 : 400, ctx.t(safeError.message, { ns: "plugin-git-manager" }));
|
|
415
|
+
}
|
|
416
|
+
await next();
|
|
417
|
+
}
|
|
418
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
419
|
+
0 && (module.exports = {
|
|
420
|
+
SUBTREE_EXECUTION_MODE,
|
|
421
|
+
recoverStuckSubtreeRuns,
|
|
422
|
+
subtreeOptions,
|
|
423
|
+
subtreePreview,
|
|
424
|
+
subtreeRunOnAppProcess,
|
|
425
|
+
validateRemoteName,
|
|
426
|
+
validateRunAgainstPreview,
|
|
427
|
+
validateSubtreeConfigInput,
|
|
428
|
+
validateSubtreePolicy,
|
|
429
|
+
validateSubtreePrefix
|
|
430
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
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 gitAccounts_exports = {};
|
|
28
|
+
__export(gitAccounts_exports, {
|
|
29
|
+
default: () => gitAccounts_default
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(gitAccounts_exports);
|
|
32
|
+
var import_database = require("@nocobase/database");
|
|
33
|
+
var gitAccounts_default = (0, import_database.defineCollection)({
|
|
34
|
+
name: "gitAccounts",
|
|
35
|
+
title: "Git Accounts",
|
|
36
|
+
autoGenId: true,
|
|
37
|
+
createdAt: true,
|
|
38
|
+
updatedAt: true,
|
|
39
|
+
fields: [
|
|
40
|
+
{
|
|
41
|
+
type: "string",
|
|
42
|
+
name: "name",
|
|
43
|
+
interface: "input",
|
|
44
|
+
uiSchema: { title: "Account Name", type: "string", "x-component": "Input", required: true }
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
type: "string",
|
|
48
|
+
name: "provider",
|
|
49
|
+
defaultValue: "gitlab",
|
|
50
|
+
interface: "select",
|
|
51
|
+
uiSchema: {
|
|
52
|
+
title: "Provider",
|
|
53
|
+
type: "string",
|
|
54
|
+
"x-component": "Select",
|
|
55
|
+
enum: [
|
|
56
|
+
{ value: "gitlab", label: "GitLab" },
|
|
57
|
+
{ value: "github", label: "GitHub" }
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
type: "string",
|
|
63
|
+
name: "baseUrl",
|
|
64
|
+
interface: "input",
|
|
65
|
+
uiSchema: { title: "Base URL", type: "string", "x-component": "Input" }
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
type: "string",
|
|
69
|
+
name: "username",
|
|
70
|
+
interface: "input",
|
|
71
|
+
uiSchema: { title: "Username", type: "string", "x-component": "Input", required: true }
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
type: "string",
|
|
75
|
+
name: "pat",
|
|
76
|
+
interface: "password",
|
|
77
|
+
uiSchema: { title: "Personal Access Token", type: "string", "x-component": "Password", required: true }
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
type: "hasMany",
|
|
81
|
+
name: "repositories",
|
|
82
|
+
target: "gitRepositories",
|
|
83
|
+
foreignKey: "gitAccountId"
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
});
|
|
@@ -50,10 +50,17 @@ var gitRepositories_default = (0, import_database.defineCollection)({
|
|
|
50
50
|
uiSchema: { title: "Repository URL", type: "string", "x-component": "Input" }
|
|
51
51
|
},
|
|
52
52
|
{
|
|
53
|
-
type: "
|
|
54
|
-
name: "
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
type: "belongsTo",
|
|
54
|
+
name: "gitAccount",
|
|
55
|
+
target: "gitAccounts",
|
|
56
|
+
foreignKey: "gitAccountId",
|
|
57
|
+
onDelete: "RESTRICT",
|
|
58
|
+
interface: "m2o",
|
|
59
|
+
uiSchema: {
|
|
60
|
+
title: "Git Account",
|
|
61
|
+
"x-component": "AssociationField",
|
|
62
|
+
"x-component-props": { fieldNames: { label: "name", value: "id" } }
|
|
63
|
+
}
|
|
57
64
|
},
|
|
58
65
|
{
|
|
59
66
|
type: "string",
|
|
@@ -61,12 +68,6 @@ var gitRepositories_default = (0, import_database.defineCollection)({
|
|
|
61
68
|
interface: "input",
|
|
62
69
|
uiSchema: { title: "Local Path", type: "string", "x-component": "Input" }
|
|
63
70
|
},
|
|
64
|
-
{
|
|
65
|
-
type: "string",
|
|
66
|
-
name: "pat",
|
|
67
|
-
interface: "password",
|
|
68
|
-
uiSchema: { title: "Personal Access Token", type: "string", "x-component": "Password" }
|
|
69
|
-
},
|
|
70
71
|
{
|
|
71
72
|
type: "string",
|
|
72
73
|
name: "defaultBranch",
|
|
@@ -0,0 +1,67 @@
|
|
|
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 gitSubtreeConfigs_exports = {};
|
|
28
|
+
__export(gitSubtreeConfigs_exports, {
|
|
29
|
+
default: () => gitSubtreeConfigs_default
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(gitSubtreeConfigs_exports);
|
|
32
|
+
var import_database = require("@nocobase/database");
|
|
33
|
+
var gitSubtreeConfigs_default = (0, import_database.defineCollection)({
|
|
34
|
+
name: "gitSubtreeConfigs",
|
|
35
|
+
title: "Git Subtree Configurations",
|
|
36
|
+
autoGenId: true,
|
|
37
|
+
createdAt: true,
|
|
38
|
+
updatedAt: true,
|
|
39
|
+
fields: [
|
|
40
|
+
{ type: "string", name: "name", allowNull: false },
|
|
41
|
+
{
|
|
42
|
+
type: "belongsTo",
|
|
43
|
+
name: "repository",
|
|
44
|
+
target: "gitRepositories",
|
|
45
|
+
foreignKey: "repositoryId",
|
|
46
|
+
onDelete: "CASCADE"
|
|
47
|
+
},
|
|
48
|
+
{ type: "string", name: "sourceBranch", allowNull: false },
|
|
49
|
+
{ type: "string", name: "sourcePrefix", allowNull: false },
|
|
50
|
+
{ type: "string", name: "targetBranch", allowNull: false },
|
|
51
|
+
{ type: "string", name: "remoteName", allowNull: false, defaultValue: "origin" },
|
|
52
|
+
{ type: "string", name: "defaultPolicy", allowNull: false, defaultValue: "fastForward" },
|
|
53
|
+
{ type: "boolean", name: "pushAfterRun", allowNull: false, defaultValue: true },
|
|
54
|
+
{ type: "boolean", name: "enabled", allowNull: false, defaultValue: true },
|
|
55
|
+
{ type: "date", name: "lastRunAt" },
|
|
56
|
+
{ type: "string", name: "lastSplitSha" },
|
|
57
|
+
{ type: "string", name: "lastStatus" },
|
|
58
|
+
{ type: "text", name: "lastError" },
|
|
59
|
+
{
|
|
60
|
+
type: "hasMany",
|
|
61
|
+
name: "runs",
|
|
62
|
+
target: "gitSubtreeRuns",
|
|
63
|
+
foreignKey: "configId",
|
|
64
|
+
onDelete: "CASCADE"
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
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 gitSubtreeRuns_exports = {};
|
|
28
|
+
__export(gitSubtreeRuns_exports, {
|
|
29
|
+
default: () => gitSubtreeRuns_default
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(gitSubtreeRuns_exports);
|
|
32
|
+
var import_database = require("@nocobase/database");
|
|
33
|
+
var gitSubtreeRuns_default = (0, import_database.defineCollection)({
|
|
34
|
+
name: "gitSubtreeRuns",
|
|
35
|
+
title: "Git Subtree Runs",
|
|
36
|
+
autoGenId: true,
|
|
37
|
+
createdAt: true,
|
|
38
|
+
updatedAt: true,
|
|
39
|
+
fields: [
|
|
40
|
+
{
|
|
41
|
+
type: "belongsTo",
|
|
42
|
+
name: "config",
|
|
43
|
+
target: "gitSubtreeConfigs",
|
|
44
|
+
foreignKey: "configId",
|
|
45
|
+
onDelete: "CASCADE"
|
|
46
|
+
},
|
|
47
|
+
{ type: "string", name: "policy", allowNull: false },
|
|
48
|
+
{ type: "string", name: "executionMode", allowNull: false, defaultValue: "app" },
|
|
49
|
+
{ type: "string", name: "sourceSha" },
|
|
50
|
+
{ type: "string", name: "splitSha" },
|
|
51
|
+
{ type: "string", name: "targetBeforeSha" },
|
|
52
|
+
{ type: "string", name: "targetAfterSha" },
|
|
53
|
+
{ type: "string", name: "status", allowNull: false, defaultValue: "running" },
|
|
54
|
+
{ type: "date", name: "startedAt", allowNull: false },
|
|
55
|
+
{ type: "date", name: "finishedAt" },
|
|
56
|
+
{ type: "text", name: "output" },
|
|
57
|
+
{ type: "text", name: "error" },
|
|
58
|
+
{ type: "bigInt", name: "triggeredById" }
|
|
59
|
+
]
|
|
60
|
+
});
|