plugin-git-manager 1.2.11 → 1.2.12
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.
|
@@ -622,13 +622,22 @@ async function runReview(app, args) {
|
|
|
622
622
|
values: { sessionId }
|
|
623
623
|
});
|
|
624
624
|
const prompt = buildReviewPrompt(args);
|
|
625
|
+
const currentRoles = await resolveBackgroundReviewRoles(db, args.userId);
|
|
626
|
+
const currentUser = args.userId ? {
|
|
627
|
+
id: args.userId,
|
|
628
|
+
roles: currentRoles.map((name) => ({ name }))
|
|
629
|
+
} : null;
|
|
625
630
|
const syntheticCtx = {
|
|
626
631
|
app,
|
|
627
632
|
db,
|
|
628
633
|
isBackgroundReview: true,
|
|
629
634
|
reviewTargetRepositoryId: args.repo.get("id"),
|
|
630
|
-
state: {
|
|
631
|
-
|
|
635
|
+
state: {
|
|
636
|
+
currentUser,
|
|
637
|
+
currentRole: currentRoles[0],
|
|
638
|
+
currentRoles
|
|
639
|
+
},
|
|
640
|
+
auth: { user: currentUser || { id: null } },
|
|
632
641
|
req: { headers: { "x-timezone": "+00:00", "x-locale": "en-US" } },
|
|
633
642
|
// AIEmployee.getSystemPrompt reads ctx.action.params.values.important
|
|
634
643
|
action: { params: { values: {} } },
|
|
@@ -770,6 +779,25 @@ async function runReview(app, args) {
|
|
|
770
779
|
}
|
|
771
780
|
}
|
|
772
781
|
}
|
|
782
|
+
async function resolveBackgroundReviewRoles(db, userId) {
|
|
783
|
+
if (!userId) return ["admin"];
|
|
784
|
+
try {
|
|
785
|
+
const roles = await db.getRepository("users.roles", userId).find({ raw: true });
|
|
786
|
+
const roleNames = (Array.isArray(roles) ? roles : []).map((role) => role == null ? void 0 : role.name).filter((name) => typeof name === "string" && !!name);
|
|
787
|
+
if (roleNames.length) return roleNames;
|
|
788
|
+
} catch {
|
|
789
|
+
}
|
|
790
|
+
try {
|
|
791
|
+
const mappings = await db.getRepository("rolesUsers").find({
|
|
792
|
+
filter: { userId },
|
|
793
|
+
raw: true
|
|
794
|
+
});
|
|
795
|
+
const roleNames = (Array.isArray(mappings) ? mappings : []).map((mapping) => mapping == null ? void 0 : mapping.roleName).filter((name) => typeof name === "string" && !!name);
|
|
796
|
+
if (roleNames.length) return roleNames;
|
|
797
|
+
} catch {
|
|
798
|
+
}
|
|
799
|
+
return ["admin"];
|
|
800
|
+
}
|
|
773
801
|
function buildReviewPrompt(args) {
|
|
774
802
|
const lines = [];
|
|
775
803
|
lines.push(`You are performing a code review on repository "${args.repo.get("name")}" (id=${args.repo.get("id")}).`);
|
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.12",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"main": "dist/server/index.js",
|
|
9
9
|
"files": [
|
|
@@ -744,6 +744,13 @@ async function runReview(app: Application, args: RunReviewArgs) {
|
|
|
744
744
|
});
|
|
745
745
|
|
|
746
746
|
const prompt = buildReviewPrompt(args);
|
|
747
|
+
const currentRoles = await resolveBackgroundReviewRoles(db, args.userId);
|
|
748
|
+
const currentUser = args.userId
|
|
749
|
+
? {
|
|
750
|
+
id: args.userId,
|
|
751
|
+
roles: currentRoles.map((name) => ({ name })),
|
|
752
|
+
}
|
|
753
|
+
: null;
|
|
747
754
|
|
|
748
755
|
// Synthesize a minimal ctx-shaped object that AIEmployee accepts.
|
|
749
756
|
// It needs `app`, `db`, `state.currentUser`, `get(headerName)`, `req.headers`,
|
|
@@ -754,8 +761,12 @@ async function runReview(app: Application, args: RunReviewArgs) {
|
|
|
754
761
|
db,
|
|
755
762
|
isBackgroundReview: true,
|
|
756
763
|
reviewTargetRepositoryId: args.repo.get('id'),
|
|
757
|
-
state: {
|
|
758
|
-
|
|
764
|
+
state: {
|
|
765
|
+
currentUser,
|
|
766
|
+
currentRole: currentRoles[0],
|
|
767
|
+
currentRoles,
|
|
768
|
+
},
|
|
769
|
+
auth: { user: currentUser || { id: null } },
|
|
759
770
|
req: { headers: { 'x-timezone': '+00:00', 'x-locale': 'en-US' } },
|
|
760
771
|
// AIEmployee.getSystemPrompt reads ctx.action.params.values.important
|
|
761
772
|
action: { params: { values: {} } },
|
|
@@ -912,6 +923,36 @@ async function runReview(app: Application, args: RunReviewArgs) {
|
|
|
912
923
|
}
|
|
913
924
|
}
|
|
914
925
|
|
|
926
|
+
async function resolveBackgroundReviewRoles(db: any, userId?: number | string | null): Promise<string[]> {
|
|
927
|
+
if (!userId) return ['admin'];
|
|
928
|
+
|
|
929
|
+
try {
|
|
930
|
+
const roles = await db.getRepository('users.roles', userId).find({ raw: true });
|
|
931
|
+
const roleNames = (Array.isArray(roles) ? roles : [])
|
|
932
|
+
.map((role: any) => role?.name)
|
|
933
|
+
.filter((name: unknown): name is string => typeof name === 'string' && !!name);
|
|
934
|
+
if (roleNames.length) return roleNames;
|
|
935
|
+
} catch {
|
|
936
|
+
// Fall back to the through table below for apps where the association
|
|
937
|
+
// repository is unavailable in a background worker context.
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
try {
|
|
941
|
+
const mappings = await db.getRepository('rolesUsers').find({
|
|
942
|
+
filter: { userId },
|
|
943
|
+
raw: true,
|
|
944
|
+
});
|
|
945
|
+
const roleNames = (Array.isArray(mappings) ? mappings : [])
|
|
946
|
+
.map((mapping: any) => mapping?.roleName)
|
|
947
|
+
.filter((name: unknown): name is string => typeof name === 'string' && !!name);
|
|
948
|
+
if (roleNames.length) return roleNames;
|
|
949
|
+
} catch {
|
|
950
|
+
// Keep the synthetic ctx valid even if role lookup is unavailable.
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
return ['admin'];
|
|
954
|
+
}
|
|
955
|
+
|
|
915
956
|
function buildReviewPrompt(args: RunReviewArgs): string {
|
|
916
957
|
const lines: string[] = [];
|
|
917
958
|
lines.push(`You are performing a code review on repository "${args.repo.get('name')}" (id=${args.repo.get('id')}).`);
|