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
@@ -0,0 +1,226 @@
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 { execFileSync } from 'child_process';
11
+ import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'fs';
12
+ import { tmpdir } from 'os';
13
+ import { join } from 'path';
14
+ import type { Database } from '@nocobase/database';
15
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
16
+ import { readPinnedReviewSource, resolveReviewSource } from '../review-source';
17
+
18
+ const projectHead = 'b'.repeat(40);
19
+ const projectBase = 'a'.repeat(40);
20
+
21
+ function record(values: Record<string, unknown>) {
22
+ return { get: (attribute: string) => values[attribute] };
23
+ }
24
+
25
+ describe('pinned Git review source', () => {
26
+ let fixture: string;
27
+ let repositoryPath: string;
28
+ let otherRepositoryPath: string;
29
+ let commitSha: string;
30
+ const originalBase = process.env.GIT_REPOS_BASE_PATH;
31
+
32
+ beforeEach(() => {
33
+ fixture = mkdtempSync(join(tmpdir(), 'git-review-source-'));
34
+ repositoryPath = join(fixture, 'repository');
35
+ otherRepositoryPath = join(fixture, 'other-repository');
36
+ mkdirSync(repositoryPath);
37
+ mkdirSync(otherRepositoryPath);
38
+ process.env.GIT_REPOS_BASE_PATH = fixture;
39
+ execFileSync('git', ['init', '-b', 'main', repositoryPath], { stdio: 'ignore' });
40
+ execFileSync('git', ['init', '-b', 'main', otherRepositoryPath], { stdio: 'ignore' });
41
+ execFileSync('git', ['-C', repositoryPath, 'config', 'user.name', 'Test'], { stdio: 'ignore' });
42
+ execFileSync('git', ['-C', repositoryPath, 'config', 'user.email', 'test@example.invalid'], { stdio: 'ignore' });
43
+ execFileSync('git', ['-C', otherRepositoryPath, 'config', 'user.name', 'Test'], { stdio: 'ignore' });
44
+ execFileSync('git', ['-C', otherRepositoryPath, 'config', 'user.email', 'test@example.invalid'], {
45
+ stdio: 'ignore',
46
+ });
47
+ writeFileSync(join(repositoryPath, 'reviewed.txt'), 'first revision\n');
48
+ execFileSync('git', ['-C', repositoryPath, 'add', 'reviewed.txt'], { stdio: 'ignore' });
49
+ execFileSync('git', ['-C', repositoryPath, 'commit', '-m', 'first revision'], { stdio: 'ignore' });
50
+ execFileSync('git', ['-C', repositoryPath, 'remote', 'add', 'origin', 'https://gitlab.test/team/project.git'], {
51
+ stdio: 'ignore',
52
+ });
53
+ writeFileSync(join(otherRepositoryPath, 'reviewed.txt'), 'other project revision\n');
54
+ execFileSync('git', ['-C', otherRepositoryPath, 'add', 'reviewed.txt'], { stdio: 'ignore' });
55
+ execFileSync('git', ['-C', otherRepositoryPath, 'commit', '-m', 'other project revision'], { stdio: 'ignore' });
56
+ execFileSync('git', ['-C', otherRepositoryPath, 'remote', 'add', 'origin', 'https://gitlab.test/team/other.git'], {
57
+ stdio: 'ignore',
58
+ });
59
+ commitSha = execFileSync('git', ['-C', repositoryPath, 'rev-parse', 'HEAD'], { encoding: 'utf8' }).trim();
60
+ });
61
+
62
+ afterEach(() => {
63
+ vi.unstubAllGlobals();
64
+ if (originalBase === undefined) delete process.env.GIT_REPOS_BASE_PATH;
65
+ else process.env.GIT_REPOS_BASE_PATH = originalBase;
66
+ if (fixture) rmSync(fixture, { recursive: true, force: true });
67
+ });
68
+
69
+ function createDatabase() {
70
+ const database = {
71
+ getRepository: vi.fn((name: string) => {
72
+ if (name !== 'gitAccounts') throw new Error(`Unexpected repository ${name}`);
73
+ return {
74
+ findOne: async () =>
75
+ record({
76
+ provider: 'gitlab',
77
+ baseUrl: 'https://gitlab.test',
78
+ pat: 'test-only-token',
79
+ username: 'test',
80
+ }),
81
+ };
82
+ }),
83
+ };
84
+ return database as unknown as Database;
85
+ }
86
+
87
+ function createRepository(id: number, repoUrl: string, localPath = 'repository') {
88
+ return record({ id, repoUrl, gitAccountId: 1, localPath, defaultBranch: 'main' });
89
+ }
90
+
91
+ function mockProject(projectId: number, webUrl = 'https://gitlab.test/team/project') {
92
+ vi.stubGlobal(
93
+ 'fetch',
94
+ vi.fn(async (input: string | URL | Request) => {
95
+ const isSeparateProject = String(input).includes('team%2Fother');
96
+ const body = isSeparateProject
97
+ ? { id: projectId + 1, web_url: 'https://gitlab.test/team/other' }
98
+ : { id: projectId, web_url: webUrl };
99
+ return new Response(JSON.stringify(body), { status: 200, headers: { 'content-type': 'application/json' } });
100
+ }),
101
+ );
102
+ }
103
+
104
+ it('maps repository URL aliases to the provider canonical project identity', async () => {
105
+ mockProject(71);
106
+ const database = createDatabase();
107
+ const aliases = await Promise.all([
108
+ resolveReviewSource(database, createRepository(1, 'https://gitlab.test/team/project.git'), {
109
+ targetType: 'commit',
110
+ commitSha,
111
+ }),
112
+ resolveReviewSource(database, createRepository(2, 'https://gitlab.test/team/project'), {
113
+ targetType: 'commit',
114
+ commitSha,
115
+ }),
116
+ ]);
117
+ const otherCommit = execFileSync('git', ['-C', otherRepositoryPath, 'rev-parse', 'HEAD'], {
118
+ encoding: 'utf8',
119
+ }).trim();
120
+ const separateProject = await resolveReviewSource(
121
+ database,
122
+ createRepository(3, 'https://gitlab.test/team/other', 'other-repository'),
123
+ { targetType: 'commit', commitSha: otherCommit },
124
+ );
125
+
126
+ expect(aliases[0].projectKey).toBe(aliases[1].projectKey);
127
+ expect(aliases[0].projectKey).not.toBe(separateProject.projectKey);
128
+ expect(aliases.map((source) => source.headSha)).toEqual([commitSha, commitSha]);
129
+ });
130
+
131
+ it('rejects a configured repository whose local checkout origin belongs to another project', async () => {
132
+ mockProject(71);
133
+
134
+ await expect(
135
+ resolveReviewSource(
136
+ createDatabase(),
137
+ createRepository(1, 'https://gitlab.test/team/project.git', 'other-repository'),
138
+ { targetType: 'commit', commitSha },
139
+ ),
140
+ ).rejects.toThrow('Checkout origin does not match the configured project');
141
+ });
142
+
143
+ it('pins a merge request to its resolved head and base commits', async () => {
144
+ const fetchMock = vi.fn(async (input: string | URL | Request) => {
145
+ const url = String(input);
146
+ const body = url.includes('/merge_requests/9')
147
+ ? { sha: projectHead, diff_refs: { base_sha: projectBase }, source_branch: 'feature/review' }
148
+ : { id: 71, web_url: 'https://gitlab.test/team/project' };
149
+ return new Response(JSON.stringify(body), { status: 200, headers: { 'content-type': 'application/json' } });
150
+ });
151
+ vi.stubGlobal('fetch', fetchMock);
152
+
153
+ const source = await resolveReviewSource(
154
+ createDatabase(),
155
+ createRepository(1, 'https://gitlab.test/team/project.git'),
156
+ {
157
+ targetType: 'mr',
158
+ mrIid: 9,
159
+ headSha: projectHead,
160
+ },
161
+ );
162
+
163
+ expect(source).toMatchObject({
164
+ targetType: 'mr',
165
+ mrIid: 9,
166
+ branch: 'feature/review',
167
+ headSha: projectHead,
168
+ baseSha: projectBase,
169
+ });
170
+ expect(fetchMock.mock.calls.map(([url]) => String(url))).toContain(
171
+ 'https://gitlab.test/api/v4/projects/team%2Fproject/merge_requests/9',
172
+ );
173
+ });
174
+
175
+ it('rejects a changed merge-request head at admission', async () => {
176
+ vi.stubGlobal(
177
+ 'fetch',
178
+ vi.fn(async (input: string | URL | Request) => {
179
+ const url = String(input);
180
+ const body = url.includes('/merge_requests/9')
181
+ ? { sha: projectHead, diff_refs: { base_sha: projectBase }, source_branch: 'feature/review' }
182
+ : { id: 71, web_url: 'https://gitlab.test/team/project' };
183
+ return new Response(JSON.stringify(body), { status: 200 });
184
+ }),
185
+ );
186
+
187
+ await expect(
188
+ resolveReviewSource(createDatabase(), createRepository(1, 'https://gitlab.test/team/project.git'), {
189
+ targetType: 'mr',
190
+ mrIid: 9,
191
+ headSha: 'c'.repeat(40),
192
+ }),
193
+ ).rejects.toThrow('Merge request head changed before review admission');
194
+ });
195
+
196
+ it('reads an admitted merge request diff at its immutable SHA pair', async () => {
197
+ const fetchMock = vi.fn(async (input: string | URL | Request) => {
198
+ const url = String(input);
199
+ const body = url.includes('/repository/compare')
200
+ ? {
201
+ compare_timeout: false,
202
+ overflow: false,
203
+ diffs: [{ old_path: 'src/action.ts', new_path: 'src/action.ts', diff: '@@ -1 +1 @@\n-old()\n+new()' }],
204
+ }
205
+ : url.includes('/merge_requests/9')
206
+ ? { sha: projectHead, diff_refs: { base_sha: projectBase }, source_branch: 'feature/review' }
207
+ : { id: 71, web_url: 'https://gitlab.test/team/project' };
208
+ return new Response(JSON.stringify(body), { status: 200, headers: { 'content-type': 'application/json' } });
209
+ });
210
+ vi.stubGlobal('fetch', fetchMock);
211
+ const database = createDatabase();
212
+ const repository = createRepository(1, 'https://gitlab.test/team/project.git');
213
+ const source = await resolveReviewSource(database, repository, {
214
+ targetType: 'mr',
215
+ mrIid: 9,
216
+ headSha: projectHead,
217
+ });
218
+
219
+ const diff = await readPinnedReviewSource(database, repository, source);
220
+
221
+ expect(diff).toContain('+new()');
222
+ expect(fetchMock.mock.calls.map(([url]) => String(url))).toContain(
223
+ `https://gitlab.test/api/v4/projects/team%2Fproject/repository/compare?from=${projectBase}&to=${projectHead}`,
224
+ );
225
+ });
226
+ });