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 React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
11
|
import {
|
|
3
12
|
Table,
|
|
@@ -30,12 +39,23 @@ import { useApp } from '@nocobase/client-v2';
|
|
|
30
39
|
import { useGitManager } from '../context/GitManagerContext';
|
|
31
40
|
import { MarkdownView } from './MarkdownView';
|
|
32
41
|
import { useT } from '../locale';
|
|
42
|
+
import { reviewApprovalHref, workflowHref } from '../workflowRoutes';
|
|
33
43
|
|
|
34
44
|
const { Text, Title, Paragraph } = Typography;
|
|
35
45
|
const { useToken } = theme;
|
|
46
|
+
type LegacyPostStatus = {
|
|
47
|
+
reviewId: number;
|
|
48
|
+
status: 'posted' | 'unknown' | 'observed';
|
|
49
|
+
attemptId: string | null;
|
|
50
|
+
canRetry: boolean;
|
|
51
|
+
holdActive: boolean;
|
|
52
|
+
baseUnverified: boolean;
|
|
53
|
+
baseAcknowledged: boolean;
|
|
54
|
+
};
|
|
36
55
|
|
|
37
56
|
const STATUS_COLOR: Record<string, string> = {
|
|
38
57
|
pending: 'default',
|
|
58
|
+
queued: 'default',
|
|
39
59
|
running: 'blue',
|
|
40
60
|
completed: 'green',
|
|
41
61
|
failed: 'red',
|
|
@@ -46,6 +66,9 @@ const POST_STATUS_COLOR: Record<string, string> = {
|
|
|
46
66
|
approved: 'cyan',
|
|
47
67
|
posted: 'green',
|
|
48
68
|
post_failed: 'red',
|
|
69
|
+
post_unknown: 'orange',
|
|
70
|
+
posting: 'blue',
|
|
71
|
+
retrying: 'blue',
|
|
49
72
|
skipped: 'default',
|
|
50
73
|
rejected: 'red',
|
|
51
74
|
};
|
|
@@ -53,7 +76,8 @@ const POST_STATUS_COLOR: Record<string, string> = {
|
|
|
53
76
|
export const ReviewHistory: React.FC<{ initialFilter?: 'all' | 'pending_approval' }> = ({ initialFilter = 'all' }) => {
|
|
54
77
|
const t = useT();
|
|
55
78
|
const { token } = useToken();
|
|
56
|
-
const
|
|
79
|
+
const app = useApp();
|
|
80
|
+
const api = app.apiClient;
|
|
57
81
|
const { repos } = useGitManager();
|
|
58
82
|
const [reviews, setReviews] = useState<any[]>([]);
|
|
59
83
|
const [loading, setLoading] = useState(false);
|
|
@@ -64,6 +88,8 @@ export const ReviewHistory: React.FC<{ initialFilter?: 'all' | 'pending_approval
|
|
|
64
88
|
const [triggerFilter, setTriggerFilter] = useState<string>('all');
|
|
65
89
|
const [selected, setSelected] = useState<any | null>(null);
|
|
66
90
|
const [editing, setEditing] = useState(false);
|
|
91
|
+
const [reconcilingPost, setReconcilingPost] = useState(false);
|
|
92
|
+
const [legacyPost, setLegacyPost] = useState<LegacyPostStatus | null>(null);
|
|
67
93
|
const [editedMarkdown, setEditedMarkdown] = useState('');
|
|
68
94
|
|
|
69
95
|
const reload = useCallback(async () => {
|
|
@@ -93,7 +119,7 @@ export const ReviewHistory: React.FC<{ initialFilter?: 'all' | 'pending_approval
|
|
|
93
119
|
|
|
94
120
|
// Auto-refresh while there are running reviews
|
|
95
121
|
useEffect(() => {
|
|
96
|
-
if (!reviews.some((r) => r.status === 'running' || r.status === 'pending')) return;
|
|
122
|
+
if (!reviews.some((r) => r.status === 'running' || r.status === 'pending' || r.status === 'queued')) return;
|
|
97
123
|
const tid = setInterval(reload, 4000);
|
|
98
124
|
return () => clearInterval(tid);
|
|
99
125
|
}, [reviews, reload]);
|
|
@@ -113,12 +139,17 @@ export const ReviewHistory: React.FC<{ initialFilter?: 'all' | 'pending_approval
|
|
|
113
139
|
const handleApprove = async (markdown: string) => {
|
|
114
140
|
if (!selected) return;
|
|
115
141
|
try {
|
|
116
|
-
await api.request({
|
|
142
|
+
const response = await api.request({
|
|
117
143
|
url: 'gitManager:reviewApprovePost',
|
|
118
144
|
method: 'post',
|
|
119
|
-
data: { reviewId: selected.id, editedMarkdown: markdown },
|
|
145
|
+
data: { reviewId: selected.id, editedMarkdown: markdown, baseConfirmation: 'LEGACY_BASE_UNVERIFIED' },
|
|
120
146
|
});
|
|
121
|
-
|
|
147
|
+
const payload = response?.data?.data;
|
|
148
|
+
const result = payload?.success ? payload.data : payload;
|
|
149
|
+
if (result?.status === 'posted') message.success(t('Review posted to merge request'));
|
|
150
|
+
else if (result?.status === 'observed')
|
|
151
|
+
message.warning(t('A matching comment was found, but its attempt cannot be confirmed'));
|
|
152
|
+
else message.warning(t('Publication outcome is still unknown'));
|
|
122
153
|
setEditing(false);
|
|
123
154
|
refreshOne(selected.id);
|
|
124
155
|
reload();
|
|
@@ -143,6 +174,85 @@ export const ReviewHistory: React.FC<{ initialFilter?: 'all' | 'pending_approval
|
|
|
143
174
|
}
|
|
144
175
|
};
|
|
145
176
|
|
|
177
|
+
const handleRetryPost = async (allowResend: boolean) => {
|
|
178
|
+
if (!selected) return;
|
|
179
|
+
setReconcilingPost(true);
|
|
180
|
+
try {
|
|
181
|
+
const response = await api.request({
|
|
182
|
+
url: 'gitManager:reviewWorkflowRetryPost',
|
|
183
|
+
method: 'post',
|
|
184
|
+
data: { reviewId: selected.id, ...(allowResend ? { confirmation: 'OUTBOUND_POST_STOPPED' } : {}) },
|
|
185
|
+
});
|
|
186
|
+
const result = response?.data?.data;
|
|
187
|
+
if (result?.status === 'posted') message.success(t('Review publication confirmed'));
|
|
188
|
+
else if (result?.status === 'observed')
|
|
189
|
+
message.info(t('Matching comment found; another publication attempt still owns the review'));
|
|
190
|
+
else if (result?.canResend)
|
|
191
|
+
message.warning(t('No matching comment found; confirm the previous post stopped before retrying'));
|
|
192
|
+
else
|
|
193
|
+
message.warning(t('A previous publication attempt may still be running; ask an administrator to recover it'));
|
|
194
|
+
await refreshOne(selected.id);
|
|
195
|
+
await reload();
|
|
196
|
+
} catch (error: unknown) {
|
|
197
|
+
const responseError = error as { response?: { data?: { errors?: Array<{ message?: string }> } } } | null;
|
|
198
|
+
message.error(
|
|
199
|
+
responseError?.response?.data?.errors?.[0]?.message ||
|
|
200
|
+
(error instanceof Error && error.message) ||
|
|
201
|
+
t('Failed to reconcile review publication'),
|
|
202
|
+
);
|
|
203
|
+
} finally {
|
|
204
|
+
setReconcilingPost(false);
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
const handleLegacyPost = async (action: 'check' | 'retry' | 'release') => {
|
|
209
|
+
if (!selected || (action !== 'check' && legacyPost?.reviewId !== selected.id)) return;
|
|
210
|
+
setReconcilingPost(true);
|
|
211
|
+
try {
|
|
212
|
+
const route =
|
|
213
|
+
action === 'check'
|
|
214
|
+
? 'reviewLegacyPostStatus'
|
|
215
|
+
: action === 'retry'
|
|
216
|
+
? 'reviewLegacyRetryPost'
|
|
217
|
+
: 'reviewLegacyReleaseHold';
|
|
218
|
+
const response = await api.request({
|
|
219
|
+
url: `gitManager:${route}`,
|
|
220
|
+
method: 'post',
|
|
221
|
+
data: {
|
|
222
|
+
reviewId: selected.id,
|
|
223
|
+
...(action === 'check'
|
|
224
|
+
? {}
|
|
225
|
+
: { confirmation: 'OUTBOUND_POST_STOPPED', expectedAttempt: legacyPost?.attemptId ?? null }),
|
|
226
|
+
...(action === 'retry' && legacyPost?.baseUnverified && !legacyPost.baseAcknowledged
|
|
227
|
+
? { baseConfirmation: 'LEGACY_BASE_UNVERIFIED' }
|
|
228
|
+
: {}),
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
const payload = response?.data?.data;
|
|
232
|
+
const result = payload?.success ? payload.data : payload;
|
|
233
|
+
if (action === 'check' && result) setLegacyPost({ ...result, reviewId: selected.id });
|
|
234
|
+
else setLegacyPost(null);
|
|
235
|
+
if (result?.status === 'posted') message.success(t('Review publication confirmed'));
|
|
236
|
+
else if (result?.status === 'observed' && result?.canRetry)
|
|
237
|
+
message.warning(t('A matching marked comment was found; confirm the previous attempt stopped to finalize it'));
|
|
238
|
+
else if (result?.status === 'observed')
|
|
239
|
+
message.warning(t('A matching comment was found, but its attempt cannot be confirmed'));
|
|
240
|
+
else if (action === 'release') message.success(t('Legacy publication hold released'));
|
|
241
|
+
else if (action === 'retry') message.warning(t('Publication outcome is still unknown'));
|
|
242
|
+
await refreshOne(selected.id);
|
|
243
|
+
await reload();
|
|
244
|
+
} catch (error: unknown) {
|
|
245
|
+
const responseError = error as { response?: { data?: { errors?: Array<{ message?: string }> } } } | null;
|
|
246
|
+
message.error(
|
|
247
|
+
responseError?.response?.data?.errors?.[0]?.message ||
|
|
248
|
+
(error instanceof Error && error.message) ||
|
|
249
|
+
t('Failed to reconcile review publication'),
|
|
250
|
+
);
|
|
251
|
+
} finally {
|
|
252
|
+
setReconcilingPost(false);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
|
|
146
256
|
const repoMap = useMemo(() => {
|
|
147
257
|
const m: Record<number, any> = {};
|
|
148
258
|
repos.forEach((r: any) => (m[r.id] = r));
|
|
@@ -293,6 +403,7 @@ export const ReviewHistory: React.FC<{ initialFilter?: 'all' | 'pending_approval
|
|
|
293
403
|
options={[
|
|
294
404
|
{ value: 'all', label: t('All statuses') },
|
|
295
405
|
{ value: 'pending', label: t('pending') },
|
|
406
|
+
{ value: 'queued', label: t('queued') },
|
|
296
407
|
{ value: 'running', label: t('running') },
|
|
297
408
|
{ value: 'completed', label: t('completed') },
|
|
298
409
|
{ value: 'failed', label: t('failed') },
|
|
@@ -309,6 +420,8 @@ export const ReviewHistory: React.FC<{ initialFilter?: 'all' | 'pending_approval
|
|
|
309
420
|
{ value: 'approved', label: t('approved') },
|
|
310
421
|
{ value: 'posted', label: t('posted') },
|
|
311
422
|
{ value: 'post_failed', label: t('post_failed') },
|
|
423
|
+
{ value: 'post_unknown', label: t('post_unknown') },
|
|
424
|
+
{ value: 'posting', label: t('posting') },
|
|
312
425
|
{ value: 'skipped', label: t('skipped') },
|
|
313
426
|
{ value: 'rejected', label: t('rejected') },
|
|
314
427
|
]}
|
|
@@ -341,6 +454,7 @@ export const ReviewHistory: React.FC<{ initialFilter?: 'all' | 'pending_approval
|
|
|
341
454
|
onClick: () => {
|
|
342
455
|
setSelected(record);
|
|
343
456
|
setEditing(false);
|
|
457
|
+
setLegacyPost(null);
|
|
344
458
|
setEditedMarkdown(record.reviewMarkdown || '');
|
|
345
459
|
},
|
|
346
460
|
})}
|
|
@@ -403,6 +517,10 @@ export const ReviewHistory: React.FC<{ initialFilter?: 'all' | 'pending_approval
|
|
|
403
517
|
onChangeMarkdown={setEditedMarkdown}
|
|
404
518
|
onApprove={handleApprove}
|
|
405
519
|
onReject={handleReject}
|
|
520
|
+
onRetryPost={handleRetryPost}
|
|
521
|
+
legacyPost={legacyPost?.reviewId === selected.id ? legacyPost : null}
|
|
522
|
+
onLegacyPost={handleLegacyPost}
|
|
523
|
+
reconcilingPost={reconcilingPost}
|
|
406
524
|
/>
|
|
407
525
|
)}
|
|
408
526
|
</Drawer>
|
|
@@ -419,19 +537,117 @@ const ReviewDetailView: React.FC<{
|
|
|
419
537
|
onChangeMarkdown: (v: string) => void;
|
|
420
538
|
onApprove: (markdown: string) => void;
|
|
421
539
|
onReject: () => void;
|
|
422
|
-
|
|
540
|
+
onRetryPost: (allowResend: boolean) => void;
|
|
541
|
+
legacyPost: LegacyPostStatus | null;
|
|
542
|
+
onLegacyPost: (action: 'check' | 'retry' | 'release') => void;
|
|
543
|
+
reconcilingPost: boolean;
|
|
544
|
+
}> = ({
|
|
545
|
+
review,
|
|
546
|
+
editing,
|
|
547
|
+
editedMarkdown,
|
|
548
|
+
onEdit,
|
|
549
|
+
onCancelEdit,
|
|
550
|
+
onChangeMarkdown,
|
|
551
|
+
onApprove,
|
|
552
|
+
onReject,
|
|
553
|
+
onRetryPost,
|
|
554
|
+
legacyPost,
|
|
555
|
+
onLegacyPost,
|
|
556
|
+
reconcilingPost,
|
|
557
|
+
}) => {
|
|
423
558
|
const t = useT();
|
|
424
559
|
const { token } = useToken();
|
|
560
|
+
const app = useApp();
|
|
425
561
|
|
|
426
562
|
const canApprove =
|
|
563
|
+
!review.metadata?.workflowManaged &&
|
|
427
564
|
review.status === 'completed' &&
|
|
428
565
|
review.targetType === 'mr' &&
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
566
|
+
review.postStatus === 'pending_approval';
|
|
567
|
+
const canRetryPost =
|
|
568
|
+
review.metadata?.workflowManaged &&
|
|
569
|
+
review.status !== 'running' &&
|
|
570
|
+
review.targetType === 'mr' &&
|
|
571
|
+
['posting', 'post_unknown', 'post_failed', 'retrying'].includes(review.postStatus);
|
|
572
|
+
const canCheckLegacy =
|
|
573
|
+
!review.metadata?.workflowManaged &&
|
|
574
|
+
review.targetType === 'mr' &&
|
|
575
|
+
['posting', 'post_unknown', 'post_failed'].includes(review.postStatus);
|
|
432
576
|
|
|
433
577
|
return (
|
|
434
578
|
<div>
|
|
579
|
+
{review.metadata?.workflowManaged && review.postStatus === 'pending_approval' && (
|
|
580
|
+
<Alert
|
|
581
|
+
type="info"
|
|
582
|
+
showIcon
|
|
583
|
+
message={t('Use the workflow approval task for this review')}
|
|
584
|
+
action={<Button href={reviewApprovalHref(app)}>{t('Open workflow tasks')}</Button>}
|
|
585
|
+
style={{ marginBottom: 16 }}
|
|
586
|
+
/>
|
|
587
|
+
)}
|
|
588
|
+
{review.metadata?.workflowExecutionId && (
|
|
589
|
+
<Button
|
|
590
|
+
href={workflowHref(app, 'execution', review.metadata.workflowExecutionId)}
|
|
591
|
+
target="_blank"
|
|
592
|
+
rel="noreferrer"
|
|
593
|
+
style={{ marginBottom: 16 }}
|
|
594
|
+
>
|
|
595
|
+
{t('Open workflow execution')}
|
|
596
|
+
</Button>
|
|
597
|
+
)}
|
|
598
|
+
{canRetryPost && (
|
|
599
|
+
<Space wrap style={{ marginBottom: 16 }}>
|
|
600
|
+
<Button loading={reconcilingPost} onClick={() => onRetryPost(false)}>
|
|
601
|
+
{t('Check publication')}
|
|
602
|
+
</Button>
|
|
603
|
+
<Popconfirm
|
|
604
|
+
title={t('Has the previous outbound post stopped and settled?')}
|
|
605
|
+
onConfirm={() => onRetryPost(true)}
|
|
606
|
+
>
|
|
607
|
+
<Button loading={reconcilingPost}>{t('Retry publication')}</Button>
|
|
608
|
+
</Popconfirm>
|
|
609
|
+
</Space>
|
|
610
|
+
)}
|
|
611
|
+
{canCheckLegacy && (
|
|
612
|
+
<Space wrap style={{ marginBottom: 16 }}>
|
|
613
|
+
<Button loading={reconcilingPost} onClick={() => onLegacyPost('check')}>
|
|
614
|
+
{t('Check publication')}
|
|
615
|
+
</Button>
|
|
616
|
+
{legacyPost?.canRetry && (
|
|
617
|
+
<Popconfirm
|
|
618
|
+
title={t('Has the previous outbound post stopped and settled?')}
|
|
619
|
+
description={
|
|
620
|
+
legacyPost.baseUnverified && !legacyPost.baseAcknowledged
|
|
621
|
+
? t(
|
|
622
|
+
'The original review base cannot be verified. Compare the review with the current merge request before continuing.',
|
|
623
|
+
)
|
|
624
|
+
: undefined
|
|
625
|
+
}
|
|
626
|
+
onConfirm={() => onLegacyPost('retry')}
|
|
627
|
+
>
|
|
628
|
+
<Button loading={reconcilingPost}>{t('Retry publication')}</Button>
|
|
629
|
+
</Popconfirm>
|
|
630
|
+
)}
|
|
631
|
+
{legacyPost?.holdActive && (
|
|
632
|
+
<Popconfirm
|
|
633
|
+
title={t('Has the previous outbound post stopped and settled?')}
|
|
634
|
+
onConfirm={() => onLegacyPost('release')}
|
|
635
|
+
>
|
|
636
|
+
<Button loading={reconcilingPost}>{t('Release legacy publication hold')}</Button>
|
|
637
|
+
</Popconfirm>
|
|
638
|
+
)}
|
|
639
|
+
</Space>
|
|
640
|
+
)}
|
|
641
|
+
{canApprove && (
|
|
642
|
+
<Alert
|
|
643
|
+
type="warning"
|
|
644
|
+
showIcon
|
|
645
|
+
message={t(
|
|
646
|
+
'The original review base cannot be verified. Compare the review with the current merge request before continuing.',
|
|
647
|
+
)}
|
|
648
|
+
style={{ marginBottom: 16 }}
|
|
649
|
+
/>
|
|
650
|
+
)}
|
|
435
651
|
{review.status === 'running' && (
|
|
436
652
|
<Alert
|
|
437
653
|
type="info"
|
|
@@ -465,9 +681,16 @@ const ReviewDetailView: React.FC<{
|
|
|
465
681
|
<Space style={{ marginBottom: 16 }} wrap>
|
|
466
682
|
{!editing ? (
|
|
467
683
|
<>
|
|
468
|
-
<
|
|
469
|
-
{t(
|
|
470
|
-
|
|
684
|
+
<Popconfirm
|
|
685
|
+
title={t(
|
|
686
|
+
'The original review base cannot be verified. Compare the review with the current merge request before continuing.',
|
|
687
|
+
)}
|
|
688
|
+
onConfirm={() => onApprove(review.reviewMarkdown)}
|
|
689
|
+
>
|
|
690
|
+
<Button type="primary" icon={<CheckOutlined />}>
|
|
691
|
+
{t('Approve & Post')}
|
|
692
|
+
</Button>
|
|
693
|
+
</Popconfirm>
|
|
471
694
|
<Button icon={<EditOutlined />} onClick={onEdit}>
|
|
472
695
|
{t('Edit & Post')}
|
|
473
696
|
</Button>
|
|
@@ -479,9 +702,16 @@ const ReviewDetailView: React.FC<{
|
|
|
479
702
|
</>
|
|
480
703
|
) : (
|
|
481
704
|
<>
|
|
482
|
-
<
|
|
483
|
-
{t(
|
|
484
|
-
|
|
705
|
+
<Popconfirm
|
|
706
|
+
title={t(
|
|
707
|
+
'The original review base cannot be verified. Compare the review with the current merge request before continuing.',
|
|
708
|
+
)}
|
|
709
|
+
onConfirm={() => onApprove(editedMarkdown)}
|
|
710
|
+
>
|
|
711
|
+
<Button type="primary" icon={<CheckOutlined />}>
|
|
712
|
+
{t('Save & Post')}
|
|
713
|
+
</Button>
|
|
714
|
+
</Popconfirm>
|
|
485
715
|
<Button onClick={onCancelEdit}>{t('Cancel')}</Button>
|
|
486
716
|
</>
|
|
487
717
|
)}
|
|
@@ -9,9 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
import React, { useCallback, useEffect, useState } from 'react';
|
|
11
11
|
import { Button, Dropdown, Modal, Form, Select, Input, message, Space, Tooltip, Tag, Alert } from 'antd';
|
|
12
|
-
import { RobotOutlined,
|
|
12
|
+
import { RobotOutlined, ThunderboltOutlined, ReloadOutlined } from '@ant-design/icons';
|
|
13
13
|
import { useApp } from '@nocobase/client-v2';
|
|
14
|
-
import type PluginAIClientV2 from '@nocobase/plugin-ai/client-v2';
|
|
15
14
|
import { REVIEW_PROMPT_TEMPLATES } from '../promptTemplates';
|
|
16
15
|
import { useT } from '../locale';
|
|
17
16
|
|
|
@@ -42,25 +41,20 @@ type Target =
|
|
|
42
41
|
|
|
43
42
|
/**
|
|
44
43
|
* Button that lets the user kick off a code review for a given target.
|
|
45
|
-
*
|
|
46
|
-
* - "Run review" → POST gitManager:triggerReview (server-side, async)
|
|
47
|
-
* - "Open chat" → call the enabled AI plugin manager,
|
|
48
|
-
* so the user can chat with the AI employee using the same context.
|
|
44
|
+
* Submits review requests through the project-scoped admission service.
|
|
49
45
|
*/
|
|
50
46
|
export const RunReviewButton: React.FC<{
|
|
51
47
|
target: Target;
|
|
48
|
+
label?: string;
|
|
52
49
|
size?: 'small' | 'middle' | 'large';
|
|
53
50
|
type?: 'default' | 'primary' | 'link';
|
|
54
51
|
onTriggered?: (reviewId: number) => void;
|
|
55
|
-
}> = ({ target, size = 'small', type = 'default', onTriggered }) => {
|
|
52
|
+
}> = ({ target, label, size = 'small', type = 'default', onTriggered }) => {
|
|
56
53
|
const t = useT();
|
|
57
|
-
const
|
|
58
|
-
const api = app.apiClient;
|
|
59
|
-
const aiManager = app.pm.get<PluginAIClientV2>('ai')?.aiManager;
|
|
54
|
+
const api = useApp().apiClient;
|
|
60
55
|
const [open, setOpen] = useState(false);
|
|
61
56
|
const [flows, setFlows] = useState<ReviewFlow[]>([]);
|
|
62
57
|
const [submitting, setSubmitting] = useState(false);
|
|
63
|
-
const [asking, setAsking] = useState(false);
|
|
64
58
|
const [existingReview, setExistingReview] = useState<ExistingReview | null>(null);
|
|
65
59
|
const [templateKey, setTemplateKey] = useState<string | undefined>();
|
|
66
60
|
const [form] = Form.useForm();
|
|
@@ -166,7 +160,7 @@ export const RunReviewButton: React.FC<{
|
|
|
166
160
|
data: params,
|
|
167
161
|
});
|
|
168
162
|
const reviewId = res?.data?.data?.reviewId;
|
|
169
|
-
message.success(t('Review
|
|
163
|
+
message.success(t('Review queued'));
|
|
170
164
|
setOpen(false);
|
|
171
165
|
form.resetFields();
|
|
172
166
|
loadExistingReview();
|
|
@@ -184,116 +178,11 @@ export const RunReviewButton: React.FC<{
|
|
|
184
178
|
}
|
|
185
179
|
};
|
|
186
180
|
|
|
187
|
-
const buildWorkContext = () => {
|
|
188
|
-
const title = target.title || buildContextHint();
|
|
189
|
-
if (target.type === 'mr') {
|
|
190
|
-
return {
|
|
191
|
-
type: 'git-merge-request',
|
|
192
|
-
uid: `${target.repositoryId}:${target.mrIid}`,
|
|
193
|
-
title,
|
|
194
|
-
content: {
|
|
195
|
-
repositoryId: target.repositoryId,
|
|
196
|
-
mrIid: target.mrIid,
|
|
197
|
-
title,
|
|
198
|
-
},
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
if (target.type === 'commit') {
|
|
202
|
-
return {
|
|
203
|
-
type: 'git-commit',
|
|
204
|
-
uid: `${target.repositoryId}:${target.commitSha}`,
|
|
205
|
-
title,
|
|
206
|
-
content: {
|
|
207
|
-
repositoryId: target.repositoryId,
|
|
208
|
-
commitSha: target.commitSha,
|
|
209
|
-
title,
|
|
210
|
-
},
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
if (target.type === 'folder') {
|
|
214
|
-
return {
|
|
215
|
-
type: 'git-repository',
|
|
216
|
-
uid: `${target.repositoryId}:folder:${target.folderPath}`,
|
|
217
|
-
title,
|
|
218
|
-
content: {
|
|
219
|
-
repositoryId: target.repositoryId,
|
|
220
|
-
folderPath: target.folderPath,
|
|
221
|
-
ref: target.ref,
|
|
222
|
-
title,
|
|
223
|
-
},
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
return {
|
|
227
|
-
type: 'git-repository',
|
|
228
|
-
uid: String(target.repositoryId),
|
|
229
|
-
title,
|
|
230
|
-
content: {
|
|
231
|
-
repositoryId: target.repositoryId,
|
|
232
|
-
branch: target.branch,
|
|
233
|
-
title,
|
|
234
|
-
},
|
|
235
|
-
};
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
const buildChatPrompt = () => {
|
|
239
|
-
if (target.type === 'mr') {
|
|
240
|
-
return `Please review merge request !${target.mrIid} (${
|
|
241
|
-
target.title || 'untitled'
|
|
242
|
-
}). Use the attached Git merge request context and the available git tools when you need more detail.`;
|
|
243
|
-
}
|
|
244
|
-
if (target.type === 'commit') {
|
|
245
|
-
return `Please review commit ${target.commitSha} (${
|
|
246
|
-
target.title || 'untitled'
|
|
247
|
-
}). Use the attached Git commit context and the available git tools when you need more detail.`;
|
|
248
|
-
}
|
|
249
|
-
if (target.type === 'folder') {
|
|
250
|
-
return `Please review the full code inside folder "${target.folderPath || '/'}" at ref ${
|
|
251
|
-
target.ref || 'HEAD'
|
|
252
|
-
}. Use git_list_files (recursive=true) to enumerate the files, then git_get_file_content to read them.`;
|
|
253
|
-
}
|
|
254
|
-
return `Please help me inspect branch ${target.branch}. Use the attached Git repository context and the available git tools when you need more detail.`;
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
const handleOpenChat = async () => {
|
|
258
|
-
if (!aiManager?.triggerTask) {
|
|
259
|
-
message.warning(t('AI plugin is not available'));
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
setAsking(true);
|
|
263
|
-
try {
|
|
264
|
-
const list = flows.length ? flows : await loadFlows();
|
|
265
|
-
const flow = pickFlow(list);
|
|
266
|
-
if (!flow?.aiEmployeeUsername) {
|
|
267
|
-
message.warning(t('No matching flow available'));
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
aiManager.triggerTask({
|
|
271
|
-
aiEmployee: flow.aiEmployeeUsername,
|
|
272
|
-
tasks: [
|
|
273
|
-
{
|
|
274
|
-
title: `${flow.name}: ${buildContextHint()}`,
|
|
275
|
-
message: {
|
|
276
|
-
user: buildChatPrompt(),
|
|
277
|
-
system: flow.instructions || undefined,
|
|
278
|
-
workContext: [buildWorkContext()],
|
|
279
|
-
},
|
|
280
|
-
model: flow.llmService && flow.model ? { llmService: flow.llmService, model: flow.model } : null,
|
|
281
|
-
autoSend: false,
|
|
282
|
-
},
|
|
283
|
-
],
|
|
284
|
-
});
|
|
285
|
-
} catch (err: unknown) {
|
|
286
|
-
message.error((err instanceof Error && err.message) || t('Failed to open AI chat'));
|
|
287
|
-
} finally {
|
|
288
|
-
setAsking(false);
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
-
|
|
292
181
|
const buildContextHint = () => {
|
|
293
182
|
if (target.type === 'mr') return `MR !${target.mrIid}`;
|
|
294
183
|
if (target.type === 'commit') return `Commit ${String(target.commitSha).slice(0, 7)}`;
|
|
295
184
|
if (target.type === 'folder') return `${t('Folder')} ${target.folderPath || '/'}`;
|
|
296
|
-
return
|
|
185
|
+
return `${t('Branch')} ${target.branch}`;
|
|
297
186
|
};
|
|
298
187
|
|
|
299
188
|
// Derive re-run state for MR targets
|
|
@@ -302,7 +191,7 @@ export const RunReviewButton: React.FC<{
|
|
|
302
191
|
existingReview.headSha &&
|
|
303
192
|
existingReview.latestSha &&
|
|
304
193
|
existingReview.headSha !== existingReview.latestSha;
|
|
305
|
-
const isReReview = !!existingReview
|
|
194
|
+
const isReReview = !!existingReview;
|
|
306
195
|
const buttonLabel = isReReview
|
|
307
196
|
? hasNewCommits
|
|
308
197
|
? t('Re-review (new commits)')
|
|
@@ -329,26 +218,13 @@ export const RunReviewButton: React.FC<{
|
|
|
329
218
|
},
|
|
330
219
|
]
|
|
331
220
|
: []),
|
|
332
|
-
{
|
|
333
|
-
key: 'chat',
|
|
334
|
-
icon: <MessageOutlined />,
|
|
335
|
-
label: t('Ask AI Employee'),
|
|
336
|
-
onClick: handleOpenChat,
|
|
337
|
-
disabled: asking || !aiManager?.triggerTask,
|
|
338
|
-
},
|
|
339
221
|
];
|
|
340
222
|
|
|
341
223
|
return (
|
|
342
224
|
<>
|
|
343
225
|
<Dropdown menu={{ items }} placement="bottomRight" trigger={['click']}>
|
|
344
|
-
<Button
|
|
345
|
-
|
|
346
|
-
type={hasNewCommits ? 'primary' : type}
|
|
347
|
-
icon={<ButtonIcon />}
|
|
348
|
-
danger={!!hasNewCommits}
|
|
349
|
-
loading={asking}
|
|
350
|
-
>
|
|
351
|
-
{buttonLabel}
|
|
226
|
+
<Button size={size} type={hasNewCommits ? 'primary' : type} icon={<ButtonIcon />} danger={!!hasNewCommits}>
|
|
227
|
+
{label ?? buttonLabel}
|
|
352
228
|
</Button>
|
|
353
229
|
</Dropdown>
|
|
354
230
|
<Modal
|
|
@@ -373,8 +249,8 @@ export const RunReviewButton: React.FC<{
|
|
|
373
249
|
style={{ marginBottom: 12 }}
|
|
374
250
|
message={
|
|
375
251
|
hasNewCommits
|
|
376
|
-
? t('New commits detected
|
|
377
|
-
: t('A review
|
|
252
|
+
? t('New commits detected. A new review will be queued.')
|
|
253
|
+
: t('A new review will be queued and existing history will be kept.')
|
|
378
254
|
}
|
|
379
255
|
description={
|
|
380
256
|
<Space size={8} wrap style={{ fontSize: 12 }}>
|
|
@@ -0,0 +1,42 @@
|
|
|
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 {
|
|
11
|
+
getModernClientPrefix,
|
|
12
|
+
getRouteRuntimeVersion,
|
|
13
|
+
getV2EffectiveBasePath,
|
|
14
|
+
stripModernClientPrefix,
|
|
15
|
+
} from '@nocobase/client-v2';
|
|
16
|
+
|
|
17
|
+
type App = Parameters<typeof getV2EffectiveBasePath>[0];
|
|
18
|
+
|
|
19
|
+
function join(base: string, path: string) {
|
|
20
|
+
return `${base.replace(/\/+$/, '')}/${path.replace(/^\/+/, '')}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function legacyBase(app: App) {
|
|
24
|
+
const configured = typeof window === 'undefined' ? undefined : window.__nocobase_public_path__;
|
|
25
|
+
return stripModernClientPrefix(configured || app.getPublicPath());
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function workflowHref(app: App, type: 'workflow' | 'execution', id: string | number) {
|
|
29
|
+
const modern = getRouteRuntimeVersion() === 'modern';
|
|
30
|
+
const path = modern
|
|
31
|
+
? `/admin/workflow/${type === 'workflow' ? 'workflows' : 'executions'}/${encodeURIComponent(String(id))}`
|
|
32
|
+
: `/admin/settings/workflow/${type === 'workflow' ? 'workflows' : 'executions'}/${encodeURIComponent(String(id))}`;
|
|
33
|
+
return join(modern ? getV2EffectiveBasePath(app) : legacyBase(app), path);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function reviewApprovalHref(app: App) {
|
|
37
|
+
const base =
|
|
38
|
+
getRouteRuntimeVersion() === 'modern'
|
|
39
|
+
? getV2EffectiveBasePath(app)
|
|
40
|
+
: join(legacyBase(app), getModernClientPrefix());
|
|
41
|
+
return join(base, '/admin/workflow/tasks/git-review-approval/pending');
|
|
42
|
+
}
|