plugin-git-manager 1.2.26 → 1.2.28
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/README.md +133 -108
- package/client-v2.d.ts +2 -2
- package/client-v2.js +1 -1
- package/client.d.ts +3 -3
- package/client.js +1 -1
- package/dist/client/{326.90c276058682b536.js → 313.d38fc1d40c4589b9.js} +1 -1
- package/dist/client/900.a48beac7e2ebee7d.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/156.445366026c1cc9a8.js +10 -0
- package/dist/client-v2/{326.42b7b53651ffab3a.js → 313.3c867179c3a1e817.js} +1 -1
- package/dist/client-v2/434.19c7579c06b9077c.js +10 -0
- package/dist/client-v2/900.e6155002a9c97e7f.js +10 -0
- package/dist/client-v2/928.bba701b5a1ece58e.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +9 -8
- package/dist/locale/en-US.json +307 -297
- package/dist/locale/vi-VN.json +295 -292
- package/dist/locale/zh-CN.json +61 -51
- package/dist/node_modules/simple-git/dist/cjs/index.js +25 -25
- package/dist/node_modules/simple-git/package.json +1 -1
- package/dist/node_modules/zod/index.cjs +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/actions/git-actions.js +90 -36
- package/dist/server/actions/gitlab-api.js +4 -2
- package/dist/server/actions/poller.js +5 -2
- package/dist/server/actions/review.js +20 -10
- package/dist/server/plugin.js +6 -4
- package/dist/server/poller.js +46 -45
- package/dist/server/request-method-policy.js +75 -0
- package/dist/server/services/registry-content-service.js +23 -10
- package/dist/server/utils/get-repo-account.js +3 -2
- package/dist/server/utils/url-security.js +24 -0
- package/package.json +61 -43
- package/server.d.ts +2 -2
- package/server.js +1 -1
- package/src/client/__tests__/RunReviewButton.test.tsx +73 -0
- package/src/client/ai-context.tsx +114 -114
- package/src/client/components/AIEmployeeSelect.tsx +63 -63
- package/src/client/components/CommitHistory.tsx +374 -374
- package/src/client/components/FileExplorer.tsx +386 -386
- package/src/client/components/GitAccounts.tsx +179 -179
- package/src/client/components/GitManagerSettings.tsx +160 -160
- package/src/client/components/GitOperations.tsx +220 -220
- package/src/client/components/LLMModelSelect.tsx +63 -63
- package/src/client/components/LLMServiceSelect.tsx +58 -58
- package/src/client/components/MarkdownView.tsx +80 -80
- package/src/client/components/MergeRequests.tsx +790 -790
- package/src/client/components/PollingStatus.tsx +225 -225
- package/src/client/components/RepositoryConfig.tsx +335 -335
- package/src/client/components/RepositoryPermissions.tsx +123 -123
- package/src/client/components/ReviewFlows.tsx +303 -303
- package/src/client/components/ReviewHistory.tsx +566 -566
- package/src/client/components/RunReviewButton.tsx +63 -55
- package/src/client/context/GitManagerContext.tsx +92 -92
- package/src/client/index.tsx +91 -82
- package/src/client/locale.ts +9 -9
- package/src/client/promptTemplates.ts +31 -31
- package/src/client-v2/ai-context.tsx +99 -0
- package/src/client-v2/components/SubtreeSplits.tsx +547 -547
- package/src/client-v2/index.tsx +1 -1
- package/src/client-v2/locale.ts +8 -8
- package/src/client-v2/plugin.tsx +67 -39
- package/src/index.ts +2 -2
- package/src/locale/en-US.json +307 -297
- package/src/locale/vi-VN.json +295 -292
- package/src/locale/zh-CN.json +61 -51
- package/src/server/__tests__/git-actions.test.ts +24 -24
- package/src/server/__tests__/git-security.test.ts +170 -0
- package/src/server/__tests__/plugin-url-security.test.ts +17 -17
- package/src/server/__tests__/poller-lifecycle.test.ts +71 -0
- package/src/server/__tests__/poller.test.ts +37 -37
- package/src/server/__tests__/repository-access.test.ts +752 -752
- package/src/server/__tests__/review.test.ts +137 -137
- package/src/server/__tests__/role-permissions.test.ts +147 -147
- package/src/server/__tests__/smoke.test.ts +139 -17
- package/src/server/__tests__/subtree.test.ts +85 -85
- package/src/server/actions/git-actions.ts +540 -480
- package/src/server/actions/gitlab-api.ts +422 -411
- package/src/server/actions/poller.ts +39 -27
- package/src/server/actions/review.ts +1388 -1369
- package/src/server/actions/role-permissions.ts +321 -321
- package/src/server/actions/subtree.ts +508 -508
- package/src/server/ai-tools.ts +319 -319
- package/src/server/collections/gitAccounts.ts +56 -56
- package/src/server/collections/gitCodeReviews.ts +199 -199
- package/src/server/collections/gitRepositories.ts +87 -87
- package/src/server/collections/gitReviewFlows.ts +108 -108
- package/src/server/collections/gitSubtreeConfigs.ts +38 -38
- package/src/server/collections/gitSubtreeRuns.ts +30 -30
- package/src/server/index.ts +2 -2
- package/src/server/migrations/20260508000000-add-auto-review-flow-id.ts +29 -29
- package/src/server/migrations/20260712000000-add-git-accounts.ts +198 -198
- package/src/server/migrations/20260730000000-migrate-legacy-repository-permissions.ts +81 -81
- package/src/server/plugin.ts +372 -361
- package/src/server/poller.ts +351 -352
- package/src/server/repository-access.ts +773 -773
- package/src/server/request-method-policy.ts +55 -0
- package/src/server/services/__tests__/registry-content-service.test.ts +359 -345
- package/src/server/services/registry-content-service.ts +33 -11
- package/src/server/utils/__tests__/redact.test.ts +56 -56
- package/src/server/utils/__tests__/url-security.test.ts +85 -85
- package/src/server/utils/get-repo-account.ts +51 -41
- package/src/server/utils/gitlab-url.ts +38 -38
- package/src/server/utils/redact.ts +87 -87
- package/src/server/utils/url-security.ts +128 -95
- package/dist/client/900.acf7d1fa22f95e71.js +0 -10
- package/dist/client-v2/434.7a27051db18526c0.js +0 -10
- package/dist/client-v2/900.f32b9dc85249fc0a.js +0 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"zod","version":"4.3.5","type":"module","license":"MIT","author":"Colin McDonnell <zod@colinhacks.com>","description":"TypeScript-first schema declaration and validation library with static type inference","homepage":"https://zod.dev","llms":"https://zod.dev/llms.txt","llmsFull":"https://zod.dev/llms-full.txt","mcpServer":"https://mcp.inkeep.com/zod/mcp","funding":"https://github.com/sponsors/colinhacks","sideEffects":false,"files":["src","**/*.js","**/*.mjs","**/*.cjs","**/*.d.ts","**/*.d.mts","**/*.d.cts","**/package.json"],"keywords":["typescript","schema","validation","type","inference"],"main":"./index.cjs","types":"./index.d.cts","module":"./index.js","zshy":{"exports":{"./package.json":"./package.json",".":"./src/index.ts","./mini":"./src/mini/index.ts","./locales":"./src/locales/index.ts","./v3":"./src/v3/index.ts","./v4":"./src/v4/index.ts","./v4-mini":"./src/v4-mini/index.ts","./v4/mini":"./src/v4/mini/index.ts","./v4/core":"./src/v4/core/index.ts","./v4/locales":"./src/v4/locales/index.ts","./v4/locales/*":"./src/v4/locales/*"},"conditions":{"@zod/source":"src"}},"exports":{"./package.json":"./package.json",".":{"@zod/source":"./src/index.ts","types":"./index.d.cts","import":"./index.js","require":"./index.cjs"},"./mini":{"@zod/source":"./src/mini/index.ts","types":"./mini/index.d.cts","import":"./mini/index.js","require":"./mini/index.cjs"},"./locales":{"@zod/source":"./src/locales/index.ts","types":"./locales/index.d.cts","import":"./locales/index.js","require":"./locales/index.cjs"},"./v3":{"@zod/source":"./src/v3/index.ts","types":"./v3/index.d.cts","import":"./v3/index.js","require":"./v3/index.cjs"},"./v4":{"@zod/source":"./src/v4/index.ts","types":"./v4/index.d.cts","import":"./v4/index.js","require":"./v4/index.cjs"},"./v4-mini":{"@zod/source":"./src/v4-mini/index.ts","types":"./v4-mini/index.d.cts","import":"./v4-mini/index.js","require":"./v4-mini/index.cjs"},"./v4/mini":{"@zod/source":"./src/v4/mini/index.ts","types":"./v4/mini/index.d.cts","import":"./v4/mini/index.js","require":"./v4/mini/index.cjs"},"./v4/core":{"@zod/source":"./src/v4/core/index.ts","types":"./v4/core/index.d.cts","import":"./v4/core/index.js","require":"./v4/core/index.cjs"},"./v4/locales":{"@zod/source":"./src/v4/locales/index.ts","types":"./v4/locales/index.d.cts","import":"./v4/locales/index.js","require":"./v4/locales/index.cjs"},"./v4/locales/*":{"@zod/source":"./src/v4/locales/*","types":"./v4/locales/*","import":"./v4/locales/*","require":"./v4/locales/*"}},"repository":{"type":"git","url":"git+https://github.com/colinhacks/zod.git"},"bugs":{"url":"https://github.com/colinhacks/zod/issues"},"support":{"backing":{"npm-funding":true}},"scripts":{"clean":"git clean -xdf . -e node_modules","build":"zshy --project tsconfig.build.json","postbuild":"tsx ../../scripts/write-stub-package-jsons.ts && pnpm biome check --write .","test:watch":"pnpm vitest","test":"pnpm vitest run","prepublishOnly":"tsx ../../scripts/check-versions.ts"},"_lastModified":"2026-
|
|
1
|
+
{"name":"zod","version":"4.3.5","type":"module","license":"MIT","author":"Colin McDonnell <zod@colinhacks.com>","description":"TypeScript-first schema declaration and validation library with static type inference","homepage":"https://zod.dev","llms":"https://zod.dev/llms.txt","llmsFull":"https://zod.dev/llms-full.txt","mcpServer":"https://mcp.inkeep.com/zod/mcp","funding":"https://github.com/sponsors/colinhacks","sideEffects":false,"files":["src","**/*.js","**/*.mjs","**/*.cjs","**/*.d.ts","**/*.d.mts","**/*.d.cts","**/package.json"],"keywords":["typescript","schema","validation","type","inference"],"main":"./index.cjs","types":"./index.d.cts","module":"./index.js","zshy":{"exports":{"./package.json":"./package.json",".":"./src/index.ts","./mini":"./src/mini/index.ts","./locales":"./src/locales/index.ts","./v3":"./src/v3/index.ts","./v4":"./src/v4/index.ts","./v4-mini":"./src/v4-mini/index.ts","./v4/mini":"./src/v4/mini/index.ts","./v4/core":"./src/v4/core/index.ts","./v4/locales":"./src/v4/locales/index.ts","./v4/locales/*":"./src/v4/locales/*"},"conditions":{"@zod/source":"src"}},"exports":{"./package.json":"./package.json",".":{"@zod/source":"./src/index.ts","types":"./index.d.cts","import":"./index.js","require":"./index.cjs"},"./mini":{"@zod/source":"./src/mini/index.ts","types":"./mini/index.d.cts","import":"./mini/index.js","require":"./mini/index.cjs"},"./locales":{"@zod/source":"./src/locales/index.ts","types":"./locales/index.d.cts","import":"./locales/index.js","require":"./locales/index.cjs"},"./v3":{"@zod/source":"./src/v3/index.ts","types":"./v3/index.d.cts","import":"./v3/index.js","require":"./v3/index.cjs"},"./v4":{"@zod/source":"./src/v4/index.ts","types":"./v4/index.d.cts","import":"./v4/index.js","require":"./v4/index.cjs"},"./v4-mini":{"@zod/source":"./src/v4-mini/index.ts","types":"./v4-mini/index.d.cts","import":"./v4-mini/index.js","require":"./v4-mini/index.cjs"},"./v4/mini":{"@zod/source":"./src/v4/mini/index.ts","types":"./v4/mini/index.d.cts","import":"./v4/mini/index.js","require":"./v4/mini/index.cjs"},"./v4/core":{"@zod/source":"./src/v4/core/index.ts","types":"./v4/core/index.d.cts","import":"./v4/core/index.js","require":"./v4/core/index.cjs"},"./v4/locales":{"@zod/source":"./src/v4/locales/index.ts","types":"./v4/locales/index.d.cts","import":"./v4/locales/index.js","require":"./v4/locales/index.cjs"},"./v4/locales/*":{"@zod/source":"./src/v4/locales/*","types":"./v4/locales/*","import":"./v4/locales/*","require":"./v4/locales/*"}},"repository":{"type":"git","url":"git+https://github.com/colinhacks/zod.git"},"bugs":{"url":"https://github.com/colinhacks/zod/issues"},"support":{"backing":{"npm-funding":true}},"scripts":{"clean":"git clean -xdf . -e node_modules","build":"zshy --project tsconfig.build.json","postbuild":"tsx ../../scripts/write-stub-package-jsons.ts && pnpm biome check --write .","test:watch":"pnpm vitest","test":"pnpm vitest run","prepublishOnly":"tsx ../../scripts/check-versions.ts"},"_lastModified":"2026-11-07T02:49:52.068Z"}
|
|
@@ -42,6 +42,7 @@ __export(git_actions_exports, {
|
|
|
42
42
|
clone: () => clone,
|
|
43
43
|
commitDetail: () => commitDetail,
|
|
44
44
|
createGit: () => createGit,
|
|
45
|
+
credentialEnvironment: () => credentialEnvironment,
|
|
45
46
|
diff: () => diff,
|
|
46
47
|
fetch: () => fetch,
|
|
47
48
|
fileContent: () => fileContent,
|
|
@@ -84,7 +85,13 @@ function acquireLock(key) {
|
|
|
84
85
|
const promise = prev.then(() => {
|
|
85
86
|
});
|
|
86
87
|
repoLocks.set(key, next);
|
|
87
|
-
return {
|
|
88
|
+
return {
|
|
89
|
+
promise,
|
|
90
|
+
release: () => {
|
|
91
|
+
release();
|
|
92
|
+
if (repoLocks.get(key) === next) repoLocks.delete(key);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
88
95
|
}
|
|
89
96
|
function validateRef(ref) {
|
|
90
97
|
if (!REF_PATTERN.test(ref)) {
|
|
@@ -112,38 +119,60 @@ function validateRepoUrl(repoUrl) {
|
|
|
112
119
|
}
|
|
113
120
|
}
|
|
114
121
|
async function withAuth(git, localPath, repoUrl, pat, fn, username, remoteName = "origin") {
|
|
115
|
-
(
|
|
116
|
-
const
|
|
117
|
-
const lock = acquireLock(lockKey);
|
|
122
|
+
validateRepoUrl(repoUrl);
|
|
123
|
+
const lock = acquireLock(localPath);
|
|
118
124
|
await lock.promise;
|
|
119
|
-
const authUrl = getAuthUrl(repoUrl, pat, username);
|
|
120
|
-
await git.remote(["set-url", remoteName, authUrl]);
|
|
121
125
|
try {
|
|
126
|
+
git.env(credentialEnvironment(repoUrl, pat, username));
|
|
127
|
+
await git.remote(["set-url", remoteName, repoUrl]);
|
|
122
128
|
return await fn();
|
|
123
|
-
} catch (
|
|
124
|
-
throw (
|
|
129
|
+
} catch (error) {
|
|
130
|
+
throw redactGitCredentialError(error, pat, username);
|
|
125
131
|
} finally {
|
|
126
132
|
try {
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
await git.remote(["set-url", remoteName, repoUrl]);
|
|
131
|
-
} catch {
|
|
132
|
-
console.error(
|
|
133
|
-
`[plugin-git-manager] CRITICAL: failed to remove PAT from remote URL for ${(0, import_redact.redactPat)(repoUrl)}. Manual cleanup of .git/config may be required.`,
|
|
134
|
-
(0, import_redact.redactError)(cleanupErr)
|
|
135
|
-
);
|
|
136
|
-
}
|
|
133
|
+
git.env(gitProcessEnvironment());
|
|
134
|
+
} finally {
|
|
135
|
+
lock.release();
|
|
137
136
|
}
|
|
138
|
-
lock.release();
|
|
139
137
|
}
|
|
140
138
|
}
|
|
141
|
-
function
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
139
|
+
function gitProcessEnvironment() {
|
|
140
|
+
const env = { ...process.env };
|
|
141
|
+
for (const key of Object.keys(env)) {
|
|
142
|
+
if (/^GIT_/i.test(key) && !/^GIT_SSL_CA(INFO|PATH)$/i.test(key) || /^(EDITOR|PAGER|PREFIX|SSH_ASKPASS)$/i.test(key)) {
|
|
143
|
+
delete env[key];
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return env;
|
|
147
|
+
}
|
|
148
|
+
function credentialEnvironment(repoUrl, pat, username) {
|
|
149
|
+
validateRepoUrl(repoUrl);
|
|
150
|
+
const authorization = Buffer.from(`${(username || "oauth2").trim()}:${pat.trim()}`).toString("base64");
|
|
151
|
+
const settings = [
|
|
152
|
+
["http.extraHeader", ""],
|
|
153
|
+
[`http.${new URL(repoUrl).toString()}.extraHeader`, `Authorization: Basic ${authorization}`],
|
|
154
|
+
["http.followRedirects", "false"],
|
|
155
|
+
["credential.helper", ""]
|
|
156
|
+
];
|
|
157
|
+
const env = {
|
|
158
|
+
...gitProcessEnvironment(),
|
|
159
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
160
|
+
GIT_CONFIG_COUNT: String(settings.length)
|
|
161
|
+
};
|
|
162
|
+
settings.forEach(([key, value], index) => {
|
|
163
|
+
env[`GIT_CONFIG_KEY_${index}`] = key;
|
|
164
|
+
env[`GIT_CONFIG_VALUE_${index}`] = value;
|
|
165
|
+
});
|
|
166
|
+
return env;
|
|
167
|
+
}
|
|
168
|
+
function redactGitCredentialError(error, pat, username) {
|
|
169
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
170
|
+
const authorization = Buffer.from(`${(username || "oauth2").trim()}:${pat.trim()}`).toString("base64");
|
|
171
|
+
let safeMessage = message;
|
|
172
|
+
for (const secret of [authorization, pat.trim()]) {
|
|
173
|
+
if (secret) safeMessage = safeMessage.split(secret).join("***");
|
|
174
|
+
}
|
|
175
|
+
return (0, import_redact.redactError)(new Error(safeMessage));
|
|
147
176
|
}
|
|
148
177
|
function getGitMissingMessage() {
|
|
149
178
|
return `Git executable "${GIT_BINARY}" was not found on the server. Install git in the app/worker container, or set GIT_BINARY_PATH to the absolute git binary path.`;
|
|
@@ -157,11 +186,15 @@ function assertGitAvailable(ctx) {
|
|
|
157
186
|
gitAvailabilityChecked = true;
|
|
158
187
|
}
|
|
159
188
|
function isMissingGitError(error) {
|
|
160
|
-
const message =
|
|
189
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
161
190
|
return (error == null ? void 0 : error.code) === "ENOENT" || /spawn .*git.*ENOENT/i.test(message);
|
|
162
191
|
}
|
|
163
192
|
function createGit(baseDir) {
|
|
164
|
-
return (0, import_simple_git.default)({
|
|
193
|
+
return (0, import_simple_git.default)({
|
|
194
|
+
baseDir,
|
|
195
|
+
binary: GIT_BINARY,
|
|
196
|
+
unsafe: { allowUnsafeConfigEnvCount: true, allowUnsafeCredentialHelper: true }
|
|
197
|
+
}).env(gitProcessEnvironment());
|
|
165
198
|
}
|
|
166
199
|
function getGitBinaryPath() {
|
|
167
200
|
return GIT_BINARY;
|
|
@@ -183,14 +216,36 @@ async function getRepo(ctx) {
|
|
|
183
216
|
}
|
|
184
217
|
return repo;
|
|
185
218
|
}
|
|
219
|
+
function canonicalPath(value) {
|
|
220
|
+
try {
|
|
221
|
+
return fs.realpathSync.native(value);
|
|
222
|
+
} catch (error) {
|
|
223
|
+
if (error.code !== "ENOENT") throw error;
|
|
224
|
+
try {
|
|
225
|
+
if (fs.lstatSync(value).isSymbolicLink()) throw new Error("Invalid local path");
|
|
226
|
+
} catch (statError) {
|
|
227
|
+
if (statError.code !== "ENOENT") throw statError;
|
|
228
|
+
}
|
|
229
|
+
const parent = path.dirname(value);
|
|
230
|
+
if (parent === value) throw error;
|
|
231
|
+
return path.join(canonicalPath(parent), path.basename(value));
|
|
232
|
+
}
|
|
233
|
+
}
|
|
186
234
|
function validateLocalPath(localPath) {
|
|
187
|
-
const basePath = process.env.GIT_REPOS_BASE_PATH || path.join(process.cwd(), "storage", "git-repos");
|
|
235
|
+
const basePath = path.resolve(process.env.GIT_REPOS_BASE_PATH || path.join(process.cwd(), "storage", "git-repos"));
|
|
188
236
|
const resolved = path.resolve(basePath, localPath);
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
237
|
+
const base = canonicalPath(basePath);
|
|
238
|
+
const candidate = canonicalPath(resolved);
|
|
239
|
+
for (const [root, target] of [
|
|
240
|
+
[basePath, resolved],
|
|
241
|
+
[base, candidate]
|
|
242
|
+
]) {
|
|
243
|
+
const relative = path.relative(root, target);
|
|
244
|
+
if (!relative || relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
|
|
245
|
+
throw new Error("Invalid local path: path traversal detected or path is outside the allowed base directory");
|
|
246
|
+
}
|
|
192
247
|
}
|
|
193
|
-
return
|
|
248
|
+
return candidate;
|
|
194
249
|
}
|
|
195
250
|
async function clone(ctx, next) {
|
|
196
251
|
const repo = await getRepo(ctx);
|
|
@@ -208,11 +263,9 @@ async function clone(ctx, next) {
|
|
|
208
263
|
if (!fs.existsSync(path.dirname(localPath))) {
|
|
209
264
|
fs.mkdirSync(path.dirname(localPath), { recursive: true });
|
|
210
265
|
}
|
|
211
|
-
const authUrl = getAuthUrl(repoUrl, pat, username);
|
|
212
266
|
assertGitAvailable(ctx);
|
|
213
267
|
try {
|
|
214
|
-
await createGit().clone(
|
|
215
|
-
await createGit(localPath).remote(["set-url", "origin", repoUrl]);
|
|
268
|
+
await createGit().env(credentialEnvironment(repoUrl, pat, username)).clone(repoUrl, localPath, ["--branch", defaultBranch]);
|
|
216
269
|
await ctx.db.getRepository("gitRepositories").update({
|
|
217
270
|
filterByTk: repo.get("id"),
|
|
218
271
|
values: { status: "connected" }
|
|
@@ -226,7 +279,7 @@ async function clone(ctx, next) {
|
|
|
226
279
|
if (isMissingGitError(err)) {
|
|
227
280
|
ctx.throw(503, getGitMissingMessage());
|
|
228
281
|
}
|
|
229
|
-
throw (
|
|
282
|
+
throw redactGitCredentialError(err, pat, username);
|
|
230
283
|
}
|
|
231
284
|
await next();
|
|
232
285
|
}
|
|
@@ -425,6 +478,7 @@ async function commitDetail(ctx, next) {
|
|
|
425
478
|
clone,
|
|
426
479
|
commitDetail,
|
|
427
480
|
createGit,
|
|
481
|
+
credentialEnvironment,
|
|
428
482
|
diff,
|
|
429
483
|
fetch,
|
|
430
484
|
fileContent,
|
|
@@ -44,6 +44,7 @@ async function gitlabFetch(apiBase, endpoint, pat, params) {
|
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
const response = await fetch(url.toString(), {
|
|
47
|
+
redirect: "error",
|
|
47
48
|
headers: {
|
|
48
49
|
"PRIVATE-TOKEN": pat,
|
|
49
50
|
Accept: "application/json"
|
|
@@ -61,6 +62,7 @@ async function gitlabFetch(apiBase, endpoint, pat, params) {
|
|
|
61
62
|
async function getRepoApiContext(ctx) {
|
|
62
63
|
const params = (0, import_repository_access.getEffectiveActionParams)(ctx);
|
|
63
64
|
const { repositoryId } = params;
|
|
65
|
+
if (typeof repositoryId !== "string" && typeof repositoryId !== "number") ctx.throw(400, "repositoryId is required");
|
|
64
66
|
const repo = await ctx.db.getRepository("gitRepositories").findOne({
|
|
65
67
|
filterByTk: repositoryId
|
|
66
68
|
});
|
|
@@ -70,7 +72,7 @@ async function getRepoApiContext(ctx) {
|
|
|
70
72
|
const account = await (0, import_get_repo_account.getRepoAccount)(ctx.db, repo);
|
|
71
73
|
const pat = (account == null ? void 0 : account.pat) || "";
|
|
72
74
|
const repoUrl = (repo.get("repoUrl") || "").trim();
|
|
73
|
-
const isGitHub = (account == null ? void 0 : account.provider) === "github" || repoUrl.
|
|
75
|
+
const isGitHub = (account == null ? void 0 : account.provider) === "github" || new URL(repoUrl).hostname === "github.com";
|
|
74
76
|
const { apiBase, encodedProject, projectPath } = (0, import_gitlab_url.parseGitLabProject)(repoUrl);
|
|
75
77
|
return { repo, pat, apiBase, encodedProject, projectPath, isGitHub };
|
|
76
78
|
}
|
|
@@ -89,7 +91,7 @@ async function githubFetch(endpoint, pat, params) {
|
|
|
89
91
|
if (pat) {
|
|
90
92
|
headers["Authorization"] = `Bearer ${pat}`;
|
|
91
93
|
}
|
|
92
|
-
const response = await fetch(url.toString(), { headers });
|
|
94
|
+
const response = await fetch(url.toString(), { headers, redirect: "error" });
|
|
93
95
|
if (!response.ok) {
|
|
94
96
|
const body = await response.text().catch(() => "");
|
|
95
97
|
throw new Error(`GitHub API error ${response.status}: ${body}`);
|
|
@@ -34,7 +34,10 @@ var import_poller = require("../poller");
|
|
|
34
34
|
var import_repository_access = require("../repository-access");
|
|
35
35
|
async function pollNow(ctx, next) {
|
|
36
36
|
const { repositoryId } = (0, import_repository_access.getEffectiveActionParams)(ctx);
|
|
37
|
-
if (repositoryId) {
|
|
37
|
+
if (repositoryId != null && typeof repositoryId !== "string" && typeof repositoryId !== "number") {
|
|
38
|
+
ctx.throw(400, "repositoryId is required");
|
|
39
|
+
}
|
|
40
|
+
if (typeof repositoryId === "string" || typeof repositoryId === "number") {
|
|
38
41
|
const repo = await ctx.db.getRepository("gitRepositories").findOne({ filterByTk: repositoryId });
|
|
39
42
|
if (!repo) ctx.throw(404, "Repository not found");
|
|
40
43
|
const result = await (0, import_poller.pollOneRepo)(ctx.app, repo);
|
|
@@ -46,7 +49,7 @@ async function pollNow(ctx, next) {
|
|
|
46
49
|
await next();
|
|
47
50
|
}
|
|
48
51
|
async function pollerStatus(ctx, next) {
|
|
49
|
-
ctx.body = { success: true, data: (0, import_poller.getPollerStatus)() };
|
|
52
|
+
ctx.body = { success: true, data: (0, import_poller.getPollerStatus)(ctx.app) };
|
|
50
53
|
await next();
|
|
51
54
|
}
|
|
52
55
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -85,7 +85,9 @@ async function triggerReview(ctx, next) {
|
|
|
85
85
|
const { flowId, repositoryId, targetType, mrIid, commitSha, branch, folderPath, extraInstructions } = params;
|
|
86
86
|
if (!repositoryId) ctx.throw(400, "repositoryId is required");
|
|
87
87
|
if (!targetType) ctx.throw(400, "targetType is required");
|
|
88
|
-
if (
|
|
88
|
+
if (targetType !== "mr" && targetType !== "commit" && targetType !== "branch" && targetType !== "folder") {
|
|
89
|
+
ctx.throw(400, "invalid targetType");
|
|
90
|
+
}
|
|
89
91
|
if (targetType === "mr" && !mrIid) ctx.throw(400, "mrIid is required for MR review");
|
|
90
92
|
if (targetType === "commit" && !commitSha) ctx.throw(400, "commitSha is required for commit review");
|
|
91
93
|
if (targetType === "branch" && !branch) ctx.throw(400, "branch is required for branch review");
|
|
@@ -96,14 +98,14 @@ async function triggerReview(ctx, next) {
|
|
|
96
98
|
const userId = (_b = (_a = ctx.state) == null ? void 0 : _a.currentUser) == null ? void 0 : _b.id;
|
|
97
99
|
try {
|
|
98
100
|
const reviewId = await triggerReviewInternal(ctx.app, {
|
|
99
|
-
flowId,
|
|
101
|
+
flowId: flowId != null ? Number(flowId) : null,
|
|
100
102
|
repositoryId: Number(repositoryId),
|
|
101
103
|
targetType,
|
|
102
104
|
mrIid: mrIid != null ? Number(mrIid) : null,
|
|
103
|
-
commitSha: commitSha
|
|
104
|
-
branch: branch
|
|
105
|
-
folderPath: targetType === "folder" ? folderPath : null,
|
|
106
|
-
extraInstructions,
|
|
105
|
+
commitSha: typeof commitSha === "string" ? commitSha : null,
|
|
106
|
+
branch: typeof branch === "string" ? branch : null,
|
|
107
|
+
folderPath: targetType === "folder" && typeof folderPath === "string" ? folderPath : null,
|
|
108
|
+
extraInstructions: typeof extraInstructions === "string" ? extraInstructions : void 0,
|
|
107
109
|
triggeredBy: "manual",
|
|
108
110
|
userId
|
|
109
111
|
});
|
|
@@ -589,7 +591,9 @@ async function reviewApprovePost(ctx, next) {
|
|
|
589
591
|
var _a, _b;
|
|
590
592
|
const params = (0, import_repository_access.getEffectiveActionParams)(ctx);
|
|
591
593
|
const { reviewId, editedMarkdown } = params;
|
|
592
|
-
if (!reviewId
|
|
594
|
+
if (!reviewId || typeof reviewId !== "string" && typeof reviewId !== "number") {
|
|
595
|
+
ctx.throw(400, "reviewId is required");
|
|
596
|
+
}
|
|
593
597
|
const reviewsRepo = ctx.db.getRepository("gitCodeReviews");
|
|
594
598
|
const review = await reviewsRepo.findOne({ filterByTk: reviewId });
|
|
595
599
|
if (!review) ctx.throw(404, "Review not found");
|
|
@@ -621,7 +625,9 @@ async function reviewReject(ctx, next) {
|
|
|
621
625
|
var _a, _b;
|
|
622
626
|
const params = (0, import_repository_access.getEffectiveActionParams)(ctx);
|
|
623
627
|
const { reviewId, reason } = params;
|
|
624
|
-
if (!reviewId
|
|
628
|
+
if (!reviewId || typeof reviewId !== "string" && typeof reviewId !== "number") {
|
|
629
|
+
ctx.throw(400, "reviewId is required");
|
|
630
|
+
}
|
|
625
631
|
const reviewsRepo = ctx.db.getRepository("gitCodeReviews");
|
|
626
632
|
const review = await reviewsRepo.findOne({ filterByTk: reviewId });
|
|
627
633
|
if (!review) ctx.throw(404, "Review not found");
|
|
@@ -961,11 +967,12 @@ async function fetchMrHeadSha(db, repo, mrIid) {
|
|
|
961
967
|
const pat = (account == null ? void 0 : account.pat) || "";
|
|
962
968
|
if (!pat) return null;
|
|
963
969
|
const repoUrl = repo.get("repoUrl");
|
|
964
|
-
const isGitHub = (account == null ? void 0 : account.provider) === "github" || repoUrl.
|
|
970
|
+
const isGitHub = (account == null ? void 0 : account.provider) === "github" || new URL(repoUrl).hostname === "github.com";
|
|
965
971
|
try {
|
|
966
972
|
if (isGitHub) {
|
|
967
973
|
const { projectPath } = (0, import_gitlab_url.parseGitLabProject)(repoUrl);
|
|
968
974
|
const response = await fetch(`https://api.github.com/repos/${projectPath}/pulls/${mrIid}`, {
|
|
975
|
+
redirect: "error",
|
|
969
976
|
headers: { Authorization: `Bearer ${pat}`, Accept: "application/vnd.github.v3+json" }
|
|
970
977
|
});
|
|
971
978
|
if (!response.ok) return null;
|
|
@@ -974,6 +981,7 @@ async function fetchMrHeadSha(db, repo, mrIid) {
|
|
|
974
981
|
} else {
|
|
975
982
|
const { apiBase, encodedProject } = (0, import_gitlab_url.parseGitLabProject)(repoUrl);
|
|
976
983
|
const response = await fetch(`${apiBase}/projects/${encodedProject}/merge_requests/${mrIid}`, {
|
|
984
|
+
redirect: "error",
|
|
977
985
|
headers: { "PRIVATE-TOKEN": pat, Accept: "application/json" }
|
|
978
986
|
});
|
|
979
987
|
if (!response.ok) return null;
|
|
@@ -988,11 +996,12 @@ async function postNoteToGitLab(db, repo, mrIid, body) {
|
|
|
988
996
|
const account = await (0, import_get_repo_account.getRepoAccount)(db, repo);
|
|
989
997
|
const pat = (account == null ? void 0 : account.pat) || "";
|
|
990
998
|
const repoUrl = repo.get("repoUrl");
|
|
991
|
-
const isGitHub = (account == null ? void 0 : account.provider) === "github" || repoUrl.
|
|
999
|
+
const isGitHub = (account == null ? void 0 : account.provider) === "github" || new URL(repoUrl).hostname === "github.com";
|
|
992
1000
|
if (isGitHub) {
|
|
993
1001
|
if (!pat) throw new Error("Repository has no PAT configured");
|
|
994
1002
|
const { projectPath } = (0, import_gitlab_url.parseGitLabProject)(repoUrl);
|
|
995
1003
|
const response = await fetch(`https://api.github.com/repos/${projectPath}/issues/${mrIid}/comments`, {
|
|
1004
|
+
redirect: "error",
|
|
996
1005
|
method: "POST",
|
|
997
1006
|
headers: {
|
|
998
1007
|
Authorization: `Bearer ${pat}`,
|
|
@@ -1011,6 +1020,7 @@ async function postNoteToGitLab(db, repo, mrIid, body) {
|
|
|
1011
1020
|
if (!pat) throw new Error("Repository has no PAT configured");
|
|
1012
1021
|
const { apiBase, encodedProject } = (0, import_gitlab_url.parseGitLabProject)(repoUrl);
|
|
1013
1022
|
const response = await fetch(`${apiBase}/projects/${encodedProject}/merge_requests/${mrIid}/notes`, {
|
|
1023
|
+
redirect: "error",
|
|
1014
1024
|
method: "POST",
|
|
1015
1025
|
headers: {
|
|
1016
1026
|
"PRIVATE-TOKEN": pat,
|
package/dist/server/plugin.js
CHANGED
|
@@ -53,6 +53,7 @@ var rolePermissionsActions = __toESM(require("./actions/role-permissions"));
|
|
|
53
53
|
var subtreeActions = __toESM(require("./actions/subtree"));
|
|
54
54
|
var import_review = require("./actions/review");
|
|
55
55
|
var import_ai_tools = require("./ai-tools");
|
|
56
|
+
var import_request_method_policy = require("./request-method-policy");
|
|
56
57
|
var import_poller = require("./poller");
|
|
57
58
|
var import_registry_content_service = require("./services/registry-content-service");
|
|
58
59
|
var import_repository_access = require("./repository-access");
|
|
@@ -124,6 +125,7 @@ class PluginGitManagerServer extends import_server.Plugin {
|
|
|
124
125
|
subtreeReplace: subtreeActions.subtreeRunOnAppProcess
|
|
125
126
|
}
|
|
126
127
|
});
|
|
128
|
+
this.app.resourceManager.use(import_request_method_policy.enforceGitRequestMethod);
|
|
127
129
|
this.app.resourceManager.use(import_repository_access.enforceRepositoryAccess);
|
|
128
130
|
this.app.resourceManager.use(import_repository_access.enforceRepositoryCollectionAccess);
|
|
129
131
|
this.app.use(async (ctx, next) => {
|
|
@@ -161,11 +163,11 @@ class PluginGitManagerServer extends import_server.Plugin {
|
|
|
161
163
|
});
|
|
162
164
|
this.app.on("beforeStop", () => {
|
|
163
165
|
(0, import_review.unregisterReviewQueue)(this.app);
|
|
164
|
-
(0, import_poller.stopPoller)();
|
|
166
|
+
(0, import_poller.stopPoller)(this.app);
|
|
165
167
|
});
|
|
166
168
|
this.app.on("beforeDestroy", () => {
|
|
167
169
|
(0, import_review.unregisterReviewQueue)(this.app);
|
|
168
|
-
(0, import_poller.stopPoller)();
|
|
170
|
+
(0, import_poller.stopPoller)(this.app);
|
|
169
171
|
});
|
|
170
172
|
this.app.acl.registerSnippet({
|
|
171
173
|
name: `pm.${this.name}.read`,
|
|
@@ -324,11 +326,11 @@ class PluginGitManagerServer extends import_server.Plugin {
|
|
|
324
326
|
}
|
|
325
327
|
async beforeDisable() {
|
|
326
328
|
(0, import_review.unregisterReviewQueue)(this.app);
|
|
327
|
-
(0, import_poller.stopPoller)();
|
|
329
|
+
(0, import_poller.stopPoller)(this.app);
|
|
328
330
|
}
|
|
329
331
|
async beforeUnload() {
|
|
330
332
|
(0, import_review.unregisterReviewQueue)(this.app);
|
|
331
|
-
(0, import_poller.stopPoller)();
|
|
333
|
+
(0, import_poller.stopPoller)(this.app);
|
|
332
334
|
}
|
|
333
335
|
}
|
|
334
336
|
async function ensureAutoReviewFlowSchema(app) {
|
package/dist/server/poller.js
CHANGED
|
@@ -38,33 +38,38 @@ var import_gitlab_url = require("./utils/gitlab-url");
|
|
|
38
38
|
var import_get_repo_account = require("./utils/get-repo-account");
|
|
39
39
|
const POLL_INTERVAL_MS = 5 * 60 * 1e3;
|
|
40
40
|
const MR_PAGE_SIZE = 50;
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
let
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
const pollers = /* @__PURE__ */ new WeakMap();
|
|
42
|
+
function stateFor(app) {
|
|
43
|
+
let state = pollers.get(app);
|
|
44
|
+
if (!state) {
|
|
45
|
+
state = { timer: null, polling: false, lastTickAt: null, lastError: null };
|
|
46
|
+
pollers.set(app, state);
|
|
47
|
+
}
|
|
48
|
+
return state;
|
|
49
|
+
}
|
|
47
50
|
function startPoller(app) {
|
|
48
51
|
var _a, _b;
|
|
49
|
-
|
|
52
|
+
const state = stateFor(app);
|
|
53
|
+
if (state.timer) return;
|
|
50
54
|
(_b = (_a = app.log) == null ? void 0 : _a.info) == null ? void 0 : _b.call(_a, "plugin-git-manager: starting MR poller (interval 5min)");
|
|
51
|
-
timer = setInterval(() => tick(app).catch((e) => {
|
|
55
|
+
state.timer = setInterval(() => tick(app).catch((e) => {
|
|
52
56
|
var _a2, _b2;
|
|
53
57
|
return (_b2 = (_a2 = app.log) == null ? void 0 : _a2.error) == null ? void 0 : _b2.call(_a2, "poller tick error", e);
|
|
54
58
|
}), POLL_INTERVAL_MS);
|
|
55
59
|
}
|
|
56
|
-
function stopPoller() {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
60
|
+
function stopPoller(app) {
|
|
61
|
+
const state = stateFor(app);
|
|
62
|
+
if (state.timer) clearInterval(state.timer);
|
|
63
|
+
state.timer = null;
|
|
61
64
|
}
|
|
62
|
-
function getPollerStatus() {
|
|
65
|
+
function getPollerStatus(app) {
|
|
66
|
+
var _a;
|
|
67
|
+
const state = stateFor(app);
|
|
63
68
|
return {
|
|
64
|
-
running: !!timer,
|
|
65
|
-
polling:
|
|
66
|
-
lastTickAt: (lastTickAt == null ? void 0 :
|
|
67
|
-
lastError,
|
|
69
|
+
running: !!state.timer,
|
|
70
|
+
polling: state.polling,
|
|
71
|
+
lastTickAt: ((_a = state.lastTickAt) == null ? void 0 : _a.toISOString()) ?? null,
|
|
72
|
+
lastError: state.lastError,
|
|
68
73
|
intervalSec: POLL_INTERVAL_MS / 1e3
|
|
69
74
|
};
|
|
70
75
|
}
|
|
@@ -133,28 +138,18 @@ async function tryAcquirePollerLock(app) {
|
|
|
133
138
|
}
|
|
134
139
|
}
|
|
135
140
|
async function pollAllRepos(app) {
|
|
136
|
-
var _a, _b, _c, _d
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
pollStartedAt = null;
|
|
142
|
-
} else {
|
|
143
|
-
return { scanned: 0, triggered: 0 };
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
const lock = await tryAcquirePollerLock(app);
|
|
147
|
-
if (!lock) {
|
|
148
|
-
(_d = (_c = app.log) == null ? void 0 : _c.debug) == null ? void 0 : _d.call(_c, "poller: another node holds the advisory lock \u2014 skipping");
|
|
149
|
-
return { scanned: 0, triggered: 0 };
|
|
150
|
-
}
|
|
151
|
-
isPolling = true;
|
|
152
|
-
pollStartedAt = Date.now();
|
|
153
|
-
lastTickAt = /* @__PURE__ */ new Date();
|
|
154
|
-
lastError = null;
|
|
141
|
+
var _a, _b, _c, _d;
|
|
142
|
+
const state = stateFor(app);
|
|
143
|
+
if (state.polling) return { scanned: 0, triggered: 0 };
|
|
144
|
+
state.polling = true;
|
|
145
|
+
let lock = null;
|
|
155
146
|
let scanned = 0;
|
|
156
147
|
let triggered = 0;
|
|
157
148
|
try {
|
|
149
|
+
lock = await tryAcquirePollerLock(app);
|
|
150
|
+
if (!lock) return { scanned: 0, triggered: 0 };
|
|
151
|
+
state.lastTickAt = /* @__PURE__ */ new Date();
|
|
152
|
+
state.lastError = null;
|
|
158
153
|
const reposRepo = app.db.getRepository("gitRepositories");
|
|
159
154
|
const repos = await reposRepo.find({ filter: { autoReview: true } });
|
|
160
155
|
for (const repo of repos) {
|
|
@@ -163,16 +158,18 @@ async function pollAllRepos(app) {
|
|
|
163
158
|
scanned += result.scanned;
|
|
164
159
|
triggered += result.triggered;
|
|
165
160
|
} catch (err) {
|
|
166
|
-
(
|
|
161
|
+
(_b = (_a = app.log) == null ? void 0 : _a.error) == null ? void 0 : _b.call(_a, `poller: repo ${repo.get("id")} failed: ${err == null ? void 0 : err.message}`);
|
|
167
162
|
}
|
|
168
163
|
}
|
|
169
164
|
} catch (err) {
|
|
170
|
-
lastError = (err == null ? void 0 : err.message) || String(err);
|
|
171
|
-
(
|
|
165
|
+
state.lastError = (err == null ? void 0 : err.message) || String(err);
|
|
166
|
+
(_d = (_c = app.log) == null ? void 0 : _c.error) == null ? void 0 : _d.call(_c, "poller: cycle failed", err);
|
|
172
167
|
} finally {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
168
|
+
try {
|
|
169
|
+
await (lock == null ? void 0 : lock.release());
|
|
170
|
+
} finally {
|
|
171
|
+
state.polling = false;
|
|
172
|
+
}
|
|
176
173
|
}
|
|
177
174
|
return { scanned, triggered };
|
|
178
175
|
}
|
|
@@ -243,7 +240,7 @@ async function pollOneRepo(app, repo) {
|
|
|
243
240
|
}
|
|
244
241
|
async function listMergeRequests(repo, pat, updatedAfter) {
|
|
245
242
|
const repoUrl = repo.get("repoUrl");
|
|
246
|
-
const isGitHub = typeof repoUrl === "string" && repoUrl.
|
|
243
|
+
const isGitHub = typeof repoUrl === "string" && new URL(repoUrl).hostname === "github.com";
|
|
247
244
|
if (isGitHub) {
|
|
248
245
|
const { projectPath } = (0, import_gitlab_url.parseGitLabProject)(repoUrl);
|
|
249
246
|
const params2 = new URLSearchParams({
|
|
@@ -254,7 +251,10 @@ async function listMergeRequests(repo, pat, updatedAfter) {
|
|
|
254
251
|
});
|
|
255
252
|
const headers = { Accept: "application/vnd.github.v3+json" };
|
|
256
253
|
if (pat) headers["Authorization"] = `Bearer ${pat}`;
|
|
257
|
-
const response2 = await fetch(`https://api.github.com/repos/${projectPath}/pulls?${params2.toString()}`, {
|
|
254
|
+
const response2 = await fetch(`https://api.github.com/repos/${projectPath}/pulls?${params2.toString()}`, {
|
|
255
|
+
headers,
|
|
256
|
+
redirect: "error"
|
|
257
|
+
});
|
|
258
258
|
if (!response2.ok) {
|
|
259
259
|
const body = await response2.text().catch(() => "");
|
|
260
260
|
throw new Error(`GitHub API error ${response2.status}: ${body}`);
|
|
@@ -289,6 +289,7 @@ async function listMergeRequests(repo, pat, updatedAfter) {
|
|
|
289
289
|
params.set("updated_after", safeBound.toISOString());
|
|
290
290
|
}
|
|
291
291
|
const response = await fetch(`${apiBase}/projects/${encodedProject}/merge_requests?${params.toString()}`, {
|
|
292
|
+
redirect: "error",
|
|
292
293
|
headers: { "PRIVATE-TOKEN": pat, Accept: "application/json" }
|
|
293
294
|
});
|
|
294
295
|
if (!response.ok) {
|
|
@@ -0,0 +1,75 @@
|
|
|
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 request_method_policy_exports = {};
|
|
28
|
+
__export(request_method_policy_exports, {
|
|
29
|
+
enforceGitRequestMethod: () => enforceGitRequestMethod
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(request_method_policy_exports);
|
|
32
|
+
const READ_ACTIONS = /* @__PURE__ */ new Set([
|
|
33
|
+
"diff",
|
|
34
|
+
"status",
|
|
35
|
+
"log",
|
|
36
|
+
"branches",
|
|
37
|
+
"fileTree",
|
|
38
|
+
"fileContent",
|
|
39
|
+
"commitDetail",
|
|
40
|
+
"mergeRequests",
|
|
41
|
+
"mergeRequestDetail",
|
|
42
|
+
"mergeRequestNotes",
|
|
43
|
+
"pollerStatus",
|
|
44
|
+
"rolePermissions"
|
|
45
|
+
]);
|
|
46
|
+
async function enforceGitRequestMethod(ctx, next) {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
if (((_a = ctx.action) == null ? void 0 : _a.resourceName) === "gitManager") {
|
|
49
|
+
const allowed = READ_ACTIONS.has(ctx.action.actionName) ? ["GET", "HEAD", "POST"] : ["POST"];
|
|
50
|
+
if (!allowed.includes(ctx.method.toUpperCase())) {
|
|
51
|
+
ctx.set("Allow", allowed.join(", "));
|
|
52
|
+
ctx.throw(405, ctx.t("Method not allowed", { ns: "plugin-git-manager" }));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
await next();
|
|
57
|
+
} catch (error) {
|
|
58
|
+
const securityMessages = [
|
|
59
|
+
"Invalid repository or account URL",
|
|
60
|
+
"Only HTTPS repository and account URLs are allowed",
|
|
61
|
+
"Repository URL must match the Git account origin",
|
|
62
|
+
"GitHub accounts currently require github.com",
|
|
63
|
+
"Invalid local path",
|
|
64
|
+
"Invalid local path: path traversal detected or path is outside the allowed base directory"
|
|
65
|
+
];
|
|
66
|
+
if (((_b = ctx.action) == null ? void 0 : _b.resourceName) === "gitManager" && error instanceof Error && securityMessages.includes(error.message)) {
|
|
67
|
+
ctx.throw(400, ctx.t(error.message, { ns: "plugin-git-manager" }));
|
|
68
|
+
}
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
+
0 && (module.exports = {
|
|
74
|
+
enforceGitRequestMethod
|
|
75
|
+
});
|