plugin-git-manager 1.2.11 → 1.2.13
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/900.ec1fa7f16eb8cce6.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/900.7a5e80bf21feda66.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +7 -7
- package/dist/locale/en-US.json +28 -1
- package/dist/locale/vi-VN.json +30 -1
- package/dist/server/actions/git-actions.js +5 -3
- package/dist/server/actions/review.js +70 -5
- package/dist/server/ai-tools.js +30 -0
- package/dist/server/collections/gitCodeReviews.js +8 -1
- package/dist/server/plugin.js +17 -10
- package/package.json +1 -1
- package/src/client/components/FileExplorer.tsx +63 -11
- package/src/client/components/ReviewFlows.tsx +33 -11
- package/src/client/components/ReviewHistory.tsx +45 -9
- package/src/client/components/RunReviewButton.tsx +436 -375
- package/src/client/promptTemplates.ts +31 -0
- package/src/locale/en-US.json +28 -1
- package/src/locale/vi-VN.json +30 -1
- package/src/server/actions/git-actions.ts +432 -430
- package/src/server/actions/review.ts +94 -9
- package/src/server/ai-tools.ts +32 -4
- package/src/server/collections/gitCodeReviews.ts +7 -0
- package/src/server/plugin.ts +250 -242
- package/dist/client/878.3e7b8b27c157996c.js +0 -10
- package/dist/client-v2/878.295f09c9d77ea6d8.js +0 -10
|
@@ -69,6 +69,9 @@ function getActionParams(ctx) {
|
|
|
69
69
|
function targetKey(args) {
|
|
70
70
|
if (args.targetType === "mr") return `${args.repositoryId}:mr:${args.mrIid}`;
|
|
71
71
|
if (args.targetType === "commit") return `${args.repositoryId}:commit:${args.commitSha}`;
|
|
72
|
+
if (args.targetType === "folder") {
|
|
73
|
+
return `${args.repositoryId}:folder:${args.branch || "HEAD"}:${args.folderPath || "/"}`;
|
|
74
|
+
}
|
|
72
75
|
return `${args.repositoryId}:branch:${args.branch}`;
|
|
73
76
|
}
|
|
74
77
|
const TRIGGER_LOCK_TTL_MS = 3e4;
|
|
@@ -79,13 +82,17 @@ async function withTriggerLock(app, key, fn) {
|
|
|
79
82
|
async function triggerReview(ctx, next) {
|
|
80
83
|
var _a, _b;
|
|
81
84
|
const params = getActionParams(ctx);
|
|
82
|
-
const { flowId, repositoryId, targetType, mrIid, commitSha, branch, extraInstructions } = params;
|
|
85
|
+
const { flowId, repositoryId, targetType, mrIid, commitSha, branch, folderPath, extraInstructions } = params;
|
|
83
86
|
if (!repositoryId) ctx.throw(400, "repositoryId is required");
|
|
84
87
|
if (!targetType) ctx.throw(400, "targetType is required");
|
|
85
|
-
if (!["mr", "commit", "branch"].includes(targetType)) ctx.throw(400, "invalid targetType");
|
|
88
|
+
if (!["mr", "commit", "branch", "folder"].includes(targetType)) ctx.throw(400, "invalid targetType");
|
|
86
89
|
if (targetType === "mr" && !mrIid) ctx.throw(400, "mrIid is required for MR review");
|
|
87
90
|
if (targetType === "commit" && !commitSha) ctx.throw(400, "commitSha is required for commit review");
|
|
88
91
|
if (targetType === "branch" && !branch) ctx.throw(400, "branch is required for branch review");
|
|
92
|
+
if (targetType === "folder") {
|
|
93
|
+
if (typeof folderPath !== "string") ctx.throw(400, "folderPath is required for folder review");
|
|
94
|
+
if (folderPath.includes("..")) ctx.throw(400, "Invalid folder path");
|
|
95
|
+
}
|
|
89
96
|
const userId = (_b = (_a = ctx.state) == null ? void 0 : _a.currentUser) == null ? void 0 : _b.id;
|
|
90
97
|
try {
|
|
91
98
|
const reviewId = await triggerReviewInternal(ctx.app, {
|
|
@@ -95,6 +102,7 @@ async function triggerReview(ctx, next) {
|
|
|
95
102
|
mrIid: mrIid != null ? Number(mrIid) : null,
|
|
96
103
|
commitSha: commitSha || null,
|
|
97
104
|
branch: branch || null,
|
|
105
|
+
folderPath: targetType === "folder" ? folderPath : null,
|
|
98
106
|
extraInstructions,
|
|
99
107
|
triggeredBy: "manual",
|
|
100
108
|
userId
|
|
@@ -146,6 +154,10 @@ async function triggerReviewInternalLocked(app, args) {
|
|
|
146
154
|
if (args.targetType === "mr") targetFilter.mrIid = args.mrIid;
|
|
147
155
|
else if (args.targetType === "commit") targetFilter.commitSha = args.commitSha;
|
|
148
156
|
else if (args.targetType === "branch") targetFilter.branch = args.branch;
|
|
157
|
+
else if (args.targetType === "folder") {
|
|
158
|
+
targetFilter.folderPath = args.folderPath ?? "";
|
|
159
|
+
targetFilter.branch = args.branch || null;
|
|
160
|
+
}
|
|
149
161
|
const existing = await reviewsRepo.findOne({ filter: targetFilter });
|
|
150
162
|
const existingLatestSha = existing == null ? void 0 : existing.get("latestSha");
|
|
151
163
|
const baseValues = {
|
|
@@ -155,6 +167,7 @@ async function triggerReviewInternalLocked(app, args) {
|
|
|
155
167
|
mrIid: args.targetType === "mr" ? args.mrIid : null,
|
|
156
168
|
commitSha: args.targetType === "commit" ? args.commitSha : null,
|
|
157
169
|
branch: args.branch || null,
|
|
170
|
+
folderPath: args.targetType === "folder" ? args.folderPath ?? "" : null,
|
|
158
171
|
headSha,
|
|
159
172
|
latestSha: headSha || existingLatestSha || null,
|
|
160
173
|
triggeredBy: args.triggeredBy || "manual",
|
|
@@ -196,6 +209,7 @@ async function triggerReviewInternalLocked(app, args) {
|
|
|
196
209
|
mrIid: args.targetType === "mr" ? args.mrIid : null,
|
|
197
210
|
commitSha: args.targetType === "commit" ? args.commitSha : null,
|
|
198
211
|
branch: args.branch || void 0,
|
|
212
|
+
folderPath: args.targetType === "folder" ? args.folderPath ?? "" : null,
|
|
199
213
|
headSha,
|
|
200
214
|
aiEmployeeUsername,
|
|
201
215
|
extraInstructions: args.extraInstructions,
|
|
@@ -419,7 +433,8 @@ function createReviewQueueMessageFromReview(review) {
|
|
|
419
433
|
targetType,
|
|
420
434
|
mrIid: targetType === "mr" ? toNullableNumber(review.get("mrIid")) : null,
|
|
421
435
|
commitSha: targetType === "commit" ? review.get("commitSha") : null,
|
|
422
|
-
branch: targetType === "branch" ? review.get("branch") : null,
|
|
436
|
+
branch: targetType === "branch" || targetType === "folder" ? review.get("branch") : null,
|
|
437
|
+
folderPath: targetType === "folder" ? review.get("folderPath") ?? "" : null,
|
|
423
438
|
headSha: review.get("headSha"),
|
|
424
439
|
aiEmployeeUsername: metadata.aiEmployeeUsername || "",
|
|
425
440
|
extraInstructions: metadata.extraInstructions || void 0,
|
|
@@ -524,6 +539,7 @@ async function processQueuedReview(app, message) {
|
|
|
524
539
|
mrIid: targetType === "mr" ? message.mrIid ?? toNullableNumber(review.get("mrIid")) : null,
|
|
525
540
|
commitSha: targetType === "commit" ? message.commitSha || review.get("commitSha") : null,
|
|
526
541
|
branch: message.branch || review.get("branch"),
|
|
542
|
+
folderPath: targetType === "folder" ? message.folderPath ?? review.get("folderPath") ?? "" : null,
|
|
527
543
|
headSha: message.headSha || review.get("headSha"),
|
|
528
544
|
aiEmployeeUsername,
|
|
529
545
|
extraInstructions: message.extraInstructions ?? metadata.extraInstructions ?? void 0,
|
|
@@ -622,13 +638,22 @@ async function runReview(app, args) {
|
|
|
622
638
|
values: { sessionId }
|
|
623
639
|
});
|
|
624
640
|
const prompt = buildReviewPrompt(args);
|
|
641
|
+
const currentRoles = await resolveBackgroundReviewRoles(db, args.userId);
|
|
642
|
+
const currentUser = args.userId ? {
|
|
643
|
+
id: args.userId,
|
|
644
|
+
roles: currentRoles.map((name) => ({ name }))
|
|
645
|
+
} : null;
|
|
625
646
|
const syntheticCtx = {
|
|
626
647
|
app,
|
|
627
648
|
db,
|
|
628
649
|
isBackgroundReview: true,
|
|
629
650
|
reviewTargetRepositoryId: args.repo.get("id"),
|
|
630
|
-
state: {
|
|
631
|
-
|
|
651
|
+
state: {
|
|
652
|
+
currentUser,
|
|
653
|
+
currentRole: currentRoles[0],
|
|
654
|
+
currentRoles
|
|
655
|
+
},
|
|
656
|
+
auth: { user: currentUser || { id: null } },
|
|
632
657
|
req: { headers: { "x-timezone": "+00:00", "x-locale": "en-US" } },
|
|
633
658
|
// AIEmployee.getSystemPrompt reads ctx.action.params.values.important
|
|
634
659
|
action: { params: { values: {} } },
|
|
@@ -770,6 +795,25 @@ async function runReview(app, args) {
|
|
|
770
795
|
}
|
|
771
796
|
}
|
|
772
797
|
}
|
|
798
|
+
async function resolveBackgroundReviewRoles(db, userId) {
|
|
799
|
+
if (!userId) return ["admin"];
|
|
800
|
+
try {
|
|
801
|
+
const roles = await db.getRepository("users.roles", userId).find({ raw: true });
|
|
802
|
+
const roleNames = (Array.isArray(roles) ? roles : []).map((role) => role == null ? void 0 : role.name).filter((name) => typeof name === "string" && !!name);
|
|
803
|
+
if (roleNames.length) return roleNames;
|
|
804
|
+
} catch {
|
|
805
|
+
}
|
|
806
|
+
try {
|
|
807
|
+
const mappings = await db.getRepository("rolesUsers").find({
|
|
808
|
+
filter: { userId },
|
|
809
|
+
raw: true
|
|
810
|
+
});
|
|
811
|
+
const roleNames = (Array.isArray(mappings) ? mappings : []).map((mapping) => mapping == null ? void 0 : mapping.roleName).filter((name) => typeof name === "string" && !!name);
|
|
812
|
+
if (roleNames.length) return roleNames;
|
|
813
|
+
} catch {
|
|
814
|
+
}
|
|
815
|
+
return ["admin"];
|
|
816
|
+
}
|
|
773
817
|
function buildReviewPrompt(args) {
|
|
774
818
|
const lines = [];
|
|
775
819
|
lines.push(`You are performing a code review on repository "${args.repo.get("name")}" (id=${args.repo.get("id")}).`);
|
|
@@ -785,6 +829,26 @@ function buildReviewPrompt(args) {
|
|
|
785
829
|
lines.push(
|
|
786
830
|
`Use the \`git_get_commit\` tool with repositoryId=${args.repo.get("id")} and commitHash=${args.commitSha} to fetch the diff.`
|
|
787
831
|
);
|
|
832
|
+
} else if (args.targetType === "folder") {
|
|
833
|
+
const folderLabel = args.folderPath || "/";
|
|
834
|
+
const ref = args.branch || "HEAD";
|
|
835
|
+
lines.push(
|
|
836
|
+
`Target: Folder \`${folderLabel}\` at ref \`${ref}\` \u2014 review the FULL current code inside this folder (not a diff).`
|
|
837
|
+
);
|
|
838
|
+
lines.push(
|
|
839
|
+
"The repository may contain multiple projects; only review files inside this folder and its subfolders."
|
|
840
|
+
);
|
|
841
|
+
lines.push(
|
|
842
|
+
`First call \`git_list_files\` with repositoryId=${args.repo.get("id")}, treePath="${args.folderPath || ""}", ref="${ref}", recursive=true to enumerate all files.`
|
|
843
|
+
);
|
|
844
|
+
lines.push(
|
|
845
|
+
`Then read each file worth reviewing with \`git_get_file_content\` (repositoryId=${args.repo.get(
|
|
846
|
+
"id"
|
|
847
|
+
)}, ref="${ref}").`
|
|
848
|
+
);
|
|
849
|
+
lines.push(
|
|
850
|
+
"Prioritize source code and configuration files; skip binaries, images, lock files, and generated/vendored code. If the listing is truncated, focus on the most important files."
|
|
851
|
+
);
|
|
788
852
|
} else {
|
|
789
853
|
lines.push(`Target: Branch ${args.branch}.`);
|
|
790
854
|
lines.push(
|
|
@@ -941,6 +1005,7 @@ function getFlowPostMode(flow) {
|
|
|
941
1005
|
function getInitialPostStatus(flow, targetType) {
|
|
942
1006
|
const postMode = getFlowPostMode(flow);
|
|
943
1007
|
if (postMode === "disabled") return "skipped";
|
|
1008
|
+
if (targetType === "folder") return "skipped";
|
|
944
1009
|
if (postMode === "auto" && targetType !== "mr") return "skipped";
|
|
945
1010
|
return "pending_approval";
|
|
946
1011
|
}
|
package/dist/server/ai-tools.js
CHANGED
|
@@ -253,6 +253,36 @@ function registerGitReviewAiTools(app) {
|
|
|
253
253
|
return (body == null ? void 0 : body.data) ?? body;
|
|
254
254
|
}
|
|
255
255
|
},
|
|
256
|
+
{
|
|
257
|
+
scope: "GENERAL",
|
|
258
|
+
execution: "backend",
|
|
259
|
+
defaultPermission: "ALLOW",
|
|
260
|
+
silence: false,
|
|
261
|
+
introduction: { title: "Git: List files" },
|
|
262
|
+
definition: {
|
|
263
|
+
name: "git_list_files",
|
|
264
|
+
description: "List files and folders of a cloned repository at a given ref. Set recursive=true with a treePath to enumerate every file under a folder, e.g. when reviewing the full code of a folder.",
|
|
265
|
+
schema: import_zod.z.object({
|
|
266
|
+
repositoryId: import_zod.z.number(),
|
|
267
|
+
treePath: import_zod.z.string().optional().describe("Folder path relative to repo root; omit for the root"),
|
|
268
|
+
ref: import_zod.z.string().optional().describe("Branch, tag or commit SHA; defaults to HEAD"),
|
|
269
|
+
recursive: import_zod.z.boolean().optional().describe("true to list all files under treePath recursively")
|
|
270
|
+
})
|
|
271
|
+
},
|
|
272
|
+
invoke: async (ctx, args) => {
|
|
273
|
+
const body = await runResourceAction(ctx, gitActions.fileTree, args, {
|
|
274
|
+
resource: "gitManager",
|
|
275
|
+
action: "fileTree"
|
|
276
|
+
});
|
|
277
|
+
const files = (body == null ? void 0 : body.data) ?? body ?? [];
|
|
278
|
+
const list = Array.isArray(files) ? files : [];
|
|
279
|
+
const MAX_ENTRIES = 500;
|
|
280
|
+
if (list.length > MAX_ENTRIES) {
|
|
281
|
+
return { files: list.slice(0, MAX_ENTRIES), totalCount: list.length, truncated: true };
|
|
282
|
+
}
|
|
283
|
+
return { files: list, totalCount: list.length, truncated: false };
|
|
284
|
+
}
|
|
285
|
+
},
|
|
256
286
|
{
|
|
257
287
|
scope: "GENERAL",
|
|
258
288
|
execution: "backend",
|
|
@@ -74,7 +74,8 @@ var gitCodeReviews_default = (0, import_database.defineCollection)({
|
|
|
74
74
|
enum: [
|
|
75
75
|
{ value: "mr", label: "Merge Request" },
|
|
76
76
|
{ value: "commit", label: "Commit" },
|
|
77
|
-
{ value: "branch", label: "Branch" }
|
|
77
|
+
{ value: "branch", label: "Branch" },
|
|
78
|
+
{ value: "folder", label: "Folder" }
|
|
78
79
|
]
|
|
79
80
|
}
|
|
80
81
|
},
|
|
@@ -96,6 +97,12 @@ var gitCodeReviews_default = (0, import_database.defineCollection)({
|
|
|
96
97
|
interface: "input",
|
|
97
98
|
uiSchema: { title: "Branch", type: "string", "x-component": "Input" }
|
|
98
99
|
},
|
|
100
|
+
{
|
|
101
|
+
type: "string",
|
|
102
|
+
name: "folderPath",
|
|
103
|
+
interface: "input",
|
|
104
|
+
uiSchema: { title: "Folder Path", type: "string", "x-component": "Input" }
|
|
105
|
+
},
|
|
99
106
|
{
|
|
100
107
|
type: "string",
|
|
101
108
|
name: "headSha",
|
package/dist/server/plugin.js
CHANGED
|
@@ -180,9 +180,7 @@ class PluginGitManagerServer extends import_server.Plugin {
|
|
|
180
180
|
});
|
|
181
181
|
this.app.acl.registerSnippet({
|
|
182
182
|
name: `pm.${this.name}.repositories`,
|
|
183
|
-
actions: [
|
|
184
|
-
"gitRepositories:*"
|
|
185
|
-
]
|
|
183
|
+
actions: ["gitRepositories:*"]
|
|
186
184
|
});
|
|
187
185
|
this.app.acl.registerSnippet({
|
|
188
186
|
name: `pm.${this.name}.manage`,
|
|
@@ -241,13 +239,22 @@ async function ensureAutoReviewFlowSchema(app) {
|
|
|
241
239
|
const queryInterface = (_b = sequelize == null ? void 0 : sequelize.getQueryInterface) == null ? void 0 : _b.call(sequelize);
|
|
242
240
|
if (!queryInterface) return;
|
|
243
241
|
const tablePrefix = ((_c = app.db.options) == null ? void 0 : _c.tablePrefix) || "";
|
|
244
|
-
const
|
|
245
|
-
const
|
|
246
|
-
if (
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
242
|
+
const repoTable = `${tablePrefix}gitRepositories`;
|
|
243
|
+
const repoInfo = await queryInterface.describeTable(repoTable).catch(() => null);
|
|
244
|
+
if (repoInfo && !repoInfo.autoReviewFlowId) {
|
|
245
|
+
await queryInterface.addColumn(repoTable, "autoReviewFlowId", {
|
|
246
|
+
type: import_sequelize.DataTypes.INTEGER,
|
|
247
|
+
allowNull: true
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
const reviewTable = `${tablePrefix}gitCodeReviews`;
|
|
251
|
+
const reviewInfo = await queryInterface.describeTable(reviewTable).catch(() => null);
|
|
252
|
+
if (reviewInfo && !reviewInfo.folderPath) {
|
|
253
|
+
await queryInterface.addColumn(reviewTable, "folderPath", {
|
|
254
|
+
type: import_sequelize.DataTypes.STRING,
|
|
255
|
+
allowNull: true
|
|
256
|
+
});
|
|
257
|
+
}
|
|
251
258
|
}
|
|
252
259
|
var plugin_default = PluginGitManagerServer;
|
|
253
260
|
// Annotate the CommonJS export names for ESM import in node:
|
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.13",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"main": "dist/server/index.js",
|
|
9
9
|
"files": [
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useEffect, useState, useCallback, useRef } from 'react';
|
|
1
|
+
import React, { useEffect, useState, useCallback, useMemo, useRef } from 'react';
|
|
2
2
|
import { Tree, Empty, Spin, Typography, Select, Space, Breadcrumb, Input, theme } from 'antd';
|
|
3
3
|
import {
|
|
4
4
|
FileOutlined,
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
} from '@ant-design/icons';
|
|
11
11
|
import { useApp } from '@nocobase/client-v2';
|
|
12
12
|
import { useGitManager } from '../context/GitManagerContext';
|
|
13
|
+
import { RunReviewButton } from './RunReviewButton';
|
|
13
14
|
import { useT } from '../locale';
|
|
14
15
|
|
|
15
16
|
const { Text } = Typography;
|
|
@@ -40,10 +41,25 @@ function getFileIcon(name: string, type: string) {
|
|
|
40
41
|
function getLanguage(filename: string): string {
|
|
41
42
|
const ext = filename.split('.').pop()?.toLowerCase() || '';
|
|
42
43
|
const map: Record<string, string> = {
|
|
43
|
-
ts: 'typescript',
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
ts: 'typescript',
|
|
45
|
+
tsx: 'typescript',
|
|
46
|
+
js: 'javascript',
|
|
47
|
+
jsx: 'javascript',
|
|
48
|
+
json: 'json',
|
|
49
|
+
md: 'markdown',
|
|
50
|
+
html: 'html',
|
|
51
|
+
css: 'css',
|
|
52
|
+
scss: 'scss',
|
|
53
|
+
py: 'python',
|
|
54
|
+
sh: 'bash',
|
|
55
|
+
yml: 'yaml',
|
|
56
|
+
yaml: 'yaml',
|
|
57
|
+
sql: 'sql',
|
|
58
|
+
xml: 'xml',
|
|
59
|
+
java: 'java',
|
|
60
|
+
go: 'go',
|
|
61
|
+
rs: 'rust',
|
|
62
|
+
rb: 'ruby',
|
|
47
63
|
};
|
|
48
64
|
return map[ext] || 'text';
|
|
49
65
|
}
|
|
@@ -67,6 +83,7 @@ export const FileExplorer: React.FC = () => {
|
|
|
67
83
|
const [loading, setLoading] = useState(false);
|
|
68
84
|
const [fileContent, setFileContent] = useState<string | null>(null);
|
|
69
85
|
const [selectedFile, setSelectedFile] = useState<string | null>(null);
|
|
86
|
+
const [selectedFolder, setSelectedFolder] = useState<string | null>(null);
|
|
70
87
|
const [currentRef, setCurrentRef] = useState('HEAD');
|
|
71
88
|
const [searchText, setSearchText] = useState('');
|
|
72
89
|
const [debouncedSearch, setDebouncedSearch] = useState('');
|
|
@@ -81,8 +98,12 @@ export const FileExplorer: React.FC = () => {
|
|
|
81
98
|
params: { repositoryId: selectedRepo.id, ref, treePath },
|
|
82
99
|
});
|
|
83
100
|
const responseData = data?.data || data || [];
|
|
84
|
-
const list = Array.isArray(responseData)
|
|
85
|
-
|
|
101
|
+
const list = Array.isArray(responseData)
|
|
102
|
+
? responseData
|
|
103
|
+
: Array.isArray(responseData?.data)
|
|
104
|
+
? responseData.data
|
|
105
|
+
: [];
|
|
106
|
+
|
|
86
107
|
return list.map((item: any) => ({
|
|
87
108
|
key: item.path,
|
|
88
109
|
title: (
|
|
@@ -123,6 +144,7 @@ export const FileExplorer: React.FC = () => {
|
|
|
123
144
|
refreshBranches();
|
|
124
145
|
setFileContent(null);
|
|
125
146
|
setSelectedFile(null);
|
|
147
|
+
setSelectedFolder(null);
|
|
126
148
|
} else {
|
|
127
149
|
setTreeData([]);
|
|
128
150
|
}
|
|
@@ -149,7 +171,11 @@ export const FileExplorer: React.FC = () => {
|
|
|
149
171
|
|
|
150
172
|
const onSelect = async (_: any, info: any) => {
|
|
151
173
|
const node = info.node;
|
|
152
|
-
if (!node.isLeaf)
|
|
174
|
+
if (!node.isLeaf) {
|
|
175
|
+
setSelectedFolder((prev) => (prev === node.filePath ? null : node.filePath));
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
setSelectedFolder(null);
|
|
153
179
|
setContentLoading(true);
|
|
154
180
|
setSelectedFile(node.filePath);
|
|
155
181
|
try {
|
|
@@ -173,6 +199,16 @@ export const FileExplorer: React.FC = () => {
|
|
|
173
199
|
return () => clearTimeout(debounceRef.current);
|
|
174
200
|
}, [searchText]);
|
|
175
201
|
|
|
202
|
+
const folderTarget = useMemo(
|
|
203
|
+
() => ({
|
|
204
|
+
type: 'folder' as const,
|
|
205
|
+
repositoryId: selectedRepo?.id ?? 0,
|
|
206
|
+
folderPath: selectedFolder ?? '',
|
|
207
|
+
ref: currentRef,
|
|
208
|
+
}),
|
|
209
|
+
[selectedRepo?.id, selectedFolder, currentRef],
|
|
210
|
+
);
|
|
211
|
+
|
|
176
212
|
if (!selectedRepo) {
|
|
177
213
|
return <Empty description={t('No repository selected')} />;
|
|
178
214
|
}
|
|
@@ -206,6 +242,7 @@ export const FileExplorer: React.FC = () => {
|
|
|
206
242
|
setCurrentRef(val);
|
|
207
243
|
setFileContent(null);
|
|
208
244
|
setSelectedFile(null);
|
|
245
|
+
setSelectedFolder(null);
|
|
209
246
|
}}
|
|
210
247
|
options={branchList.map((b) => ({ label: b, value: b }))}
|
|
211
248
|
placeholder="Branch"
|
|
@@ -216,18 +253,31 @@ export const FileExplorer: React.FC = () => {
|
|
|
216
253
|
allowClear
|
|
217
254
|
onChange={(e) => setSearchText(e.target.value)}
|
|
218
255
|
/>
|
|
256
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
|
|
257
|
+
<Text
|
|
258
|
+
type="secondary"
|
|
259
|
+
ellipsis
|
|
260
|
+
title={selectedFolder || t('Entire repository')}
|
|
261
|
+
style={{ flex: 1, minWidth: 0, fontSize: 12 }}
|
|
262
|
+
>
|
|
263
|
+
{selectedFolder || t('Entire repository')}
|
|
264
|
+
</Text>
|
|
265
|
+
<RunReviewButton target={folderTarget} />
|
|
266
|
+
</div>
|
|
219
267
|
</Space>
|
|
220
268
|
</div>
|
|
221
269
|
<div style={{ flex: 1, overflow: 'auto', padding: '4px 0' }}>
|
|
222
270
|
{loading ? (
|
|
223
|
-
<div style={{ textAlign: 'center', padding: 40 }}
|
|
271
|
+
<div style={{ textAlign: 'center', padding: 40 }}>
|
|
272
|
+
<Spin />
|
|
273
|
+
</div>
|
|
224
274
|
) : (
|
|
225
275
|
<Tree
|
|
226
276
|
showIcon
|
|
227
277
|
treeData={filteredTree}
|
|
228
278
|
loadData={onLoadData}
|
|
229
279
|
onSelect={onSelect}
|
|
230
|
-
selectedKeys={selectedFile ? [selectedFile] : []}
|
|
280
|
+
selectedKeys={selectedFile ? [selectedFile] : selectedFolder ? [selectedFolder] : []}
|
|
231
281
|
style={{ fontSize: 13 }}
|
|
232
282
|
blockNode
|
|
233
283
|
/>
|
|
@@ -260,7 +310,9 @@ export const FileExplorer: React.FC = () => {
|
|
|
260
310
|
</div>
|
|
261
311
|
<div style={{ flex: 1, overflow: 'auto' }}>
|
|
262
312
|
{contentLoading ? (
|
|
263
|
-
<div style={{ textAlign: 'center', padding: 40 }}
|
|
313
|
+
<div style={{ textAlign: 'center', padding: 40 }}>
|
|
314
|
+
<Spin />
|
|
315
|
+
</div>
|
|
264
316
|
) : (
|
|
265
317
|
<pre
|
|
266
318
|
style={{
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useState } from 'react';
|
|
2
2
|
import {
|
|
3
|
-
Table,
|
|
3
|
+
Table,
|
|
4
|
+
Button,
|
|
5
|
+
Space,
|
|
6
|
+
Modal,
|
|
7
|
+
Form,
|
|
8
|
+
Input,
|
|
9
|
+
Select,
|
|
10
|
+
Switch,
|
|
11
|
+
Tag,
|
|
12
|
+
Popconfirm,
|
|
13
|
+
message,
|
|
14
|
+
Empty,
|
|
15
|
+
Tooltip,
|
|
4
16
|
} from 'antd';
|
|
5
17
|
import { PlusOutlined, EditOutlined, DeleteOutlined, BranchesOutlined } from '@ant-design/icons';
|
|
6
18
|
import { useApp } from '@nocobase/client-v2';
|
|
@@ -8,6 +20,7 @@ import { useGitManager } from '../context/GitManagerContext';
|
|
|
8
20
|
import { AIEmployeeSelect } from './AIEmployeeSelect';
|
|
9
21
|
import { LLMServiceSelect } from './LLMServiceSelect';
|
|
10
22
|
import { LLMModelSelect } from './LLMModelSelect';
|
|
23
|
+
import { REVIEW_PROMPT_TEMPLATES } from '../promptTemplates';
|
|
11
24
|
import { useT } from '../locale';
|
|
12
25
|
|
|
13
26
|
const TRIGGER_LABELS: Record<string, string> = {
|
|
@@ -22,15 +35,6 @@ const POST_LABELS: Record<string, string> = {
|
|
|
22
35
|
disabled: 'Disabled',
|
|
23
36
|
};
|
|
24
37
|
|
|
25
|
-
const DEFAULT_INSTRUCTION = `Please review the code changes with a focus on:
|
|
26
|
-
1. Best Practices & Style:
|
|
27
|
-
- C#/VB.NET: Follow standard naming conventions (PascalCase for methods/properties, camelCase for fields). Ensure proper use of async/await (avoid .Result/.Wait()). Use LINQ efficiently.
|
|
28
|
-
- JS/TS: Use strict equality (===), prefer const/let. Ensure TypeScript types are explicit and avoid 'any'.
|
|
29
|
-
2. Performance: Watch out for N+1 queries, unnecessary loops, and memory leaks.
|
|
30
|
-
3. Security: Identify potential SQL injections, XSS vulnerabilities, and improper data validation.
|
|
31
|
-
4. Maintainability: Check for readability, SOLID principles, and DRY. Ensure meaningful naming.
|
|
32
|
-
5. Error Handling: Verify that exceptions are properly caught, handled, and logged.`;
|
|
33
|
-
|
|
34
38
|
export const ReviewFlows: React.FC = () => {
|
|
35
39
|
const t = useT();
|
|
36
40
|
const api = useApp().apiClient;
|
|
@@ -39,6 +43,7 @@ export const ReviewFlows: React.FC = () => {
|
|
|
39
43
|
const [loading, setLoading] = useState(false);
|
|
40
44
|
const [editing, setEditing] = useState<any | null>(null);
|
|
41
45
|
const [open, setOpen] = useState(false);
|
|
46
|
+
const [templateKey, setTemplateKey] = useState<string | undefined>();
|
|
42
47
|
const [form] = Form.useForm();
|
|
43
48
|
|
|
44
49
|
const load = useCallback(async () => {
|
|
@@ -76,6 +81,7 @@ export const ReviewFlows: React.FC = () => {
|
|
|
76
81
|
}
|
|
77
82
|
setOpen(false);
|
|
78
83
|
setEditing(null);
|
|
84
|
+
setTemplateKey(undefined);
|
|
79
85
|
form.resetFields();
|
|
80
86
|
load();
|
|
81
87
|
} catch (err: any) {
|
|
@@ -97,17 +103,19 @@ export const ReviewFlows: React.FC = () => {
|
|
|
97
103
|
const openCreate = () => {
|
|
98
104
|
setEditing(null);
|
|
99
105
|
form.resetFields();
|
|
106
|
+
setTemplateKey('application');
|
|
100
107
|
form.setFieldsValue({
|
|
101
108
|
enabled: true,
|
|
102
109
|
triggerMode: 'manual',
|
|
103
110
|
postMode: 'manual',
|
|
104
|
-
instructions:
|
|
111
|
+
instructions: REVIEW_PROMPT_TEMPLATES.find((tpl) => tpl.key === 'application')?.text,
|
|
105
112
|
});
|
|
106
113
|
setOpen(true);
|
|
107
114
|
};
|
|
108
115
|
|
|
109
116
|
const openEdit = (record: any) => {
|
|
110
117
|
setEditing(record);
|
|
118
|
+
setTemplateKey(undefined);
|
|
111
119
|
form.setFieldsValue(record);
|
|
112
120
|
setOpen(true);
|
|
113
121
|
};
|
|
@@ -200,6 +208,7 @@ export const ReviewFlows: React.FC = () => {
|
|
|
200
208
|
onCancel={() => {
|
|
201
209
|
setOpen(false);
|
|
202
210
|
setEditing(null);
|
|
211
|
+
setTemplateKey(undefined);
|
|
203
212
|
form.resetFields();
|
|
204
213
|
}}
|
|
205
214
|
onOk={handleSave}
|
|
@@ -268,6 +277,19 @@ export const ReviewFlows: React.FC = () => {
|
|
|
268
277
|
<Form.Item name="branchFilter" label={t('Branch Filter (regex, optional)')}>
|
|
269
278
|
<Input placeholder="^(feature|hotfix)/.*$" />
|
|
270
279
|
</Form.Item>
|
|
280
|
+
<Form.Item label={t('Prompt template')} extra={t('Selecting a template replaces the instructions text')}>
|
|
281
|
+
<Select
|
|
282
|
+
allowClear
|
|
283
|
+
value={templateKey}
|
|
284
|
+
placeholder={t('Load a default prompt by code type')}
|
|
285
|
+
options={REVIEW_PROMPT_TEMPLATES.map((tpl) => ({ value: tpl.key, label: t(tpl.label) }))}
|
|
286
|
+
onChange={(key) => {
|
|
287
|
+
setTemplateKey(key);
|
|
288
|
+
const tpl = REVIEW_PROMPT_TEMPLATES.find((item) => item.key === key);
|
|
289
|
+
if (tpl) form.setFieldsValue({ instructions: tpl.text });
|
|
290
|
+
}}
|
|
291
|
+
/>
|
|
292
|
+
</Form.Item>
|
|
271
293
|
<Form.Item name="instructions" label={t('Additional Instructions (optional)')}>
|
|
272
294
|
<Input.TextArea rows={8} placeholder={t('Extra guidance appended to every review prompt')} />
|
|
273
295
|
</Form.Item>
|
|
@@ -1,10 +1,30 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import {
|
|
3
|
-
Table,
|
|
3
|
+
Table,
|
|
4
|
+
Tag,
|
|
5
|
+
Drawer,
|
|
6
|
+
Space,
|
|
7
|
+
Button,
|
|
8
|
+
Typography,
|
|
9
|
+
Empty,
|
|
10
|
+
Tooltip,
|
|
11
|
+
Popconfirm,
|
|
12
|
+
message,
|
|
13
|
+
Select,
|
|
14
|
+
Tabs,
|
|
15
|
+
Input,
|
|
16
|
+
Alert,
|
|
17
|
+
theme,
|
|
4
18
|
} from 'antd';
|
|
5
19
|
import {
|
|
6
|
-
RobotOutlined,
|
|
7
|
-
|
|
20
|
+
RobotOutlined,
|
|
21
|
+
ReloadOutlined,
|
|
22
|
+
CheckOutlined,
|
|
23
|
+
CloseOutlined,
|
|
24
|
+
ClockCircleOutlined,
|
|
25
|
+
FileTextOutlined,
|
|
26
|
+
ExportOutlined,
|
|
27
|
+
EditOutlined,
|
|
8
28
|
} from '@ant-design/icons';
|
|
9
29
|
import { useApp } from '@nocobase/client-v2';
|
|
10
30
|
import { useGitManager } from '../context/GitManagerContext';
|
|
@@ -30,9 +50,7 @@ const POST_STATUS_COLOR: Record<string, string> = {
|
|
|
30
50
|
rejected: 'red',
|
|
31
51
|
};
|
|
32
52
|
|
|
33
|
-
export const ReviewHistory: React.FC<{ initialFilter?: 'all' | 'pending_approval' }> = ({
|
|
34
|
-
initialFilter = 'all',
|
|
35
|
-
}) => {
|
|
53
|
+
export const ReviewHistory: React.FC<{ initialFilter?: 'all' | 'pending_approval' }> = ({ initialFilter = 'all' }) => {
|
|
36
54
|
const t = useT();
|
|
37
55
|
const { token } = useToken();
|
|
38
56
|
const api = useApp().apiClient;
|
|
@@ -40,7 +58,9 @@ export const ReviewHistory: React.FC<{ initialFilter?: 'all' | 'pending_approval
|
|
|
40
58
|
const [reviews, setReviews] = useState<any[]>([]);
|
|
41
59
|
const [loading, setLoading] = useState(false);
|
|
42
60
|
const [statusFilter, setStatusFilter] = useState<string>('all');
|
|
43
|
-
const [postFilter, setPostFilter] = useState<string>(
|
|
61
|
+
const [postFilter, setPostFilter] = useState<string>(
|
|
62
|
+
initialFilter === 'pending_approval' ? 'pending_approval' : 'all',
|
|
63
|
+
);
|
|
44
64
|
const [triggerFilter, setTriggerFilter] = useState<string>('all');
|
|
45
65
|
const [selected, setSelected] = useState<any | null>(null);
|
|
46
66
|
const [editing, setEditing] = useState(false);
|
|
@@ -154,6 +174,15 @@ export const ReviewHistory: React.FC<{ initialFilter?: 'all' | 'pending_approval
|
|
|
154
174
|
</Space>
|
|
155
175
|
);
|
|
156
176
|
}
|
|
177
|
+
if (record.targetType === 'folder') {
|
|
178
|
+
return (
|
|
179
|
+
<Space size={4}>
|
|
180
|
+
<Text strong>{repoName}</Text>
|
|
181
|
+
<Text type="secondary">{record.folderPath || '/'}</Text>
|
|
182
|
+
{record.branch && <Tag style={{ fontSize: 11 }}>{record.branch}</Tag>}
|
|
183
|
+
</Space>
|
|
184
|
+
);
|
|
185
|
+
}
|
|
157
186
|
return (
|
|
158
187
|
<Space size={4}>
|
|
159
188
|
<Text strong>{repoName}</Text>
|
|
@@ -497,12 +526,19 @@ const ReviewDetailView: React.FC<{
|
|
|
497
526
|
<Meta label={t('Status')} value={review.status} />
|
|
498
527
|
<Meta label={t('Post Status')} value={review.postStatus} />
|
|
499
528
|
<Meta label={t('Trigger Type')} value={review.targetType} />
|
|
529
|
+
{review.targetType === 'folder' && <Meta label={t('Folder')} value={review.folderPath || '/'} />}
|
|
500
530
|
<Meta label={t('Triggered By')} value={review.triggeredBy} />
|
|
501
531
|
<Meta label={t('Reviewed SHA')} value={review.headSha || '—'} />
|
|
502
532
|
<Meta label={t('Latest SHA')} value={review.latestSha || '—'} />
|
|
503
533
|
<Meta label={t('Started At')} value={review.startedAt && new Date(review.startedAt).toLocaleString()} />
|
|
504
|
-
<Meta
|
|
505
|
-
|
|
534
|
+
<Meta
|
|
535
|
+
label={t('Finished At')}
|
|
536
|
+
value={review.finishedAt && new Date(review.finishedAt).toLocaleString()}
|
|
537
|
+
/>
|
|
538
|
+
<Meta
|
|
539
|
+
label={t('Duration')}
|
|
540
|
+
value={review.durationMs ? `${(review.durationMs / 1000).toFixed(1)}s` : '—'}
|
|
541
|
+
/>
|
|
506
542
|
<Meta label={t('Posted Note ID')} value={review.postedNoteId || '—'} />
|
|
507
543
|
<Meta label={t('Approved By')} value={review.approvedBy || '—'} />
|
|
508
544
|
<Meta
|