plugin-git-manager 1.2.27 → 1.2.28

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 (108) hide show
  1. package/README.md +133 -108
  2. package/client-v2.d.ts +2 -2
  3. package/client-v2.js +1 -1
  4. package/client.d.ts +3 -3
  5. package/client.js +1 -1
  6. package/dist/client/{326.90c276058682b536.js → 313.d38fc1d40c4589b9.js} +1 -1
  7. package/dist/client/900.a48beac7e2ebee7d.js +10 -0
  8. package/dist/client/index.js +1 -1
  9. package/dist/client-v2/156.445366026c1cc9a8.js +10 -0
  10. package/dist/client-v2/{326.42b7b53651ffab3a.js → 313.3c867179c3a1e817.js} +1 -1
  11. package/dist/client-v2/434.19c7579c06b9077c.js +10 -0
  12. package/dist/client-v2/900.e6155002a9c97e7f.js +10 -0
  13. package/dist/client-v2/928.bba701b5a1ece58e.js +10 -0
  14. package/dist/client-v2/index.js +1 -1
  15. package/dist/externalVersion.js +9 -8
  16. package/dist/locale/en-US.json +307 -297
  17. package/dist/locale/vi-VN.json +295 -292
  18. package/dist/locale/zh-CN.json +61 -51
  19. package/dist/node_modules/simple-git/dist/cjs/index.js +25 -25
  20. package/dist/node_modules/simple-git/package.json +1 -1
  21. package/dist/node_modules/zod/index.cjs +1 -1
  22. package/dist/node_modules/zod/package.json +1 -1
  23. package/dist/server/actions/git-actions.js +90 -36
  24. package/dist/server/actions/gitlab-api.js +4 -2
  25. package/dist/server/actions/poller.js +5 -2
  26. package/dist/server/actions/review.js +20 -10
  27. package/dist/server/plugin.js +6 -4
  28. package/dist/server/poller.js +46 -45
  29. package/dist/server/request-method-policy.js +75 -0
  30. package/dist/server/services/registry-content-service.js +4 -3
  31. package/dist/server/utils/get-repo-account.js +3 -2
  32. package/dist/server/utils/url-security.js +24 -0
  33. package/package.json +61 -43
  34. package/server.d.ts +2 -2
  35. package/server.js +1 -1
  36. package/src/client/__tests__/RunReviewButton.test.tsx +73 -0
  37. package/src/client/ai-context.tsx +114 -114
  38. package/src/client/components/AIEmployeeSelect.tsx +63 -63
  39. package/src/client/components/CommitHistory.tsx +374 -374
  40. package/src/client/components/FileExplorer.tsx +386 -386
  41. package/src/client/components/GitAccounts.tsx +179 -179
  42. package/src/client/components/GitManagerSettings.tsx +160 -160
  43. package/src/client/components/GitOperations.tsx +220 -220
  44. package/src/client/components/LLMModelSelect.tsx +63 -63
  45. package/src/client/components/LLMServiceSelect.tsx +58 -58
  46. package/src/client/components/MarkdownView.tsx +80 -80
  47. package/src/client/components/MergeRequests.tsx +790 -790
  48. package/src/client/components/PollingStatus.tsx +225 -225
  49. package/src/client/components/RepositoryConfig.tsx +335 -335
  50. package/src/client/components/RepositoryPermissions.tsx +123 -123
  51. package/src/client/components/ReviewFlows.tsx +303 -303
  52. package/src/client/components/ReviewHistory.tsx +566 -566
  53. package/src/client/components/RunReviewButton.tsx +63 -55
  54. package/src/client/context/GitManagerContext.tsx +92 -92
  55. package/src/client/index.tsx +91 -82
  56. package/src/client/locale.ts +9 -9
  57. package/src/client/promptTemplates.ts +31 -31
  58. package/src/client-v2/ai-context.tsx +99 -0
  59. package/src/client-v2/components/SubtreeSplits.tsx +547 -547
  60. package/src/client-v2/index.tsx +1 -1
  61. package/src/client-v2/locale.ts +8 -8
  62. package/src/client-v2/plugin.tsx +67 -39
  63. package/src/index.ts +2 -2
  64. package/src/locale/en-US.json +307 -297
  65. package/src/locale/vi-VN.json +295 -292
  66. package/src/locale/zh-CN.json +61 -51
  67. package/src/server/__tests__/git-actions.test.ts +24 -24
  68. package/src/server/__tests__/git-security.test.ts +170 -0
  69. package/src/server/__tests__/plugin-url-security.test.ts +17 -17
  70. package/src/server/__tests__/poller-lifecycle.test.ts +71 -0
  71. package/src/server/__tests__/poller.test.ts +37 -37
  72. package/src/server/__tests__/repository-access.test.ts +752 -752
  73. package/src/server/__tests__/review.test.ts +137 -137
  74. package/src/server/__tests__/role-permissions.test.ts +147 -147
  75. package/src/server/__tests__/smoke.test.ts +139 -17
  76. package/src/server/__tests__/subtree.test.ts +85 -85
  77. package/src/server/actions/git-actions.ts +540 -480
  78. package/src/server/actions/gitlab-api.ts +422 -411
  79. package/src/server/actions/poller.ts +39 -27
  80. package/src/server/actions/review.ts +1388 -1369
  81. package/src/server/actions/role-permissions.ts +321 -321
  82. package/src/server/actions/subtree.ts +508 -508
  83. package/src/server/ai-tools.ts +319 -319
  84. package/src/server/collections/gitAccounts.ts +56 -56
  85. package/src/server/collections/gitCodeReviews.ts +199 -199
  86. package/src/server/collections/gitRepositories.ts +87 -87
  87. package/src/server/collections/gitReviewFlows.ts +108 -108
  88. package/src/server/collections/gitSubtreeConfigs.ts +38 -38
  89. package/src/server/collections/gitSubtreeRuns.ts +30 -30
  90. package/src/server/index.ts +2 -2
  91. package/src/server/migrations/20260508000000-add-auto-review-flow-id.ts +29 -29
  92. package/src/server/migrations/20260712000000-add-git-accounts.ts +198 -198
  93. package/src/server/migrations/20260730000000-migrate-legacy-repository-permissions.ts +81 -81
  94. package/src/server/plugin.ts +372 -361
  95. package/src/server/poller.ts +351 -352
  96. package/src/server/repository-access.ts +773 -773
  97. package/src/server/request-method-policy.ts +55 -0
  98. package/src/server/services/__tests__/registry-content-service.test.ts +359 -345
  99. package/src/server/services/registry-content-service.ts +495 -484
  100. package/src/server/utils/__tests__/redact.test.ts +56 -56
  101. package/src/server/utils/__tests__/url-security.test.ts +85 -85
  102. package/src/server/utils/get-repo-account.ts +51 -41
  103. package/src/server/utils/gitlab-url.ts +38 -38
  104. package/src/server/utils/redact.ts +87 -87
  105. package/src/server/utils/url-security.ts +128 -95
  106. package/dist/client/900.acf7d1fa22f95e71.js +0 -10
  107. package/dist/client-v2/434.7a27051db18526c0.js +0 -10
  108. package/dist/client-v2/900.f32b9dc85249fc0a.js +0 -10
@@ -1,790 +1,790 @@
1
- import React, { useEffect, useState, useCallback, memo } from 'react';
2
- import {
3
- Table,
4
- Empty,
5
- Spin,
6
- Typography,
7
- Tag,
8
- Drawer,
9
- Space,
10
- Avatar,
11
- Select,
12
- Button,
13
- Tooltip,
14
- Input,
15
- Badge,
16
- Tabs,
17
- Divider,
18
- theme,
19
- } from 'antd';
20
- import {
21
- MergeOutlined,
22
- BranchesOutlined,
23
- UserOutlined,
24
- ClockCircleOutlined,
25
- CommentOutlined,
26
- ExportOutlined,
27
- SearchOutlined,
28
- CheckCircleOutlined,
29
- CloseCircleOutlined,
30
- ExclamationCircleOutlined,
31
- FileTextOutlined,
32
- ReloadOutlined,
33
- } from '@ant-design/icons';
34
- import { useApp } from '@nocobase/client-v2';
35
- import { useGitManager } from '../context/GitManagerContext';
36
- import { RunReviewButton } from './RunReviewButton';
37
- import { useT } from '../locale';
38
-
39
- const { Text, Paragraph, Title } = Typography;
40
- const { useToken } = theme;
41
-
42
- const STATE_CONFIG: Record<string, { color: string; icon: React.ReactNode; label: string }> = {
43
- opened: { color: 'blue', icon: <MergeOutlined />, label: 'Open' },
44
- merged: { color: 'purple', icon: <CheckCircleOutlined />, label: 'Merged' },
45
- closed: { color: 'red', icon: <CloseCircleOutlined />, label: 'Closed' },
46
- };
47
-
48
- export const MergeRequests: React.FC = () => {
49
- const t = useT();
50
- const { token } = useToken();
51
- const api = useApp().apiClient;
52
- const { selectedRepo } = useGitManager();
53
- const [mergeRequestsList, setMergeRequestsList] = useState<any[]>([]);
54
- const [loading, setLoading] = useState(false);
55
- const [stateFilter, setStateFilter] = useState('opened');
56
- const [searchText, setSearchText] = useState('');
57
- const [pagination, setPagination] = useState({ page: 1, perPage: 20, total: 0, totalPages: 0 });
58
- const [selectedMR, setSelectedMR] = useState<any>(null);
59
- const [mrDetail, setMrDetail] = useState<any>(null);
60
- const [detailLoading, setDetailLoading] = useState(false);
61
- const [notes, setNotes] = useState<any[]>([]);
62
- const [notesLoading, setNotesLoading] = useState(false);
63
-
64
- const loadMergeRequests = useCallback(
65
- async (page = 1) => {
66
- if (!selectedRepo) return;
67
- setLoading(true);
68
- try {
69
- const { data } = await api.request({
70
- url: 'gitManager:mergeRequests',
71
- params: {
72
- repositoryId: selectedRepo.id,
73
- state: stateFilter,
74
- search: searchText || undefined,
75
- page,
76
- perPage: 20,
77
- },
78
- });
79
- const responseData = data?.data || data;
80
- setMergeRequestsList(responseData?.data || []);
81
- if (responseData?.pagination) {
82
- setPagination(responseData.pagination);
83
- }
84
- } catch (err: any) {
85
- setMergeRequestsList([]);
86
- } finally {
87
- setLoading(false);
88
- }
89
- },
90
- [api, selectedRepo, stateFilter, searchText],
91
- );
92
-
93
- useEffect(() => {
94
- if (selectedRepo?.status === 'connected') {
95
- loadMergeRequests(1);
96
- } else {
97
- setMergeRequestsList([]);
98
- }
99
- }, [selectedRepo, stateFilter]);
100
-
101
- const handleSearch = () => {
102
- loadMergeRequests(1);
103
- };
104
-
105
- const openMRDetail = async (mr: any) => {
106
- setSelectedMR(mr);
107
- setDetailLoading(true);
108
- setNotes([]);
109
- try {
110
- const [detailRes, notesRes] = await Promise.all([
111
- api.request({
112
- url: 'gitManager:mergeRequestDetail',
113
- params: { repositoryId: selectedRepo!.id, mrIid: mr.iid },
114
- }),
115
- api.request({
116
- url: 'gitManager:mergeRequestNotes',
117
- params: { repositoryId: selectedRepo!.id, mrIid: mr.iid },
118
- }),
119
- ]);
120
- const detailData = detailRes?.data?.data?.data || detailRes?.data?.data;
121
- setMrDetail(detailData);
122
- const notesData = notesRes?.data?.data?.data || notesRes?.data?.data;
123
- setNotes(Array.isArray(notesData) ? notesData : []);
124
- } catch {
125
- setMrDetail(null);
126
- } finally {
127
- setDetailLoading(false);
128
- }
129
- };
130
-
131
- if (!selectedRepo) {
132
- return <Empty description={t('No repository selected')} />;
133
- }
134
- if (selectedRepo.status !== 'connected') {
135
- return <Empty description={t('Repository not cloned yet')} />;
136
- }
137
-
138
- const columns = [
139
- {
140
- title: '',
141
- key: 'state_icon',
142
- width: 40,
143
- render: (_: any, record: any) => {
144
- const cfg = STATE_CONFIG[record.state] || STATE_CONFIG.opened;
145
- return (
146
- <Tooltip title={cfg.label}>
147
- <span
148
- style={{
149
- color:
150
- token[`color${cfg.color === 'blue' ? 'Primary' : cfg.color === 'purple' ? 'PurpleText' : 'Error'}`] ||
151
- cfg.color,
152
- fontSize: 16,
153
- }}
154
- >
155
- {cfg.icon}
156
- </span>
157
- </Tooltip>
158
- );
159
- },
160
- },
161
- {
162
- title: t('Title'),
163
- key: 'title',
164
- render: (_: any, record: any) => (
165
- <div>
166
- <div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
167
- {record.draft && (
168
- <Tag color="default" style={{ fontSize: 11, lineHeight: '16px' }}>
169
- DRAFT
170
- </Tag>
171
- )}
172
- <Text strong style={{ fontSize: 13 }}>
173
- {record.title}
174
- </Text>
175
- {record.hasConflicts && (
176
- <Tooltip title={t('Has conflicts')}>
177
- <ExclamationCircleOutlined style={{ color: token.colorWarning }} />
178
- </Tooltip>
179
- )}
180
- </div>
181
- <div style={{ marginTop: 2 }}>
182
- <Text type="secondary" style={{ fontSize: 12 }}>
183
- !{record.iid}
184
- <span style={{ margin: '0 6px' }}>·</span>
185
- <UserOutlined style={{ marginRight: 3 }} />
186
- {record.author?.name || record.author?.username || 'Unknown'}
187
- <span style={{ margin: '0 6px' }}>·</span>
188
- <ClockCircleOutlined style={{ marginRight: 3 }} />
189
- {formatDate(record.updatedAt)}
190
- </Text>
191
- </div>
192
- </div>
193
- ),
194
- },
195
- {
196
- title: '',
197
- key: 'branches',
198
- width: 250,
199
- render: (_: any, record: any) => (
200
- <div style={{ fontSize: 12 }}>
201
- <Tag color="blue" style={{ fontSize: 11 }}>
202
- <BranchesOutlined /> {record.sourceBranch}
203
- </Tag>
204
- <span style={{ margin: '0 4px', color: token.colorTextSecondary }}>→</span>
205
- <Tag color="green" style={{ fontSize: 11 }}>
206
- <BranchesOutlined /> {record.targetBranch}
207
- </Tag>
208
- </div>
209
- ),
210
- },
211
- {
212
- title: '',
213
- key: 'labels',
214
- width: 180,
215
- render: (_: any, record: any) => (
216
- <Space size={2} wrap>
217
- {(record.labels || []).slice(0, 3).map((label: string) => (
218
- <Tag key={label} style={{ fontSize: 11 }}>
219
- {label}
220
- </Tag>
221
- ))}
222
- {record.labels?.length > 3 && (
223
- <Text type="secondary" style={{ fontSize: 11 }}>
224
- +{record.labels.length - 3}
225
- </Text>
226
- )}
227
- </Space>
228
- ),
229
- },
230
- {
231
- title: '',
232
- key: 'meta',
233
- width: 120,
234
- render: (_: any, record: any) => (
235
- <Space size={12}>
236
- {record.userNotesCount > 0 && (
237
- <Tooltip title={`${record.userNotesCount} comments`}>
238
- <Badge count={record.userNotesCount} size="small" color={token.colorTextSecondary}>
239
- <CommentOutlined style={{ fontSize: 14, color: token.colorTextSecondary }} />
240
- </Badge>
241
- </Tooltip>
242
- )}
243
- {record.assignees?.length > 0 && (
244
- <Avatar.Group size="small" max={{ count: 2 }}>
245
- {record.assignees.map((a: any) => (
246
- <Tooltip key={a.username} title={a.name}>
247
- <Avatar size="small" src={a.avatarUrl}>
248
- {a.name?.[0]}
249
- </Avatar>
250
- </Tooltip>
251
- ))}
252
- </Avatar.Group>
253
- )}
254
- </Space>
255
- ),
256
- },
257
- {
258
- title: '',
259
- key: 'actions',
260
- width: 160,
261
- render: (_: any, record: any) => (
262
- <Space onClick={(e) => e.stopPropagation()}>
263
- <RunReviewButton
264
- target={{ type: 'mr', repositoryId: selectedRepo!.id, mrIid: record.iid, title: record.title }}
265
- size="small"
266
- />
267
- <Tooltip title={t('View Details')}>
268
- <Button
269
- size="small"
270
- icon={<FileTextOutlined />}
271
- onClick={(e) => {
272
- e.stopPropagation();
273
- openMRDetail(record);
274
- }}
275
- />
276
- </Tooltip>
277
- <Tooltip title={t('Open in GitLab')}>
278
- <Button
279
- size="small"
280
- icon={<ExportOutlined />}
281
- onClick={(e) => {
282
- e.stopPropagation();
283
- window.open(record.webUrl, '_blank');
284
- }}
285
- />
286
- </Tooltip>
287
- </Space>
288
- ),
289
- },
290
- ];
291
-
292
- return (
293
- <div>
294
- {/* Filters bar */}
295
- <div style={{ marginBottom: 12, display: 'flex', alignItems: 'center', gap: 12, flexWrap: 'wrap' }}>
296
- <Select
297
- size="small"
298
- style={{ width: 140 }}
299
- value={stateFilter}
300
- onChange={(v) => setStateFilter(v)}
301
- options={[
302
- { label: `🟢 ${t('Open')}`, value: 'opened' },
303
- { label: `🟣 ${t('Merged')}`, value: 'merged' },
304
- { label: `🔴 ${t('Closed')}`, value: 'closed' },
305
- { label: `📋 ${t('All')}`, value: 'all' },
306
- ]}
307
- />
308
- <Input.Search
309
- size="small"
310
- style={{ width: 260 }}
311
- placeholder={t('Search merge requests...')}
312
- value={searchText}
313
- onChange={(e) => setSearchText(e.target.value)}
314
- onSearch={handleSearch}
315
- allowClear
316
- />
317
- <Button size="small" icon={<ReloadOutlined />} onClick={() => loadMergeRequests(1)}>
318
- {t('Refresh')}
319
- </Button>
320
- <Text type="secondary" style={{ fontSize: 12 }}>
321
- {pagination.total != null ? `${pagination.total} ${t('total')}` : ''}
322
- </Text>
323
- </div>
324
-
325
- {loading ? (
326
- <Spin />
327
- ) : (
328
- <Table
329
- dataSource={mergeRequestsList}
330
- columns={columns}
331
- rowKey="iid"
332
- size="small"
333
- pagination={{
334
- current: pagination.page,
335
- pageSize: pagination.perPage,
336
- total: pagination.total || undefined,
337
- onChange: (page) => loadMergeRequests(page),
338
- showSizeChanger: false,
339
- }}
340
- onRow={(record) => ({
341
- style: { cursor: 'pointer' },
342
- onClick: () => openMRDetail(record),
343
- })}
344
- />
345
- )}
346
-
347
- {/* MR Detail Drawer */}
348
- <Drawer
349
- title={
350
- selectedMR ? (
351
- <div>
352
- <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
353
- {(() => {
354
- const cfg = STATE_CONFIG[selectedMR.state] || STATE_CONFIG.opened;
355
- return (
356
- <Tag color={cfg.color}>
357
- {cfg.icon} {cfg.label}
358
- </Tag>
359
- );
360
- })()}
361
- {selectedMR.draft && <Tag>DRAFT</Tag>}
362
- <Text strong style={{ fontSize: 15 }}>
363
- !{selectedMR.iid}
364
- </Text>
365
- </div>
366
- <Text strong style={{ fontSize: 16, display: 'block', marginTop: 4 }}>
367
- {selectedMR.title}
368
- </Text>
369
- </div>
370
- ) : (
371
- t('Merge Request')
372
- )
373
- }
374
- open={!!selectedMR}
375
- onClose={() => {
376
- setSelectedMR(null);
377
- setMrDetail(null);
378
- setNotes([]);
379
- }}
380
- width={900}
381
- extra={
382
- selectedMR && (
383
- <Space>
384
- <RunReviewButton
385
- target={{
386
- type: 'mr',
387
- repositoryId: selectedRepo!.id,
388
- mrIid: selectedMR.iid,
389
- title: selectedMR.title,
390
- }}
391
- size="small"
392
- />
393
- <Button type="link" icon={<ExportOutlined />} onClick={() => window.open(selectedMR.webUrl, '_blank')}>
394
- {t('Open in GitLab')}
395
- </Button>
396
- </Space>
397
- )
398
- }
399
- >
400
- {detailLoading ? (
401
- <Spin />
402
- ) : mrDetail ? (
403
- <Tabs
404
- defaultActiveKey="overview"
405
- items={[
406
- {
407
- key: 'overview',
408
- label: t('Overview'),
409
- children: <MROverview mr={mrDetail} />,
410
- },
411
- {
412
- key: 'changes',
413
- label: `${t('Changes')} (${mrDetail.changes?.length || 0})`,
414
- children: <MRChanges changes={mrDetail.changes || []} />,
415
- },
416
- {
417
- key: 'comments',
418
- label: (
419
- <Badge count={notes.length} size="small" offset={[6, 0]}>
420
- {t('Comments')}
421
- </Badge>
422
- ),
423
- children: <MRNotes notes={notes} />,
424
- },
425
- ]}
426
- />
427
- ) : null}
428
- </Drawer>
429
- </div>
430
- );
431
- };
432
-
433
- /* ─── Sub-components ─── */
434
-
435
- const MROverview: React.FC<{ mr: any }> = ({ mr }) => {
436
- const t = useT();
437
- const { token } = useToken();
438
-
439
- return (
440
- <div>
441
- {/* Branch info */}
442
- <div
443
- style={{
444
- padding: '12px 16px',
445
- background: token.colorBgLayout,
446
- borderRadius: 8,
447
- marginBottom: 16,
448
- display: 'flex',
449
- alignItems: 'center',
450
- gap: 8,
451
- }}
452
- >
453
- <Tag color="blue">
454
- <BranchesOutlined /> {mr.sourceBranch}
455
- </Tag>
456
- <span style={{ color: token.colorTextSecondary, fontSize: 16 }}>→</span>
457
- <Tag color="green">
458
- <BranchesOutlined /> {mr.targetBranch}
459
- </Tag>
460
- {mr.hasConflicts && (
461
- <Tag color="warning" icon={<ExclamationCircleOutlined />}>
462
- {t('Has conflicts')}
463
- </Tag>
464
- )}
465
- </div>
466
-
467
- {/* Description */}
468
- {mr.description && (
469
- <div style={{ marginBottom: 16 }}>
470
- <Text strong>{t('Description')}</Text>
471
- <div
472
- style={{
473
- marginTop: 8,
474
- padding: '12px 16px',
475
- background: token.colorBgLayout,
476
- borderRadius: 8,
477
- whiteSpace: 'pre-wrap',
478
- wordBreak: 'break-word',
479
- fontSize: 13,
480
- lineHeight: 1.6,
481
- }}
482
- >
483
- {mr.description}
484
- </div>
485
- </div>
486
- )}
487
-
488
- {/* Metadata grid */}
489
- <div
490
- style={{
491
- display: 'grid',
492
- gridTemplateColumns: '1fr 1fr',
493
- gap: '12px 24px',
494
- fontSize: 13,
495
- }}
496
- >
497
- <MetaItem
498
- label={t('Author')}
499
- value={
500
- mr.author && (
501
- <Space size={6}>
502
- <Avatar size="small" src={mr.author.avatarUrl}>
503
- {mr.author.name?.[0]}
504
- </Avatar>
505
- <Text>{mr.author.name}</Text>
506
- <Text type="secondary">@{mr.author.username}</Text>
507
- </Space>
508
- )
509
- }
510
- />
511
-
512
- <MetaItem
513
- label={t('Assignees')}
514
- value={
515
- mr.assignees?.length > 0 ? (
516
- <Space size={4} wrap>
517
- {mr.assignees.map((a: any) => (
518
- <Tooltip key={a.username} title={a.name}>
519
- <Tag
520
- icon={
521
- <Avatar size={14} src={a.avatarUrl}>
522
- {a.name?.[0]}
523
- </Avatar>
524
- }
525
- >
526
- {a.name}
527
- </Tag>
528
- </Tooltip>
529
- ))}
530
- </Space>
531
- ) : (
532
- <Text type="secondary">—</Text>
533
- )
534
- }
535
- />
536
-
537
- <MetaItem
538
- label={t('Reviewers')}
539
- value={
540
- mr.reviewers?.length > 0 ? (
541
- <Space size={4} wrap>
542
- {mr.reviewers.map((r: any) => (
543
- <Tag key={r.username}>{r.name}</Tag>
544
- ))}
545
- </Space>
546
- ) : (
547
- <Text type="secondary">—</Text>
548
- )
549
- }
550
- />
551
-
552
- <MetaItem
553
- label={t('Labels')}
554
- value={
555
- mr.labels?.length > 0 ? (
556
- <Space size={4} wrap>
557
- {mr.labels.map((l: string) => (
558
- <Tag key={l}>{l}</Tag>
559
- ))}
560
- </Space>
561
- ) : (
562
- <Text type="secondary">—</Text>
563
- )
564
- }
565
- />
566
-
567
- <MetaItem label={t('Created')} value={<Text>{formatDateFull(mr.createdAt)}</Text>} />
568
- <MetaItem label={t('Updated')} value={<Text>{formatDateFull(mr.updatedAt)}</Text>} />
569
-
570
- {mr.mergedBy && (
571
- <MetaItem
572
- label={t('Merged by')}
573
- value={
574
- <Text>
575
- {mr.mergedBy.name} — {formatDateFull(mr.mergedAt)}
576
- </Text>
577
- }
578
- />
579
- )}
580
- {mr.closedBy && (
581
- <MetaItem
582
- label={t('Closed by')}
583
- value={
584
- <Text>
585
- {mr.closedBy.name} — {formatDateFull(mr.closedAt)}
586
- </Text>
587
- }
588
- />
589
- )}
590
- </div>
591
- </div>
592
- );
593
- };
594
-
595
- const MetaItem: React.FC<{ label: string; value: React.ReactNode }> = ({ label, value }) => (
596
- <div>
597
- <Text type="secondary" style={{ fontSize: 12, display: 'block', marginBottom: 2 }}>
598
- {label}
599
- </Text>
600
- <div>{value}</div>
601
- </div>
602
- );
603
-
604
- const MRChanges: React.FC<{ changes: any[] }> = ({ changes }) => {
605
- const { token } = useToken();
606
- const t = useT();
607
- const [expandedFile, setExpandedFile] = useState<string | null>(null);
608
-
609
- if (!changes.length) {
610
- return <Empty description={t('No changes')} />;
611
- }
612
-
613
- return (
614
- <div>
615
- {changes.map((change, idx) => {
616
- const filePath = change.newPath || change.oldPath;
617
- const isExpanded = expandedFile === filePath;
618
- let statusTag: React.ReactNode = null;
619
- if (change.newFile) statusTag = <Tag color="green">NEW</Tag>;
620
- else if (change.deletedFile) statusTag = <Tag color="red">DEL</Tag>;
621
- else if (change.renamedFile) statusTag = <Tag color="orange">RENAMED</Tag>;
622
- else statusTag = <Tag color="blue">MOD</Tag>;
623
-
624
- return (
625
- <div key={idx} style={{ marginBottom: 8 }}>
626
- <div
627
- style={{
628
- padding: '6px 12px',
629
- background: isExpanded ? token.colorPrimaryBg : token.colorBgLayout,
630
- borderRadius: 6,
631
- cursor: 'pointer',
632
- display: 'flex',
633
- alignItems: 'center',
634
- gap: 8,
635
- }}
636
- onClick={() => setExpandedFile(isExpanded ? null : filePath)}
637
- >
638
- {statusTag}
639
- <Text style={{ fontSize: 13, fontFamily: 'monospace' }}>{filePath}</Text>
640
- {change.renamedFile && change.oldPath !== change.newPath && (
641
- <Text type="secondary" style={{ fontSize: 11 }}>
642
- (← {change.oldPath})
643
- </Text>
644
- )}
645
- </div>
646
- {isExpanded && change.diff && <DiffViewer content={change.diff} />}
647
- </div>
648
- );
649
- })}
650
- </div>
651
- );
652
- };
653
-
654
- const MRNotes: React.FC<{ notes: any[] }> = ({ notes }) => {
655
- const { token } = useToken();
656
- const t = useT();
657
-
658
- if (!notes.length) {
659
- return <Empty description={t('No comments')} />;
660
- }
661
-
662
- return (
663
- <div>
664
- {notes.map((note) => (
665
- <div
666
- key={note.id}
667
- style={{
668
- padding: '12px 16px',
669
- marginBottom: 12,
670
- background: token.colorBgLayout,
671
- borderRadius: 8,
672
- borderLeft: `3px solid ${note.resolved ? token.colorSuccess : token.colorBorderSecondary}`,
673
- }}
674
- >
675
- <div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 8 }}>
676
- <Avatar size="small" src={note.author?.avatarUrl}>
677
- {note.author?.name?.[0]}
678
- </Avatar>
679
- <Text strong style={{ fontSize: 13 }}>
680
- {note.author?.name}
681
- </Text>
682
- <Text type="secondary" style={{ fontSize: 12 }}>
683
- @{note.author?.username}
684
- </Text>
685
- <Text type="secondary" style={{ fontSize: 11, marginLeft: 'auto' }}>
686
- {formatDate(note.createdAt)}
687
- </Text>
688
- {note.resolvable && (
689
- <Tag color={note.resolved ? 'success' : 'default'} style={{ fontSize: 11 }}>
690
- {note.resolved ? t('Resolved') : t('Unresolved')}
691
- </Tag>
692
- )}
693
- </div>
694
- <div style={{ whiteSpace: 'pre-wrap', wordBreak: 'break-word', fontSize: 13, lineHeight: 1.6 }}>
695
- {note.body}
696
- </div>
697
- </div>
698
- ))}
699
- </div>
700
- );
701
- };
702
-
703
- const DiffViewer: React.FC<{ content: string }> = memo(({ content }) => {
704
- const { token } = useToken();
705
- const lines = content.split('\n');
706
-
707
- return (
708
- <div
709
- style={{
710
- fontFamily: "'JetBrains Mono', 'Fira Code', Consolas, monospace",
711
- fontSize: 12,
712
- lineHeight: 1.5,
713
- border: `1px solid ${token.colorBorderSecondary}`,
714
- borderRadius: 6,
715
- overflow: 'auto',
716
- maxHeight: 400,
717
- margin: '4px 0',
718
- }}
719
- >
720
- {lines.map((line, i) => {
721
- let bg = 'transparent';
722
- let color = token.colorText;
723
- if (line.startsWith('+') && !line.startsWith('+++')) {
724
- bg = 'rgba(46, 160, 67, 0.12)';
725
- color = '#2ea043';
726
- } else if (line.startsWith('-') && !line.startsWith('---')) {
727
- bg = 'rgba(248, 81, 73, 0.12)';
728
- color = '#f85149';
729
- } else if (line.startsWith('@@')) {
730
- bg = 'rgba(56, 139, 253, 0.08)';
731
- color = '#388bfd';
732
- } else if (line.startsWith('diff') || line.startsWith('index')) {
733
- color = token.colorTextSecondary;
734
- }
735
- return (
736
- <div
737
- key={i}
738
- style={{
739
- padding: '0 12px',
740
- background: bg,
741
- color,
742
- whiteSpace: 'pre',
743
- minHeight: 20,
744
- }}
745
- >
746
- <span
747
- style={{
748
- display: 'inline-block',
749
- width: 40,
750
- color: token.colorTextQuaternary,
751
- userSelect: 'none',
752
- textAlign: 'right',
753
- marginRight: 12,
754
- }}
755
- >
756
- {i + 1}
757
- </span>
758
- {line}
759
- </div>
760
- );
761
- })}
762
- </div>
763
- );
764
- });
765
-
766
- /* ─── Utilities ─── */
767
-
768
- function formatDate(dateStr: string): string {
769
- if (!dateStr) return '';
770
- const d = new Date(dateStr);
771
- const now = new Date();
772
- const diffMs = now.getTime() - d.getTime();
773
- const diffHours = diffMs / (1000 * 60 * 60);
774
-
775
- if (diffHours < 1) return `${Math.round(diffMs / 60000)}m ago`;
776
- if (diffHours < 24) return `${Math.round(diffHours)}h ago`;
777
- if (diffHours < 168) return `${Math.round(diffHours / 24)}d ago`;
778
- return d.toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' });
779
- }
780
-
781
- function formatDateFull(dateStr: string): string {
782
- if (!dateStr) return '';
783
- return new Date(dateStr).toLocaleString('en-US', {
784
- year: 'numeric',
785
- month: 'short',
786
- day: 'numeric',
787
- hour: '2-digit',
788
- minute: '2-digit',
789
- });
790
- }
1
+ import React, { useEffect, useState, useCallback, memo } from 'react';
2
+ import {
3
+ Table,
4
+ Empty,
5
+ Spin,
6
+ Typography,
7
+ Tag,
8
+ Drawer,
9
+ Space,
10
+ Avatar,
11
+ Select,
12
+ Button,
13
+ Tooltip,
14
+ Input,
15
+ Badge,
16
+ Tabs,
17
+ Divider,
18
+ theme,
19
+ } from 'antd';
20
+ import {
21
+ MergeOutlined,
22
+ BranchesOutlined,
23
+ UserOutlined,
24
+ ClockCircleOutlined,
25
+ CommentOutlined,
26
+ ExportOutlined,
27
+ SearchOutlined,
28
+ CheckCircleOutlined,
29
+ CloseCircleOutlined,
30
+ ExclamationCircleOutlined,
31
+ FileTextOutlined,
32
+ ReloadOutlined,
33
+ } from '@ant-design/icons';
34
+ import { useApp } from '@nocobase/client-v2';
35
+ import { useGitManager } from '../context/GitManagerContext';
36
+ import { RunReviewButton } from './RunReviewButton';
37
+ import { useT } from '../locale';
38
+
39
+ const { Text, Paragraph, Title } = Typography;
40
+ const { useToken } = theme;
41
+
42
+ const STATE_CONFIG: Record<string, { color: string; icon: React.ReactNode; label: string }> = {
43
+ opened: { color: 'blue', icon: <MergeOutlined />, label: 'Open' },
44
+ merged: { color: 'purple', icon: <CheckCircleOutlined />, label: 'Merged' },
45
+ closed: { color: 'red', icon: <CloseCircleOutlined />, label: 'Closed' },
46
+ };
47
+
48
+ export const MergeRequests: React.FC = () => {
49
+ const t = useT();
50
+ const { token } = useToken();
51
+ const api = useApp().apiClient;
52
+ const { selectedRepo } = useGitManager();
53
+ const [mergeRequestsList, setMergeRequestsList] = useState<any[]>([]);
54
+ const [loading, setLoading] = useState(false);
55
+ const [stateFilter, setStateFilter] = useState('opened');
56
+ const [searchText, setSearchText] = useState('');
57
+ const [pagination, setPagination] = useState({ page: 1, perPage: 20, total: 0, totalPages: 0 });
58
+ const [selectedMR, setSelectedMR] = useState<any>(null);
59
+ const [mrDetail, setMrDetail] = useState<any>(null);
60
+ const [detailLoading, setDetailLoading] = useState(false);
61
+ const [notes, setNotes] = useState<any[]>([]);
62
+ const [notesLoading, setNotesLoading] = useState(false);
63
+
64
+ const loadMergeRequests = useCallback(
65
+ async (page = 1) => {
66
+ if (!selectedRepo) return;
67
+ setLoading(true);
68
+ try {
69
+ const { data } = await api.request({
70
+ url: 'gitManager:mergeRequests',
71
+ params: {
72
+ repositoryId: selectedRepo.id,
73
+ state: stateFilter,
74
+ search: searchText || undefined,
75
+ page,
76
+ perPage: 20,
77
+ },
78
+ });
79
+ const responseData = data?.data || data;
80
+ setMergeRequestsList(responseData?.data || []);
81
+ if (responseData?.pagination) {
82
+ setPagination(responseData.pagination);
83
+ }
84
+ } catch (err: any) {
85
+ setMergeRequestsList([]);
86
+ } finally {
87
+ setLoading(false);
88
+ }
89
+ },
90
+ [api, selectedRepo, stateFilter, searchText],
91
+ );
92
+
93
+ useEffect(() => {
94
+ if (selectedRepo?.status === 'connected') {
95
+ loadMergeRequests(1);
96
+ } else {
97
+ setMergeRequestsList([]);
98
+ }
99
+ }, [selectedRepo, stateFilter]);
100
+
101
+ const handleSearch = () => {
102
+ loadMergeRequests(1);
103
+ };
104
+
105
+ const openMRDetail = async (mr: any) => {
106
+ setSelectedMR(mr);
107
+ setDetailLoading(true);
108
+ setNotes([]);
109
+ try {
110
+ const [detailRes, notesRes] = await Promise.all([
111
+ api.request({
112
+ url: 'gitManager:mergeRequestDetail',
113
+ params: { repositoryId: selectedRepo!.id, mrIid: mr.iid },
114
+ }),
115
+ api.request({
116
+ url: 'gitManager:mergeRequestNotes',
117
+ params: { repositoryId: selectedRepo!.id, mrIid: mr.iid },
118
+ }),
119
+ ]);
120
+ const detailData = detailRes?.data?.data?.data || detailRes?.data?.data;
121
+ setMrDetail(detailData);
122
+ const notesData = notesRes?.data?.data?.data || notesRes?.data?.data;
123
+ setNotes(Array.isArray(notesData) ? notesData : []);
124
+ } catch {
125
+ setMrDetail(null);
126
+ } finally {
127
+ setDetailLoading(false);
128
+ }
129
+ };
130
+
131
+ if (!selectedRepo) {
132
+ return <Empty description={t('No repository selected')} />;
133
+ }
134
+ if (selectedRepo.status !== 'connected') {
135
+ return <Empty description={t('Repository not cloned yet')} />;
136
+ }
137
+
138
+ const columns = [
139
+ {
140
+ title: '',
141
+ key: 'state_icon',
142
+ width: 40,
143
+ render: (_: any, record: any) => {
144
+ const cfg = STATE_CONFIG[record.state] || STATE_CONFIG.opened;
145
+ return (
146
+ <Tooltip title={cfg.label}>
147
+ <span
148
+ style={{
149
+ color:
150
+ token[`color${cfg.color === 'blue' ? 'Primary' : cfg.color === 'purple' ? 'PurpleText' : 'Error'}`] ||
151
+ cfg.color,
152
+ fontSize: 16,
153
+ }}
154
+ >
155
+ {cfg.icon}
156
+ </span>
157
+ </Tooltip>
158
+ );
159
+ },
160
+ },
161
+ {
162
+ title: t('Title'),
163
+ key: 'title',
164
+ render: (_: any, record: any) => (
165
+ <div>
166
+ <div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
167
+ {record.draft && (
168
+ <Tag color="default" style={{ fontSize: 11, lineHeight: '16px' }}>
169
+ DRAFT
170
+ </Tag>
171
+ )}
172
+ <Text strong style={{ fontSize: 13 }}>
173
+ {record.title}
174
+ </Text>
175
+ {record.hasConflicts && (
176
+ <Tooltip title={t('Has conflicts')}>
177
+ <ExclamationCircleOutlined style={{ color: token.colorWarning }} />
178
+ </Tooltip>
179
+ )}
180
+ </div>
181
+ <div style={{ marginTop: 2 }}>
182
+ <Text type="secondary" style={{ fontSize: 12 }}>
183
+ !{record.iid}
184
+ <span style={{ margin: '0 6px' }}>·</span>
185
+ <UserOutlined style={{ marginRight: 3 }} />
186
+ {record.author?.name || record.author?.username || 'Unknown'}
187
+ <span style={{ margin: '0 6px' }}>·</span>
188
+ <ClockCircleOutlined style={{ marginRight: 3 }} />
189
+ {formatDate(record.updatedAt)}
190
+ </Text>
191
+ </div>
192
+ </div>
193
+ ),
194
+ },
195
+ {
196
+ title: '',
197
+ key: 'branches',
198
+ width: 250,
199
+ render: (_: any, record: any) => (
200
+ <div style={{ fontSize: 12 }}>
201
+ <Tag color="blue" style={{ fontSize: 11 }}>
202
+ <BranchesOutlined /> {record.sourceBranch}
203
+ </Tag>
204
+ <span style={{ margin: '0 4px', color: token.colorTextSecondary }}>→</span>
205
+ <Tag color="green" style={{ fontSize: 11 }}>
206
+ <BranchesOutlined /> {record.targetBranch}
207
+ </Tag>
208
+ </div>
209
+ ),
210
+ },
211
+ {
212
+ title: '',
213
+ key: 'labels',
214
+ width: 180,
215
+ render: (_: any, record: any) => (
216
+ <Space size={2} wrap>
217
+ {(record.labels || []).slice(0, 3).map((label: string) => (
218
+ <Tag key={label} style={{ fontSize: 11 }}>
219
+ {label}
220
+ </Tag>
221
+ ))}
222
+ {record.labels?.length > 3 && (
223
+ <Text type="secondary" style={{ fontSize: 11 }}>
224
+ +{record.labels.length - 3}
225
+ </Text>
226
+ )}
227
+ </Space>
228
+ ),
229
+ },
230
+ {
231
+ title: '',
232
+ key: 'meta',
233
+ width: 120,
234
+ render: (_: any, record: any) => (
235
+ <Space size={12}>
236
+ {record.userNotesCount > 0 && (
237
+ <Tooltip title={`${record.userNotesCount} comments`}>
238
+ <Badge count={record.userNotesCount} size="small" color={token.colorTextSecondary}>
239
+ <CommentOutlined style={{ fontSize: 14, color: token.colorTextSecondary }} />
240
+ </Badge>
241
+ </Tooltip>
242
+ )}
243
+ {record.assignees?.length > 0 && (
244
+ <Avatar.Group size="small" max={{ count: 2 }}>
245
+ {record.assignees.map((a: any) => (
246
+ <Tooltip key={a.username} title={a.name}>
247
+ <Avatar size="small" src={a.avatarUrl}>
248
+ {a.name?.[0]}
249
+ </Avatar>
250
+ </Tooltip>
251
+ ))}
252
+ </Avatar.Group>
253
+ )}
254
+ </Space>
255
+ ),
256
+ },
257
+ {
258
+ title: '',
259
+ key: 'actions',
260
+ width: 160,
261
+ render: (_: any, record: any) => (
262
+ <Space onClick={(e) => e.stopPropagation()}>
263
+ <RunReviewButton
264
+ target={{ type: 'mr', repositoryId: selectedRepo!.id, mrIid: record.iid, title: record.title }}
265
+ size="small"
266
+ />
267
+ <Tooltip title={t('View Details')}>
268
+ <Button
269
+ size="small"
270
+ icon={<FileTextOutlined />}
271
+ onClick={(e) => {
272
+ e.stopPropagation();
273
+ openMRDetail(record);
274
+ }}
275
+ />
276
+ </Tooltip>
277
+ <Tooltip title={t('Open in GitLab')}>
278
+ <Button
279
+ size="small"
280
+ icon={<ExportOutlined />}
281
+ onClick={(e) => {
282
+ e.stopPropagation();
283
+ window.open(record.webUrl, '_blank');
284
+ }}
285
+ />
286
+ </Tooltip>
287
+ </Space>
288
+ ),
289
+ },
290
+ ];
291
+
292
+ return (
293
+ <div>
294
+ {/* Filters bar */}
295
+ <div style={{ marginBottom: 12, display: 'flex', alignItems: 'center', gap: 12, flexWrap: 'wrap' }}>
296
+ <Select
297
+ size="small"
298
+ style={{ width: 140 }}
299
+ value={stateFilter}
300
+ onChange={(v) => setStateFilter(v)}
301
+ options={[
302
+ { label: `🟢 ${t('Open')}`, value: 'opened' },
303
+ { label: `🟣 ${t('Merged')}`, value: 'merged' },
304
+ { label: `🔴 ${t('Closed')}`, value: 'closed' },
305
+ { label: `📋 ${t('All')}`, value: 'all' },
306
+ ]}
307
+ />
308
+ <Input.Search
309
+ size="small"
310
+ style={{ width: 260 }}
311
+ placeholder={t('Search merge requests...')}
312
+ value={searchText}
313
+ onChange={(e) => setSearchText(e.target.value)}
314
+ onSearch={handleSearch}
315
+ allowClear
316
+ />
317
+ <Button size="small" icon={<ReloadOutlined />} onClick={() => loadMergeRequests(1)}>
318
+ {t('Refresh')}
319
+ </Button>
320
+ <Text type="secondary" style={{ fontSize: 12 }}>
321
+ {pagination.total != null ? `${pagination.total} ${t('total')}` : ''}
322
+ </Text>
323
+ </div>
324
+
325
+ {loading ? (
326
+ <Spin />
327
+ ) : (
328
+ <Table
329
+ dataSource={mergeRequestsList}
330
+ columns={columns}
331
+ rowKey="iid"
332
+ size="small"
333
+ pagination={{
334
+ current: pagination.page,
335
+ pageSize: pagination.perPage,
336
+ total: pagination.total || undefined,
337
+ onChange: (page) => loadMergeRequests(page),
338
+ showSizeChanger: false,
339
+ }}
340
+ onRow={(record) => ({
341
+ style: { cursor: 'pointer' },
342
+ onClick: () => openMRDetail(record),
343
+ })}
344
+ />
345
+ )}
346
+
347
+ {/* MR Detail Drawer */}
348
+ <Drawer
349
+ title={
350
+ selectedMR ? (
351
+ <div>
352
+ <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
353
+ {(() => {
354
+ const cfg = STATE_CONFIG[selectedMR.state] || STATE_CONFIG.opened;
355
+ return (
356
+ <Tag color={cfg.color}>
357
+ {cfg.icon} {cfg.label}
358
+ </Tag>
359
+ );
360
+ })()}
361
+ {selectedMR.draft && <Tag>DRAFT</Tag>}
362
+ <Text strong style={{ fontSize: 15 }}>
363
+ !{selectedMR.iid}
364
+ </Text>
365
+ </div>
366
+ <Text strong style={{ fontSize: 16, display: 'block', marginTop: 4 }}>
367
+ {selectedMR.title}
368
+ </Text>
369
+ </div>
370
+ ) : (
371
+ t('Merge Request')
372
+ )
373
+ }
374
+ open={!!selectedMR}
375
+ onClose={() => {
376
+ setSelectedMR(null);
377
+ setMrDetail(null);
378
+ setNotes([]);
379
+ }}
380
+ width={900}
381
+ extra={
382
+ selectedMR && (
383
+ <Space>
384
+ <RunReviewButton
385
+ target={{
386
+ type: 'mr',
387
+ repositoryId: selectedRepo!.id,
388
+ mrIid: selectedMR.iid,
389
+ title: selectedMR.title,
390
+ }}
391
+ size="small"
392
+ />
393
+ <Button type="link" icon={<ExportOutlined />} onClick={() => window.open(selectedMR.webUrl, '_blank')}>
394
+ {t('Open in GitLab')}
395
+ </Button>
396
+ </Space>
397
+ )
398
+ }
399
+ >
400
+ {detailLoading ? (
401
+ <Spin />
402
+ ) : mrDetail ? (
403
+ <Tabs
404
+ defaultActiveKey="overview"
405
+ items={[
406
+ {
407
+ key: 'overview',
408
+ label: t('Overview'),
409
+ children: <MROverview mr={mrDetail} />,
410
+ },
411
+ {
412
+ key: 'changes',
413
+ label: `${t('Changes')} (${mrDetail.changes?.length || 0})`,
414
+ children: <MRChanges changes={mrDetail.changes || []} />,
415
+ },
416
+ {
417
+ key: 'comments',
418
+ label: (
419
+ <Badge count={notes.length} size="small" offset={[6, 0]}>
420
+ {t('Comments')}
421
+ </Badge>
422
+ ),
423
+ children: <MRNotes notes={notes} />,
424
+ },
425
+ ]}
426
+ />
427
+ ) : null}
428
+ </Drawer>
429
+ </div>
430
+ );
431
+ };
432
+
433
+ /* ─── Sub-components ─── */
434
+
435
+ const MROverview: React.FC<{ mr: any }> = ({ mr }) => {
436
+ const t = useT();
437
+ const { token } = useToken();
438
+
439
+ return (
440
+ <div>
441
+ {/* Branch info */}
442
+ <div
443
+ style={{
444
+ padding: '12px 16px',
445
+ background: token.colorBgLayout,
446
+ borderRadius: 8,
447
+ marginBottom: 16,
448
+ display: 'flex',
449
+ alignItems: 'center',
450
+ gap: 8,
451
+ }}
452
+ >
453
+ <Tag color="blue">
454
+ <BranchesOutlined /> {mr.sourceBranch}
455
+ </Tag>
456
+ <span style={{ color: token.colorTextSecondary, fontSize: 16 }}>→</span>
457
+ <Tag color="green">
458
+ <BranchesOutlined /> {mr.targetBranch}
459
+ </Tag>
460
+ {mr.hasConflicts && (
461
+ <Tag color="warning" icon={<ExclamationCircleOutlined />}>
462
+ {t('Has conflicts')}
463
+ </Tag>
464
+ )}
465
+ </div>
466
+
467
+ {/* Description */}
468
+ {mr.description && (
469
+ <div style={{ marginBottom: 16 }}>
470
+ <Text strong>{t('Description')}</Text>
471
+ <div
472
+ style={{
473
+ marginTop: 8,
474
+ padding: '12px 16px',
475
+ background: token.colorBgLayout,
476
+ borderRadius: 8,
477
+ whiteSpace: 'pre-wrap',
478
+ wordBreak: 'break-word',
479
+ fontSize: 13,
480
+ lineHeight: 1.6,
481
+ }}
482
+ >
483
+ {mr.description}
484
+ </div>
485
+ </div>
486
+ )}
487
+
488
+ {/* Metadata grid */}
489
+ <div
490
+ style={{
491
+ display: 'grid',
492
+ gridTemplateColumns: '1fr 1fr',
493
+ gap: '12px 24px',
494
+ fontSize: 13,
495
+ }}
496
+ >
497
+ <MetaItem
498
+ label={t('Author')}
499
+ value={
500
+ mr.author && (
501
+ <Space size={6}>
502
+ <Avatar size="small" src={mr.author.avatarUrl}>
503
+ {mr.author.name?.[0]}
504
+ </Avatar>
505
+ <Text>{mr.author.name}</Text>
506
+ <Text type="secondary">@{mr.author.username}</Text>
507
+ </Space>
508
+ )
509
+ }
510
+ />
511
+
512
+ <MetaItem
513
+ label={t('Assignees')}
514
+ value={
515
+ mr.assignees?.length > 0 ? (
516
+ <Space size={4} wrap>
517
+ {mr.assignees.map((a: any) => (
518
+ <Tooltip key={a.username} title={a.name}>
519
+ <Tag
520
+ icon={
521
+ <Avatar size={14} src={a.avatarUrl}>
522
+ {a.name?.[0]}
523
+ </Avatar>
524
+ }
525
+ >
526
+ {a.name}
527
+ </Tag>
528
+ </Tooltip>
529
+ ))}
530
+ </Space>
531
+ ) : (
532
+ <Text type="secondary">—</Text>
533
+ )
534
+ }
535
+ />
536
+
537
+ <MetaItem
538
+ label={t('Reviewers')}
539
+ value={
540
+ mr.reviewers?.length > 0 ? (
541
+ <Space size={4} wrap>
542
+ {mr.reviewers.map((r: any) => (
543
+ <Tag key={r.username}>{r.name}</Tag>
544
+ ))}
545
+ </Space>
546
+ ) : (
547
+ <Text type="secondary">—</Text>
548
+ )
549
+ }
550
+ />
551
+
552
+ <MetaItem
553
+ label={t('Labels')}
554
+ value={
555
+ mr.labels?.length > 0 ? (
556
+ <Space size={4} wrap>
557
+ {mr.labels.map((l: string) => (
558
+ <Tag key={l}>{l}</Tag>
559
+ ))}
560
+ </Space>
561
+ ) : (
562
+ <Text type="secondary">—</Text>
563
+ )
564
+ }
565
+ />
566
+
567
+ <MetaItem label={t('Created')} value={<Text>{formatDateFull(mr.createdAt)}</Text>} />
568
+ <MetaItem label={t('Updated')} value={<Text>{formatDateFull(mr.updatedAt)}</Text>} />
569
+
570
+ {mr.mergedBy && (
571
+ <MetaItem
572
+ label={t('Merged by')}
573
+ value={
574
+ <Text>
575
+ {mr.mergedBy.name} — {formatDateFull(mr.mergedAt)}
576
+ </Text>
577
+ }
578
+ />
579
+ )}
580
+ {mr.closedBy && (
581
+ <MetaItem
582
+ label={t('Closed by')}
583
+ value={
584
+ <Text>
585
+ {mr.closedBy.name} — {formatDateFull(mr.closedAt)}
586
+ </Text>
587
+ }
588
+ />
589
+ )}
590
+ </div>
591
+ </div>
592
+ );
593
+ };
594
+
595
+ const MetaItem: React.FC<{ label: string; value: React.ReactNode }> = ({ label, value }) => (
596
+ <div>
597
+ <Text type="secondary" style={{ fontSize: 12, display: 'block', marginBottom: 2 }}>
598
+ {label}
599
+ </Text>
600
+ <div>{value}</div>
601
+ </div>
602
+ );
603
+
604
+ const MRChanges: React.FC<{ changes: any[] }> = ({ changes }) => {
605
+ const { token } = useToken();
606
+ const t = useT();
607
+ const [expandedFile, setExpandedFile] = useState<string | null>(null);
608
+
609
+ if (!changes.length) {
610
+ return <Empty description={t('No changes')} />;
611
+ }
612
+
613
+ return (
614
+ <div>
615
+ {changes.map((change, idx) => {
616
+ const filePath = change.newPath || change.oldPath;
617
+ const isExpanded = expandedFile === filePath;
618
+ let statusTag: React.ReactNode = null;
619
+ if (change.newFile) statusTag = <Tag color="green">NEW</Tag>;
620
+ else if (change.deletedFile) statusTag = <Tag color="red">DEL</Tag>;
621
+ else if (change.renamedFile) statusTag = <Tag color="orange">RENAMED</Tag>;
622
+ else statusTag = <Tag color="blue">MOD</Tag>;
623
+
624
+ return (
625
+ <div key={idx} style={{ marginBottom: 8 }}>
626
+ <div
627
+ style={{
628
+ padding: '6px 12px',
629
+ background: isExpanded ? token.colorPrimaryBg : token.colorBgLayout,
630
+ borderRadius: 6,
631
+ cursor: 'pointer',
632
+ display: 'flex',
633
+ alignItems: 'center',
634
+ gap: 8,
635
+ }}
636
+ onClick={() => setExpandedFile(isExpanded ? null : filePath)}
637
+ >
638
+ {statusTag}
639
+ <Text style={{ fontSize: 13, fontFamily: 'monospace' }}>{filePath}</Text>
640
+ {change.renamedFile && change.oldPath !== change.newPath && (
641
+ <Text type="secondary" style={{ fontSize: 11 }}>
642
+ (← {change.oldPath})
643
+ </Text>
644
+ )}
645
+ </div>
646
+ {isExpanded && change.diff && <DiffViewer content={change.diff} />}
647
+ </div>
648
+ );
649
+ })}
650
+ </div>
651
+ );
652
+ };
653
+
654
+ const MRNotes: React.FC<{ notes: any[] }> = ({ notes }) => {
655
+ const { token } = useToken();
656
+ const t = useT();
657
+
658
+ if (!notes.length) {
659
+ return <Empty description={t('No comments')} />;
660
+ }
661
+
662
+ return (
663
+ <div>
664
+ {notes.map((note) => (
665
+ <div
666
+ key={note.id}
667
+ style={{
668
+ padding: '12px 16px',
669
+ marginBottom: 12,
670
+ background: token.colorBgLayout,
671
+ borderRadius: 8,
672
+ borderLeft: `3px solid ${note.resolved ? token.colorSuccess : token.colorBorderSecondary}`,
673
+ }}
674
+ >
675
+ <div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 8 }}>
676
+ <Avatar size="small" src={note.author?.avatarUrl}>
677
+ {note.author?.name?.[0]}
678
+ </Avatar>
679
+ <Text strong style={{ fontSize: 13 }}>
680
+ {note.author?.name}
681
+ </Text>
682
+ <Text type="secondary" style={{ fontSize: 12 }}>
683
+ @{note.author?.username}
684
+ </Text>
685
+ <Text type="secondary" style={{ fontSize: 11, marginLeft: 'auto' }}>
686
+ {formatDate(note.createdAt)}
687
+ </Text>
688
+ {note.resolvable && (
689
+ <Tag color={note.resolved ? 'success' : 'default'} style={{ fontSize: 11 }}>
690
+ {note.resolved ? t('Resolved') : t('Unresolved')}
691
+ </Tag>
692
+ )}
693
+ </div>
694
+ <div style={{ whiteSpace: 'pre-wrap', wordBreak: 'break-word', fontSize: 13, lineHeight: 1.6 }}>
695
+ {note.body}
696
+ </div>
697
+ </div>
698
+ ))}
699
+ </div>
700
+ );
701
+ };
702
+
703
+ const DiffViewer: React.FC<{ content: string }> = memo(({ content }) => {
704
+ const { token } = useToken();
705
+ const lines = content.split('\n');
706
+
707
+ return (
708
+ <div
709
+ style={{
710
+ fontFamily: "'JetBrains Mono', 'Fira Code', Consolas, monospace",
711
+ fontSize: 12,
712
+ lineHeight: 1.5,
713
+ border: `1px solid ${token.colorBorderSecondary}`,
714
+ borderRadius: 6,
715
+ overflow: 'auto',
716
+ maxHeight: 400,
717
+ margin: '4px 0',
718
+ }}
719
+ >
720
+ {lines.map((line, i) => {
721
+ let bg = 'transparent';
722
+ let color = token.colorText;
723
+ if (line.startsWith('+') && !line.startsWith('+++')) {
724
+ bg = 'rgba(46, 160, 67, 0.12)';
725
+ color = '#2ea043';
726
+ } else if (line.startsWith('-') && !line.startsWith('---')) {
727
+ bg = 'rgba(248, 81, 73, 0.12)';
728
+ color = '#f85149';
729
+ } else if (line.startsWith('@@')) {
730
+ bg = 'rgba(56, 139, 253, 0.08)';
731
+ color = '#388bfd';
732
+ } else if (line.startsWith('diff') || line.startsWith('index')) {
733
+ color = token.colorTextSecondary;
734
+ }
735
+ return (
736
+ <div
737
+ key={i}
738
+ style={{
739
+ padding: '0 12px',
740
+ background: bg,
741
+ color,
742
+ whiteSpace: 'pre',
743
+ minHeight: 20,
744
+ }}
745
+ >
746
+ <span
747
+ style={{
748
+ display: 'inline-block',
749
+ width: 40,
750
+ color: token.colorTextQuaternary,
751
+ userSelect: 'none',
752
+ textAlign: 'right',
753
+ marginRight: 12,
754
+ }}
755
+ >
756
+ {i + 1}
757
+ </span>
758
+ {line}
759
+ </div>
760
+ );
761
+ })}
762
+ </div>
763
+ );
764
+ });
765
+
766
+ /* ─── Utilities ─── */
767
+
768
+ function formatDate(dateStr: string): string {
769
+ if (!dateStr) return '';
770
+ const d = new Date(dateStr);
771
+ const now = new Date();
772
+ const diffMs = now.getTime() - d.getTime();
773
+ const diffHours = diffMs / (1000 * 60 * 60);
774
+
775
+ if (diffHours < 1) return `${Math.round(diffMs / 60000)}m ago`;
776
+ if (diffHours < 24) return `${Math.round(diffHours)}h ago`;
777
+ if (diffHours < 168) return `${Math.round(diffHours / 24)}d ago`;
778
+ return d.toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' });
779
+ }
780
+
781
+ function formatDateFull(dateStr: string): string {
782
+ if (!dateStr) return '';
783
+ return new Date(dateStr).toLocaleString('en-US', {
784
+ year: 'numeric',
785
+ month: 'short',
786
+ day: 'numeric',
787
+ hour: '2-digit',
788
+ minute: '2-digit',
789
+ });
790
+ }