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.
Files changed (108) hide show
  1. package/README.md +133 -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/900.a48beac7e2ebee7d.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/900.e6155002a9c97e7f.js +10 -0
  13. package/dist/client-v2/928.bba701b5a1ece58e.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 +307 -297
  17. package/dist/locale/vi-VN.json +295 -292
  18. package/dist/locale/zh-CN.json +61 -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.js +20 -10
  27. package/dist/server/plugin.js +6 -4
  28. package/dist/server/poller.js +46 -45
  29. package/dist/server/request-method-policy.js +75 -0
  30. package/dist/server/services/registry-content-service.js +23 -10
  31. package/dist/server/utils/get-repo-account.js +3 -2
  32. package/dist/server/utils/url-security.js +24 -0
  33. package/package.json +61 -43
  34. package/server.d.ts +2 -2
  35. package/server.js +1 -1
  36. package/src/client/__tests__/RunReviewButton.test.tsx +73 -0
  37. package/src/client/ai-context.tsx +114 -114
  38. package/src/client/components/AIEmployeeSelect.tsx +63 -63
  39. package/src/client/components/CommitHistory.tsx +374 -374
  40. package/src/client/components/FileExplorer.tsx +386 -386
  41. package/src/client/components/GitAccounts.tsx +179 -179
  42. package/src/client/components/GitManagerSettings.tsx +160 -160
  43. package/src/client/components/GitOperations.tsx +220 -220
  44. package/src/client/components/LLMModelSelect.tsx +63 -63
  45. package/src/client/components/LLMServiceSelect.tsx +58 -58
  46. package/src/client/components/MarkdownView.tsx +80 -80
  47. package/src/client/components/MergeRequests.tsx +790 -790
  48. package/src/client/components/PollingStatus.tsx +225 -225
  49. package/src/client/components/RepositoryConfig.tsx +335 -335
  50. package/src/client/components/RepositoryPermissions.tsx +123 -123
  51. package/src/client/components/ReviewFlows.tsx +303 -303
  52. package/src/client/components/ReviewHistory.tsx +566 -566
  53. package/src/client/components/RunReviewButton.tsx +63 -55
  54. package/src/client/context/GitManagerContext.tsx +92 -92
  55. package/src/client/index.tsx +91 -82
  56. package/src/client/locale.ts +9 -9
  57. package/src/client/promptTemplates.ts +31 -31
  58. package/src/client-v2/ai-context.tsx +99 -0
  59. package/src/client-v2/components/SubtreeSplits.tsx +547 -547
  60. package/src/client-v2/index.tsx +1 -1
  61. package/src/client-v2/locale.ts +8 -8
  62. package/src/client-v2/plugin.tsx +67 -39
  63. package/src/index.ts +2 -2
  64. package/src/locale/en-US.json +307 -297
  65. package/src/locale/vi-VN.json +295 -292
  66. package/src/locale/zh-CN.json +61 -51
  67. package/src/server/__tests__/git-actions.test.ts +24 -24
  68. package/src/server/__tests__/git-security.test.ts +170 -0
  69. package/src/server/__tests__/plugin-url-security.test.ts +17 -17
  70. package/src/server/__tests__/poller-lifecycle.test.ts +71 -0
  71. package/src/server/__tests__/poller.test.ts +37 -37
  72. package/src/server/__tests__/repository-access.test.ts +752 -752
  73. package/src/server/__tests__/review.test.ts +137 -137
  74. package/src/server/__tests__/role-permissions.test.ts +147 -147
  75. package/src/server/__tests__/smoke.test.ts +139 -17
  76. package/src/server/__tests__/subtree.test.ts +85 -85
  77. package/src/server/actions/git-actions.ts +540 -480
  78. package/src/server/actions/gitlab-api.ts +422 -411
  79. package/src/server/actions/poller.ts +39 -27
  80. package/src/server/actions/review.ts +1388 -1369
  81. package/src/server/actions/role-permissions.ts +321 -321
  82. package/src/server/actions/subtree.ts +508 -508
  83. package/src/server/ai-tools.ts +319 -319
  84. package/src/server/collections/gitAccounts.ts +56 -56
  85. package/src/server/collections/gitCodeReviews.ts +199 -199
  86. package/src/server/collections/gitRepositories.ts +87 -87
  87. package/src/server/collections/gitReviewFlows.ts +108 -108
  88. package/src/server/collections/gitSubtreeConfigs.ts +38 -38
  89. package/src/server/collections/gitSubtreeRuns.ts +30 -30
  90. package/src/server/index.ts +2 -2
  91. package/src/server/migrations/20260508000000-add-auto-review-flow-id.ts +29 -29
  92. package/src/server/migrations/20260712000000-add-git-accounts.ts +198 -198
  93. package/src/server/migrations/20260730000000-migrate-legacy-repository-permissions.ts +81 -81
  94. package/src/server/plugin.ts +372 -361
  95. package/src/server/poller.ts +351 -352
  96. package/src/server/repository-access.ts +773 -773
  97. package/src/server/request-method-policy.ts +55 -0
  98. package/src/server/services/__tests__/registry-content-service.test.ts +359 -345
  99. package/src/server/services/registry-content-service.ts +33 -11
  100. package/src/server/utils/__tests__/redact.test.ts +56 -56
  101. package/src/server/utils/__tests__/url-security.test.ts +85 -85
  102. package/src/server/utils/get-repo-account.ts +51 -41
  103. package/src/server/utils/gitlab-url.ts +38 -38
  104. package/src/server/utils/redact.ts +87 -87
  105. package/src/server/utils/url-security.ts +128 -95
  106. package/dist/client/900.acf7d1fa22f95e71.js +0 -10
  107. package/dist/client-v2/434.7a27051db18526c0.js +0 -10
  108. package/dist/client-v2/900.f32b9dc85249fc0a.js +0 -10
@@ -1,3 +1,12 @@
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
+
1
10
  import { spawn } from 'child_process';
2
11
  import { existsSync } from 'fs';
3
12
  import type { Readable } from 'stream';
@@ -26,17 +35,16 @@ export interface RegistryGitContentLimits {
26
35
  maxTreeOutputBytes: number;
27
36
  }
28
37
 
29
- // Getter-based limits re-read env vars on every access, so runtime settings
30
- // applied via Skill Registry's applyRuntimeOverrides() take effect without restart.
38
+ // Deployment ceilings are read from the environment.
31
39
  const DEFAULT_REGISTRY_GIT_CONTENT_LIMITS: RegistryGitContentLimits = {
32
40
  get maxFileBytes() {
33
- return positiveLimit(process.env.SKILL_REGISTRY_MAX_SOURCE_FILE_BYTES, 10 * 1024 * 1024);
41
+ return positiveLimit(process.env.SKILL_REGISTRY_MAX_SOURCE_FILE_BYTES, 100 * 1024 * 1024);
34
42
  },
35
43
  get maxTreeEntries() {
36
- return positiveLimit(process.env.SKILL_REGISTRY_MAX_SOURCE_TREE_ENTRIES, 5000);
44
+ return positiveLimit(process.env.SKILL_REGISTRY_MAX_SOURCE_TREE_ENTRIES, 50000);
37
45
  },
38
46
  get maxTreeOutputBytes() {
39
- return positiveLimit(process.env.SKILL_REGISTRY_MAX_SOURCE_TREE_OUTPUT_BYTES, 4 * 1024 * 1024);
47
+ return positiveLimit(process.env.SKILL_REGISTRY_MAX_SOURCE_TREE_OUTPUT_BYTES, 64 * 1024 * 1024);
40
48
  },
41
49
  };
42
50
 
@@ -59,6 +67,7 @@ export const REGISTRY_GIT_CONTENT_CONTRACT_VERSION = 2;
59
67
  export const REGISTRY_GIT_CONTENT_CAPABILITIES = [
60
68
  'registry-content-with-actor',
61
69
  'registry-content-authorize-source',
70
+ 'registry-content-tree-limits',
62
71
  ] as const;
63
72
  export const SKILL_HUB_GIT_CONTENT_CONTRACT_VERSION = 2;
64
73
  export const SKILL_HUB_GIT_CONTENT_CAPABILITIES = ['skill-hub-content-with-actor'] as const;
@@ -111,6 +120,17 @@ export class RegistryGitFileNotFoundError extends Error {
111
120
  }
112
121
  }
113
122
 
123
+ export const REGISTRY_GIT_COMMAND_FAILED = 'REGISTRY_GIT_COMMAND_FAILED';
124
+
125
+ export class RegistryGitCommandError extends Error {
126
+ readonly code = REGISTRY_GIT_COMMAND_FAILED;
127
+
128
+ constructor(message: string) {
129
+ super(message);
130
+ this.name = 'RegistryGitCommandError';
131
+ }
132
+ }
133
+
114
134
  interface GitContentAccessPolicy {
115
135
  contractVersion: number;
116
136
  capabilities: readonly string[];
@@ -207,7 +227,7 @@ function runGitBuffer(localPath: string, args: string[], maximumBytes: number, t
207
227
  reject(new RegistryGitFileNotFoundError());
208
228
  return;
209
229
  }
210
- reject(new Error(`git command failed: ${stderr.trim() || String(code)}`));
230
+ reject(new RegistryGitCommandError(`git command failed: ${stderr.trim() || String(code)}`));
211
231
  return;
212
232
  }
213
233
  resolve(Buffer.concat(chunks, outputBytes));
@@ -294,7 +314,7 @@ class GitContentService {
294
314
  .toString('utf8')
295
315
  .trim();
296
316
  if (!/^[a-f0-9]{40,64}$/i.test(result)) {
297
- throw new Error('Git reference did not resolve to a commit SHA');
317
+ throw new RegistryGitCommandError('Git reference did not resolve to a commit SHA');
298
318
  }
299
319
  return result.toLowerCase();
300
320
  }
@@ -305,6 +325,8 @@ class GitContentService {
305
325
  commitSha: string;
306
326
  rootPath: string;
307
327
  recursive: boolean;
328
+ maxTreeEntries?: number;
329
+ maxTreeOutputBytes?: number;
308
330
  },
309
331
  access?: RegistryGitAccessContext,
310
332
  ): Promise<RegistryGitTreeEntry[]> {
@@ -319,11 +341,11 @@ class GitContentService {
319
341
  const output = await runGitBuffer(
320
342
  localPath,
321
343
  ['ls-tree', '-l', ...(input.recursive ? ['-r'] : []), target],
322
- this.limits.maxTreeOutputBytes,
344
+ boundedPositive(input.maxTreeOutputBytes, this.limits.maxTreeOutputBytes, this.limits.maxTreeOutputBytes),
323
345
  DEFAULT_GIT_TIMEOUT_MS,
324
346
  );
325
347
  const lines = output.toString('utf8').trim().split('\n').filter(Boolean);
326
- if (lines.length > this.limits.maxTreeEntries) {
348
+ if (lines.length > boundedPositive(input.maxTreeEntries, this.limits.maxTreeEntries, this.limits.maxTreeEntries)) {
327
349
  throw new RegistryContentLimitError('Git tree contains too many entries for registry export.');
328
350
  }
329
351
  return lines
@@ -387,7 +409,7 @@ class GitContentService {
387
409
  child.once('spawn', () => resolve(child.stdout));
388
410
  child.once('close', (code) => {
389
411
  if (code !== 0) {
390
- child.stdout.destroy(new Error(`git archive failed: ${stderr.trim() || String(code)}`));
412
+ child.stdout.destroy(new RegistryGitCommandError(`git archive failed: ${stderr.trim() || String(code)}`));
391
413
  }
392
414
  });
393
415
  });
@@ -446,7 +468,7 @@ class GitContentService {
446
468
  private assertCommitSha(value: string): string {
447
469
  const normalized = validateRef(value);
448
470
  if (!/^[a-f0-9]{40,64}$/i.test(normalized)) {
449
- throw new Error('Registry reads require a full commit SHA');
471
+ throw new RegistryGitCommandError('Registry reads require a full commit SHA');
450
472
  }
451
473
  return normalized.toLowerCase();
452
474
  }
@@ -1,56 +1,56 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { isGitManagerResourceResponse, REDACTED_PAT, redactCredentialFields } from '../redact';
3
-
4
- describe('Git Manager credential response redaction', () => {
5
- it('redacts PATs recursively through nested associations and dataValues', () => {
6
- const response = {
7
- data: [
8
- {
9
- gitAccount: {
10
- pat: 'top-level-secret',
11
- dataValues: { pat: 'top-level-data-values-secret' },
12
- },
13
- dataValues: {
14
- gitAccount: {
15
- pat: 'nested-secret',
16
- dataValues: { pat: 'nested-data-values-secret' },
17
- },
18
- },
19
- },
20
- ],
21
- };
22
-
23
- redactCredentialFields(response);
24
-
25
- expect(response.data[0].gitAccount.pat).toBe(REDACTED_PAT);
26
- expect(response.data[0].gitAccount.dataValues.pat).toBe(REDACTED_PAT);
27
- expect(response.data[0].dataValues.gitAccount.pat).toBe(REDACTED_PAT);
28
- expect(response.data[0].dataValues.gitAccount.dataValues.pat).toBe(REDACTED_PAT);
29
- });
30
-
31
- it('handles circular response objects without leaving a PAT exposed', () => {
32
- const response: { pat: string; self?: unknown } = { pat: 'secret' };
33
- response.self = response;
34
-
35
- redactCredentialFields(response);
36
-
37
- expect(response.pat).toBe(REDACTED_PAT);
38
- });
39
-
40
- it.each([
41
- 'gitManager',
42
- 'gitRepositories',
43
- 'gitReviewFlows',
44
- 'gitCodeReviews',
45
- 'gitSubtreeConfigs',
46
- 'gitSubtreeRuns',
47
- 'gitAccounts.1.repositories',
48
- 'gitRepositories.10.gitAccount',
49
- ])('recognizes nested Git Manager response route %s', (resourceName) => {
50
- expect(isGitManagerResourceResponse(resourceName)).toBe(true);
51
- });
52
-
53
- it('does not scrub unrelated resource responses', () => {
54
- expect(isGitManagerResourceResponse('users')).toBe(false);
55
- });
56
- });
1
+ import { describe, expect, it } from 'vitest';
2
+ import { isGitManagerResourceResponse, REDACTED_PAT, redactCredentialFields } from '../redact';
3
+
4
+ describe('Git Manager credential response redaction', () => {
5
+ it('redacts PATs recursively through nested associations and dataValues', () => {
6
+ const response = {
7
+ data: [
8
+ {
9
+ gitAccount: {
10
+ pat: 'top-level-secret',
11
+ dataValues: { pat: 'top-level-data-values-secret' },
12
+ },
13
+ dataValues: {
14
+ gitAccount: {
15
+ pat: 'nested-secret',
16
+ dataValues: { pat: 'nested-data-values-secret' },
17
+ },
18
+ },
19
+ },
20
+ ],
21
+ };
22
+
23
+ redactCredentialFields(response);
24
+
25
+ expect(response.data[0].gitAccount.pat).toBe(REDACTED_PAT);
26
+ expect(response.data[0].gitAccount.dataValues.pat).toBe(REDACTED_PAT);
27
+ expect(response.data[0].dataValues.gitAccount.pat).toBe(REDACTED_PAT);
28
+ expect(response.data[0].dataValues.gitAccount.dataValues.pat).toBe(REDACTED_PAT);
29
+ });
30
+
31
+ it('handles circular response objects without leaving a PAT exposed', () => {
32
+ const response: { pat: string; self?: unknown } = { pat: 'secret' };
33
+ response.self = response;
34
+
35
+ redactCredentialFields(response);
36
+
37
+ expect(response.pat).toBe(REDACTED_PAT);
38
+ });
39
+
40
+ it.each([
41
+ 'gitManager',
42
+ 'gitRepositories',
43
+ 'gitReviewFlows',
44
+ 'gitCodeReviews',
45
+ 'gitSubtreeConfigs',
46
+ 'gitSubtreeRuns',
47
+ 'gitAccounts.1.repositories',
48
+ 'gitRepositories.10.gitAccount',
49
+ ])('recognizes nested Git Manager response route %s', (resourceName) => {
50
+ expect(isGitManagerResourceResponse(resourceName)).toBe(true);
51
+ });
52
+
53
+ it('does not scrub unrelated resource responses', () => {
54
+ expect(isGitManagerResourceResponse('users')).toBe(false);
55
+ });
56
+ });
@@ -1,85 +1,85 @@
1
- import { describe, expect, it } from 'vitest';
2
-
3
- import { validateRepoUrl } from '../../actions/git-actions';
4
- import { parseGitLabProject } from '../gitlab-url';
5
- import { redactCredentialFields } from '../redact';
6
- import {
7
- assertUrlHasNoUserInfo,
8
- containsCredentialBearingUrlField,
9
- hasUrlUserInfo,
10
- redactUrlUserInfo,
11
- URL_USERINFO_NOT_ALLOWED,
12
- } from '../url-security';
13
-
14
- const CREDENTIAL_URL = 'https://user:secret@example.test/group/repository.git';
15
- const USERNAME_ONLY_URL = 'https://user@example.test/group/repository.git';
16
- const REPOSITORY_URL_FIELDS = new Set(['repoUrl']);
17
- const ACCOUNT_URL_FIELDS = new Set(['baseUrl']);
18
- const GIT_CONFIGURATION_URL_FIELDS = new Set(['repoUrl', 'baseUrl']);
19
-
20
- describe('Git Manager URL credential security', () => {
21
- it('rejects URLs with a username or password', () => {
22
- expect(hasUrlUserInfo(CREDENTIAL_URL)).toBe(true);
23
- expect(hasUrlUserInfo(USERNAME_ONLY_URL)).toBe(true);
24
- expect(() => assertUrlHasNoUserInfo(CREDENTIAL_URL)).toThrow(URL_USERINFO_NOT_ALLOWED);
25
- expect(() => assertUrlHasNoUserInfo(USERNAME_ONLY_URL)).toThrow(URL_USERINFO_NOT_ALLOWED);
26
- });
27
-
28
- it.each([
29
- ['direct repository URL', { repoUrl: CREDENTIAL_URL }, REPOSITORY_URL_FIELDS],
30
- ['dotted repository URL', { 'values.repoUrl': CREDENTIAL_URL }, REPOSITORY_URL_FIELDS],
31
- ['bracket account URL', { 'values[baseUrl]': USERNAME_ONLY_URL }, ACCOUNT_URL_FIELDS],
32
- ['nested account URL', { values: { updateAssociationValues: { baseUrl: CREDENTIAL_URL } } }, ACCOUNT_URL_FIELDS],
33
- [
34
- 'repository association account URL',
35
- { values: { gitAccount: { baseUrl: CREDENTIAL_URL } } },
36
- GIT_CONFIGURATION_URL_FIELDS,
37
- ],
38
- [
39
- 'account association repository URL',
40
- { values: { repositories: [{ repoUrl: CREDENTIAL_URL }] } },
41
- GIT_CONFIGURATION_URL_FIELDS,
42
- ],
43
- ['serialized query values', JSON.stringify({ values: { repoUrl: CREDENTIAL_URL } }), REPOSITORY_URL_FIELDS],
44
- ])('finds a credential-bearing URL in %s', (_source, value, fields) => {
45
- expect(containsCredentialBearingUrlField(value, fields)).toBe(true);
46
- });
47
-
48
- it('allows clean URLs and ignores other field names', () => {
49
- expect(
50
- containsCredentialBearingUrlField(
51
- { values: { repoUrl: 'https://example.test/group/repository.git' } },
52
- REPOSITORY_URL_FIELDS,
53
- ),
54
- ).toBe(false);
55
- expect(containsCredentialBearingUrlField({ otherUrl: CREDENTIAL_URL }, REPOSITORY_URL_FIELDS)).toBe(false);
56
- expect(() => validateRepoUrl('https://example.test/group/repository.git')).not.toThrow();
57
- });
58
-
59
- it('rejects credential-bearing URLs in Git entry points', () => {
60
- expect(() => validateRepoUrl(CREDENTIAL_URL)).toThrow(URL_USERINFO_NOT_ALLOWED);
61
- expect(() => parseGitLabProject(USERNAME_ONLY_URL)).toThrow(URL_USERINFO_NOT_ALLOWED);
62
- });
63
-
64
- it('redacts userinfo from nested repository and account responses', () => {
65
- const response = {
66
- data: {
67
- repoUrl: CREDENTIAL_URL,
68
- gitAccount: {
69
- baseUrl: USERNAME_ONLY_URL,
70
- },
71
- },
72
- };
73
-
74
- redactCredentialFields(response);
75
-
76
- expect(response.data.repoUrl).toBe('https://***:***@example.test/group/repository.git');
77
- expect(response.data.gitAccount.baseUrl).toBe('https://***:***@example.test/group/repository.git');
78
- });
79
-
80
- it('does not leak a password segment when legacy userinfo contains another at sign', () => {
81
- expect(redactUrlUserInfo('https://user:secret@still-secret@example.test/repository.git')).toBe(
82
- 'https://***:***@example.test/repository.git',
83
- );
84
- });
85
- });
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { validateRepoUrl } from '../../actions/git-actions';
4
+ import { parseGitLabProject } from '../gitlab-url';
5
+ import { redactCredentialFields } from '../redact';
6
+ import {
7
+ assertUrlHasNoUserInfo,
8
+ containsCredentialBearingUrlField,
9
+ hasUrlUserInfo,
10
+ redactUrlUserInfo,
11
+ URL_USERINFO_NOT_ALLOWED,
12
+ } from '../url-security';
13
+
14
+ const CREDENTIAL_URL = 'https://user:secret@example.test/group/repository.git';
15
+ const USERNAME_ONLY_URL = 'https://user@example.test/group/repository.git';
16
+ const REPOSITORY_URL_FIELDS = new Set(['repoUrl']);
17
+ const ACCOUNT_URL_FIELDS = new Set(['baseUrl']);
18
+ const GIT_CONFIGURATION_URL_FIELDS = new Set(['repoUrl', 'baseUrl']);
19
+
20
+ describe('Git Manager URL credential security', () => {
21
+ it('rejects URLs with a username or password', () => {
22
+ expect(hasUrlUserInfo(CREDENTIAL_URL)).toBe(true);
23
+ expect(hasUrlUserInfo(USERNAME_ONLY_URL)).toBe(true);
24
+ expect(() => assertUrlHasNoUserInfo(CREDENTIAL_URL)).toThrow(URL_USERINFO_NOT_ALLOWED);
25
+ expect(() => assertUrlHasNoUserInfo(USERNAME_ONLY_URL)).toThrow(URL_USERINFO_NOT_ALLOWED);
26
+ });
27
+
28
+ it.each([
29
+ ['direct repository URL', { repoUrl: CREDENTIAL_URL }, REPOSITORY_URL_FIELDS],
30
+ ['dotted repository URL', { 'values.repoUrl': CREDENTIAL_URL }, REPOSITORY_URL_FIELDS],
31
+ ['bracket account URL', { 'values[baseUrl]': USERNAME_ONLY_URL }, ACCOUNT_URL_FIELDS],
32
+ ['nested account URL', { values: { updateAssociationValues: { baseUrl: CREDENTIAL_URL } } }, ACCOUNT_URL_FIELDS],
33
+ [
34
+ 'repository association account URL',
35
+ { values: { gitAccount: { baseUrl: CREDENTIAL_URL } } },
36
+ GIT_CONFIGURATION_URL_FIELDS,
37
+ ],
38
+ [
39
+ 'account association repository URL',
40
+ { values: { repositories: [{ repoUrl: CREDENTIAL_URL }] } },
41
+ GIT_CONFIGURATION_URL_FIELDS,
42
+ ],
43
+ ['serialized query values', JSON.stringify({ values: { repoUrl: CREDENTIAL_URL } }), REPOSITORY_URL_FIELDS],
44
+ ])('finds a credential-bearing URL in %s', (_source, value, fields) => {
45
+ expect(containsCredentialBearingUrlField(value, fields)).toBe(true);
46
+ });
47
+
48
+ it('allows clean URLs and ignores other field names', () => {
49
+ expect(
50
+ containsCredentialBearingUrlField(
51
+ { values: { repoUrl: 'https://example.test/group/repository.git' } },
52
+ REPOSITORY_URL_FIELDS,
53
+ ),
54
+ ).toBe(false);
55
+ expect(containsCredentialBearingUrlField({ otherUrl: CREDENTIAL_URL }, REPOSITORY_URL_FIELDS)).toBe(false);
56
+ expect(() => validateRepoUrl('https://example.test/group/repository.git')).not.toThrow();
57
+ });
58
+
59
+ it('rejects credential-bearing URLs in Git entry points', () => {
60
+ expect(() => validateRepoUrl(CREDENTIAL_URL)).toThrow(URL_USERINFO_NOT_ALLOWED);
61
+ expect(() => parseGitLabProject(USERNAME_ONLY_URL)).toThrow(URL_USERINFO_NOT_ALLOWED);
62
+ });
63
+
64
+ it('redacts userinfo from nested repository and account responses', () => {
65
+ const response = {
66
+ data: {
67
+ repoUrl: CREDENTIAL_URL,
68
+ gitAccount: {
69
+ baseUrl: USERNAME_ONLY_URL,
70
+ },
71
+ },
72
+ };
73
+
74
+ redactCredentialFields(response);
75
+
76
+ expect(response.data.repoUrl).toBe('https://***:***@example.test/group/repository.git');
77
+ expect(response.data.gitAccount.baseUrl).toBe('https://***:***@example.test/group/repository.git');
78
+ });
79
+
80
+ it('does not leak a password segment when legacy userinfo contains another at sign', () => {
81
+ expect(redactUrlUserInfo('https://user:secret@still-secret@example.test/repository.git')).toBe(
82
+ 'https://***:***@example.test/repository.git',
83
+ );
84
+ });
85
+ });
@@ -1,41 +1,51 @@
1
- import { assertUrlHasNoUserInfo } from './url-security';
2
-
3
- export interface GitAccountCredentials {
4
- pat: string;
5
- username: string;
6
- baseUrl: string | null;
7
- provider: string;
8
- }
9
-
10
- type RecordGetter = {
11
- get(attribute: string): unknown;
12
- };
13
-
14
- type GitAccountDatabase = {
15
- getRepository(name: 'gitAccounts'): {
16
- findOne(input: { filterByTk: number | string }): Promise<RecordGetter | null>;
17
- };
18
- };
19
-
20
- export async function getRepoAccount(
21
- db: GitAccountDatabase,
22
- repo: RecordGetter,
23
- ): Promise<GitAccountCredentials | null> {
24
- const gitAccountId = repo.get('gitAccountId');
25
- if (typeof gitAccountId !== 'number' && typeof gitAccountId !== 'string') return null;
26
-
27
- const account = await db.getRepository('gitAccounts').findOne({
28
- filterByTk: gitAccountId,
29
- });
30
- if (!account) return null;
31
-
32
- const baseUrl = ((account.get('baseUrl') as string) || '').trim() || null;
33
- if (baseUrl) assertUrlHasNoUserInfo(baseUrl);
34
-
35
- return {
36
- pat: ((account.get('pat') as string) || '').trim(),
37
- username: ((account.get('username') as string) || '').trim(),
38
- baseUrl,
39
- provider: ((account.get('provider') as string) || 'gitlab').trim(),
40
- };
41
- }
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
+ import { assertAccountRepositoryUrl } from './url-security';
11
+
12
+ export interface GitAccountCredentials {
13
+ pat: string;
14
+ username: string;
15
+ baseUrl: string | null;
16
+ provider: string;
17
+ }
18
+
19
+ type RecordGetter = {
20
+ get(attribute: string): unknown;
21
+ };
22
+
23
+ type GitAccountDatabase = {
24
+ getRepository(name: 'gitAccounts'): {
25
+ findOne(input: { filterByTk: number | string }): Promise<RecordGetter | null>;
26
+ };
27
+ };
28
+
29
+ export async function getRepoAccount(
30
+ db: GitAccountDatabase,
31
+ repo: RecordGetter,
32
+ ): Promise<GitAccountCredentials | null> {
33
+ const gitAccountId = repo.get('gitAccountId');
34
+ if (typeof gitAccountId !== 'number' && typeof gitAccountId !== 'string') return null;
35
+
36
+ const account = await db.getRepository('gitAccounts').findOne({
37
+ filterByTk: gitAccountId,
38
+ });
39
+ if (!account) return null;
40
+
41
+ const baseUrl = ((account.get('baseUrl') as string) || '').trim() || null;
42
+ const provider = ((account.get('provider') as string) || 'gitlab').trim();
43
+ assertAccountRepositoryUrl(String(repo.get('repoUrl') || ''), baseUrl, provider);
44
+
45
+ return {
46
+ pat: ((account.get('pat') as string) || '').trim(),
47
+ username: ((account.get('username') as string) || '').trim(),
48
+ baseUrl,
49
+ provider,
50
+ };
51
+ }
@@ -1,38 +1,38 @@
1
- import { assertUrlHasNoUserInfo } from './url-security';
2
-
3
- /**
4
- * Shared utility for parsing GitLab repository URLs.
5
- * Extracted to avoid duplicating URL-parsing logic across
6
- * gitlab-api.ts, poller.ts, and review.ts.
7
- */
8
-
9
- export interface GitLabProject {
10
- /** Full API base URL, e.g. https://gitlab.com/api/v4 */
11
- apiBase: string;
12
- /** Raw project path, e.g. group/sub/project */
13
- projectPath: string;
14
- /** URL-encoded project path for use in API endpoints */
15
- encodedProject: string;
16
- }
17
-
18
- /**
19
- * Extract GitLab API base URL and project path from a repository URL.
20
- * Supports: https://gitlab.com/group/project.git
21
- * https://self-hosted.gitlab.com/group/sub/project.git
22
- *
23
- * @throws Error if the URL cannot be parsed or has no project path
24
- */
25
- export function parseGitLabProject(repoUrl: string): GitLabProject {
26
- assertUrlHasNoUserInfo(repoUrl);
27
- const url = new URL(repoUrl);
28
- // Remove .git suffix and leading slash
29
- const projectPath = url.pathname.replace(/\.git$/, '').replace(/^\//, '');
30
- if (!projectPath) {
31
- throw new Error('Cannot extract project path from repository URL');
32
- }
33
- return {
34
- apiBase: `${url.protocol}//${url.host}/api/v4`,
35
- projectPath,
36
- encodedProject: encodeURIComponent(projectPath),
37
- };
38
- }
1
+ import { assertUrlHasNoUserInfo } from './url-security';
2
+
3
+ /**
4
+ * Shared utility for parsing GitLab repository URLs.
5
+ * Extracted to avoid duplicating URL-parsing logic across
6
+ * gitlab-api.ts, poller.ts, and review.ts.
7
+ */
8
+
9
+ export interface GitLabProject {
10
+ /** Full API base URL, e.g. https://gitlab.com/api/v4 */
11
+ apiBase: string;
12
+ /** Raw project path, e.g. group/sub/project */
13
+ projectPath: string;
14
+ /** URL-encoded project path for use in API endpoints */
15
+ encodedProject: string;
16
+ }
17
+
18
+ /**
19
+ * Extract GitLab API base URL and project path from a repository URL.
20
+ * Supports: https://gitlab.com/group/project.git
21
+ * https://self-hosted.gitlab.com/group/sub/project.git
22
+ *
23
+ * @throws Error if the URL cannot be parsed or has no project path
24
+ */
25
+ export function parseGitLabProject(repoUrl: string): GitLabProject {
26
+ assertUrlHasNoUserInfo(repoUrl);
27
+ const url = new URL(repoUrl);
28
+ // Remove .git suffix and leading slash
29
+ const projectPath = url.pathname.replace(/\.git$/, '').replace(/^\//, '');
30
+ if (!projectPath) {
31
+ throw new Error('Cannot extract project path from repository URL');
32
+ }
33
+ return {
34
+ apiBase: `${url.protocol}//${url.host}/api/v4`,
35
+ projectPath,
36
+ encodedProject: encodeURIComponent(projectPath),
37
+ };
38
+ }