plugin-git-manager 1.3.1 → 1.3.3

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 (63) hide show
  1. package/LICENSE +201 -0
  2. package/dist/client/317.17ed0018e3e7db00.js +10 -0
  3. package/dist/client/453.fc3042c9740d8fab.js +10 -0
  4. package/dist/client/index.js +1 -1
  5. package/dist/client-v2/317.d2466574d00f94d0.js +10 -0
  6. package/dist/client-v2/453.5e507c94c59277b1.js +10 -0
  7. package/dist/client-v2/index.js +1 -1
  8. package/dist/externalVersion.js +2 -2
  9. package/dist/node_modules/simple-git/package.json +1 -1
  10. package/dist/node_modules/zod/package.json +1 -1
  11. package/dist/server/actions/review-cutover.js +121 -7
  12. package/dist/server/plugin.js +90 -9
  13. package/dist/server/repository-access.js +41 -3
  14. package/dist/server/services/legacy-post-service.js +10 -6
  15. package/dist/server/services/review-service.js +30 -7
  16. package/dist/server/services/review-source.js +7 -4
  17. package/package.json +2 -2
  18. package/src/client/__tests__/CommitHistory.test.tsx +1 -8
  19. package/src/client/__tests__/ReviewHistory.test.tsx +1 -8
  20. package/src/client/__tests__/RunReviewButton.test.tsx +1 -8
  21. package/src/client/__tests__/workflowRoutes.test.ts +3 -10
  22. package/src/client/components/CommitHistory.tsx +1 -8
  23. package/src/client/components/ReviewFlows.tsx +53 -19
  24. package/src/client/components/ReviewHistory.tsx +1 -8
  25. package/src/client/components/RunReviewButton.tsx +1 -8
  26. package/src/client/index.tsx +11 -8
  27. package/src/client/workflowRoutes.ts +3 -18
  28. package/src/client-v2/plugin.tsx +11 -0
  29. package/src/server/__tests__/git-security.test.ts +1 -8
  30. package/src/server/__tests__/poller-lifecycle.test.ts +1 -8
  31. package/src/server/__tests__/repository-access.test.ts +1 -8
  32. package/src/server/__tests__/review-service.integration.test.ts +1 -8
  33. package/src/server/__tests__/review.test.ts +1 -8
  34. package/src/server/__tests__/smoke.test.ts +1 -8
  35. package/src/server/actions/git-actions.ts +1 -8
  36. package/src/server/actions/gitlab-api.ts +1 -8
  37. package/src/server/actions/poller.ts +1 -8
  38. package/src/server/actions/review-cutover.ts +135 -15
  39. package/src/server/actions/review.ts +1 -8
  40. package/src/server/actions/role-permissions.ts +1 -8
  41. package/src/server/ai-tools.ts +1 -8
  42. package/src/server/collections/gitCodeReviews.ts +1 -8
  43. package/src/server/collections/gitReviewCutover.ts +1 -8
  44. package/src/server/collections/gitReviewFlows.ts +1 -8
  45. package/src/server/collections/gitReviewInbox.ts +1 -8
  46. package/src/server/collections/gitReviewProjects.ts +1 -8
  47. package/src/server/collections/gitReviewRequests.ts +1 -8
  48. package/src/server/index.ts +1 -8
  49. package/src/server/plugin.ts +88 -8
  50. package/src/server/poller.ts +1 -8
  51. package/src/server/repository-access.ts +36 -9
  52. package/src/server/request-method-policy.ts +1 -8
  53. package/src/server/review-control-access.ts +1 -8
  54. package/src/server/services/__tests__/registry-content-service.test.ts +1 -8
  55. package/src/server/services/__tests__/review-source.test.ts +33 -8
  56. package/src/server/services/legacy-post-service.ts +11 -14
  57. package/src/server/services/registry-content-service.ts +1 -8
  58. package/src/server/services/review-service.ts +35 -21
  59. package/src/server/services/review-source.ts +8 -12
  60. package/src/server/utils/get-repo-account.ts +1 -8
  61. package/src/server/utils/url-security.ts +1 -8
  62. package/dist/client/941.1793e67472872992.js +0 -10
  63. package/dist/client-v2/941.b0d55429cd053f32.js +0 -10
@@ -1,11 +1,4 @@
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
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import { defineCollection } from '@nocobase/database';
11
4
 
@@ -1,11 +1,4 @@
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
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import { defineCollection } from '@nocobase/database';
11
4
 
@@ -1,11 +1,4 @@
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
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import { defineCollection } from '@nocobase/database';
11
4
 
@@ -1,11 +1,4 @@
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
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import { defineCollection } from '@nocobase/database';
11
4
 
@@ -1,11 +1,4 @@
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
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import { defineCollection } from '@nocobase/database';
11
4
 
@@ -1,11 +1,4 @@
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
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  export { default } from './plugin';
11
4
  export { PluginGitManagerServer } from './plugin';
@@ -1,13 +1,7 @@
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
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import { Plugin } from '@nocobase/server';
4
+ import type { Context } from '@nocobase/actions';
11
5
  import type { Database } from '@nocobase/database';
12
6
  import { resolve } from 'path';
13
7
  import { DataTypes } from 'sequelize';
@@ -32,6 +26,20 @@ import { containsCredentialBearingUrlField, URL_USERINFO_NOT_ALLOWED } from './u
32
26
 
33
27
  const GIT_CONFIGURATION_URL_FIELDS = new Set(['repoUrl', 'baseUrl']);
34
28
 
29
+ function isConcurrentSchemaChange(error: unknown) {
30
+ if (!error || typeof error !== 'object') return false;
31
+ const databaseError = error as { original?: { code?: string; errno?: number; message?: string }; message?: string };
32
+ const code = databaseError.original?.code;
33
+ const number = databaseError.original?.errno;
34
+ const message = databaseError.original?.message || databaseError.message || '';
35
+ return (
36
+ ['42701', '42P07', 'ER_DUP_FIELDNAME', 'ER_DUP_KEYNAME'].includes(code || '') ||
37
+ number === 1060 ||
38
+ number === 1061 ||
39
+ /duplicate column name|index .* already exists/i.test(message)
40
+ );
41
+ }
42
+
35
43
  export function isGitConfigurationUrlMutation(resourceName: unknown, actionName: unknown): boolean {
36
44
  return (
37
45
  typeof actionName === 'string' &&
@@ -138,6 +146,45 @@ export class PluginGitManagerServer extends Plugin {
138
146
  ],
139
147
  });
140
148
 
149
+ // Existing repository permissions are stored on fileContent and triggerReview.
150
+ // Aliases let the ACL apply those same grants and scopes to review controls.
151
+ for (const [action, aliases] of [
152
+ ['fileContent', ['reviewCutoverStatus']],
153
+ [
154
+ 'triggerReview',
155
+ [
156
+ 'reviewConfirmCutover',
157
+ 'reviewCancelLegacy',
158
+ 'reviewRecover',
159
+ 'reviewResetPostClaim',
160
+ 'reviewCancelQueued',
161
+ 'reviewLegacyReleaseHold',
162
+ ],
163
+ ],
164
+ ] as const) {
165
+ const registered = this.app.acl.getAvailableAction(action);
166
+ const previous = registered?.options?.aliases;
167
+ this.app.acl.setAvailableAction(action, {
168
+ ...registered?.options,
169
+ aliases: [...(Array.isArray(previous) ? previous : previous ? [previous] : []), ...aliases],
170
+ });
171
+ }
172
+
173
+ for (const action of ['list', 'get', 'create', 'update', 'destroy'] as const) {
174
+ this.app.acl.allow('gitReviewFlows', action, (ctx: Context) => {
175
+ const roles = ctx.state?.currentRoles;
176
+ if (!ctx.state?.currentUser?.id || !Array.isArray(roles)) return false;
177
+ const gitAction = action === 'list' || action === 'get' ? 'fileContent' : 'triggerReview';
178
+ return roles.some((role) => {
179
+ if (typeof role !== 'string') return false;
180
+ const collection = ctx.app.acl.getRole(role)?.getResource('gitReviewFlows');
181
+ const permission = ctx.app.acl.can({ role, resource: 'gitReviewFlows', action });
182
+ if (collection && !permission) return false;
183
+ return Boolean(ctx.app.acl.can({ role, resource: 'gitManager', action: gitAction }));
184
+ });
185
+ });
186
+ }
187
+
141
188
  this.app.resourceManager.use(enforceGitRequestMethod);
142
189
  this.app.resourceManager.use(enforceReviewControlAccess);
143
190
  (this as any).app.resourceManager.use(enforceRepositoryAccess);
@@ -168,6 +215,9 @@ export class PluginGitManagerServer extends Plugin {
168
215
  await ensureAutoReviewFlowSchema((this as any).app).catch(
169
216
  (err) => (this as any).app.log?.error?.('plugin-git-manager: ensure schema error', err),
170
217
  );
218
+ await this.ensureReviewSchema().catch(
219
+ (error) => this.app.log?.error?.('plugin-git-manager: review schema error', error),
220
+ );
171
221
  this.reviewService.start();
172
222
  subtreeActions
173
223
  .recoverStuckSubtreeRuns((this as any).app)
@@ -214,6 +264,8 @@ export class PluginGitManagerServer extends Plugin {
214
264
  'gitManager:pollerStatus',
215
265
  'gitManager:subtreePreview',
216
266
  'gitManager:subtreeOptions',
267
+ 'gitManager:reviewCutoverStatus',
268
+ 'workflowGitReview:status',
217
269
  ],
218
270
  });
219
271
 
@@ -246,6 +298,14 @@ export class PluginGitManagerServer extends Plugin {
246
298
  'gitSubtreeConfigs:update',
247
299
  'gitSubtreeConfigs:destroy',
248
300
  'gitManager:subtreeRun',
301
+ 'gitManager:reviewConfirmCutover',
302
+ 'gitManager:reviewCancelLegacy',
303
+ 'gitManager:reviewRecover',
304
+ 'gitManager:reviewResetPostClaim',
305
+ 'gitManager:reviewCancelQueued',
306
+ 'gitManager:reviewLegacyReleaseHold',
307
+ 'workflowGitReview:setup',
308
+ 'workflowGitReview:repair',
249
309
  ],
250
310
  });
251
311
 
@@ -365,6 +425,26 @@ export class PluginGitManagerServer extends Plugin {
365
425
  await (this as any).app.db.getCollection('gitReviewInbox')?.sync();
366
426
  await (this as any).app.db.getCollection('gitReviewRequests')?.sync();
367
427
  await (this as any).app.db.getCollection('gitReviewCutover')?.sync();
428
+ await this.ensureReviewSchema();
429
+ }
430
+
431
+ async ensureReviewSchema() {
432
+ const lock = await this.app.lockManager.tryAcquire('git-manager-review-schema', 60_000);
433
+ await lock.runExclusive(async () => {
434
+ for (const name of ['gitReviewFlows', 'gitCodeReviews']) {
435
+ const collection = this.db.getCollection(name);
436
+ if (!collection) continue;
437
+ for (let attempt = 0; ; attempt++) {
438
+ try {
439
+ await collection.model.sync({ alter: { drop: false } });
440
+ break;
441
+ } catch (error) {
442
+ if (attempt >= 3 || !isConcurrentSchemaChange(error)) throw error;
443
+ await new Promise((resolve) => setTimeout(resolve, 50 * (attempt + 1)));
444
+ }
445
+ }
446
+ }
447
+ }, 300_000);
368
448
  }
369
449
 
370
450
  async beforeDisable() {
@@ -1,11 +1,4 @@
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
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import type { Application } from '@nocobase/server';
11
4
  import { triggerReviewInternal, branchMatches } from './actions/review';
@@ -1,11 +1,4 @@
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
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  const REPOSITORY_ID_ACTIONS = new Set([
11
4
  'clone',
@@ -78,6 +71,7 @@ export interface RepositoryPermissionChecker {
78
71
  resource: string;
79
72
  action: string;
80
73
  }): Promise<RepositoryPermissionResult> | RepositoryPermissionResult;
74
+ getRole?(name: string): { getResource(name: string): unknown } | undefined;
81
75
  }
82
76
 
83
77
  type RepositoryLookup = {
@@ -245,7 +239,7 @@ export async function hasRepositoryAccess(input: {
245
239
  return Boolean(permission && scopeIncludesRepository(permission.params?.filter, input.repositoryId));
246
240
  }
247
241
 
248
- async function hasUnrestrictedRepositoryAccess(input: {
242
+ export async function hasUnrestrictedRepositoryAccess(input: {
249
243
  acl?: RepositoryPermissionChecker;
250
244
  roles: string[];
251
245
  action: string;
@@ -658,6 +652,39 @@ export async function enforceRepositoryCollectionAccess(
658
652
  }
659
653
 
660
654
  const roles = currentRoles(ctx);
655
+ if (collectionName === 'gitReviewFlows' && actionName && ['list', 'get'].includes(actionName)) {
656
+ const readPermission = await ctx.app.acl.can({ roles, resource: 'gitManager', action: 'fileContent' });
657
+ if (readPermission) {
658
+ const readScope = resolveRepositoryScope(readPermission.params?.filter);
659
+ if (!readScope.supported) ctx.throw(403, 'Permission denied');
660
+ if (!readScope.unrestricted) {
661
+ rejectScopedCredentialAssociationRoute(ctx);
662
+ rejectScopedRepositoryCredentialAssociationRead(ctx, actionName);
663
+ if (!ctx.action?.mergeParams) ctx.throw(403, 'Permission denied');
664
+ ctx.action.mergeParams({ filter: collectionFilter(collectionName, readScope.ids) });
665
+ }
666
+ }
667
+ }
668
+ if (collectionName === 'gitReviewFlows' && actionName && ['create', 'update', 'destroy'].includes(actionName)) {
669
+ const writePermission = await ctx.app.acl.can({ roles, resource: 'gitManager', action: 'triggerReview' });
670
+ const readPermission = await ctx.app.acl.can({ roles, resource: 'gitRepositories', action: 'list' });
671
+ const hasGitManagerPermissions = roles.some((role) => ctx.app.acl.getRole?.(role)?.getResource('gitManager'));
672
+ if (!writePermission && (readPermission || hasGitManagerPermissions)) ctx.throw(403, 'Permission denied');
673
+ if (writePermission) {
674
+ const writeScope = resolveRepositoryScope(writePermission.params?.filter);
675
+ if (!writeScope.supported) ctx.throw(403, 'Permission denied');
676
+ if (!writeScope.unrestricted) {
677
+ rejectScopedCredentialAssociationRoute(ctx);
678
+ if (actionName === 'create' || actionName === 'update') {
679
+ rejectScopedBulkMutationValues(ctx, actionName);
680
+ rejectScopedAssociationMutation(ctx, REPOSITORY_ASSOCIATION_SEGMENTS);
681
+ requireScopedRepositoryValue(ctx, effectiveMutationValues(ctx), writeScope, actionName);
682
+ }
683
+ if (!ctx.action?.mergeParams) ctx.throw(403, 'Permission denied');
684
+ ctx.action.mergeParams({ filter: collectionFilter(collectionName, writeScope.ids) });
685
+ }
686
+ }
687
+ }
661
688
  if (roles.includes('root')) {
662
689
  await next();
663
690
  return;
@@ -1,11 +1,4 @@
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
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import type { Context } from '@nocobase/actions';
11
4
 
@@ -1,11 +1,4 @@
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
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import type { Context } from '@nocobase/actions';
11
4
 
@@ -1,11 +1,4 @@
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
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import { execFileSync } from 'child_process';
11
4
  import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'fs';
@@ -1,11 +1,4 @@
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
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import { execFileSync } from 'child_process';
11
4
  import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'fs';
@@ -223,4 +216,36 @@ describe('pinned Git review source', () => {
223
216
  `https://gitlab.test/api/v4/projects/team%2Fproject/repository/compare?from=${projectBase}&to=${projectHead}`,
224
217
  );
225
218
  });
219
+
220
+ it('marks collapsed or binary merge-request patches as omitted instead of failing the review context', async () => {
221
+ const fetchMock = vi.fn(async (input: string | URL | Request) => {
222
+ const url = String(input);
223
+ const body = url.includes('/repository/compare')
224
+ ? {
225
+ compare_timeout: false,
226
+ overflow: false,
227
+ diffs: [
228
+ { old_path: 'src/action.ts', new_path: 'src/action.ts', diff: '@@ -1 +1 @@\n-old()\n+new()' },
229
+ { old_path: 'yarn.lock', new_path: 'yarn.lock', collapsed: true, too_large: true, diff: '' },
230
+ ],
231
+ }
232
+ : url.includes('/merge_requests/9')
233
+ ? { sha: projectHead, diff_refs: { base_sha: projectBase }, source_branch: 'feature/review' }
234
+ : { id: 71, web_url: 'https://gitlab.test/team/project' };
235
+ return new Response(JSON.stringify(body), { status: 200, headers: { 'content-type': 'application/json' } });
236
+ });
237
+ vi.stubGlobal('fetch', fetchMock);
238
+ const database = createDatabase();
239
+ const repository = createRepository(1, 'https://gitlab.test/team/project.git');
240
+ const source = await resolveReviewSource(database, repository, {
241
+ targetType: 'mr',
242
+ mrIid: 9,
243
+ headSha: projectHead,
244
+ });
245
+
246
+ const diff = await readPinnedReviewSource(database, repository, source);
247
+
248
+ expect(diff).toContain('+new()');
249
+ expect(diff).toContain('Binary files a/yarn.lock and b/yarn.lock differ (patch omitted by provider)');
250
+ });
226
251
  });
@@ -1,11 +1,4 @@
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
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import { createHash, randomUUID } from 'crypto';
11
4
  import type { Application } from '@nocobase/server';
@@ -484,13 +477,8 @@ export class LegacyPostService {
484
477
  }
485
478
 
486
479
  async releaseHold(reviewId: Id, actor: Id, roles: string[], expectedAttempt: string | null): Promise<void> {
487
- if (!roles.includes('root')) {
488
- const error = new Error('Permission denied') as Error & { status: number };
489
- error.status = 403;
490
- throw error;
491
- }
492
480
  const currentRoles = await resolveBackgroundReviewRoles(this.app.db, actor);
493
- if (!currentRoles.includes('root')) {
481
+ if (!roles.length || roles.some((role) => !currentRoles.includes(role))) {
494
482
  const error = new Error('Permission denied') as Error & { status: number };
495
483
  error.status = 403;
496
484
  throw error;
@@ -504,6 +492,12 @@ export class LegacyPostService {
504
492
  (await this.app.db.getRepository('gitReviewInbox').findOne({ filter: { reviewId } }))
505
493
  )
506
494
  conflict('Legacy review is not available');
495
+ const repositoryId = value<Id>(review, 'repositoryId');
496
+ if (!(await hasRepositoryAccess({ acl: this.app.acl, roles, repositoryId, action: 'reviewLegacyReleaseHold' }))) {
497
+ const error = new Error('Permission denied') as Error & { status: number };
498
+ error.status = 403;
499
+ throw error;
500
+ }
507
501
  const projectKey = value<string | null>(review, 'legacyPostProjectKey') || sourceOf(review)?.projectKey;
508
502
  if (!projectKey) conflict('Legacy review has no publication hold');
509
503
  const db = this.app.db;
@@ -511,6 +505,9 @@ export class LegacyPostService {
511
505
  const current = await db
512
506
  .getCollection('gitCodeReviews')
513
507
  .model.findOne({ where: { id: reviewId }, transaction, lock: transaction.LOCK.UPDATE });
508
+ if (current && String(value<Id>(current, 'repositoryId')) !== String(repositoryId)) {
509
+ conflict('Review repository changed');
510
+ }
514
511
  if (
515
512
  !current ||
516
513
  (value<string | null>(current, 'legacyPostClaim') ?? null) !== expectedAttempt ||
@@ -1,11 +1,4 @@
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
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import { spawn } from 'child_process';
11
4
  import { existsSync } from 'fs';
@@ -1,11 +1,4 @@
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
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import { createHash, randomUUID } from 'crypto';
11
4
  import type { Application } from '@nocobase/server';
@@ -302,7 +295,7 @@ export class GitReviewService {
302
295
  return legacy;
303
296
  }
304
297
 
305
- async cutoverStatus(): Promise<{
298
+ async cutoverStatus(canViewRepository?: (repositoryId: unknown) => Promise<boolean>): Promise<{
306
299
  state: string;
307
300
  legacyPending: number;
308
301
  legacyRunning: number;
@@ -334,8 +327,15 @@ export class GitReviewService {
334
327
  record = await model.findOne({ where: { key: 'global' } });
335
328
  }
336
329
  }
337
- const legacy = await this.legacyRows();
338
- const failed = await db.getRepository('gitCodeReviews').find({ filter: { status: 'failed' }, sort: ['id'] });
330
+ const visibleRows = async <T extends Getter>(rows: T[]): Promise<T[]> => {
331
+ if (!canViewRepository) return rows;
332
+ const allowed = await Promise.all(rows.map((row) => canViewRepository(value<unknown>(row, 'repositoryId'))));
333
+ return rows.filter((_row, index) => allowed[index]);
334
+ };
335
+ const legacy = await visibleRows(await this.legacyRows());
336
+ const failed = await visibleRows(
337
+ await db.getRepository('gitCodeReviews').find({ filter: { status: 'failed' }, sort: ['id'] }),
338
+ );
339
339
  const uncertain: Getter[] = [];
340
340
  for (const review of failed) {
341
341
  const metadata = value<Record<string, unknown> | null>(review, 'metadata');
@@ -343,9 +343,11 @@ export class GitReviewService {
343
343
  if (!(await db.getRepository('gitReviewInbox').findOne({ filter: { reviewId: value<Id>(review, 'id') } })))
344
344
  uncertain.push(review);
345
345
  }
346
- const activeRows = await db
347
- .getRepository('gitReviewInbox')
348
- .find({ filter: { state: { $in: ['dispatched', 'running', 'quarantined'] } }, sort: ['id'] });
346
+ const activeRows = await visibleRows(
347
+ await db
348
+ .getRepository('gitReviewInbox')
349
+ .find({ filter: { state: { $in: ['dispatched', 'running', 'quarantined'] } }, sort: ['id'] }),
350
+ );
349
351
  const quarantined: Array<{ requestId: Id; executionId: Id | null; reviewId: Id; reason: string }> = [];
350
352
  const orphaned: Array<{ inboxId: Id; reviewId: Id }> = [];
351
353
  const postUnknownReviews: Array<{ reviewId: Id; postStatus: string; hasClaim: boolean; attemptId: string | null }> =
@@ -354,23 +356,35 @@ export class GitReviewService {
354
356
  const legacyProjects = await db.getRepository('gitReviewProjects').find({
355
357
  filter: { legacyPostReviewId: { $ne: null } },
356
358
  sort: ['id'],
357
- limit: 100,
359
+ ...(canViewRepository ? {} : { limit: 100 }),
358
360
  });
359
361
  for (const project of legacyProjects) {
360
362
  const reviewId = value<Id>(project, 'legacyPostReviewId');
361
363
  const heldReview = await db.getRepository('gitCodeReviews').findOne({ filterByTk: reviewId });
364
+ if (canViewRepository && !(await canViewRepository(heldReview ? value(heldReview, 'repositoryId') : null)))
365
+ continue;
366
+ if (legacyPublicationHolds.length >= 100) break;
362
367
  legacyPublicationHolds.push({
363
368
  reviewId,
364
369
  repositoryId: heldReview ? value<Id>(heldReview, 'repositoryId') : null,
365
370
  attemptId: heldReview ? value<string | null>(heldReview, 'legacyPostClaim') ?? null : null,
366
371
  });
367
372
  }
368
- const queuedBlocked = await db
369
- .getRepository('gitReviewInbox')
370
- .find({ filter: { state: 'queued', blockedReason: { $ne: null } }, sort: ['queuedAt', 'id'], limit: 100 });
371
- const unresolved = await db
372
- .getRepository('gitCodeReviews')
373
- .find({ filter: { postStatus: { $in: ['posting', 'post_unknown', 'post_failed', 'retrying'] } }, sort: ['id'] });
373
+ const queuedBlocked = (
374
+ await visibleRows(
375
+ await db.getRepository('gitReviewInbox').find({
376
+ filter: { state: 'queued', blockedReason: { $ne: null } },
377
+ sort: ['queuedAt', 'id'],
378
+ ...(canViewRepository ? {} : { limit: 100 }),
379
+ }),
380
+ )
381
+ ).slice(0, 100);
382
+ const unresolved = await visibleRows(
383
+ await db.getRepository('gitCodeReviews').find({
384
+ filter: { postStatus: { $in: ['posting', 'post_unknown', 'post_failed', 'retrying'] } },
385
+ sort: ['id'],
386
+ }),
387
+ );
374
388
  for (const review of unresolved) {
375
389
  if (
376
390
  value<{ workflowManaged?: boolean } | null>(review, 'metadata')?.workflowManaged &&
@@ -1,11 +1,4 @@
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
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import { createHash } from 'crypto';
11
4
  import type { Database } from '@nocobase/database';
@@ -192,9 +185,11 @@ export async function readPinnedReviewSource(
192
185
  content = files
193
186
  .map((item) => {
194
187
  const file = object(item);
195
- if (typeof file.filename !== 'string' || typeof file.patch !== 'string')
196
- throw new Error('GitHub comparison contains an unavailable patch');
188
+ if (typeof file.filename !== 'string') throw new Error('GitHub comparison contains an unavailable patch');
197
189
  if (/[\r\n]/.test(file.filename)) throw new Error('GitHub comparison has an unsupported filename');
190
+ if (typeof file.patch !== 'string') {
191
+ return `Binary files a/${file.filename} and b/${file.filename} differ (patch omitted by provider)`;
192
+ }
198
193
  return `--- a/${file.filename}\n+++ b/${file.filename}\n${file.patch}`;
199
194
  })
200
195
  .join('\n');
@@ -209,11 +204,12 @@ export async function readPinnedReviewSource(
209
204
  content = comparison.diffs
210
205
  .map((item) => {
211
206
  const file = object(item);
212
- if (file.too_large || file.collapsed || typeof file.diff !== 'string')
213
- throw new Error('GitLab comparison contains an unavailable patch');
214
207
  const oldPath = String(file.old_path || '');
215
208
  const newPath = String(file.new_path || '');
216
209
  if (/[\r\n]/.test(oldPath + newPath)) throw new Error('GitLab comparison has an unsupported filename');
210
+ if (file.too_large || file.collapsed || typeof file.diff !== 'string') {
211
+ return `Binary files a/${oldPath} and b/${newPath} differ (patch omitted by provider)`;
212
+ }
217
213
  return `--- a/${oldPath}\n+++ b/${newPath}\n${file.diff}`;
218
214
  })
219
215
  .join('\n');
@@ -1,11 +1,4 @@
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
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  import { assertAccountRepositoryUrl } from './url-security';
11
4
 
@@ -1,11 +1,4 @@
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
- */
1
+ // SPDX-License-Identifier: Apache-2.0
9
2
 
10
3
  export const URL_USERINFO_NOT_ALLOWED = 'Credential-bearing URLs are not allowed';
11
4