plugin-git-manager 1.2.28 → 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.
- package/README.md +58 -40
- package/dist/client/941.1793e67472872992.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/941.b0d55429cd053f32.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/locale/en-US.json +90 -1
- package/dist/locale/vi-VN.json +90 -1
- package/dist/locale/zh-CN.json +90 -1
- package/dist/node_modules/simple-git/package.json +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/actions/review-cutover.js +137 -0
- package/dist/server/actions/review.js +132 -43
- package/dist/server/actions/role-permissions.js +1 -0
- package/dist/server/ai-tools.js +8 -9
- package/dist/server/collections/gitCodeReviews.js +10 -0
- package/dist/server/collections/gitReviewCutover.js +44 -0
- package/dist/server/collections/gitReviewFlows.js +3 -0
- package/dist/server/collections/gitReviewInbox.js +51 -0
- package/dist/server/collections/gitReviewProjects.js +43 -0
- package/dist/server/collections/gitReviewRequests.js +56 -0
- package/dist/server/index.js +8 -2
- package/dist/server/plugin.js +51 -16
- package/dist/server/poller.js +54 -34
- package/dist/server/repository-access.js +23 -5
- package/dist/server/request-method-policy.js +2 -1
- package/dist/server/review-control-access.js +79 -0
- package/dist/server/services/legacy-post-service.js +412 -0
- package/dist/server/services/review-service.js +1451 -0
- package/dist/server/services/review-source.js +325 -0
- package/package.json +2 -2
- package/src/client/__tests__/CommitHistory.test.tsx +79 -0
- package/src/client/__tests__/ReviewHistory.test.tsx +126 -0
- package/src/client/__tests__/RunReviewButton.test.tsx +46 -35
- package/src/client/__tests__/workflowRoutes.test.ts +65 -0
- package/src/client/components/CommitHistory.tsx +61 -6
- package/src/client/components/ReviewFlows.tsx +90 -41
- package/src/client/components/ReviewHistory.tsx +245 -15
- package/src/client/components/RunReviewButton.tsx +12 -136
- package/src/client/workflowRoutes.ts +42 -0
- package/src/locale/en-US.json +90 -1
- package/src/locale/vi-VN.json +90 -1
- package/src/locale/zh-CN.json +90 -1
- package/src/server/__tests__/repository-access.test.ts +11 -3
- package/src/server/__tests__/review-service.integration.test.ts +1263 -0
- package/src/server/__tests__/review.test.ts +37 -98
- package/src/server/actions/review-cutover.ts +121 -0
- package/src/server/actions/review.ts +148 -38
- package/src/server/actions/role-permissions.ts +10 -0
- package/src/server/ai-tools.ts +23 -8
- package/src/server/collections/gitCodeReviews.ts +19 -0
- package/src/server/collections/gitReviewCutover.ts +23 -0
- package/src/server/collections/gitReviewFlows.ts +12 -0
- package/src/server/collections/gitReviewInbox.ts +30 -0
- package/src/server/collections/gitReviewProjects.ts +22 -0
- package/src/server/collections/gitReviewRequests.ts +35 -0
- package/src/server/index.ts +12 -0
- package/src/server/plugin.ts +43 -6
- package/src/server/poller.ts +54 -40
- package/src/server/repository-access.ts +32 -2
- package/src/server/request-method-policy.ts +1 -0
- package/src/server/review-control-access.ts +71 -0
- package/src/server/services/__tests__/review-source.test.ts +226 -0
- package/src/server/services/legacy-post-service.ts +550 -0
- package/src/server/services/review-service.ts +1899 -0
- package/src/server/services/review-source.ts +359 -0
- package/dist/client/900.a48beac7e2ebee7d.js +0 -10
- package/dist/client-v2/900.e6155002a9c97e7f.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 { defineCollection } from '@nocobase/database';
|
|
2
11
|
|
|
3
12
|
export default defineCollection({
|
|
@@ -103,6 +112,7 @@ export default defineCollection({
|
|
|
103
112
|
'x-component': 'Select',
|
|
104
113
|
enum: [
|
|
105
114
|
{ value: 'pending', label: 'Pending' },
|
|
115
|
+
{ value: 'queued', label: 'Queued' },
|
|
106
116
|
{ value: 'running', label: 'Running' },
|
|
107
117
|
{ value: 'completed', label: 'Completed' },
|
|
108
118
|
{ value: 'failed', label: 'Failed' },
|
|
@@ -154,6 +164,15 @@ export default defineCollection({
|
|
|
154
164
|
name: 'postedNoteId',
|
|
155
165
|
interface: 'input',
|
|
156
166
|
},
|
|
167
|
+
{ type: 'string', name: 'legacyPostFingerprint' },
|
|
168
|
+
{ type: 'string', name: 'legacyPostClaim' },
|
|
169
|
+
{ type: 'string', name: 'legacyPostProjectKey' },
|
|
170
|
+
{ type: 'json', name: 'legacyPostSource' },
|
|
171
|
+
{ type: 'string', name: 'legacyBaseProvenance' },
|
|
172
|
+
{ type: 'string', name: 'legacyBaseAcknowledgedBy' },
|
|
173
|
+
{ type: 'date', name: 'legacyBaseAcknowledgedAt' },
|
|
174
|
+
{ type: 'string', name: 'legacyHoldReleasedBy' },
|
|
175
|
+
{ type: 'date', name: 'legacyHoldReleasedAt' },
|
|
157
176
|
{
|
|
158
177
|
type: 'string',
|
|
159
178
|
name: 'approvedBy',
|
|
@@ -0,0 +1,23 @@
|
|
|
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 { defineCollection } from '@nocobase/database';
|
|
11
|
+
|
|
12
|
+
export default defineCollection({
|
|
13
|
+
name: 'gitReviewCutover',
|
|
14
|
+
autoGenId: true,
|
|
15
|
+
createdAt: true,
|
|
16
|
+
updatedAt: true,
|
|
17
|
+
fields: [
|
|
18
|
+
{ name: 'key', type: 'string', unique: true, allowNull: false },
|
|
19
|
+
{ name: 'state', type: 'string', allowNull: false },
|
|
20
|
+
{ name: 'confirmedBy', type: 'string' },
|
|
21
|
+
{ name: 'confirmedAt', type: 'date' },
|
|
22
|
+
],
|
|
23
|
+
});
|
|
@@ -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 { defineCollection } from '@nocobase/database';
|
|
2
11
|
|
|
3
12
|
export default defineCollection({
|
|
@@ -9,6 +18,9 @@ export default defineCollection({
|
|
|
9
18
|
createdAt: true,
|
|
10
19
|
updatedAt: true,
|
|
11
20
|
fields: [
|
|
21
|
+
{ type: 'bigInt', name: 'workflowId' },
|
|
22
|
+
{ type: 'string', name: 'workflowKey' },
|
|
23
|
+
{ type: 'boolean', name: 'reviewOnNewCommits', defaultValue: false },
|
|
12
24
|
{
|
|
13
25
|
type: 'string',
|
|
14
26
|
name: 'name',
|
|
@@ -0,0 +1,30 @@
|
|
|
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 { defineCollection } from '@nocobase/database';
|
|
11
|
+
|
|
12
|
+
export default defineCollection({
|
|
13
|
+
name: 'gitReviewInbox',
|
|
14
|
+
autoGenId: true,
|
|
15
|
+
createdAt: true,
|
|
16
|
+
updatedAt: true,
|
|
17
|
+
fields: [
|
|
18
|
+
{ name: 'projectKey', type: 'string', allowNull: false, index: true },
|
|
19
|
+
{ name: 'repositoryId', type: 'integer', allowNull: false },
|
|
20
|
+
{ name: 'reviewId', type: 'integer', allowNull: false, unique: true },
|
|
21
|
+
{ name: 'legacyReviewId', type: 'integer', unique: true },
|
|
22
|
+
{ name: 'eventKey', type: 'string', unique: true },
|
|
23
|
+
{ name: 'queuedAt', type: 'date', allowNull: false },
|
|
24
|
+
{ name: 'recoveredBy', type: 'string' },
|
|
25
|
+
{ name: 'recoveredAt', type: 'date' },
|
|
26
|
+
{ name: 'state', type: 'string', allowNull: false, defaultValue: 'queued' },
|
|
27
|
+
{ name: 'blockedReason', type: 'string' },
|
|
28
|
+
{ name: 'payload', type: 'json', allowNull: false },
|
|
29
|
+
],
|
|
30
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
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 { defineCollection } from '@nocobase/database';
|
|
11
|
+
|
|
12
|
+
export default defineCollection({
|
|
13
|
+
name: 'gitReviewProjects',
|
|
14
|
+
autoGenId: true,
|
|
15
|
+
createdAt: true,
|
|
16
|
+
updatedAt: true,
|
|
17
|
+
fields: [
|
|
18
|
+
{ name: 'projectKey', type: 'string', unique: true, allowNull: false },
|
|
19
|
+
{ name: 'activeInboxId', type: 'integer' },
|
|
20
|
+
{ name: 'legacyPostReviewId', type: 'integer' },
|
|
21
|
+
],
|
|
22
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
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 { defineCollection } from '@nocobase/database';
|
|
11
|
+
|
|
12
|
+
export default defineCollection({
|
|
13
|
+
name: 'gitReviewRequests',
|
|
14
|
+
autoGenId: true,
|
|
15
|
+
createdAt: true,
|
|
16
|
+
updatedAt: true,
|
|
17
|
+
fields: [
|
|
18
|
+
{ name: 'inboxId', type: 'integer', allowNull: false, unique: true },
|
|
19
|
+
{ name: 'reviewId', type: 'integer', allowNull: false },
|
|
20
|
+
{ name: 'repositoryId', type: 'integer', allowNull: false },
|
|
21
|
+
{ name: 'flowId', type: 'integer', allowNull: false },
|
|
22
|
+
{ name: 'workflowId', type: 'bigInt', allowNull: false },
|
|
23
|
+
{ name: 'workflowKey', type: 'string' },
|
|
24
|
+
{ name: 'eventType', type: 'string', allowNull: false },
|
|
25
|
+
{ name: 'executionId', type: 'bigInt', unique: true },
|
|
26
|
+
{ name: 'fenced', type: 'boolean', allowNull: false, defaultValue: false },
|
|
27
|
+
{ name: 'llmClaims', type: 'json' },
|
|
28
|
+
{ name: 'resultFingerprint', type: 'string' },
|
|
29
|
+
{ name: 'postClaim', type: 'string' },
|
|
30
|
+
{ name: 'postClaimedAt', type: 'date' },
|
|
31
|
+
{ name: 'postResetBy', type: 'string' },
|
|
32
|
+
{ name: 'postResetAt', type: 'date' },
|
|
33
|
+
{ name: 'aiSettled', type: 'boolean', allowNull: false, defaultValue: false },
|
|
34
|
+
],
|
|
35
|
+
});
|
package/src/server/index.ts
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
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
|
export { default } from './plugin';
|
|
2
11
|
export { PluginGitManagerServer } from './plugin';
|
|
12
|
+
export { GitReviewService } from './services/review-service';
|
|
13
|
+
export type { ReviewAdmission } from './services/review-service';
|
|
14
|
+
export { hasRepositoryAccess } from './repository-access';
|
package/src/server/plugin.ts
CHANGED
|
@@ -14,14 +14,18 @@ import { DataTypes } from 'sequelize';
|
|
|
14
14
|
import * as gitActions from './actions/git-actions';
|
|
15
15
|
import * as gitlabApi from './actions/gitlab-api';
|
|
16
16
|
import * as reviewActions from './actions/review';
|
|
17
|
+
import * as reviewCutoverActions from './actions/review-cutover';
|
|
17
18
|
import * as pollerActions from './actions/poller';
|
|
18
19
|
import * as rolePermissionsActions from './actions/role-permissions';
|
|
19
20
|
import * as subtreeActions from './actions/subtree';
|
|
20
|
-
import {
|
|
21
|
+
import { unregisterReviewQueue } from './actions/review';
|
|
21
22
|
import { registerGitReviewAiTools } from './ai-tools';
|
|
22
23
|
import { enforceGitRequestMethod } from './request-method-policy';
|
|
23
24
|
import { startPoller, stopPoller } from './poller';
|
|
24
25
|
import { RegistryGitContentService, SkillHubGitContentService } from './services/registry-content-service';
|
|
26
|
+
import { GitReviewService } from './services/review-service';
|
|
27
|
+
import { LegacyPostService } from './services/legacy-post-service';
|
|
28
|
+
import { enforceReviewControlAccess } from './review-control-access';
|
|
25
29
|
import { enforceRepositoryAccess, enforceRepositoryCollectionAccess } from './repository-access';
|
|
26
30
|
import { isGitManagerResourceResponse, redactCredentialFields } from './utils/redact';
|
|
27
31
|
import { containsCredentialBearingUrlField, URL_USERINFO_NOT_ALLOWED } from './utils/url-security';
|
|
@@ -43,8 +47,12 @@ export class PluginGitManagerServer extends Plugin {
|
|
|
43
47
|
declare db: any;
|
|
44
48
|
registryContentService!: RegistryGitContentService;
|
|
45
49
|
skillHubContentService!: SkillHubGitContentService;
|
|
50
|
+
reviewService!: GitReviewService;
|
|
51
|
+
legacyPostService!: LegacyPostService;
|
|
46
52
|
|
|
47
53
|
async afterAdd() {
|
|
54
|
+
this.reviewService = new GitReviewService(this.app);
|
|
55
|
+
this.legacyPostService = new LegacyPostService(this.app);
|
|
48
56
|
this.registryContentService = new RegistryGitContentService(
|
|
49
57
|
(this as unknown as { db: Database }).db,
|
|
50
58
|
undefined,
|
|
@@ -97,7 +105,17 @@ export class PluginGitManagerServer extends Plugin {
|
|
|
97
105
|
mergeRequestNotes: gitlabApi.mergeRequestNotes,
|
|
98
106
|
triggerReview: reviewActions.triggerReview,
|
|
99
107
|
reviewApprovePost: reviewActions.reviewApprovePost,
|
|
108
|
+
reviewLegacyPostStatus: reviewActions.reviewLegacyPostStatus,
|
|
109
|
+
reviewLegacyRetryPost: reviewActions.reviewLegacyRetryPost,
|
|
110
|
+
reviewLegacyReleaseHold: reviewActions.reviewLegacyReleaseHold,
|
|
100
111
|
reviewReject: reviewActions.reviewReject,
|
|
112
|
+
reviewWorkflowRetryPost: reviewActions.reviewWorkflowRetryPost,
|
|
113
|
+
reviewCutoverStatus: reviewCutoverActions.reviewCutoverStatus,
|
|
114
|
+
reviewConfirmCutover: reviewCutoverActions.reviewConfirmCutover,
|
|
115
|
+
reviewCancelLegacy: reviewCutoverActions.reviewCancelLegacy,
|
|
116
|
+
reviewRecover: reviewCutoverActions.reviewRecover,
|
|
117
|
+
reviewResetPostClaim: reviewCutoverActions.reviewResetPostClaim,
|
|
118
|
+
reviewCancelQueued: reviewCutoverActions.reviewCancelQueued,
|
|
101
119
|
pollNow: pollerActions.pollNow,
|
|
102
120
|
pollerStatus: pollerActions.pollerStatus,
|
|
103
121
|
rolePermissions: rolePermissionsActions.rolePermissions,
|
|
@@ -109,7 +127,19 @@ export class PluginGitManagerServer extends Plugin {
|
|
|
109
127
|
},
|
|
110
128
|
});
|
|
111
129
|
|
|
130
|
+
const legacyApprovalAction = this.app.acl.getAvailableAction('reviewApprovePost');
|
|
131
|
+
const priorAliases = legacyApprovalAction?.options?.aliases;
|
|
132
|
+
this.app.acl.setAvailableAction('reviewApprovePost', {
|
|
133
|
+
...legacyApprovalAction?.options,
|
|
134
|
+
aliases: [
|
|
135
|
+
...(Array.isArray(priorAliases) ? priorAliases : priorAliases ? [priorAliases] : []),
|
|
136
|
+
'reviewLegacyPostStatus',
|
|
137
|
+
'reviewLegacyRetryPost',
|
|
138
|
+
],
|
|
139
|
+
});
|
|
140
|
+
|
|
112
141
|
this.app.resourceManager.use(enforceGitRequestMethod);
|
|
142
|
+
this.app.resourceManager.use(enforceReviewControlAccess);
|
|
113
143
|
(this as any).app.resourceManager.use(enforceRepositoryAccess);
|
|
114
144
|
(this as any).app.resourceManager.use(enforceRepositoryCollectionAccess);
|
|
115
145
|
|
|
@@ -132,17 +162,13 @@ export class PluginGitManagerServer extends Plugin {
|
|
|
132
162
|
return next();
|
|
133
163
|
});
|
|
134
164
|
|
|
135
|
-
registerReviewQueue((this as any).app);
|
|
136
165
|
registerGitReviewAiTools((this as any).app);
|
|
137
166
|
|
|
138
167
|
(this as any).app.on('afterStart', async () => {
|
|
139
168
|
await ensureAutoReviewFlowSchema((this as any).app).catch(
|
|
140
169
|
(err) => (this as any).app.log?.error?.('plugin-git-manager: ensure schema error', err),
|
|
141
170
|
);
|
|
142
|
-
|
|
143
|
-
recoverStuckReviews((this as any).app).catch(
|
|
144
|
-
(err) => (this as any).app.log?.error?.('plugin-git-manager: recoverStuckReviews error', err),
|
|
145
|
-
);
|
|
171
|
+
this.reviewService.start();
|
|
146
172
|
subtreeActions
|
|
147
173
|
.recoverStuckSubtreeRuns((this as any).app)
|
|
148
174
|
.catch((err) => (this as any).app.log?.error?.('plugin-git-manager: recover subtree runs error', err));
|
|
@@ -150,10 +176,12 @@ export class PluginGitManagerServer extends Plugin {
|
|
|
150
176
|
});
|
|
151
177
|
(this as any).app.on('beforeStop', () => {
|
|
152
178
|
unregisterReviewQueue((this as any).app);
|
|
179
|
+
this.reviewService.stop();
|
|
153
180
|
stopPoller(this.app);
|
|
154
181
|
});
|
|
155
182
|
(this as any).app.on('beforeDestroy', () => {
|
|
156
183
|
unregisterReviewQueue((this as any).app);
|
|
184
|
+
this.reviewService.stop();
|
|
157
185
|
stopPoller(this.app);
|
|
158
186
|
});
|
|
159
187
|
|
|
@@ -209,7 +237,10 @@ export class PluginGitManagerServer extends Plugin {
|
|
|
209
237
|
'gitManager:checkout',
|
|
210
238
|
'gitManager:triggerReview',
|
|
211
239
|
'gitManager:reviewApprovePost',
|
|
240
|
+
'gitManager:reviewLegacyPostStatus',
|
|
241
|
+
'gitManager:reviewLegacyRetryPost',
|
|
212
242
|
'gitManager:reviewReject',
|
|
243
|
+
'gitManager:reviewWorkflowRetryPost',
|
|
213
244
|
'gitManager:pollNow',
|
|
214
245
|
'gitSubtreeConfigs:create',
|
|
215
246
|
'gitSubtreeConfigs:update',
|
|
@@ -330,15 +361,21 @@ export class PluginGitManagerServer extends Plugin {
|
|
|
330
361
|
await (this as any).app.db.getCollection('gitRepositories')?.sync();
|
|
331
362
|
await (this as any).app.db.getCollection('gitSubtreeConfigs')?.sync();
|
|
332
363
|
await (this as any).app.db.getCollection('gitSubtreeRuns')?.sync();
|
|
364
|
+
await (this as any).app.db.getCollection('gitReviewProjects')?.sync();
|
|
365
|
+
await (this as any).app.db.getCollection('gitReviewInbox')?.sync();
|
|
366
|
+
await (this as any).app.db.getCollection('gitReviewRequests')?.sync();
|
|
367
|
+
await (this as any).app.db.getCollection('gitReviewCutover')?.sync();
|
|
333
368
|
}
|
|
334
369
|
|
|
335
370
|
async beforeDisable() {
|
|
336
371
|
unregisterReviewQueue((this as any).app);
|
|
372
|
+
this.reviewService.stop();
|
|
337
373
|
stopPoller(this.app);
|
|
338
374
|
}
|
|
339
375
|
|
|
340
376
|
async beforeUnload() {
|
|
341
377
|
unregisterReviewQueue((this as any).app);
|
|
378
|
+
this.reviewService.stop();
|
|
342
379
|
stopPoller(this.app);
|
|
343
380
|
}
|
|
344
381
|
}
|
package/src/server/poller.ts
CHANGED
|
@@ -172,7 +172,7 @@ export async function pollAllRepos(app: Application): Promise<{ scanned: number;
|
|
|
172
172
|
const repos = await reposRepo.find({ filter: { autoReview: true } });
|
|
173
173
|
for (const repo of repos) {
|
|
174
174
|
try {
|
|
175
|
-
const result = await
|
|
175
|
+
const result = await pollOneRepoUnlocked(app, repo);
|
|
176
176
|
scanned += result.scanned;
|
|
177
177
|
triggered += result.triggered;
|
|
178
178
|
} catch (err: any) {
|
|
@@ -200,6 +200,24 @@ async function tick(app: Application) {
|
|
|
200
200
|
* Poll a single repo for MR changes. Returns counts.
|
|
201
201
|
*/
|
|
202
202
|
export async function pollOneRepo(app: Application, repo: any): Promise<{ scanned: number; triggered: number }> {
|
|
203
|
+
const state = stateFor(app);
|
|
204
|
+
if (state.polling) return { scanned: 0, triggered: 0 };
|
|
205
|
+
state.polling = true;
|
|
206
|
+
let lock: PollerLockHandle | null = null;
|
|
207
|
+
try {
|
|
208
|
+
lock = await tryAcquirePollerLock(app);
|
|
209
|
+
if (!lock) return { scanned: 0, triggered: 0 };
|
|
210
|
+
return await pollOneRepoUnlocked(app, repo);
|
|
211
|
+
} finally {
|
|
212
|
+
try {
|
|
213
|
+
await lock?.release();
|
|
214
|
+
} finally {
|
|
215
|
+
state.polling = false;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
async function pollOneRepoUnlocked(app: Application, repo: any): Promise<{ scanned: number; triggered: number }> {
|
|
203
221
|
const flowsRepo = app.db.getRepository('gitReviewFlows');
|
|
204
222
|
const reviewsRepo = app.db.getRepository('gitCodeReviews');
|
|
205
223
|
const reposRepo = app.db.getRepository('gitRepositories');
|
|
@@ -225,10 +243,11 @@ export async function pollOneRepo(app: Application, repo: any): Promise<{ scanne
|
|
|
225
243
|
const pat = account?.pat || '';
|
|
226
244
|
if (!pat) return { scanned: 0, triggered: 0 };
|
|
227
245
|
|
|
228
|
-
const
|
|
229
|
-
const mrs = await listMergeRequests(repo, pat
|
|
246
|
+
const pollStartedAt = new Date();
|
|
247
|
+
const mrs = await listMergeRequests(repo, pat);
|
|
230
248
|
|
|
231
249
|
let triggered = 0;
|
|
250
|
+
let failed = false;
|
|
232
251
|
for (const mr of mrs) {
|
|
233
252
|
// Prefer the repository's configured primary auto-review flow, then fall
|
|
234
253
|
// back to the first matching auto-trigger flow.
|
|
@@ -238,15 +257,14 @@ export async function pollOneRepo(app: Application, repo: any): Promise<{ scanne
|
|
|
238
257
|
: flows.find((f: any) => branchMatches(f, mr.source_branch));
|
|
239
258
|
if (!flow) continue;
|
|
240
259
|
|
|
241
|
-
//
|
|
242
|
-
// For existing reviews we just refresh latestSha so the UI can flag
|
|
243
|
-
// "new commits available" — re-review must be done manually by the user.
|
|
260
|
+
// Preserve the previous one-review-per-MR policy unless new-head reviews are explicitly enabled.
|
|
244
261
|
const existing = await reviewsRepo.findOne({
|
|
245
262
|
filter: {
|
|
246
263
|
repositoryId: repo.get('id'),
|
|
247
264
|
targetType: 'mr',
|
|
248
265
|
mrIid: mr.iid,
|
|
249
266
|
},
|
|
267
|
+
sort: ['-id'],
|
|
250
268
|
});
|
|
251
269
|
if (existing) {
|
|
252
270
|
if (existing.get('latestSha') !== mr.sha) {
|
|
@@ -255,7 +273,7 @@ export async function pollOneRepo(app: Application, repo: any): Promise<{ scanne
|
|
|
255
273
|
values: { latestSha: mr.sha },
|
|
256
274
|
});
|
|
257
275
|
}
|
|
258
|
-
continue;
|
|
276
|
+
if (!flow.get('reviewOnNewCommits') || existing.get('headSha') === mr.sha) continue;
|
|
259
277
|
}
|
|
260
278
|
|
|
261
279
|
try {
|
|
@@ -267,28 +285,29 @@ export async function pollOneRepo(app: Application, repo: any): Promise<{ scanne
|
|
|
267
285
|
branch: mr.source_branch,
|
|
268
286
|
headSha: mr.sha,
|
|
269
287
|
triggeredBy: 'poll',
|
|
288
|
+
eventType: existing ? 'head_changed' : 'change_opened',
|
|
270
289
|
});
|
|
271
290
|
triggered++;
|
|
272
291
|
} catch (err: any) {
|
|
292
|
+
failed = true;
|
|
273
293
|
app.log?.error?.(`poller: triggerReviewInternal failed for MR !${mr.iid}: ${err?.message}`);
|
|
274
294
|
}
|
|
275
295
|
}
|
|
276
296
|
|
|
297
|
+
if (failed) throw new Error('One or more merge requests could not be queued');
|
|
277
298
|
await reposRepo.update({
|
|
278
299
|
filterByTk: repo.get('id'),
|
|
279
|
-
values: { lastPolledAt:
|
|
300
|
+
values: { lastPolledAt: pollStartedAt },
|
|
280
301
|
});
|
|
281
302
|
|
|
282
303
|
return { scanned: mrs.length, triggered };
|
|
283
304
|
}
|
|
284
305
|
|
|
285
|
-
async function listMergeRequests(repo: any, pat: string
|
|
306
|
+
async function listMergeRequests(repo: any, pat: string): Promise<any[]> {
|
|
286
307
|
const repoUrl = repo.get('repoUrl') as string;
|
|
287
308
|
const isGitHub = typeof repoUrl === 'string' && new URL(repoUrl).hostname === 'github.com';
|
|
288
309
|
|
|
289
310
|
if (isGitHub) {
|
|
290
|
-
// GitHub PRs: list endpoint sorts by updated; GitHub has no `updated_after`,
|
|
291
|
-
// so we filter client-side after fetching the most recently updated page.
|
|
292
311
|
const { projectPath } = parseGitLabProject(repoUrl);
|
|
293
312
|
const params = new URLSearchParams({
|
|
294
313
|
state: 'open',
|
|
@@ -299,21 +318,18 @@ async function listMergeRequests(repo: any, pat: string, updatedAfter: Date | nu
|
|
|
299
318
|
const headers: Record<string, string> = { Accept: 'application/vnd.github.v3+json' };
|
|
300
319
|
if (pat) headers['Authorization'] = `Bearer ${pat}`;
|
|
301
320
|
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
throw new Error(`GitHub API error ${response.status}: ${body}`);
|
|
309
|
-
}
|
|
310
|
-
let prs = (await response.json()) as any[];
|
|
311
|
-
if (Array.isArray(prs) && updatedAfter) {
|
|
312
|
-
const cutoff = updatedAfter.getTime() - 1000;
|
|
313
|
-
prs = prs.filter((pr: any) => {
|
|
314
|
-
const t = pr?.updated_at ? new Date(pr.updated_at).getTime() : 0;
|
|
315
|
-
return t >= cutoff;
|
|
321
|
+
const prs: any[] = [];
|
|
322
|
+
for (let page = 1; ; page++) {
|
|
323
|
+
params.set('page', String(page));
|
|
324
|
+
const response = await fetch(`https://api.github.com/repos/${projectPath}/pulls?${params.toString()}`, {
|
|
325
|
+
headers,
|
|
326
|
+
redirect: 'error',
|
|
316
327
|
});
|
|
328
|
+
if (!response.ok) throw new Error(`GitHub API error ${response.status}`);
|
|
329
|
+
const items = await response.json();
|
|
330
|
+
if (!Array.isArray(items)) throw new Error('Invalid GitHub pull request response');
|
|
331
|
+
prs.push(...items);
|
|
332
|
+
if (items.length < MR_PAGE_SIZE) break;
|
|
317
333
|
}
|
|
318
334
|
// Normalise to the GitLab MR shape that pollOneRepo consumes.
|
|
319
335
|
return (prs || []).map((pr: any) => ({
|
|
@@ -332,20 +348,18 @@ async function listMergeRequests(repo: any, pat: string, updatedAfter: Date | nu
|
|
|
332
348
|
order_by: 'updated_at',
|
|
333
349
|
sort: 'desc',
|
|
334
350
|
});
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
const body = await response.text().catch(() => '');
|
|
348
|
-
throw new Error(`GitLab API error ${response.status}: ${body}`);
|
|
351
|
+
const mrs: any[] = [];
|
|
352
|
+
for (let page = 1; ; page++) {
|
|
353
|
+
params.set('page', String(page));
|
|
354
|
+
const response = await fetch(`${apiBase}/projects/${encodedProject}/merge_requests?${params.toString()}`, {
|
|
355
|
+
redirect: 'error',
|
|
356
|
+
headers: { 'PRIVATE-TOKEN': pat, Accept: 'application/json' },
|
|
357
|
+
});
|
|
358
|
+
if (!response.ok) throw new Error(`GitLab API error ${response.status}`);
|
|
359
|
+
const items = await response.json();
|
|
360
|
+
if (!Array.isArray(items)) throw new Error('Invalid GitLab merge request response');
|
|
361
|
+
mrs.push(...items);
|
|
362
|
+
if (items.length < MR_PAGE_SIZE) break;
|
|
349
363
|
}
|
|
350
|
-
return
|
|
364
|
+
return mrs;
|
|
351
365
|
}
|
|
@@ -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
|
const REPOSITORY_ID_ACTIONS = new Set([
|
|
2
11
|
'clone',
|
|
3
12
|
'pull',
|
|
@@ -20,7 +29,14 @@ const REPOSITORY_ID_ACTIONS = new Set([
|
|
|
20
29
|
|
|
21
30
|
const SUBTREE_CONFIG_ACTIONS = new Set(['subtreePreview', 'subtreeRun', 'subtreeReplace']);
|
|
22
31
|
|
|
23
|
-
const REVIEW_ID_ACTIONS = new Set([
|
|
32
|
+
const REVIEW_ID_ACTIONS = new Set([
|
|
33
|
+
'reviewApprovePost',
|
|
34
|
+
'reviewReject',
|
|
35
|
+
'reviewWorkflowRetryPost',
|
|
36
|
+
'reviewLegacyPostStatus',
|
|
37
|
+
'reviewLegacyRetryPost',
|
|
38
|
+
'reviewLegacyReleaseHold',
|
|
39
|
+
]);
|
|
24
40
|
|
|
25
41
|
type RepositoryId = number | string;
|
|
26
42
|
|
|
@@ -626,6 +642,21 @@ export async function enforceRepositoryCollectionAccess(
|
|
|
626
642
|
|
|
627
643
|
rejectTargetCollectionOverride(ctx, collectionName);
|
|
628
644
|
|
|
645
|
+
const actionName = ctx.action?.actionName;
|
|
646
|
+
if (collectionName === 'gitCodeReviews' && actionName && ['create', 'update', 'destroy'].includes(actionName)) {
|
|
647
|
+
ctx.throw(403, 'Permission denied');
|
|
648
|
+
}
|
|
649
|
+
if (collectionName === 'gitReviewFlows' && actionName && ['create', 'update'].includes(actionName)) {
|
|
650
|
+
const bindingFields = new Set(['workflowId', 'workflowKey']);
|
|
651
|
+
if (
|
|
652
|
+
[ctx.action?.params, ctx.request?.body, ctx.query, ctx.request?.query].some((source) =>
|
|
653
|
+
containsMutationField(source, bindingFields),
|
|
654
|
+
)
|
|
655
|
+
) {
|
|
656
|
+
ctx.throw(403, 'Permission denied');
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
|
|
629
660
|
const roles = currentRoles(ctx);
|
|
630
661
|
if (roles.includes('root')) {
|
|
631
662
|
await next();
|
|
@@ -651,7 +682,6 @@ export async function enforceRepositoryCollectionAccess(
|
|
|
651
682
|
return;
|
|
652
683
|
}
|
|
653
684
|
|
|
654
|
-
const actionName = ctx.action?.actionName;
|
|
655
685
|
if (!actionName || !STANDARD_COLLECTION_ACTIONS.has(actionName)) {
|
|
656
686
|
ctx.throw(403, 'Permission denied');
|
|
657
687
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
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 type { Context } from '@nocobase/actions';
|
|
11
|
+
|
|
12
|
+
const CONTROL_COLLECTIONS = new Set(['gitReviewProjects', 'gitReviewInbox', 'gitReviewRequests', 'gitReviewCutover']);
|
|
13
|
+
const REVIEW_COLLECTION = new Set(['gitCodeReviews']);
|
|
14
|
+
const ROUTE_KEYS = new Set([
|
|
15
|
+
'resourceName',
|
|
16
|
+
'targetCollection',
|
|
17
|
+
'associatedName',
|
|
18
|
+
'__collection',
|
|
19
|
+
'appends',
|
|
20
|
+
'include',
|
|
21
|
+
'fields',
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
function containsCollection(value: unknown, collections = CONTROL_COLLECTIONS): boolean {
|
|
25
|
+
if (typeof value === 'string') return value.split(/[.[\],:/()=\s]+/).some((part) => collections.has(part));
|
|
26
|
+
if (Array.isArray(value)) return value.some((item) => containsCollection(item, collections));
|
|
27
|
+
if (value && typeof value === 'object')
|
|
28
|
+
return Object.entries(value).some(
|
|
29
|
+
([key, nested]) => containsCollection(key, collections) || containsCollection(nested, collections),
|
|
30
|
+
);
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function containsRouteOverride(value: unknown, collections = CONTROL_COLLECTIONS): boolean {
|
|
35
|
+
if (Array.isArray(value)) return value.some((item) => containsRouteOverride(item, collections));
|
|
36
|
+
if (!value || typeof value !== 'object') return false;
|
|
37
|
+
return Object.entries(value).some(([key, nested]) => {
|
|
38
|
+
const keyParts = key.split(/[.[\],:/()=\s]+/);
|
|
39
|
+
return (
|
|
40
|
+
(keyParts.some((part) => ROUTE_KEYS.has(part)) && containsCollection(nested, collections)) ||
|
|
41
|
+
containsRouteOverride(nested, collections)
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function enforceReviewControlAccess(ctx: Context, next: () => Promise<void>): Promise<void> {
|
|
47
|
+
let currentTarget: string | undefined;
|
|
48
|
+
try {
|
|
49
|
+
const current = ctx.getCurrentRepository?.();
|
|
50
|
+
currentTarget = current?.targetCollection?.name || current?.collection?.name;
|
|
51
|
+
} catch {
|
|
52
|
+
// Custom actions need not have a backing collection.
|
|
53
|
+
}
|
|
54
|
+
if (
|
|
55
|
+
containsCollection(ctx.action?.resourceName) ||
|
|
56
|
+
containsCollection(currentTarget) ||
|
|
57
|
+
[ctx.action?.params, ctx.request?.body, ctx.query, ctx.request?.query].some((input) => containsRouteOverride(input))
|
|
58
|
+
)
|
|
59
|
+
ctx.throw(403, 'Permission denied');
|
|
60
|
+
if (
|
|
61
|
+
ctx.action?.actionName &&
|
|
62
|
+
!['list', 'get'].includes(ctx.action.actionName) &&
|
|
63
|
+
(containsCollection(ctx.action.resourceName, REVIEW_COLLECTION) ||
|
|
64
|
+
containsCollection(currentTarget, REVIEW_COLLECTION) ||
|
|
65
|
+
[ctx.action.params, ctx.request?.body, ctx.query, ctx.request?.query].some((input) =>
|
|
66
|
+
containsRouteOverride(input, REVIEW_COLLECTION),
|
|
67
|
+
))
|
|
68
|
+
)
|
|
69
|
+
ctx.throw(403, 'Permission denied');
|
|
70
|
+
await next();
|
|
71
|
+
}
|