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.
Files changed (67) hide show
  1. package/README.md +58 -40
  2. package/dist/client/941.1793e67472872992.js +10 -0
  3. package/dist/client/index.js +1 -1
  4. package/dist/client-v2/941.b0d55429cd053f32.js +10 -0
  5. package/dist/client-v2/index.js +1 -1
  6. package/dist/locale/en-US.json +90 -1
  7. package/dist/locale/vi-VN.json +90 -1
  8. package/dist/locale/zh-CN.json +90 -1
  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 +137 -0
  12. package/dist/server/actions/review.js +132 -43
  13. package/dist/server/actions/role-permissions.js +1 -0
  14. package/dist/server/ai-tools.js +8 -9
  15. package/dist/server/collections/gitCodeReviews.js +10 -0
  16. package/dist/server/collections/gitReviewCutover.js +44 -0
  17. package/dist/server/collections/gitReviewFlows.js +3 -0
  18. package/dist/server/collections/gitReviewInbox.js +51 -0
  19. package/dist/server/collections/gitReviewProjects.js +43 -0
  20. package/dist/server/collections/gitReviewRequests.js +56 -0
  21. package/dist/server/index.js +8 -2
  22. package/dist/server/plugin.js +51 -16
  23. package/dist/server/poller.js +54 -34
  24. package/dist/server/repository-access.js +23 -5
  25. package/dist/server/request-method-policy.js +2 -1
  26. package/dist/server/review-control-access.js +79 -0
  27. package/dist/server/services/legacy-post-service.js +412 -0
  28. package/dist/server/services/review-service.js +1451 -0
  29. package/dist/server/services/review-source.js +325 -0
  30. package/package.json +2 -2
  31. package/src/client/__tests__/CommitHistory.test.tsx +79 -0
  32. package/src/client/__tests__/ReviewHistory.test.tsx +126 -0
  33. package/src/client/__tests__/RunReviewButton.test.tsx +46 -35
  34. package/src/client/__tests__/workflowRoutes.test.ts +65 -0
  35. package/src/client/components/CommitHistory.tsx +61 -6
  36. package/src/client/components/ReviewFlows.tsx +90 -41
  37. package/src/client/components/ReviewHistory.tsx +245 -15
  38. package/src/client/components/RunReviewButton.tsx +12 -136
  39. package/src/client/workflowRoutes.ts +42 -0
  40. package/src/locale/en-US.json +90 -1
  41. package/src/locale/vi-VN.json +90 -1
  42. package/src/locale/zh-CN.json +90 -1
  43. package/src/server/__tests__/repository-access.test.ts +11 -3
  44. package/src/server/__tests__/review-service.integration.test.ts +1263 -0
  45. package/src/server/__tests__/review.test.ts +37 -98
  46. package/src/server/actions/review-cutover.ts +121 -0
  47. package/src/server/actions/review.ts +148 -38
  48. package/src/server/actions/role-permissions.ts +10 -0
  49. package/src/server/ai-tools.ts +23 -8
  50. package/src/server/collections/gitCodeReviews.ts +19 -0
  51. package/src/server/collections/gitReviewCutover.ts +23 -0
  52. package/src/server/collections/gitReviewFlows.ts +12 -0
  53. package/src/server/collections/gitReviewInbox.ts +30 -0
  54. package/src/server/collections/gitReviewProjects.ts +22 -0
  55. package/src/server/collections/gitReviewRequests.ts +35 -0
  56. package/src/server/index.ts +12 -0
  57. package/src/server/plugin.ts +43 -6
  58. package/src/server/poller.ts +54 -40
  59. package/src/server/repository-access.ts +32 -2
  60. package/src/server/request-method-policy.ts +1 -0
  61. package/src/server/review-control-access.ts +71 -0
  62. package/src/server/services/__tests__/review-source.test.ts +226 -0
  63. package/src/server/services/legacy-post-service.ts +550 -0
  64. package/src/server/services/review-service.ts +1899 -0
  65. package/src/server/services/review-source.ts +359 -0
  66. package/dist/client/900.a48beac7e2ebee7d.js +0 -10
  67. package/dist/client-v2/900.e6155002a9c97e7f.js +0 -10
@@ -0,0 +1,65 @@
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 { reviewApprovalHref, workflowHref } from '../workflowRoutes';
11
+
12
+ type RouteWindow = Window & {
13
+ __nocobase_modern_client_prefix__?: string;
14
+ __nocobase_public_path__?: string;
15
+ };
16
+
17
+ const routeWindow = window as RouteWindow;
18
+ const createApp = (publicPath: string, basename?: string) =>
19
+ ({
20
+ getPublicPath: () => publicPath,
21
+ router: { getBasename: () => basename },
22
+ }) as unknown as Parameters<typeof workflowHref>[0];
23
+
24
+ describe('Git review workflow route resolution', () => {
25
+ let originalPath: string;
26
+ let originalPublicPath: string | undefined;
27
+ let originalModernPrefix: string | undefined;
28
+
29
+ beforeEach(() => {
30
+ originalPath = window.location.pathname;
31
+ originalPublicPath = routeWindow.__nocobase_public_path__;
32
+ originalModernPrefix = routeWindow.__nocobase_modern_client_prefix__;
33
+ });
34
+
35
+ afterEach(() => {
36
+ window.history.replaceState({}, '', originalPath);
37
+ if (originalPublicPath === undefined) delete routeWindow.__nocobase_public_path__;
38
+ else routeWindow.__nocobase_public_path__ = originalPublicPath;
39
+ if (originalModernPrefix === undefined) delete routeWindow.__nocobase_modern_client_prefix__;
40
+ else routeWindow.__nocobase_modern_client_prefix__ = originalModernPrefix;
41
+ });
42
+
43
+ it('keeps workflow links in the legacy shell and sends approval tasks through the modern prefix', () => {
44
+ routeWindow.__nocobase_modern_client_prefix__ = 'v3-custom';
45
+ routeWindow.__nocobase_public_path__ = '/tenant/app/v3-custom/';
46
+ window.history.replaceState({}, '', '/tenant/app/admin/settings/workflow');
47
+ const app = createApp('/tenant/app/v3-custom/');
48
+
49
+ expect(workflowHref(app, 'workflow', 'flow/42')).toBe('/tenant/app/admin/settings/workflow/workflows/flow%2F42');
50
+ expect(workflowHref(app, 'execution', 73)).toBe('/tenant/app/admin/settings/workflow/executions/73');
51
+ expect(reviewApprovalHref(app)).toBe('/tenant/app/v3-custom/admin/workflow/tasks/git-review-approval/pending');
52
+ });
53
+
54
+ it('uses the effective modern basename and custom modern prefix for v2 workflow links', () => {
55
+ routeWindow.__nocobase_modern_client_prefix__ = 'ops-ui';
56
+ routeWindow.__nocobase_public_path__ = '/org/portal/ops-ui/';
57
+ window.history.replaceState({}, '', '/org/portal/ops-ui/admin/workflow');
58
+ const app = createApp('/org/portal/ops-ui/', '/org/portal/ops-ui/');
59
+
60
+ expect(workflowHref(app, 'workflow', 'review flow')).toBe(
61
+ '/org/portal/ops-ui/admin/workflow/workflows/review%20flow',
62
+ );
63
+ expect(reviewApprovalHref(app)).toBe('/org/portal/ops-ui/admin/workflow/tasks/git-review-approval/pending');
64
+ });
65
+ });
@@ -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, { useEffect, useState, useCallback, memo } from 'react';
2
11
  import { Table, Empty, Spin, Typography, Tag, Drawer, List, Button, Space, Select, Input, theme } from 'antd';
3
12
  import {
@@ -29,7 +38,13 @@ export const CommitHistory: React.FC = () => {
29
38
  const t = useT();
30
39
  const { token } = useToken();
31
40
  const api = useApp().apiClient;
32
- const { selectedRepo, branches: branchList, currentBranch } = useGitManager();
41
+ const { selectedRepo } = useGitManager();
42
+ const repositoryId = selectedRepo?.id;
43
+ const [branchSnapshot, setBranchSnapshot] = useState<{
44
+ repositoryId: number;
45
+ branch: string;
46
+ branches: string[];
47
+ } | null>(null);
33
48
  const [commits, setCommits] = useState<any[]>([]);
34
49
  const [loading, setLoading] = useState(false);
35
50
  const [selectedCommit, setSelectedCommit] = useState<any>(null);
@@ -39,6 +54,35 @@ export const CommitHistory: React.FC = () => {
39
54
  const [diffFile, setDiffFile] = useState<string | null>(null);
40
55
  const [searchKeyword, setSearchKeyword] = useState('');
41
56
 
57
+ useEffect(() => {
58
+ let cancelled = false;
59
+ const repositoryId = selectedRepo?.id;
60
+ setBranchSnapshot(null);
61
+ if (!repositoryId || selectedRepo.status !== 'connected')
62
+ return () => {
63
+ cancelled = true;
64
+ };
65
+ api
66
+ .request({ url: 'gitManager:branches', params: { repositoryId } })
67
+ .then(({ data }) => {
68
+ const result = data?.data?.data || data?.data;
69
+ if (
70
+ !cancelled &&
71
+ result?.detached === false &&
72
+ typeof result?.current === 'string' &&
73
+ result.current &&
74
+ Array.isArray(result.all) &&
75
+ result.all.includes(result.current)
76
+ ) {
77
+ setBranchSnapshot({ repositoryId, branch: result.current, branches: result.all });
78
+ }
79
+ })
80
+ .catch(() => undefined);
81
+ return () => {
82
+ cancelled = true;
83
+ };
84
+ }, [api, selectedRepo?.id, selectedRepo?.status]);
85
+
42
86
  const loadHistory = useCallback(async () => {
43
87
  if (!selectedRepo) return;
44
88
  setLoading(true);
@@ -63,7 +107,7 @@ export const CommitHistory: React.FC = () => {
63
107
  } else {
64
108
  setCommits([]);
65
109
  }
66
- }, [selectedRepo]);
110
+ }, [selectedRepo, loadHistory]);
67
111
 
68
112
  const filteredCommits = commits.filter((commit) => {
69
113
  const keyword = searchKeyword.trim().toLowerCase();
@@ -74,6 +118,7 @@ export const CommitHistory: React.FC = () => {
74
118
  });
75
119
 
76
120
  const openCommitDetail = async (commit: any) => {
121
+ if (repositoryId == null) return;
77
122
  setSelectedCommit(commit);
78
123
  setDetailLoading(true);
79
124
  setDiffContent(null);
@@ -81,7 +126,7 @@ export const CommitHistory: React.FC = () => {
81
126
  try {
82
127
  const { data } = await api.request({
83
128
  url: 'gitManager:commitDetail',
84
- params: { repositoryId: selectedRepo.id, commitHash: commit.hash },
129
+ params: { repositoryId, commitHash: commit.hash },
85
130
  });
86
131
  const responseData = data?.data?.data || data?.data;
87
132
  setCommitDetail(responseData);
@@ -93,11 +138,12 @@ export const CommitHistory: React.FC = () => {
93
138
  };
94
139
 
95
140
  const loadFileDiff = async (commitHash: string, file: string) => {
141
+ if (repositoryId == null) return;
96
142
  setDiffFile(file);
97
143
  try {
98
144
  const { data } = await api.request({
99
145
  url: 'gitManager:diff',
100
- params: { repositoryId: selectedRepo.id, commitHash, file },
146
+ params: { repositoryId, commitHash, file },
101
147
  });
102
148
  const responseData = data?.data?.data || data?.data;
103
149
  setDiffContent(responseData || '');
@@ -113,6 +159,8 @@ export const CommitHistory: React.FC = () => {
113
159
  return <Empty description={t('Repository not cloned yet')} />;
114
160
  }
115
161
 
162
+ const currentBranch = branchSnapshot?.repositoryId === selectedRepo.id ? branchSnapshot : null;
163
+
116
164
  const columns = [
117
165
  {
118
166
  title: '',
@@ -184,10 +232,17 @@ export const CommitHistory: React.FC = () => {
184
232
  <Select
185
233
  size="small"
186
234
  style={{ width: 200 }}
187
- value={currentBranch}
188
- options={branchList.map((b) => ({ label: b, value: b }))}
235
+ value={currentBranch?.branch}
236
+ options={(currentBranch?.branches ?? []).map((branch) => ({ label: branch, value: branch }))}
189
237
  disabled
190
238
  />
239
+ {currentBranch && (
240
+ <RunReviewButton
241
+ label={t('Review branch')}
242
+ target={{ type: 'branch', repositoryId: selectedRepo.id, branch: currentBranch.branch }}
243
+ size="small"
244
+ />
245
+ )}
191
246
  <Input.Search
192
247
  allowClear
193
248
  size="small"
@@ -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, useState } from 'react';
2
11
  import {
3
12
  Table,
@@ -13,6 +22,7 @@ import {
13
22
  message,
14
23
  Empty,
15
24
  Tooltip,
25
+ Alert,
16
26
  } from 'antd';
17
27
  import { PlusOutlined, EditOutlined, DeleteOutlined, BranchesOutlined } from '@ant-design/icons';
18
28
  import { useApp } from '@nocobase/client-v2';
@@ -22,6 +32,7 @@ import { LLMServiceSelect } from './LLMServiceSelect';
22
32
  import { LLMModelSelect } from './LLMModelSelect';
23
33
  import { REVIEW_PROMPT_TEMPLATES } from '../promptTemplates';
24
34
  import { useT } from '../locale';
35
+ import { workflowHref } from '../workflowRoutes';
25
36
 
26
37
  const TRIGGER_LABELS: Record<string, string> = {
27
38
  manual: 'Manual',
@@ -37,7 +48,8 @@ const POST_LABELS: Record<string, string> = {
37
48
 
38
49
  export const ReviewFlows: React.FC = () => {
39
50
  const t = useT();
40
- const api = useApp().apiClient;
51
+ const app = useApp();
52
+ const api = app.apiClient;
41
53
  const { repos } = useGitManager();
42
54
  const [flows, setFlows] = useState<any[]>([]);
43
55
  const [loading, setLoading] = useState(false);
@@ -216,6 +228,19 @@ export const ReviewFlows: React.FC = () => {
216
228
  destroyOnClose
217
229
  >
218
230
  <Form form={form} layout="vertical">
231
+ {editing?.workflowId && (
232
+ <Alert
233
+ type="info"
234
+ showIcon
235
+ message={t('Edit the AI employee, model and prompt in the bound workflow')}
236
+ action={
237
+ <Button href={workflowHref(app, 'workflow', editing.workflowId)} target="_blank" rel="noreferrer">
238
+ {t('Open workflow')}
239
+ </Button>
240
+ }
241
+ style={{ marginBottom: 16 }}
242
+ />
243
+ )}
219
244
  <Form.Item name="name" label={t('Name')} rules={[{ required: true }]}>
220
245
  <Input placeholder={t('e.g. Default review flow')} />
221
246
  </Form.Item>
@@ -226,31 +251,38 @@ export const ReviewFlows: React.FC = () => {
226
251
  options={repos.map((r: any) => ({ value: r.id, label: r.name }))}
227
252
  />
228
253
  </Form.Item>
229
- <Form.Item name="aiEmployeeUsername" label={t('AI Employee')} rules={[{ required: true }]}>
254
+ <Form.Item
255
+ name="aiEmployeeUsername"
256
+ label={t('AI Employee')}
257
+ rules={[{ required: true }]}
258
+ hidden={!!editing?.workflowId}
259
+ >
230
260
  <AIEmployeeSelect placeholder={t('Select an AI employee')} />
231
261
  </Form.Item>
232
- <Space.Compact style={{ width: '100%' }}>
233
- <Form.Item name="llmService" label={t('LLM Service (optional)')} style={{ flex: 1, marginRight: 8 }}>
234
- <LLMServiceSelect placeholder={t('Override flow LLM service')} />
235
- </Form.Item>
236
- <Form.Item
237
- noStyle
238
- shouldUpdate={(prevValues, currentValues) => prevValues.llmService !== currentValues.llmService}
239
- >
240
- {({ getFieldValue }) => {
241
- const llmService = getFieldValue('llmService');
242
- return (
243
- <Form.Item name="model" label={t('Model (optional)')} style={{ flex: 1 }}>
244
- {llmService ? (
245
- <LLMModelSelect llmService={llmService} placeholder={t('Override LLM model')} />
246
- ) : (
247
- <Input placeholder={t('Select an LLM service first')} disabled />
248
- )}
249
- </Form.Item>
250
- );
251
- }}
252
- </Form.Item>
253
- </Space.Compact>
262
+ {!editing?.workflowId && (
263
+ <Space.Compact style={{ width: '100%' }}>
264
+ <Form.Item name="llmService" label={t('LLM Service (optional)')} style={{ flex: 1, marginRight: 8 }}>
265
+ <LLMServiceSelect placeholder={t('Override flow LLM service')} />
266
+ </Form.Item>
267
+ <Form.Item
268
+ noStyle
269
+ shouldUpdate={(prevValues, currentValues) => prevValues.llmService !== currentValues.llmService}
270
+ >
271
+ {({ getFieldValue }) => {
272
+ const llmService = getFieldValue('llmService');
273
+ return (
274
+ <Form.Item name="model" label={t('Model (optional)')} style={{ flex: 1 }}>
275
+ {llmService ? (
276
+ <LLMModelSelect llmService={llmService} placeholder={t('Override LLM model')} />
277
+ ) : (
278
+ <Input placeholder={t('Select an LLM service first')} disabled />
279
+ )}
280
+ </Form.Item>
281
+ );
282
+ }}
283
+ </Form.Item>
284
+ </Space.Compact>
285
+ )}
254
286
  <Form.Item
255
287
  name="triggerMode"
256
288
  label={t('Trigger Mode')}
@@ -265,7 +297,20 @@ export const ReviewFlows: React.FC = () => {
265
297
  ]}
266
298
  />
267
299
  </Form.Item>
268
- <Form.Item name="postMode" label={t('Post Mode')} rules={[{ required: true }]}>
300
+ <Form.Item
301
+ name="reviewOnNewCommits"
302
+ label={t('Review new commits automatically')}
303
+ valuePropName="checked"
304
+ extra={t('Only applies to automatic merge request reviews')}
305
+ >
306
+ <Switch />
307
+ </Form.Item>
308
+ <Form.Item
309
+ name="postMode"
310
+ label={t('Post Mode')}
311
+ rules={[{ required: true }]}
312
+ extra={editing?.workflowId ? t('Reconfigure the workflow after changing post mode') : undefined}
313
+ >
269
314
  <Select
270
315
  options={[
271
316
  { value: 'auto', label: t('Auto post to MR') },
@@ -277,22 +322,26 @@ export const ReviewFlows: React.FC = () => {
277
322
  <Form.Item name="branchFilter" label={t('Branch Filter (regex, optional)')}>
278
323
  <Input placeholder="^(feature|hotfix)/.*$" />
279
324
  </Form.Item>
280
- <Form.Item label={t('Prompt template')} extra={t('Selecting a template replaces the instructions text')}>
281
- <Select
282
- allowClear
283
- value={templateKey}
284
- placeholder={t('Load a default prompt by code type')}
285
- options={REVIEW_PROMPT_TEMPLATES.map((tpl) => ({ value: tpl.key, label: t(tpl.label) }))}
286
- onChange={(key) => {
287
- setTemplateKey(key);
288
- const tpl = REVIEW_PROMPT_TEMPLATES.find((item) => item.key === key);
289
- if (tpl) form.setFieldsValue({ instructions: tpl.text });
290
- }}
291
- />
292
- </Form.Item>
293
- <Form.Item name="instructions" label={t('Additional Instructions (optional)')}>
294
- <Input.TextArea rows={8} placeholder={t('Extra guidance appended to every review prompt')} />
295
- </Form.Item>
325
+ {!editing?.workflowId && (
326
+ <Form.Item label={t('Prompt template')} extra={t('Selecting a template replaces the instructions text')}>
327
+ <Select
328
+ allowClear
329
+ value={templateKey}
330
+ placeholder={t('Load a default prompt by code type')}
331
+ options={REVIEW_PROMPT_TEMPLATES.map((tpl) => ({ value: tpl.key, label: t(tpl.label) }))}
332
+ onChange={(key) => {
333
+ setTemplateKey(key);
334
+ const tpl = REVIEW_PROMPT_TEMPLATES.find((item) => item.key === key);
335
+ if (tpl) form.setFieldsValue({ instructions: tpl.text });
336
+ }}
337
+ />
338
+ </Form.Item>
339
+ )}
340
+ {!editing?.workflowId && (
341
+ <Form.Item name="instructions" label={t('Additional Instructions (optional)')}>
342
+ <Input.TextArea rows={8} placeholder={t('Extra guidance appended to every review prompt')} />
343
+ </Form.Item>
344
+ )}
296
345
  <Form.Item name="enabled" label={t('Enabled')} valuePropName="checked">
297
346
  <Switch />
298
347
  </Form.Item>