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,87 +1,87 @@
1
- import { redactUrlUserInfo } from './url-security';
2
-
3
- export const REDACTED_PAT = '••••••••';
4
-
5
- const GIT_MANAGER_RESOURCE_SEGMENTS = new Set([
6
- 'gitManager',
7
- 'gitRepositories',
8
- 'gitAccounts',
9
- 'gitReviewFlows',
10
- 'gitCodeReviews',
11
- 'gitSubtreeConfigs',
12
- 'gitSubtreeRuns',
13
- ]);
14
-
15
- /**
16
- * Association routes use names such as `gitAccounts.1.repositories`, not the
17
- * raw collection name. Redact every Git Manager resource response so those
18
- * routes cannot bypass credential scrubbing merely because their name is
19
- * nested.
20
- */
21
- export function isGitManagerResourceResponse(resourceName: unknown): boolean {
22
- return (
23
- typeof resourceName === 'string' &&
24
- resourceName.split(/[.[\],:/()=\s]+/).some((segment) => GIT_MANAGER_RESOURCE_SEGMENTS.has(segment))
25
- );
26
- }
27
-
28
- /**
29
- * Redact embedded credentials from URLs in arbitrary strings.
30
- * Matches `scheme://user:password@host` and replaces with `scheme://***:***@host`.
31
- * Used to scrub error messages before persisting them to the DB or
32
- * returning them to the client, since simple-git often echoes the
33
- * authenticated remote URL in stderr.
34
- */
35
- export function redactPat(s: unknown): string {
36
- if (typeof s !== 'string') return s == null ? '' : String(s);
37
- return redactUrlUserInfo(s);
38
- }
39
-
40
- /**
41
- * Mutate `err.message` (and common fields where simple-git stashes stderr)
42
- * to remove any embedded PAT before the error propagates further.
43
- */
44
- export function redactError<T>(err: T): T {
45
- if (!err || typeof err !== 'object') return err;
46
- const error = err as { message?: unknown; stderr?: unknown; stdout?: unknown };
47
- if (typeof error.message === 'string') error.message = redactPat(error.message);
48
- if (typeof error.stderr === 'string') error.stderr = redactPat(error.stderr);
49
- if (typeof error.stdout === 'string') error.stdout = redactPat(error.stdout);
50
- return err;
51
- }
52
-
53
- /**
54
- * Redact PAT fields anywhere in a serializable API response. Repository
55
- * responses can contain a nested `gitAccount` (and Sequelize's nested
56
- * `dataValues`), so a shallow top-level scrub is not sufficient.
57
- */
58
- export function redactCredentialFields(value: unknown): void {
59
- const visited = new WeakSet<object>();
60
-
61
- const visit = (current: unknown): void => {
62
- if (!current || typeof current !== 'object' || visited.has(current)) {
63
- return;
64
- }
65
- visited.add(current);
66
-
67
- if (Array.isArray(current)) {
68
- current.forEach(visit);
69
- return;
70
- }
71
-
72
- const record = current as Record<string, unknown>;
73
- for (const [key, nestedValue] of Object.entries(record)) {
74
- if (key === 'pat') {
75
- record[key] = REDACTED_PAT;
76
- continue;
77
- }
78
- if ((key === 'repoUrl' || key === 'baseUrl') && typeof nestedValue === 'string') {
79
- record[key] = redactUrlUserInfo(nestedValue);
80
- continue;
81
- }
82
- visit(nestedValue);
83
- }
84
- };
85
-
86
- visit(value);
87
- }
1
+ import { redactUrlUserInfo } from './url-security';
2
+
3
+ export const REDACTED_PAT = '••••••••';
4
+
5
+ const GIT_MANAGER_RESOURCE_SEGMENTS = new Set([
6
+ 'gitManager',
7
+ 'gitRepositories',
8
+ 'gitAccounts',
9
+ 'gitReviewFlows',
10
+ 'gitCodeReviews',
11
+ 'gitSubtreeConfigs',
12
+ 'gitSubtreeRuns',
13
+ ]);
14
+
15
+ /**
16
+ * Association routes use names such as `gitAccounts.1.repositories`, not the
17
+ * raw collection name. Redact every Git Manager resource response so those
18
+ * routes cannot bypass credential scrubbing merely because their name is
19
+ * nested.
20
+ */
21
+ export function isGitManagerResourceResponse(resourceName: unknown): boolean {
22
+ return (
23
+ typeof resourceName === 'string' &&
24
+ resourceName.split(/[.[\],:/()=\s]+/).some((segment) => GIT_MANAGER_RESOURCE_SEGMENTS.has(segment))
25
+ );
26
+ }
27
+
28
+ /**
29
+ * Redact embedded credentials from URLs in arbitrary strings.
30
+ * Matches `scheme://user:password@host` and replaces with `scheme://***:***@host`.
31
+ * Used to scrub error messages before persisting them to the DB or
32
+ * returning them to the client, since simple-git often echoes the
33
+ * authenticated remote URL in stderr.
34
+ */
35
+ export function redactPat(s: unknown): string {
36
+ if (typeof s !== 'string') return s == null ? '' : String(s);
37
+ return redactUrlUserInfo(s);
38
+ }
39
+
40
+ /**
41
+ * Mutate `err.message` (and common fields where simple-git stashes stderr)
42
+ * to remove any embedded PAT before the error propagates further.
43
+ */
44
+ export function redactError<T>(err: T): T {
45
+ if (!err || typeof err !== 'object') return err;
46
+ const error = err as { message?: unknown; stderr?: unknown; stdout?: unknown };
47
+ if (typeof error.message === 'string') error.message = redactPat(error.message);
48
+ if (typeof error.stderr === 'string') error.stderr = redactPat(error.stderr);
49
+ if (typeof error.stdout === 'string') error.stdout = redactPat(error.stdout);
50
+ return err;
51
+ }
52
+
53
+ /**
54
+ * Redact PAT fields anywhere in a serializable API response. Repository
55
+ * responses can contain a nested `gitAccount` (and Sequelize's nested
56
+ * `dataValues`), so a shallow top-level scrub is not sufficient.
57
+ */
58
+ export function redactCredentialFields(value: unknown): void {
59
+ const visited = new WeakSet<object>();
60
+
61
+ const visit = (current: unknown): void => {
62
+ if (!current || typeof current !== 'object' || visited.has(current)) {
63
+ return;
64
+ }
65
+ visited.add(current);
66
+
67
+ if (Array.isArray(current)) {
68
+ current.forEach(visit);
69
+ return;
70
+ }
71
+
72
+ const record = current as Record<string, unknown>;
73
+ for (const [key, nestedValue] of Object.entries(record)) {
74
+ if (key === 'pat') {
75
+ record[key] = REDACTED_PAT;
76
+ continue;
77
+ }
78
+ if ((key === 'repoUrl' || key === 'baseUrl') && typeof nestedValue === 'string') {
79
+ record[key] = redactUrlUserInfo(nestedValue);
80
+ continue;
81
+ }
82
+ visit(nestedValue);
83
+ }
84
+ };
85
+
86
+ visit(value);
87
+ }
@@ -1,95 +1,128 @@
1
- export const URL_USERINFO_NOT_ALLOWED = 'Credential-bearing URLs are not allowed';
2
-
3
- function pathSegments(value: string): string[] {
4
- return value.split(/[.[\],:/()=\s'"]+/);
5
- }
6
-
7
- function parseStructuredValue(value: string): unknown {
8
- const trimmed = value.trim();
9
- if (!trimmed.startsWith('{') && !trimmed.startsWith('[')) {
10
- return undefined;
11
- }
12
-
13
- try {
14
- return JSON.parse(trimmed);
15
- } catch {
16
- return undefined;
17
- }
18
- }
19
-
20
- export function hasUrlUserInfo(value: unknown): boolean {
21
- if (typeof value !== 'string' || !value.trim()) {
22
- return false;
23
- }
24
-
25
- try {
26
- const url = new URL(value.trim());
27
- return Boolean(url.username || url.password);
28
- } catch {
29
- return false;
30
- }
31
- }
32
-
33
- export function assertUrlHasNoUserInfo(value: unknown): void {
34
- if (hasUrlUserInfo(value)) {
35
- throw new Error(URL_USERINFO_NOT_ALLOWED);
36
- }
37
- }
38
-
39
- function containsUrlUserInfo(value: unknown, visited = new WeakSet<object>()): boolean {
40
- if (typeof value === 'string') {
41
- return hasUrlUserInfo(value);
42
- }
43
- if (!value || typeof value !== 'object' || visited.has(value)) {
44
- return false;
45
- }
46
- visited.add(value);
47
-
48
- if (Array.isArray(value)) {
49
- return value.some((item) => containsUrlUserInfo(item, visited));
50
- }
51
-
52
- return Object.values(value as Record<string, unknown>).some((item) => containsUrlUserInfo(item, visited));
53
- }
54
-
55
- /**
56
- * Generic NocoBase actions can place values directly, inside `values`, or in
57
- * dotted/bracket paths that UpdateGuard normalizes later. Find userinfo only
58
- * when it belongs to one of the URL-bearing configuration fields.
59
- */
60
- export function containsCredentialBearingUrlField(
61
- value: unknown,
62
- fieldNames: ReadonlySet<string>,
63
- visited = new WeakSet<object>(),
64
- ): boolean {
65
- if (typeof value === 'string') {
66
- const structuredValue = parseStructuredValue(value);
67
- return structuredValue ? containsCredentialBearingUrlField(structuredValue, fieldNames, visited) : false;
68
- }
69
- if (!value || typeof value !== 'object' || visited.has(value)) {
70
- return false;
71
- }
72
- visited.add(value);
73
-
74
- if (Array.isArray(value)) {
75
- return value.some((item) => containsCredentialBearingUrlField(item, fieldNames, visited));
76
- }
77
-
78
- return Object.entries(value as Record<string, unknown>).some(([key, item]) => {
79
- if (pathSegments(key).some((segment) => fieldNames.has(segment)) && containsUrlUserInfo(item)) {
80
- return true;
81
- }
82
- return containsCredentialBearingUrlField(item, fieldNames, visited);
83
- });
84
- }
85
-
86
- /**
87
- * Preserve the rest of a URL while masking URL userinfo in legacy data or an
88
- * accidentally nested API response.
89
- */
90
- export function redactUrlUserInfo(value: string): string {
91
- // Userinfo may itself contain an unescaped `@`; match through the final
92
- // authority `@` rather than stopping at the first one and leaking part of
93
- // a password in a malformed or legacy URL.
94
- return value.replace(/([a-z][a-z\d+.-]*:\/\/)([^/?#\s]+)@/gi, '$1***:***@');
95
- }
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
+ export const URL_USERINFO_NOT_ALLOWED = 'Credential-bearing URLs are not allowed';
11
+
12
+ export function assertAccountRepositoryUrl(repoUrl: string, baseUrl: string | null, provider: string): void {
13
+ assertUrlHasNoUserInfo(repoUrl);
14
+ const trustedUrl = baseUrl || (provider === 'github' ? 'https://github.com' : 'https://gitlab.com');
15
+ assertUrlHasNoUserInfo(trustedUrl);
16
+ let repository: URL;
17
+ let account: URL;
18
+ try {
19
+ repository = new URL(repoUrl);
20
+ account = new URL(trustedUrl);
21
+ } catch {
22
+ throw new Error('Invalid repository or account URL');
23
+ }
24
+ if (repository.protocol !== 'https:' || account.protocol !== 'https:') {
25
+ throw new Error('Only HTTPS repository and account URLs are allowed');
26
+ }
27
+ if (repository.origin !== account.origin) {
28
+ throw new Error('Repository URL must match the Git account origin');
29
+ }
30
+ // This plugin currently implements the public GitHub API, not GitHub Enterprise endpoints.
31
+ if (provider === 'github' && repository.origin !== 'https://github.com') {
32
+ throw new Error('GitHub accounts currently require github.com');
33
+ }
34
+ }
35
+
36
+ function pathSegments(value: string): string[] {
37
+ return value.split(/[.[\],:/()=\s'"]+/);
38
+ }
39
+
40
+ function parseStructuredValue(value: string): unknown {
41
+ const trimmed = value.trim();
42
+ if (!trimmed.startsWith('{') && !trimmed.startsWith('[')) {
43
+ return undefined;
44
+ }
45
+
46
+ try {
47
+ return JSON.parse(trimmed);
48
+ } catch {
49
+ return undefined;
50
+ }
51
+ }
52
+
53
+ export function hasUrlUserInfo(value: unknown): boolean {
54
+ if (typeof value !== 'string' || !value.trim()) {
55
+ return false;
56
+ }
57
+
58
+ try {
59
+ const url = new URL(value.trim());
60
+ return Boolean(url.username || url.password);
61
+ } catch {
62
+ return false;
63
+ }
64
+ }
65
+
66
+ export function assertUrlHasNoUserInfo(value: unknown): void {
67
+ if (hasUrlUserInfo(value)) {
68
+ throw new Error(URL_USERINFO_NOT_ALLOWED);
69
+ }
70
+ }
71
+
72
+ function containsUrlUserInfo(value: unknown, visited = new WeakSet<object>()): boolean {
73
+ if (typeof value === 'string') {
74
+ return hasUrlUserInfo(value);
75
+ }
76
+ if (!value || typeof value !== 'object' || visited.has(value)) {
77
+ return false;
78
+ }
79
+ visited.add(value);
80
+
81
+ if (Array.isArray(value)) {
82
+ return value.some((item) => containsUrlUserInfo(item, visited));
83
+ }
84
+
85
+ return Object.values(value as Record<string, unknown>).some((item) => containsUrlUserInfo(item, visited));
86
+ }
87
+
88
+ /**
89
+ * Generic NocoBase actions can place values directly, inside `values`, or in
90
+ * dotted/bracket paths that UpdateGuard normalizes later. Find userinfo only
91
+ * when it belongs to one of the URL-bearing configuration fields.
92
+ */
93
+ export function containsCredentialBearingUrlField(
94
+ value: unknown,
95
+ fieldNames: ReadonlySet<string>,
96
+ visited = new WeakSet<object>(),
97
+ ): boolean {
98
+ if (typeof value === 'string') {
99
+ const structuredValue = parseStructuredValue(value);
100
+ return structuredValue ? containsCredentialBearingUrlField(structuredValue, fieldNames, visited) : false;
101
+ }
102
+ if (!value || typeof value !== 'object' || visited.has(value)) {
103
+ return false;
104
+ }
105
+ visited.add(value);
106
+
107
+ if (Array.isArray(value)) {
108
+ return value.some((item) => containsCredentialBearingUrlField(item, fieldNames, visited));
109
+ }
110
+
111
+ return Object.entries(value as Record<string, unknown>).some(([key, item]) => {
112
+ if (pathSegments(key).some((segment) => fieldNames.has(segment)) && containsUrlUserInfo(item)) {
113
+ return true;
114
+ }
115
+ return containsCredentialBearingUrlField(item, fieldNames, visited);
116
+ });
117
+ }
118
+
119
+ /**
120
+ * Preserve the rest of a URL while masking URL userinfo in legacy data or an
121
+ * accidentally nested API response.
122
+ */
123
+ export function redactUrlUserInfo(value: string): string {
124
+ // Userinfo may itself contain an unescaped `@`; match through the final
125
+ // authority `@` rather than stopping at the first one and leaking part of
126
+ // a password in a malformed or legacy URL.
127
+ return value.replace(/([a-z][a-z\d+.-]*:\/\/)([^/?#\s]+)@/gi, '$1***:***@');
128
+ }