plugin-git-manager 1.2.27 → 1.3.1

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.
Files changed (138) hide show
  1. package/README.md +151 -108
  2. package/client-v2.d.ts +2 -2
  3. package/client-v2.js +1 -1
  4. package/client.d.ts +3 -3
  5. package/client.js +1 -1
  6. package/dist/client/{326.90c276058682b536.js → 313.d38fc1d40c4589b9.js} +1 -1
  7. package/dist/client/941.1793e67472872992.js +10 -0
  8. package/dist/client/index.js +1 -1
  9. package/dist/client-v2/156.445366026c1cc9a8.js +10 -0
  10. package/dist/client-v2/{326.42b7b53651ffab3a.js → 313.3c867179c3a1e817.js} +1 -1
  11. package/dist/client-v2/434.19c7579c06b9077c.js +10 -0
  12. package/dist/client-v2/928.bba701b5a1ece58e.js +10 -0
  13. package/dist/client-v2/941.b0d55429cd053f32.js +10 -0
  14. package/dist/client-v2/index.js +1 -1
  15. package/dist/externalVersion.js +9 -8
  16. package/dist/locale/en-US.json +396 -297
  17. package/dist/locale/vi-VN.json +384 -292
  18. package/dist/locale/zh-CN.json +150 -51
  19. package/dist/node_modules/simple-git/dist/cjs/index.js +25 -25
  20. package/dist/node_modules/simple-git/package.json +1 -1
  21. package/dist/node_modules/zod/index.cjs +1 -1
  22. package/dist/node_modules/zod/package.json +1 -1
  23. package/dist/server/actions/git-actions.js +90 -36
  24. package/dist/server/actions/gitlab-api.js +4 -2
  25. package/dist/server/actions/poller.js +5 -2
  26. package/dist/server/actions/review-cutover.js +137 -0
  27. package/dist/server/actions/review.js +150 -51
  28. package/dist/server/actions/role-permissions.js +1 -0
  29. package/dist/server/ai-tools.js +8 -9
  30. package/dist/server/collections/gitCodeReviews.js +10 -0
  31. package/dist/server/collections/gitReviewCutover.js +44 -0
  32. package/dist/server/collections/gitReviewFlows.js +3 -0
  33. package/dist/server/collections/gitReviewInbox.js +51 -0
  34. package/dist/server/collections/gitReviewProjects.js +43 -0
  35. package/dist/server/collections/gitReviewRequests.js +56 -0
  36. package/dist/server/index.js +8 -2
  37. package/dist/server/plugin.js +57 -20
  38. package/dist/server/poller.js +95 -74
  39. package/dist/server/repository-access.js +23 -5
  40. package/dist/server/request-method-policy.js +76 -0
  41. package/dist/server/review-control-access.js +79 -0
  42. package/dist/server/services/legacy-post-service.js +412 -0
  43. package/dist/server/services/registry-content-service.js +4 -3
  44. package/dist/server/services/review-service.js +1451 -0
  45. package/dist/server/services/review-source.js +325 -0
  46. package/dist/server/utils/get-repo-account.js +3 -2
  47. package/dist/server/utils/url-security.js +24 -0
  48. package/package.json +61 -43
  49. package/server.d.ts +2 -2
  50. package/server.js +1 -1
  51. package/src/client/__tests__/CommitHistory.test.tsx +79 -0
  52. package/src/client/__tests__/ReviewHistory.test.tsx +126 -0
  53. package/src/client/__tests__/RunReviewButton.test.tsx +84 -0
  54. package/src/client/__tests__/workflowRoutes.test.ts +65 -0
  55. package/src/client/ai-context.tsx +114 -114
  56. package/src/client/components/AIEmployeeSelect.tsx +63 -63
  57. package/src/client/components/CommitHistory.tsx +429 -374
  58. package/src/client/components/FileExplorer.tsx +386 -386
  59. package/src/client/components/GitAccounts.tsx +179 -179
  60. package/src/client/components/GitManagerSettings.tsx +160 -160
  61. package/src/client/components/GitOperations.tsx +220 -220
  62. package/src/client/components/LLMModelSelect.tsx +63 -63
  63. package/src/client/components/LLMServiceSelect.tsx +58 -58
  64. package/src/client/components/MarkdownView.tsx +80 -80
  65. package/src/client/components/MergeRequests.tsx +790 -790
  66. package/src/client/components/PollingStatus.tsx +225 -225
  67. package/src/client/components/RepositoryConfig.tsx +335 -335
  68. package/src/client/components/RepositoryPermissions.tsx +123 -123
  69. package/src/client/components/ReviewFlows.tsx +352 -303
  70. package/src/client/components/ReviewHistory.tsx +796 -566
  71. package/src/client/components/RunReviewButton.tsx +57 -173
  72. package/src/client/context/GitManagerContext.tsx +92 -92
  73. package/src/client/index.tsx +91 -82
  74. package/src/client/locale.ts +9 -9
  75. package/src/client/promptTemplates.ts +31 -31
  76. package/src/client/workflowRoutes.ts +42 -0
  77. package/src/client-v2/ai-context.tsx +99 -0
  78. package/src/client-v2/components/SubtreeSplits.tsx +547 -547
  79. package/src/client-v2/index.tsx +1 -1
  80. package/src/client-v2/locale.ts +8 -8
  81. package/src/client-v2/plugin.tsx +67 -39
  82. package/src/index.ts +2 -2
  83. package/src/locale/en-US.json +396 -297
  84. package/src/locale/vi-VN.json +384 -292
  85. package/src/locale/zh-CN.json +150 -51
  86. package/src/server/__tests__/git-actions.test.ts +24 -24
  87. package/src/server/__tests__/git-security.test.ts +170 -0
  88. package/src/server/__tests__/plugin-url-security.test.ts +17 -17
  89. package/src/server/__tests__/poller-lifecycle.test.ts +71 -0
  90. package/src/server/__tests__/poller.test.ts +37 -37
  91. package/src/server/__tests__/repository-access.test.ts +760 -752
  92. package/src/server/__tests__/review-service.integration.test.ts +1263 -0
  93. package/src/server/__tests__/review.test.ts +76 -137
  94. package/src/server/__tests__/role-permissions.test.ts +147 -147
  95. package/src/server/__tests__/smoke.test.ts +139 -17
  96. package/src/server/__tests__/subtree.test.ts +85 -85
  97. package/src/server/actions/git-actions.ts +540 -480
  98. package/src/server/actions/gitlab-api.ts +422 -411
  99. package/src/server/actions/poller.ts +39 -27
  100. package/src/server/actions/review-cutover.ts +121 -0
  101. package/src/server/actions/review.ts +1498 -1369
  102. package/src/server/actions/role-permissions.ts +331 -321
  103. package/src/server/actions/subtree.ts +508 -508
  104. package/src/server/ai-tools.ts +334 -319
  105. package/src/server/collections/gitAccounts.ts +56 -56
  106. package/src/server/collections/gitCodeReviews.ts +218 -199
  107. package/src/server/collections/gitRepositories.ts +87 -87
  108. package/src/server/collections/gitReviewCutover.ts +23 -0
  109. package/src/server/collections/gitReviewFlows.ts +120 -108
  110. package/src/server/collections/gitReviewInbox.ts +30 -0
  111. package/src/server/collections/gitReviewProjects.ts +22 -0
  112. package/src/server/collections/gitReviewRequests.ts +35 -0
  113. package/src/server/collections/gitSubtreeConfigs.ts +38 -38
  114. package/src/server/collections/gitSubtreeRuns.ts +30 -30
  115. package/src/server/index.ts +14 -2
  116. package/src/server/migrations/20260508000000-add-auto-review-flow-id.ts +29 -29
  117. package/src/server/migrations/20260712000000-add-git-accounts.ts +198 -198
  118. package/src/server/migrations/20260730000000-migrate-legacy-repository-permissions.ts +81 -81
  119. package/src/server/plugin.ts +409 -361
  120. package/src/server/poller.ts +365 -352
  121. package/src/server/repository-access.ts +803 -773
  122. package/src/server/request-method-policy.ts +56 -0
  123. package/src/server/review-control-access.ts +71 -0
  124. package/src/server/services/__tests__/registry-content-service.test.ts +359 -345
  125. package/src/server/services/__tests__/review-source.test.ts +226 -0
  126. package/src/server/services/legacy-post-service.ts +550 -0
  127. package/src/server/services/registry-content-service.ts +495 -484
  128. package/src/server/services/review-service.ts +1899 -0
  129. package/src/server/services/review-source.ts +359 -0
  130. package/src/server/utils/__tests__/redact.test.ts +56 -56
  131. package/src/server/utils/__tests__/url-security.test.ts +85 -85
  132. package/src/server/utils/get-repo-account.ts +51 -41
  133. package/src/server/utils/gitlab-url.ts +38 -38
  134. package/src/server/utils/redact.ts +87 -87
  135. package/src/server/utils/url-security.ts +128 -95
  136. package/dist/client/900.acf7d1fa22f95e71.js +0 -10
  137. package/dist/client-v2/434.7a27051db18526c0.js +0 -10
  138. 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-04-30T05:48:39.715Z"}
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-10T14:42:28.568Z"}
@@ -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 { promise, release };
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
- (0, import_url_security.assertUrlHasNoUserInfo)(repoUrl);
116
- const lockKey = localPath;
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 (err) {
124
- throw (0, import_redact.redactError)(err);
129
+ } catch (error) {
130
+ throw redactGitCredentialError(error, pat, username);
125
131
  } finally {
126
132
  try {
127
- await git.remote(["set-url", remoteName, repoUrl]);
128
- } catch (cleanupErr) {
129
- try {
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 getAuthUrl(repoUrl, pat, username) {
142
- (0, import_url_security.assertUrlHasNoUserInfo)(repoUrl);
143
- const url = new URL(repoUrl.trim());
144
- url.username = (username || "oauth2").trim();
145
- url.password = pat.trim();
146
- return url.toString();
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 = (error == null ? void 0 : error.message) || String(error);
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)({ baseDir, binary: GIT_BINARY });
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 strictBasePath = path.resolve(basePath) + path.sep;
190
- if (!resolved.startsWith(strictBasePath) && resolved !== path.resolve(basePath)) {
191
- throw new Error("Invalid local path: path traversal detected or path is outside the allowed base directory");
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 resolved;
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(authUrl, localPath, ["--branch", defaultBranch]);
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 (0, import_redact.redactError)(err);
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.includes("github.com");
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:
@@ -0,0 +1,137 @@
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 review_cutover_exports = {};
28
+ __export(review_cutover_exports, {
29
+ reviewCancelLegacy: () => reviewCancelLegacy,
30
+ reviewCancelQueued: () => reviewCancelQueued,
31
+ reviewConfirmCutover: () => reviewConfirmCutover,
32
+ reviewCutoverStatus: () => reviewCutoverStatus,
33
+ reviewRecover: () => reviewRecover,
34
+ reviewResetPostClaim: () => reviewResetPostClaim
35
+ });
36
+ module.exports = __toCommonJS(review_cutover_exports);
37
+ var import_repository_access = require("../repository-access");
38
+ function service(ctx) {
39
+ var _a, _b, _c;
40
+ const roles = (_a = ctx.state) == null ? void 0 : _a.currentRoles;
41
+ if (!Array.isArray(roles) || !roles.includes("root") || !((_c = (_b = ctx.state) == null ? void 0 : _b.currentUser) == null ? void 0 : _c.id))
42
+ ctx.throw(403, "Permission denied");
43
+ const plugin = ctx.app.pm.get("plugin-git-manager") || ctx.app.pm.get("git-manager");
44
+ if (!(plugin == null ? void 0 : plugin.reviewService)) ctx.throw(503, "Git review workflow service is unavailable");
45
+ return plugin.reviewService;
46
+ }
47
+ async function reviewCutoverStatus(ctx, next) {
48
+ ctx.body = { success: true, data: await service(ctx).cutoverStatus() };
49
+ await next();
50
+ }
51
+ async function reviewConfirmCutover(ctx, next) {
52
+ const reviewService = service(ctx);
53
+ if ((0, import_repository_access.getEffectiveActionParams)(ctx).confirmation !== "OLD_WORKERS_AND_AI_STOPPED")
54
+ ctx.throw(400, ctx.t("Worker and AI stop confirmation is required", { ns: "plugin-git-manager" }));
55
+ await reviewService.confirmCutover(ctx.state.currentUser.id);
56
+ ctx.body = { success: true, data: await reviewService.cutoverStatus() };
57
+ await next();
58
+ }
59
+ async function reviewCancelLegacy(ctx, next) {
60
+ const reviewService = service(ctx);
61
+ const { confirmation, legacyReviewId } = (0, import_repository_access.getEffectiveActionParams)(ctx);
62
+ if (confirmation !== "CANCEL_LEGACY_REVIEW")
63
+ ctx.throw(400, ctx.t("Legacy review cancellation confirmation is required", { ns: "plugin-git-manager" }));
64
+ if (typeof legacyReviewId !== "string" && typeof legacyReviewId !== "number")
65
+ ctx.throw(400, ctx.t("Legacy review identifier is required", { ns: "plugin-git-manager" }));
66
+ await reviewService.cancelLegacy(legacyReviewId, ctx.state.currentUser.id);
67
+ ctx.body = { success: true };
68
+ await next();
69
+ }
70
+ async function reviewRecover(ctx, next) {
71
+ const reviewService = service(ctx);
72
+ const { confirmation, requestId, executionId, legacyReviewId, inboxId } = (0, import_repository_access.getEffectiveActionParams)(ctx);
73
+ if (confirmation !== "AI_STOPPED")
74
+ ctx.throw(400, ctx.t("AI stop confirmation is required", { ns: "plugin-git-manager" }));
75
+ try {
76
+ if (typeof legacyReviewId === "string" || typeof legacyReviewId === "number") {
77
+ await reviewService.recoverLegacy(legacyReviewId, ctx.state.currentUser.id);
78
+ } else if (typeof inboxId === "string" || typeof inboxId === "number") {
79
+ await reviewService.recoverOrphaned(inboxId, ctx.state.currentUser.id);
80
+ } else if ((typeof requestId === "string" || typeof requestId === "number") && (executionId == null || typeof executionId === "string" || typeof executionId === "number")) {
81
+ await reviewService.recover(requestId, executionId ?? null, ctx.state.currentUser.id);
82
+ } else {
83
+ ctx.throw(400, "Review and execution identifiers are required");
84
+ }
85
+ } catch (error) {
86
+ if (error instanceof Error && error.message === "Resolve publication or reset the stopped post attempt before recovery") {
87
+ ctx.throw(
88
+ 409,
89
+ ctx.t("Resolve publication or reset the stopped post attempt before recovery", { ns: "plugin-git-manager" })
90
+ );
91
+ }
92
+ throw error;
93
+ }
94
+ ctx.body = { success: true };
95
+ await next();
96
+ }
97
+ async function reviewResetPostClaim(ctx, next) {
98
+ const reviewService = service(ctx);
99
+ const params = (0, import_repository_access.getEffectiveActionParams)(ctx);
100
+ const { confirmation, reviewId, expectedAttempt } = params;
101
+ if (confirmation !== "OUTBOUND_POST_STOPPED")
102
+ ctx.throw(400, ctx.t("Outbound post stop confirmation is required", { ns: "plugin-git-manager" }));
103
+ if (typeof reviewId !== "string" && typeof reviewId !== "number") ctx.throw(400, "reviewId is required");
104
+ if (!Object.prototype.hasOwnProperty.call(params, "expectedAttempt") || expectedAttempt !== null && typeof expectedAttempt !== "string") {
105
+ ctx.throw(400, ctx.t("Refresh publication status before recovery", { ns: "plugin-git-manager" }));
106
+ }
107
+ try {
108
+ await reviewService.resetPostClaim(reviewId, ctx.state.currentUser.id, expectedAttempt);
109
+ } catch (error) {
110
+ const status = error && typeof error === "object" && "status" in error && typeof error.status === "number" ? error.status : 400;
111
+ ctx.throw(
112
+ status,
113
+ ctx.t(error instanceof Error ? error.message : "Could not reset publication claim", { ns: "plugin-git-manager" })
114
+ );
115
+ }
116
+ ctx.body = { success: true };
117
+ await next();
118
+ }
119
+ async function reviewCancelQueued(ctx, next) {
120
+ const reviewService = service(ctx);
121
+ const { confirmation, inboxId } = (0, import_repository_access.getEffectiveActionParams)(ctx);
122
+ if (confirmation !== "CANCEL_QUEUED_REVIEW")
123
+ ctx.throw(400, ctx.t("Queued review cancellation confirmation is required", { ns: "plugin-git-manager" }));
124
+ if (typeof inboxId !== "string" && typeof inboxId !== "number") ctx.throw(400, "inboxId is required");
125
+ await reviewService.cancelQueued(inboxId, ctx.state.currentUser.id);
126
+ ctx.body = { success: true };
127
+ await next();
128
+ }
129
+ // Annotate the CommonJS export names for ESM import in node:
130
+ 0 && (module.exports = {
131
+ reviewCancelLegacy,
132
+ reviewCancelQueued,
133
+ reviewConfirmCutover,
134
+ reviewCutoverStatus,
135
+ reviewRecover,
136
+ reviewResetPostClaim
137
+ });