plugin-git-manager 1.2.13 → 1.2.15
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 +32 -16
- 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 +41 -20
- 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,186 @@
|
|
|
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 add_git_accounts_exports = {};
|
|
28
|
+
__export(add_git_accounts_exports, {
|
|
29
|
+
default: () => AddGitAccountsMigration
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(add_git_accounts_exports);
|
|
32
|
+
var import_server = require("@nocobase/server");
|
|
33
|
+
var import_sequelize = require("sequelize");
|
|
34
|
+
class AddGitAccountsMigration extends import_server.Migration {
|
|
35
|
+
on = "afterSync";
|
|
36
|
+
async up() {
|
|
37
|
+
var _a;
|
|
38
|
+
const queryInterface = this.db.sequelize.getQueryInterface();
|
|
39
|
+
const sequelize = this.db.sequelize;
|
|
40
|
+
const tablePrefix = ((_a = this.db.options) == null ? void 0 : _a.tablePrefix) || "";
|
|
41
|
+
const repoTable = `${tablePrefix}gitRepositories`;
|
|
42
|
+
const accountsTable = `${tablePrefix}gitAccounts`;
|
|
43
|
+
const quoteTable = (tableName) => queryInterface.queryGenerator.quoteTable(tableName);
|
|
44
|
+
const quoteIdentifier = (identifier) => queryInterface.queryGenerator.quoteIdentifier(identifier);
|
|
45
|
+
const quotedRepoTable = quoteTable(repoTable);
|
|
46
|
+
const quotedAccountsTable = quoteTable(accountsTable);
|
|
47
|
+
const repoInfo = await queryInterface.describeTable(repoTable).catch(() => null);
|
|
48
|
+
if (!repoInfo) return;
|
|
49
|
+
const accountsExists = await queryInterface.describeTable(accountsTable).catch(() => null);
|
|
50
|
+
if (!accountsExists) {
|
|
51
|
+
await queryInterface.createTable(accountsTable, {
|
|
52
|
+
id: { type: import_sequelize.DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
|
|
53
|
+
name: { type: import_sequelize.DataTypes.STRING, allowNull: false },
|
|
54
|
+
provider: { type: import_sequelize.DataTypes.STRING, allowNull: false, defaultValue: "gitlab" },
|
|
55
|
+
baseUrl: { type: import_sequelize.DataTypes.STRING, allowNull: true },
|
|
56
|
+
username: { type: import_sequelize.DataTypes.STRING, allowNull: false },
|
|
57
|
+
pat: { type: import_sequelize.DataTypes.STRING, allowNull: false },
|
|
58
|
+
createdAt: { type: import_sequelize.DataTypes.DATE, allowNull: false },
|
|
59
|
+
updatedAt: { type: import_sequelize.DataTypes.DATE, allowNull: false }
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
if (!repoInfo.gitAccountId) {
|
|
63
|
+
await queryInterface.addColumn(repoTable, "gitAccountId", {
|
|
64
|
+
type: import_sequelize.DataTypes.BIGINT,
|
|
65
|
+
allowNull: true
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (repoInfo.username && repoInfo.pat) {
|
|
69
|
+
const rows = await sequelize.query(
|
|
70
|
+
`SELECT ${quoteIdentifier("id")}, ${quoteIdentifier("repoUrl")}, ${quoteIdentifier(
|
|
71
|
+
"username"
|
|
72
|
+
)}, ${quoteIdentifier("pat")}
|
|
73
|
+
FROM ${quotedRepoTable}
|
|
74
|
+
WHERE ${quoteIdentifier("pat")} IS NOT NULL AND ${quoteIdentifier("pat")} != ''`,
|
|
75
|
+
{ type: import_sequelize.QueryTypes.SELECT }
|
|
76
|
+
);
|
|
77
|
+
if (rows.length > 0) {
|
|
78
|
+
const now = /* @__PURE__ */ new Date();
|
|
79
|
+
const groups = /* @__PURE__ */ new Map();
|
|
80
|
+
for (const row of rows) {
|
|
81
|
+
let host = "";
|
|
82
|
+
try {
|
|
83
|
+
host = row.repoUrl ? new URL(row.repoUrl).host : "";
|
|
84
|
+
} catch {
|
|
85
|
+
}
|
|
86
|
+
const username = row.username || "";
|
|
87
|
+
const key = `${host}::${username}::${row.pat}`;
|
|
88
|
+
if (!groups.has(key)) {
|
|
89
|
+
groups.set(key, { host, username, pat: row.pat, repoIds: [] });
|
|
90
|
+
}
|
|
91
|
+
const group = groups.get(key);
|
|
92
|
+
if (group) group.repoIds.push(row.id);
|
|
93
|
+
}
|
|
94
|
+
for (const [, group] of groups) {
|
|
95
|
+
const name = group.host ? `${group.host} (${group.username})` : `${group.username}`;
|
|
96
|
+
const baseUrl = group.host ? `https://${group.host}` : null;
|
|
97
|
+
const provider = group.host.toLowerCase().includes("github") ? "github" : "gitlab";
|
|
98
|
+
const accountsRepository = this.db.getRepository("gitAccounts");
|
|
99
|
+
const existingAccount = await accountsRepository.findOne({
|
|
100
|
+
filter: { provider, baseUrl, username: group.username, pat: group.pat }
|
|
101
|
+
});
|
|
102
|
+
const account = existingAccount || await accountsRepository.create({
|
|
103
|
+
values: {
|
|
104
|
+
name,
|
|
105
|
+
provider,
|
|
106
|
+
baseUrl,
|
|
107
|
+
username: group.username,
|
|
108
|
+
pat: group.pat,
|
|
109
|
+
createdAt: now,
|
|
110
|
+
updatedAt: now
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
const accountId = account.get("id");
|
|
114
|
+
if (accountId) {
|
|
115
|
+
for (const repoId of group.repoIds) {
|
|
116
|
+
await sequelize.query(
|
|
117
|
+
`UPDATE ${quotedRepoTable}
|
|
118
|
+
SET ${quoteIdentifier("gitAccountId")} = :accountId
|
|
119
|
+
WHERE ${quoteIdentifier("id")} = :repoId`,
|
|
120
|
+
{ replacements: { accountId, repoId } }
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (repoInfo.username) {
|
|
128
|
+
await queryInterface.removeColumn(repoTable, "username");
|
|
129
|
+
}
|
|
130
|
+
if (repoInfo.pat) {
|
|
131
|
+
await queryInterface.removeColumn(repoTable, "pat");
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async down() {
|
|
135
|
+
var _a;
|
|
136
|
+
const queryInterface = this.db.sequelize.getQueryInterface();
|
|
137
|
+
const sequelize = this.db.sequelize;
|
|
138
|
+
const tablePrefix = ((_a = this.db.options) == null ? void 0 : _a.tablePrefix) || "";
|
|
139
|
+
const repoTable = `${tablePrefix}gitRepositories`;
|
|
140
|
+
const accountsTable = `${tablePrefix}gitAccounts`;
|
|
141
|
+
const quoteTable = (tableName) => queryInterface.queryGenerator.quoteTable(tableName);
|
|
142
|
+
const quoteIdentifier = (identifier) => queryInterface.queryGenerator.quoteIdentifier(identifier);
|
|
143
|
+
const quotedRepoTable = quoteTable(repoTable);
|
|
144
|
+
const quotedAccountsTable = quoteTable(accountsTable);
|
|
145
|
+
const repoInfo = await queryInterface.describeTable(repoTable).catch(() => null);
|
|
146
|
+
if (!repoInfo) return;
|
|
147
|
+
if (!repoInfo.username) {
|
|
148
|
+
await queryInterface.addColumn(repoTable, "username", {
|
|
149
|
+
type: import_sequelize.DataTypes.STRING,
|
|
150
|
+
allowNull: true
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
if (!repoInfo.pat) {
|
|
154
|
+
await queryInterface.addColumn(repoTable, "pat", {
|
|
155
|
+
type: import_sequelize.DataTypes.STRING,
|
|
156
|
+
allowNull: true
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
const accountsExists = await queryInterface.describeTable(accountsTable).catch(() => null);
|
|
160
|
+
if (repoInfo.gitAccountId && accountsExists) {
|
|
161
|
+
const credentials = await sequelize.query(
|
|
162
|
+
`SELECT r.${quoteIdentifier("id")} AS ${quoteIdentifier("id")},
|
|
163
|
+
a.${quoteIdentifier("username")} AS ${quoteIdentifier("username")},
|
|
164
|
+
a.${quoteIdentifier("pat")} AS ${quoteIdentifier("pat")}
|
|
165
|
+
FROM ${quotedRepoTable} r
|
|
166
|
+
INNER JOIN ${quotedAccountsTable} a
|
|
167
|
+
ON r.${quoteIdentifier("gitAccountId")} = a.${quoteIdentifier("id")}`,
|
|
168
|
+
{ type: import_sequelize.QueryTypes.SELECT }
|
|
169
|
+
);
|
|
170
|
+
for (const credential of credentials) {
|
|
171
|
+
await sequelize.query(
|
|
172
|
+
`UPDATE ${quotedRepoTable}
|
|
173
|
+
SET ${quoteIdentifier("username")} = :username, ${quoteIdentifier("pat")} = :pat
|
|
174
|
+
WHERE ${quoteIdentifier("id")} = :id`,
|
|
175
|
+
{ replacements: credential }
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (repoInfo.gitAccountId) {
|
|
180
|
+
await queryInterface.removeColumn(repoTable, "gitAccountId");
|
|
181
|
+
}
|
|
182
|
+
if (accountsExists) {
|
|
183
|
+
await queryInterface.dropTable(accountsTable);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
package/dist/server/plugin.js
CHANGED
|
@@ -49,6 +49,7 @@ var gitlabApi = __toESM(require("./actions/gitlab-api"));
|
|
|
49
49
|
var reviewActions = __toESM(require("./actions/review"));
|
|
50
50
|
var pollerActions = __toESM(require("./actions/poller"));
|
|
51
51
|
var rolePermissionsActions = __toESM(require("./actions/role-permissions"));
|
|
52
|
+
var subtreeActions = __toESM(require("./actions/subtree"));
|
|
52
53
|
var import_review = require("./actions/review");
|
|
53
54
|
var import_ai_tools = require("./ai-tools");
|
|
54
55
|
var import_poller = require("./poller");
|
|
@@ -93,7 +94,11 @@ class PluginGitManagerServer extends import_server.Plugin {
|
|
|
93
94
|
pollNow: pollerActions.pollNow,
|
|
94
95
|
pollerStatus: pollerActions.pollerStatus,
|
|
95
96
|
rolePermissions: rolePermissionsActions.rolePermissions,
|
|
96
|
-
updateRolePermissions: rolePermissionsActions.updateRolePermissions
|
|
97
|
+
updateRolePermissions: rolePermissionsActions.updateRolePermissions,
|
|
98
|
+
subtreePreview: subtreeActions.subtreePreview,
|
|
99
|
+
subtreeOptions: subtreeActions.subtreeOptions,
|
|
100
|
+
subtreeRun: subtreeActions.subtreeRunOnAppProcess,
|
|
101
|
+
subtreeReplace: subtreeActions.subtreeRunOnAppProcess
|
|
97
102
|
}
|
|
98
103
|
});
|
|
99
104
|
this.app.use(async (ctx, next) => {
|
|
@@ -123,6 +128,10 @@ class PluginGitManagerServer extends import_server.Plugin {
|
|
|
123
128
|
return (_b = (_a = this.app.log) == null ? void 0 : _a.error) == null ? void 0 : _b.call(_a, "plugin-git-manager: recoverStuckReviews error", err);
|
|
124
129
|
}
|
|
125
130
|
);
|
|
131
|
+
subtreeActions.recoverStuckSubtreeRuns(this.app).catch((err) => {
|
|
132
|
+
var _a, _b;
|
|
133
|
+
return (_b = (_a = this.app.log) == null ? void 0 : _a.error) == null ? void 0 : _b.call(_a, "plugin-git-manager: recover subtree runs error", err);
|
|
134
|
+
});
|
|
126
135
|
(0, import_poller.startPoller)(this.app);
|
|
127
136
|
});
|
|
128
137
|
this.app.on("beforeStop", () => {
|
|
@@ -138,10 +147,16 @@ class PluginGitManagerServer extends import_server.Plugin {
|
|
|
138
147
|
actions: [
|
|
139
148
|
"gitRepositories:list",
|
|
140
149
|
"gitRepositories:get",
|
|
150
|
+
"gitAccounts:list",
|
|
151
|
+
"gitAccounts:get",
|
|
141
152
|
"gitReviewFlows:list",
|
|
142
153
|
"gitReviewFlows:get",
|
|
143
154
|
"gitCodeReviews:list",
|
|
144
155
|
"gitCodeReviews:get",
|
|
156
|
+
"gitSubtreeConfigs:list",
|
|
157
|
+
"gitSubtreeConfigs:get",
|
|
158
|
+
"gitSubtreeRuns:list",
|
|
159
|
+
"gitSubtreeRuns:get",
|
|
145
160
|
"gitManager:status",
|
|
146
161
|
"gitManager:log",
|
|
147
162
|
"gitManager:branches",
|
|
@@ -152,7 +167,9 @@ class PluginGitManagerServer extends import_server.Plugin {
|
|
|
152
167
|
"gitManager:mergeRequests",
|
|
153
168
|
"gitManager:mergeRequestDetail",
|
|
154
169
|
"gitManager:mergeRequestNotes",
|
|
155
|
-
"gitManager:pollerStatus"
|
|
170
|
+
"gitManager:pollerStatus",
|
|
171
|
+
"gitManager:subtreePreview",
|
|
172
|
+
"gitManager:subtreeOptions"
|
|
156
173
|
]
|
|
157
174
|
});
|
|
158
175
|
this.app.acl.registerSnippet({
|
|
@@ -175,28 +192,71 @@ class PluginGitManagerServer extends import_server.Plugin {
|
|
|
175
192
|
"gitManager:triggerReview",
|
|
176
193
|
"gitManager:reviewApprovePost",
|
|
177
194
|
"gitManager:reviewReject",
|
|
178
|
-
"gitManager:pollNow"
|
|
195
|
+
"gitManager:pollNow",
|
|
196
|
+
"gitSubtreeConfigs:create",
|
|
197
|
+
"gitSubtreeConfigs:update",
|
|
198
|
+
"gitSubtreeConfigs:destroy",
|
|
199
|
+
"gitManager:subtreeRun"
|
|
179
200
|
]
|
|
180
201
|
});
|
|
202
|
+
this.app.acl.registerSnippet({
|
|
203
|
+
name: `pm.${this.name}.subtreeReplace`,
|
|
204
|
+
actions: ["gitManager:subtreeReplace"]
|
|
205
|
+
});
|
|
181
206
|
this.app.acl.registerSnippet({
|
|
182
207
|
name: `pm.${this.name}.repositories`,
|
|
183
|
-
actions: ["gitRepositories:*"]
|
|
208
|
+
actions: ["gitRepositories:*", "gitAccounts:*"]
|
|
184
209
|
});
|
|
185
210
|
this.app.acl.registerSnippet({
|
|
186
211
|
name: `pm.${this.name}.manage`,
|
|
187
212
|
actions: [
|
|
188
213
|
`pm.${this.name}.repositories`,
|
|
189
214
|
`pm.${this.name}.read`,
|
|
190
|
-
`pm.${this.name}.write
|
|
215
|
+
`pm.${this.name}.write`,
|
|
216
|
+
`pm.${this.name}.subtreeReplace`
|
|
191
217
|
]
|
|
192
218
|
});
|
|
193
219
|
this.app.resourceManager.use(async (ctx, next) => {
|
|
194
|
-
var _a, _b, _c, _d, _e;
|
|
195
|
-
|
|
196
|
-
|
|
220
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
221
|
+
const resource = (_a = ctx.action) == null ? void 0 : _a.resourceName;
|
|
222
|
+
if (resource === "gitSubtreeConfigs" && ["create", "update"].includes((_b = ctx.action) == null ? void 0 : _b.actionName) && ((_c = ctx.action.params) == null ? void 0 : _c.values)) {
|
|
223
|
+
try {
|
|
224
|
+
subtreeActions.validateSubtreeConfigInput(ctx.action.params.values);
|
|
225
|
+
} catch (error) {
|
|
226
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
227
|
+
ctx.throw(400, ctx.t(message, { ns: this.name }));
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (resource === "gitAccounts" && ((_d = ctx.action) == null ? void 0 : _d.actionName) === "destroy") {
|
|
231
|
+
const accounts = await ctx.db.getRepository("gitAccounts").find({
|
|
232
|
+
filterByTk: (_e = ctx.action.params) == null ? void 0 : _e.filterByTk,
|
|
233
|
+
filter: (_f = ctx.action.params) == null ? void 0 : _f.filter,
|
|
234
|
+
fields: ["id"]
|
|
235
|
+
});
|
|
236
|
+
const accountIds = [];
|
|
237
|
+
for (const account of accounts) {
|
|
238
|
+
accountIds.push(account.get("id"));
|
|
239
|
+
}
|
|
240
|
+
if (accountIds.length > 0) {
|
|
241
|
+
const repositoryCount = await ctx.db.getRepository("gitRepositories").count({
|
|
242
|
+
filter: { gitAccountId: { $in: accountIds } }
|
|
243
|
+
});
|
|
244
|
+
if (repositoryCount > 0) {
|
|
245
|
+
ctx.throw(
|
|
246
|
+
409,
|
|
247
|
+
ctx.t("Cannot delete this Git account because {{count}} repositories are using it", {
|
|
248
|
+
ns: this.name,
|
|
249
|
+
count: repositoryCount
|
|
250
|
+
})
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if ((resource === "gitRepositories" || resource === "gitAccounts") && ["create", "update"].includes((_g = ctx.action) == null ? void 0 : _g.actionName)) {
|
|
256
|
+
if (((_i = (_h = ctx.action.params) == null ? void 0 : _h.values) == null ? void 0 : _i.pat) === "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022") {
|
|
197
257
|
delete ctx.action.params.values.pat;
|
|
198
258
|
}
|
|
199
|
-
if (((
|
|
259
|
+
if (((_j = ctx.request.body) == null ? void 0 : _j.pat) === "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022") {
|
|
200
260
|
delete ctx.request.body.pat;
|
|
201
261
|
}
|
|
202
262
|
}
|
|
@@ -204,7 +264,8 @@ class PluginGitManagerServer extends import_server.Plugin {
|
|
|
204
264
|
});
|
|
205
265
|
this.app.resourceManager.use(async (ctx, next) => {
|
|
206
266
|
var _a, _b;
|
|
207
|
-
|
|
267
|
+
const resource = (_a = ctx.action) == null ? void 0 : _a.resourceName;
|
|
268
|
+
if (resource !== "gitRepositories" && resource !== "gitAccounts") {
|
|
208
269
|
return next();
|
|
209
270
|
}
|
|
210
271
|
await next();
|
|
@@ -221,8 +282,11 @@ class PluginGitManagerServer extends import_server.Plugin {
|
|
|
221
282
|
});
|
|
222
283
|
}
|
|
223
284
|
async install() {
|
|
224
|
-
var _a;
|
|
225
|
-
await ((_a = this.app.db.getCollection("
|
|
285
|
+
var _a, _b, _c, _d;
|
|
286
|
+
await ((_a = this.app.db.getCollection("gitAccounts")) == null ? void 0 : _a.sync());
|
|
287
|
+
await ((_b = this.app.db.getCollection("gitRepositories")) == null ? void 0 : _b.sync());
|
|
288
|
+
await ((_c = this.app.db.getCollection("gitSubtreeConfigs")) == null ? void 0 : _c.sync());
|
|
289
|
+
await ((_d = this.app.db.getCollection("gitSubtreeRuns")) == null ? void 0 : _d.sync());
|
|
226
290
|
}
|
|
227
291
|
async beforeDisable() {
|
|
228
292
|
(0, import_review.unregisterReviewQueue)(this.app);
|
package/dist/server/poller.js
CHANGED
|
@@ -35,6 +35,7 @@ __export(poller_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(poller_exports);
|
|
36
36
|
var import_review = require("./actions/review");
|
|
37
37
|
var import_gitlab_url = require("./utils/gitlab-url");
|
|
38
|
+
var import_get_repo_account = require("./utils/get-repo-account");
|
|
38
39
|
const POLL_INTERVAL_MS = 5 * 60 * 1e3;
|
|
39
40
|
const MR_PAGE_SIZE = 50;
|
|
40
41
|
const STALE_POLL_TIMEOUT_MS = 10 * 60 * 1e3;
|
|
@@ -86,16 +87,12 @@ async function tryAcquirePollerLock(app) {
|
|
|
86
87
|
try {
|
|
87
88
|
let acquired = false;
|
|
88
89
|
if (dialect === "postgres") {
|
|
89
|
-
const [results] = await sequelize.query(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
);
|
|
90
|
+
const [results] = await sequelize.query(`SELECT pg_try_advisory_lock(${ADVISORY_LOCK_KEY}) AS locked`, {
|
|
91
|
+
transaction
|
|
92
|
+
});
|
|
93
93
|
acquired = ((_b = results == null ? void 0 : results[0]) == null ? void 0 : _b.locked) === true;
|
|
94
94
|
} else {
|
|
95
|
-
const [results] = await sequelize.query(
|
|
96
|
-
`SELECT GET_LOCK('git_poller', 0) AS locked`,
|
|
97
|
-
{ transaction }
|
|
98
|
-
);
|
|
95
|
+
const [results] = await sequelize.query(`SELECT GET_LOCK('git_poller', 0) AS locked`, { transaction });
|
|
99
96
|
const v = (_c = results == null ? void 0 : results[0]) == null ? void 0 : _c.locked;
|
|
100
97
|
acquired = v === 1 || v === "1" || v === true;
|
|
101
98
|
}
|
|
@@ -110,15 +107,9 @@ async function tryAcquirePollerLock(app) {
|
|
|
110
107
|
release: async () => {
|
|
111
108
|
try {
|
|
112
109
|
if (dialect === "postgres") {
|
|
113
|
-
await sequelize.query(
|
|
114
|
-
`SELECT pg_advisory_unlock(${ADVISORY_LOCK_KEY})`,
|
|
115
|
-
{ transaction }
|
|
116
|
-
);
|
|
110
|
+
await sequelize.query(`SELECT pg_advisory_unlock(${ADVISORY_LOCK_KEY})`, { transaction });
|
|
117
111
|
} else {
|
|
118
|
-
await sequelize.query(
|
|
119
|
-
`SELECT RELEASE_LOCK('git_poller')`,
|
|
120
|
-
{ transaction }
|
|
121
|
-
);
|
|
112
|
+
await sequelize.query(`SELECT RELEASE_LOCK('git_poller')`, { transaction });
|
|
122
113
|
}
|
|
123
114
|
} catch {
|
|
124
115
|
} finally {
|
|
@@ -204,10 +195,11 @@ async function pollOneRepo(app, repo) {
|
|
|
204
195
|
if (!(flows == null ? void 0 : flows.length)) return { scanned: 0, triggered: 0 };
|
|
205
196
|
const primaryFlowId = repo.get("autoReviewFlowId");
|
|
206
197
|
const primaryFlow = primaryFlowId ? flows.find((flow) => Number(flow.get("id")) === Number(primaryFlowId)) : null;
|
|
207
|
-
const
|
|
198
|
+
const account = await (0, import_get_repo_account.getRepoAccount)(app.db, repo);
|
|
199
|
+
const pat = (account == null ? void 0 : account.pat) || "";
|
|
208
200
|
if (!pat) return { scanned: 0, triggered: 0 };
|
|
209
201
|
const lastPolledAt = repo.get("lastPolledAt");
|
|
210
|
-
const mrs = await listMergeRequests(repo, lastPolledAt);
|
|
202
|
+
const mrs = await listMergeRequests(repo, pat, lastPolledAt);
|
|
211
203
|
let triggered = 0;
|
|
212
204
|
for (const mr of mrs) {
|
|
213
205
|
const flow = primaryFlow && (0, import_review.branchMatches)(primaryFlow, mr.source_branch) ? primaryFlow : flows.find((f) => (0, import_review.branchMatches)(f, mr.source_branch));
|
|
@@ -249,9 +241,8 @@ async function pollOneRepo(app, repo) {
|
|
|
249
241
|
});
|
|
250
242
|
return { scanned: mrs.length, triggered };
|
|
251
243
|
}
|
|
252
|
-
async function listMergeRequests(repo, updatedAfter) {
|
|
244
|
+
async function listMergeRequests(repo, pat, updatedAfter) {
|
|
253
245
|
const repoUrl = repo.get("repoUrl");
|
|
254
|
-
const pat = repo.get("pat");
|
|
255
246
|
const isGitHub = typeof repoUrl === "string" && repoUrl.includes("github.com");
|
|
256
247
|
if (isGitHub) {
|
|
257
248
|
const { projectPath } = (0, import_gitlab_url.parseGitLabProject)(repoUrl);
|
|
@@ -263,10 +254,7 @@ async function listMergeRequests(repo, updatedAfter) {
|
|
|
263
254
|
});
|
|
264
255
|
const headers = { Accept: "application/vnd.github.v3+json" };
|
|
265
256
|
if (pat) headers["Authorization"] = `Bearer ${pat}`;
|
|
266
|
-
const response2 = await fetch(
|
|
267
|
-
`https://api.github.com/repos/${projectPath}/pulls?${params2.toString()}`,
|
|
268
|
-
{ headers }
|
|
269
|
-
);
|
|
257
|
+
const response2 = await fetch(`https://api.github.com/repos/${projectPath}/pulls?${params2.toString()}`, { headers });
|
|
270
258
|
if (!response2.ok) {
|
|
271
259
|
const body = await response2.text().catch(() => "");
|
|
272
260
|
throw new Error(`GitHub API error ${response2.status}: ${body}`);
|
|
@@ -0,0 +1,49 @@
|
|
|
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 get_repo_account_exports = {};
|
|
28
|
+
__export(get_repo_account_exports, {
|
|
29
|
+
getRepoAccount: () => getRepoAccount
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(get_repo_account_exports);
|
|
32
|
+
async function getRepoAccount(db, repo) {
|
|
33
|
+
const gitAccountId = repo.get("gitAccountId");
|
|
34
|
+
if (!gitAccountId) return null;
|
|
35
|
+
const account = await db.getRepository("gitAccounts").findOne({
|
|
36
|
+
filterByTk: gitAccountId
|
|
37
|
+
});
|
|
38
|
+
if (!account) return null;
|
|
39
|
+
return {
|
|
40
|
+
pat: (account.get("pat") || "").trim(),
|
|
41
|
+
username: (account.get("username") || "").trim(),
|
|
42
|
+
baseUrl: (account.get("baseUrl") || "").trim() || null,
|
|
43
|
+
provider: (account.get("provider") || "gitlab").trim()
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
getRepoAccount
|
|
49
|
+
});
|
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.2.
|
|
6
|
+
"version": "1.2.15",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"main": "dist/server/index.js",
|
|
9
9
|
"files": [
|
|
@@ -68,7 +68,9 @@ export const CommitHistory: React.FC = () => {
|
|
|
68
68
|
const filteredCommits = commits.filter((commit) => {
|
|
69
69
|
const keyword = searchKeyword.trim().toLowerCase();
|
|
70
70
|
if (!keyword) return true;
|
|
71
|
-
return String(commit.message || commit.subject || commit.body || '')
|
|
71
|
+
return String(commit.message || commit.subject || commit.body || '')
|
|
72
|
+
.toLowerCase()
|
|
73
|
+
.includes(keyword);
|
|
72
74
|
});
|
|
73
75
|
|
|
74
76
|
const openCommitDetail = async (commit: any) => {
|
|
@@ -137,7 +139,9 @@ export const CommitHistory: React.FC = () => {
|
|
|
137
139
|
key: 'message',
|
|
138
140
|
render: (text: string, record: any) => (
|
|
139
141
|
<div>
|
|
140
|
-
<Text strong style={{ fontSize: 13 }}>
|
|
142
|
+
<Text strong style={{ fontSize: 13 }}>
|
|
143
|
+
{text}
|
|
144
|
+
</Text>
|
|
141
145
|
<div style={{ marginTop: 2 }}>
|
|
142
146
|
<Text type="secondary" style={{ fontSize: 12 }}>
|
|
143
147
|
<UserOutlined style={{ marginRight: 4 }} />
|
|
@@ -215,11 +219,14 @@ export const CommitHistory: React.FC = () => {
|
|
|
215
219
|
<Text strong>{selectedCommit.message}</Text>
|
|
216
220
|
<div>
|
|
217
221
|
<Text type="secondary" style={{ fontSize: 12 }}>
|
|
218
|
-
{selectedCommit.hash?.substring(0, 7)} · {selectedCommit.author_name} ·
|
|
222
|
+
{selectedCommit.hash?.substring(0, 7)} · {selectedCommit.author_name} ·{' '}
|
|
223
|
+
{formatDate(selectedCommit.date)}
|
|
219
224
|
</Text>
|
|
220
225
|
</div>
|
|
221
226
|
</div>
|
|
222
|
-
) :
|
|
227
|
+
) : (
|
|
228
|
+
'Commit Detail'
|
|
229
|
+
)
|
|
223
230
|
}
|
|
224
231
|
open={!!selectedCommit}
|
|
225
232
|
onClose={() => {
|
|
@@ -333,7 +340,16 @@ const DiffViewer: React.FC<{ content: string }> = memo(({ content }) => {
|
|
|
333
340
|
minHeight: 20,
|
|
334
341
|
}}
|
|
335
342
|
>
|
|
336
|
-
<span
|
|
343
|
+
<span
|
|
344
|
+
style={{
|
|
345
|
+
display: 'inline-block',
|
|
346
|
+
width: 40,
|
|
347
|
+
color: token.colorTextQuaternary,
|
|
348
|
+
userSelect: 'none',
|
|
349
|
+
textAlign: 'right',
|
|
350
|
+
marginRight: 12,
|
|
351
|
+
}}
|
|
352
|
+
>
|
|
337
353
|
{i + 1}
|
|
338
354
|
</span>
|
|
339
355
|
{line}
|