plugin-git-manager 1.3.3 → 1.4.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/dist/client/{156.c27c2392746e7866.js → 156.8e36af3e2cee173e.js} +1 -1
- package/dist/client/317.e7b1d59371812c30.js +10 -0
- package/dist/client/434.05d0ba2b821105dc.js +10 -0
- package/dist/client/453.cdcba6d2d0c9522b.js +10 -0
- package/dist/client/454.625da741a7e1161f.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/317.4e116f84ed9081b6.js +10 -0
- package/dist/client-v2/434.764113d20743a45b.js +10 -0
- package/dist/client-v2/453.5ab80c06d8e61a7e.js +10 -0
- package/dist/client-v2/454.b885b1d35ef7ff72.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +10 -9
- package/dist/locale/en-US.json +38 -1
- package/dist/locale/vi-VN.json +38 -1
- package/dist/locale/zh-CN.json +41 -1
- package/dist/node_modules/simple-git/package.json +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/actions/chat-context.js +282 -0
- package/dist/server/actions/git-actions.js +387 -80
- package/dist/server/actions/gitlab-api.js +101 -15
- package/dist/server/actions/subtree.js +20 -10
- package/dist/server/chat-context-admission.js +187 -0
- package/dist/server/plugin.js +142 -10
- package/dist/server/repository-access.js +2 -2
- package/dist/server/request-method-policy.js +4 -1
- package/dist/server/services/review-source.js +2 -1
- package/dist/server/utils/cluster-git.js +181 -0
- package/package.json +2 -2
- package/src/client/__tests__/FileExplorerAndManage.test.tsx +236 -0
- package/src/client/__tests__/GitContextPicker.test.tsx +120 -0
- package/src/client/__tests__/ai-context.test.tsx +119 -0
- package/src/client/__tests__/workflowRoutes.test.ts +3 -1
- package/src/client/ai-context.tsx +3 -113
- package/src/client/components/CommitHistory.tsx +19 -7
- package/src/client/components/FileExplorer.tsx +80 -34
- package/src/client/components/GitManagerSettings.tsx +21 -5
- package/src/client/components/GitOperations.tsx +25 -4
- package/src/client/components/GitRuntimeBanner.tsx +97 -0
- package/src/client/components/RepositoryConfig.tsx +28 -6
- package/src/client/context/GitManagerContext.tsx +174 -15
- package/src/client/index.tsx +3 -5
- package/src/client/workflowRoutes.ts +11 -0
- package/src/client-v2/ai-context.tsx +135 -72
- package/src/client-v2/components/GitContextPicker.tsx +418 -0
- package/src/client-v2/git-context-api.ts +59 -0
- package/src/client-v2/plugin.tsx +2 -4
- package/src/locale/en-US.json +38 -1
- package/src/locale/vi-VN.json +38 -1
- package/src/locale/zh-CN.json +41 -1
- package/src/server/__tests__/chat-context-admission.test.ts +276 -0
- package/src/server/__tests__/chat-context-options.test.ts +144 -0
- package/src/server/__tests__/git-actions.test.ts +329 -4
- package/src/server/__tests__/git-chat-context.test.ts +138 -0
- package/src/server/__tests__/git-security.test.ts +52 -0
- package/src/server/__tests__/smoke.test.ts +232 -1
- package/src/server/actions/chat-context.ts +302 -0
- package/src/server/actions/git-actions.ts +428 -89
- package/src/server/actions/gitlab-api.ts +113 -14
- package/src/server/actions/subtree.ts +23 -6
- package/src/server/chat-context-admission.ts +182 -0
- package/src/server/plugin.ts +163 -3
- package/src/server/repository-access.ts +2 -2
- package/src/server/request-method-policy.ts +3 -0
- package/src/server/services/review-source.ts +3 -2
- package/src/server/utils/cluster-git.ts +209 -0
- package/dist/client/317.17ed0018e3e7db00.js +0 -10
- package/dist/client/434.b2eeaaef33aae6e0.js +0 -10
- package/dist/client/453.fc3042c9740d8fab.js +0 -10
- package/dist/client-v2/317.d2466574d00f94d0.js +0 -10
- package/dist/client-v2/434.19c7579c06b9077c.js +0 -10
- package/dist/client-v2/453.5e507c94c59277b1.js +0 -10
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
|
|
3
|
+
import { Alert, Button, Form, Input, Select, Space, Spin, Typography } from 'antd';
|
|
4
|
+
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
|
5
|
+
import { useTranslation } from 'react-i18next';
|
|
6
|
+
import {
|
|
7
|
+
actionBody,
|
|
8
|
+
actionData,
|
|
9
|
+
fetchGitContext,
|
|
10
|
+
getCurrentGitRepository,
|
|
11
|
+
type GitContextApp,
|
|
12
|
+
type GitContextKind,
|
|
13
|
+
} from '../git-context-api';
|
|
14
|
+
|
|
15
|
+
type Repository = { id: number; name?: string; defaultBranch?: string; status?: string };
|
|
16
|
+
type MergeRequest = {
|
|
17
|
+
iid: number;
|
|
18
|
+
title: string;
|
|
19
|
+
sourceBranch?: string;
|
|
20
|
+
targetBranch?: string;
|
|
21
|
+
author?: { name?: string; username?: string };
|
|
22
|
+
updatedAt?: string;
|
|
23
|
+
};
|
|
24
|
+
type Commit = { hash: string; message?: string; subject?: string; author_name?: string; date?: string };
|
|
25
|
+
type ContextSelection = { uid: string; title?: string };
|
|
26
|
+
|
|
27
|
+
const PAGE_SIZE = 30;
|
|
28
|
+
|
|
29
|
+
function formatDate(value?: string): string {
|
|
30
|
+
if (!value) return '';
|
|
31
|
+
const date = new Date(value);
|
|
32
|
+
return Number.isNaN(date.getTime()) ? value : date.toLocaleString();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function GitContextPicker({
|
|
36
|
+
app,
|
|
37
|
+
kind,
|
|
38
|
+
onAdd,
|
|
39
|
+
isActive,
|
|
40
|
+
onClose,
|
|
41
|
+
}: {
|
|
42
|
+
app: GitContextApp;
|
|
43
|
+
kind: GitContextKind;
|
|
44
|
+
onAdd: (item: ContextSelection) => void;
|
|
45
|
+
isActive?: () => boolean;
|
|
46
|
+
onClose: () => void;
|
|
47
|
+
}) {
|
|
48
|
+
const { t } = useTranslation('plugin-git-manager');
|
|
49
|
+
const [repositoryQuery, setRepositoryQuery] = useState('');
|
|
50
|
+
const [repositoryPage, setRepositoryPage] = useState(1);
|
|
51
|
+
const [repositories, setRepositories] = useState<Repository[]>([]);
|
|
52
|
+
const [repositoryHasMore, setRepositoryHasMore] = useState(false);
|
|
53
|
+
const [repository, setRepository] = useState<Repository>();
|
|
54
|
+
const [repositoryLoading, setRepositoryLoading] = useState(false);
|
|
55
|
+
const [branchLoading, setBranchLoading] = useState(false);
|
|
56
|
+
const [branches, setBranches] = useState<string[]>([]);
|
|
57
|
+
const [branch, setBranch] = useState<string>();
|
|
58
|
+
const [state, setState] = useState('opened');
|
|
59
|
+
const [itemQuery, setItemQuery] = useState('');
|
|
60
|
+
const [itemPage, setItemPage] = useState(1);
|
|
61
|
+
const [mergeRequests, setMergeRequests] = useState<MergeRequest[]>([]);
|
|
62
|
+
const [commits, setCommits] = useState<Commit[]>([]);
|
|
63
|
+
const [itemHasMore, setItemHasMore] = useState(false);
|
|
64
|
+
const [itemLoading, setItemLoading] = useState(false);
|
|
65
|
+
const [selectedItem, setSelectedItem] = useState<string>();
|
|
66
|
+
const [repositoryError, setRepositoryError] = useState('');
|
|
67
|
+
const [branchError, setBranchError] = useState('');
|
|
68
|
+
const [itemError, setItemError] = useState('');
|
|
69
|
+
const [attachmentError, setAttachmentError] = useState('');
|
|
70
|
+
const [submitting, setSubmitting] = useState(false);
|
|
71
|
+
const repositoryTouched = useRef(false);
|
|
72
|
+
const mounted = useRef(true);
|
|
73
|
+
const submittingRef = useRef(false);
|
|
74
|
+
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
mounted.current = true;
|
|
77
|
+
return () => {
|
|
78
|
+
mounted.current = false;
|
|
79
|
+
};
|
|
80
|
+
}, []);
|
|
81
|
+
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
const repositoryId = getCurrentGitRepository(app);
|
|
84
|
+
if (repositoryId == null) return;
|
|
85
|
+
let cancelled = false;
|
|
86
|
+
app.apiClient
|
|
87
|
+
.request({
|
|
88
|
+
url: 'gitManager:chatContextOptions',
|
|
89
|
+
params: { kind, repositoryId, page: 1, pageSize: 1 },
|
|
90
|
+
skipNotify: true,
|
|
91
|
+
})
|
|
92
|
+
.then((response) => {
|
|
93
|
+
const data = actionData(response) as { items?: Repository[] } | undefined;
|
|
94
|
+
if (!cancelled && !repositoryTouched.current && data?.items?.[0]) setRepository(data.items[0]);
|
|
95
|
+
})
|
|
96
|
+
.catch(() => undefined);
|
|
97
|
+
return () => {
|
|
98
|
+
cancelled = true;
|
|
99
|
+
};
|
|
100
|
+
}, [app, kind]);
|
|
101
|
+
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
let cancelled = false;
|
|
104
|
+
setRepositoryLoading(true);
|
|
105
|
+
app.apiClient
|
|
106
|
+
.request({
|
|
107
|
+
url: 'gitManager:chatContextOptions',
|
|
108
|
+
params: { kind, search: repositoryQuery, page: repositoryPage, pageSize: PAGE_SIZE },
|
|
109
|
+
skipNotify: true,
|
|
110
|
+
})
|
|
111
|
+
.then((response) => {
|
|
112
|
+
if (cancelled) return;
|
|
113
|
+
const data = actionData(response) as { items?: Repository[]; hasMore?: boolean } | undefined;
|
|
114
|
+
const items = Array.isArray(data?.items) ? data.items : [];
|
|
115
|
+
setRepositories((current) => (repositoryPage === 1 ? items : [...current, ...items]));
|
|
116
|
+
setRepositoryHasMore(data?.hasMore === true);
|
|
117
|
+
setRepositoryError('');
|
|
118
|
+
})
|
|
119
|
+
.finally(() => {
|
|
120
|
+
if (!cancelled) setRepositoryLoading(false);
|
|
121
|
+
})
|
|
122
|
+
.catch(() => {
|
|
123
|
+
if (!cancelled) setRepositoryError(t('Unable to load Git context. Check your access and try again.'));
|
|
124
|
+
});
|
|
125
|
+
return () => {
|
|
126
|
+
cancelled = true;
|
|
127
|
+
};
|
|
128
|
+
}, [app, kind, repositoryPage, repositoryQuery, t]);
|
|
129
|
+
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
setBranches([]);
|
|
132
|
+
setBranch(undefined);
|
|
133
|
+
setBranchError('');
|
|
134
|
+
setBranchLoading(false);
|
|
135
|
+
if (kind !== 'commit' || !repository) return;
|
|
136
|
+
let cancelled = false;
|
|
137
|
+
setBranchLoading(true);
|
|
138
|
+
app.apiClient
|
|
139
|
+
.request({ url: 'gitManager:branches', params: { repositoryId: repository.id }, skipNotify: true })
|
|
140
|
+
.then((response) => {
|
|
141
|
+
if (cancelled) return;
|
|
142
|
+
const data = actionData(response) as { all?: string[]; current?: string; detached?: boolean } | undefined;
|
|
143
|
+
const available = Array.isArray(data?.all) ? data.all : [];
|
|
144
|
+
setBranches(available);
|
|
145
|
+
const current = !data?.detached && data?.current ? data.current : undefined;
|
|
146
|
+
const preferred = current && available.includes(current) ? current : repository.defaultBranch;
|
|
147
|
+
setBranch(preferred && available.includes(preferred) ? preferred : available[0]);
|
|
148
|
+
setBranchError('');
|
|
149
|
+
})
|
|
150
|
+
.finally(() => {
|
|
151
|
+
if (!cancelled) setBranchLoading(false);
|
|
152
|
+
})
|
|
153
|
+
.catch(() => {
|
|
154
|
+
if (!cancelled) setBranchError(t('Unable to load Git context. Check your access and try again.'));
|
|
155
|
+
});
|
|
156
|
+
return () => {
|
|
157
|
+
cancelled = true;
|
|
158
|
+
};
|
|
159
|
+
}, [app, kind, repository, t]);
|
|
160
|
+
|
|
161
|
+
useEffect(() => {
|
|
162
|
+
if (!repository || kind === 'repository' || (kind === 'commit' && !branch)) {
|
|
163
|
+
setItemLoading(false);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
let cancelled = false;
|
|
167
|
+
setItemLoading(true);
|
|
168
|
+
const params =
|
|
169
|
+
kind === 'merge-request'
|
|
170
|
+
? { repositoryId: repository.id, state, page: itemPage, perPage: PAGE_SIZE }
|
|
171
|
+
: { repositoryId: repository.id, branch, skip: (itemPage - 1) * PAGE_SIZE, maxCount: PAGE_SIZE };
|
|
172
|
+
app.apiClient
|
|
173
|
+
.request({
|
|
174
|
+
url: kind === 'merge-request' ? 'gitManager:mergeRequests' : 'gitManager:log',
|
|
175
|
+
params,
|
|
176
|
+
skipNotify: true,
|
|
177
|
+
})
|
|
178
|
+
.then((response) => {
|
|
179
|
+
if (cancelled) return;
|
|
180
|
+
if (kind === 'merge-request') {
|
|
181
|
+
const items = actionData(response);
|
|
182
|
+
const list = Array.isArray(items) ? (items as MergeRequest[]) : [];
|
|
183
|
+
const body = actionBody(response) as
|
|
184
|
+
| { pagination?: { totalPages?: number | null; hasMore?: boolean } }
|
|
185
|
+
| undefined;
|
|
186
|
+
setMergeRequests((current) => (itemPage === 1 ? list : [...current, ...list]));
|
|
187
|
+
setItemHasMore(
|
|
188
|
+
body?.pagination?.hasMore ??
|
|
189
|
+
(body?.pagination?.totalPages != null
|
|
190
|
+
? itemPage < body.pagination.totalPages
|
|
191
|
+
: list.length === PAGE_SIZE),
|
|
192
|
+
);
|
|
193
|
+
} else {
|
|
194
|
+
const data = actionData(response) as { all?: Commit[] } | undefined;
|
|
195
|
+
const list = Array.isArray(data?.all) ? data.all : [];
|
|
196
|
+
setCommits((current) => (itemPage === 1 ? list : [...current, ...list]));
|
|
197
|
+
setItemHasMore(list.length === PAGE_SIZE);
|
|
198
|
+
}
|
|
199
|
+
setItemError('');
|
|
200
|
+
})
|
|
201
|
+
.finally(() => {
|
|
202
|
+
if (!cancelled) setItemLoading(false);
|
|
203
|
+
})
|
|
204
|
+
.catch(() => {
|
|
205
|
+
if (!cancelled) setItemError(t('Unable to load Git context. Check your access and try again.'));
|
|
206
|
+
});
|
|
207
|
+
return () => {
|
|
208
|
+
cancelled = true;
|
|
209
|
+
};
|
|
210
|
+
}, [app, branch, itemPage, kind, repository, state, t]);
|
|
211
|
+
|
|
212
|
+
const filteredMergeRequests = useMemo(() => {
|
|
213
|
+
const query = itemQuery.trim().toLowerCase().replace(/^!/, '');
|
|
214
|
+
return mergeRequests.filter((item) => `${item.iid} ${item.title}`.toLowerCase().includes(query));
|
|
215
|
+
}, [itemQuery, mergeRequests]);
|
|
216
|
+
const filteredCommits = useMemo(() => {
|
|
217
|
+
const query = itemQuery.trim().toLowerCase();
|
|
218
|
+
return commits.filter((item) => `${item.hash} ${item.subject || item.message || ''}`.toLowerCase().includes(query));
|
|
219
|
+
}, [itemQuery, commits]);
|
|
220
|
+
|
|
221
|
+
const changeRepository = (id: number) => {
|
|
222
|
+
repositoryTouched.current = true;
|
|
223
|
+
setRepository(repositories.find((item) => item.id === id));
|
|
224
|
+
setBranch(undefined);
|
|
225
|
+
setBranches([]);
|
|
226
|
+
setSelectedItem(undefined);
|
|
227
|
+
setItemPage(1);
|
|
228
|
+
setMergeRequests([]);
|
|
229
|
+
setCommits([]);
|
|
230
|
+
setItemHasMore(false);
|
|
231
|
+
setItemQuery('');
|
|
232
|
+
setItemError('');
|
|
233
|
+
setAttachmentError('');
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
const attach = async () => {
|
|
237
|
+
if (submittingRef.current || !repository || (kind !== 'repository' && !selectedItem)) return;
|
|
238
|
+
const uid = kind === 'repository' ? String(repository.id) : `${repository.id}:${selectedItem}`;
|
|
239
|
+
const selectedMR = mergeRequests.find((item) => String(item.iid) === selectedItem);
|
|
240
|
+
const selectedCommit = commits.find((item) => item.hash === selectedItem);
|
|
241
|
+
const repoName = repository.name || String(repository.id);
|
|
242
|
+
const title =
|
|
243
|
+
kind === 'repository'
|
|
244
|
+
? repoName
|
|
245
|
+
: kind === 'merge-request'
|
|
246
|
+
? `${repoName} · !${selectedItem} · ${selectedMR?.title || ''}`
|
|
247
|
+
: `${repoName} · ${selectedItem?.slice(0, 7)} · ${selectedCommit?.subject || selectedCommit?.message || ''}`;
|
|
248
|
+
submittingRef.current = true;
|
|
249
|
+
setSubmitting(true);
|
|
250
|
+
try {
|
|
251
|
+
await fetchGitContext(app, kind, uid);
|
|
252
|
+
if (!mounted.current || (isActive && !isActive())) return;
|
|
253
|
+
onAdd({ uid, title });
|
|
254
|
+
onClose();
|
|
255
|
+
} catch {
|
|
256
|
+
if (mounted.current) setAttachmentError(t('Git context is unavailable. Check your access and select it again.'));
|
|
257
|
+
} finally {
|
|
258
|
+
submittingRef.current = false;
|
|
259
|
+
if (mounted.current) setSubmitting(false);
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
return (
|
|
264
|
+
<Form layout="vertical" onFinish={attach} disabled={submitting}>
|
|
265
|
+
<Form.Item label={t('Search repositories')}>
|
|
266
|
+
<Input.Search
|
|
267
|
+
allowClear
|
|
268
|
+
onSearch={(value, event) => {
|
|
269
|
+
event?.preventDefault();
|
|
270
|
+
repositoryTouched.current = true;
|
|
271
|
+
setRepositoryPage(1);
|
|
272
|
+
setRepositoryQuery(value);
|
|
273
|
+
}}
|
|
274
|
+
aria-label={t('Search repositories')}
|
|
275
|
+
/>
|
|
276
|
+
</Form.Item>
|
|
277
|
+
<Form.Item label={t('Repository')} required>
|
|
278
|
+
<Select
|
|
279
|
+
aria-label={t('Repository')}
|
|
280
|
+
loading={repositoryLoading}
|
|
281
|
+
value={repository?.id}
|
|
282
|
+
onChange={changeRepository}
|
|
283
|
+
placeholder={t('Select a repository')}
|
|
284
|
+
options={(repository && !repositories.some((item) => item.id === repository.id)
|
|
285
|
+
? [repository, ...repositories]
|
|
286
|
+
: repositories
|
|
287
|
+
).map((item) => ({
|
|
288
|
+
value: item.id,
|
|
289
|
+
label: [item.name || String(item.id), item.defaultBranch, item.status].filter(Boolean).join(' · '),
|
|
290
|
+
}))}
|
|
291
|
+
notFoundContent={repositoryLoading ? <Spin size="small" /> : t('No repositories available')}
|
|
292
|
+
/>
|
|
293
|
+
{repositoryHasMore && (
|
|
294
|
+
<Button type="link" loading={repositoryLoading} onClick={() => setRepositoryPage((page) => page + 1)}>
|
|
295
|
+
{t('Load more repositories')}
|
|
296
|
+
</Button>
|
|
297
|
+
)}
|
|
298
|
+
</Form.Item>
|
|
299
|
+
{kind === 'commit' && repository && (
|
|
300
|
+
<Form.Item label={t('Branch')} required>
|
|
301
|
+
<Select
|
|
302
|
+
aria-label={t('Branch')}
|
|
303
|
+
loading={branchLoading}
|
|
304
|
+
value={branch}
|
|
305
|
+
placeholder={t('Select a branch')}
|
|
306
|
+
options={branches.map((name) => ({ value: name, label: name }))}
|
|
307
|
+
onChange={(value) => {
|
|
308
|
+
setBranch(value);
|
|
309
|
+
setItemPage(1);
|
|
310
|
+
setCommits([]);
|
|
311
|
+
setItemHasMore(false);
|
|
312
|
+
setSelectedItem(undefined);
|
|
313
|
+
setItemError('');
|
|
314
|
+
setAttachmentError('');
|
|
315
|
+
}}
|
|
316
|
+
/>
|
|
317
|
+
</Form.Item>
|
|
318
|
+
)}
|
|
319
|
+
{kind === 'merge-request' && repository && (
|
|
320
|
+
<Form.Item label={t('State')}>
|
|
321
|
+
<Select
|
|
322
|
+
aria-label={t('State')}
|
|
323
|
+
value={state}
|
|
324
|
+
options={['opened', 'merged', 'closed', 'all'].map((value) => ({ value, label: t(value) }))}
|
|
325
|
+
onChange={(value) => {
|
|
326
|
+
setState(value);
|
|
327
|
+
setItemPage(1);
|
|
328
|
+
setMergeRequests([]);
|
|
329
|
+
setItemHasMore(false);
|
|
330
|
+
setSelectedItem(undefined);
|
|
331
|
+
setItemError('');
|
|
332
|
+
setAttachmentError('');
|
|
333
|
+
}}
|
|
334
|
+
/>
|
|
335
|
+
</Form.Item>
|
|
336
|
+
)}
|
|
337
|
+
{kind !== 'repository' && repository && (kind !== 'commit' || branch) && (
|
|
338
|
+
<>
|
|
339
|
+
<Form.Item label={t('Search loaded results')}>
|
|
340
|
+
<Input
|
|
341
|
+
aria-label={t('Search loaded results')}
|
|
342
|
+
value={itemQuery}
|
|
343
|
+
onChange={(event) => {
|
|
344
|
+
setItemQuery(event.target.value);
|
|
345
|
+
setSelectedItem(undefined);
|
|
346
|
+
setAttachmentError('');
|
|
347
|
+
}}
|
|
348
|
+
onPressEnter={(event) => event.preventDefault()}
|
|
349
|
+
allowClear
|
|
350
|
+
/>
|
|
351
|
+
</Form.Item>
|
|
352
|
+
<Form.Item label={t(kind === 'commit' ? 'Commit' : 'Merge Request')} required>
|
|
353
|
+
<Select
|
|
354
|
+
aria-label={t(kind === 'commit' ? 'Commit' : 'Merge Request')}
|
|
355
|
+
loading={itemLoading}
|
|
356
|
+
value={selectedItem}
|
|
357
|
+
onChange={setSelectedItem}
|
|
358
|
+
placeholder={t(kind === 'commit' ? 'Select a commit' : 'Select a merge request')}
|
|
359
|
+
options={
|
|
360
|
+
kind === 'merge-request'
|
|
361
|
+
? filteredMergeRequests.map((item) => ({
|
|
362
|
+
value: String(item.iid),
|
|
363
|
+
label: [
|
|
364
|
+
`!${item.iid} · ${item.title}`,
|
|
365
|
+
item.sourceBranch && item.targetBranch ? `${item.sourceBranch} → ${item.targetBranch}` : '',
|
|
366
|
+
item.author?.name || item.author?.username,
|
|
367
|
+
formatDate(item.updatedAt),
|
|
368
|
+
]
|
|
369
|
+
.filter(Boolean)
|
|
370
|
+
.join(' · '),
|
|
371
|
+
}))
|
|
372
|
+
: filteredCommits.map((item) => ({
|
|
373
|
+
value: item.hash,
|
|
374
|
+
label: [
|
|
375
|
+
item.hash.slice(0, 7),
|
|
376
|
+
item.subject || item.message,
|
|
377
|
+
item.author_name,
|
|
378
|
+
formatDate(item.date),
|
|
379
|
+
]
|
|
380
|
+
.filter(Boolean)
|
|
381
|
+
.join(' · '),
|
|
382
|
+
}))
|
|
383
|
+
}
|
|
384
|
+
notFoundContent={itemLoading ? <Spin size="small" /> : t('No results')}
|
|
385
|
+
/>
|
|
386
|
+
{itemHasMore && (
|
|
387
|
+
<Button type="link" loading={itemLoading} onClick={() => setItemPage((page) => page + 1)}>
|
|
388
|
+
{t('Load more results')}
|
|
389
|
+
</Button>
|
|
390
|
+
)}
|
|
391
|
+
</Form.Item>
|
|
392
|
+
</>
|
|
393
|
+
)}
|
|
394
|
+
{(attachmentError || itemError || branchError || repositoryError) && (
|
|
395
|
+
<Alert
|
|
396
|
+
type="error"
|
|
397
|
+
showIcon
|
|
398
|
+
message={attachmentError || itemError || branchError || repositoryError}
|
|
399
|
+
style={{ marginBottom: 16 }}
|
|
400
|
+
/>
|
|
401
|
+
)}
|
|
402
|
+
<Space style={{ display: 'flex', justifyContent: 'flex-end' }}>
|
|
403
|
+
<Button onClick={onClose}>{t('Cancel')}</Button>
|
|
404
|
+
<Button
|
|
405
|
+
type="primary"
|
|
406
|
+
htmlType="submit"
|
|
407
|
+
loading={submitting}
|
|
408
|
+
disabled={!repository || (kind !== 'repository' && !selectedItem)}
|
|
409
|
+
>
|
|
410
|
+
{t('Attach to chat')}
|
|
411
|
+
</Button>
|
|
412
|
+
</Space>
|
|
413
|
+
<Typography.Text type="secondary" aria-live="polite">
|
|
414
|
+
{itemLoading || repositoryLoading || branchLoading ? t('Loading') : ''}
|
|
415
|
+
</Typography.Text>
|
|
416
|
+
</Form>
|
|
417
|
+
);
|
|
418
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
|
|
3
|
+
export type GitContextKind = 'repository' | 'merge-request' | 'commit';
|
|
4
|
+
export type GitContextApp = {
|
|
5
|
+
apiClient: {
|
|
6
|
+
request: (config: {
|
|
7
|
+
url: string;
|
|
8
|
+
params?: Record<string, unknown>;
|
|
9
|
+
skipNotify?: boolean;
|
|
10
|
+
timeout?: number;
|
|
11
|
+
}) => Promise<unknown>;
|
|
12
|
+
auth?: { token?: string | null };
|
|
13
|
+
};
|
|
14
|
+
eventBus: EventTarget;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const currentRepositories = new WeakMap<object, number>();
|
|
18
|
+
|
|
19
|
+
export function setCurrentGitRepository(app: object, repositoryId?: number) {
|
|
20
|
+
if (repositoryId == null) currentRepositories.delete(app);
|
|
21
|
+
else currentRepositories.set(app, repositoryId);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function getCurrentGitRepository(app: object): number | undefined {
|
|
25
|
+
return currentRepositories.get(app);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function actionBody(response: unknown): unknown {
|
|
29
|
+
return (response as { data?: { data?: unknown } } | null)?.data?.data;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function actionData(response: unknown): unknown {
|
|
33
|
+
const body = actionBody(response);
|
|
34
|
+
if (body && typeof body === 'object' && 'success' in body && 'data' in body) {
|
|
35
|
+
return (body as { data: unknown }).data;
|
|
36
|
+
}
|
|
37
|
+
return body;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function contextParams(kind: GitContextKind, uid: string): Record<string, unknown> {
|
|
41
|
+
if (kind === 'repository') return { kind, repositoryId: uid };
|
|
42
|
+
const separator = uid.indexOf(':');
|
|
43
|
+
const repositoryId = uid.slice(0, separator);
|
|
44
|
+
const target = uid.slice(separator + 1);
|
|
45
|
+
if (separator <= 0 || !target) throw new Error('Invalid Git context');
|
|
46
|
+
if (kind === 'merge-request') return { kind, repositoryId, mrIid: target };
|
|
47
|
+
return { kind, repositoryId, commitHash: target };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function fetchGitContext(app: GitContextApp, kind: GitContextKind, uid: string): Promise<unknown> {
|
|
51
|
+
const response = await app.apiClient.request({
|
|
52
|
+
url: 'gitManager:chatContextContent',
|
|
53
|
+
params: contextParams(kind, uid),
|
|
54
|
+
skipNotify: true,
|
|
55
|
+
});
|
|
56
|
+
const data = actionData(response);
|
|
57
|
+
if (!data || typeof data !== 'object') throw new Error('Git context is unavailable');
|
|
58
|
+
return data;
|
|
59
|
+
}
|
package/src/client-v2/plugin.tsx
CHANGED
|
@@ -5,14 +5,12 @@ import type PluginAIClientV2 from '@nocobase/plugin-ai/client-v2';
|
|
|
5
5
|
import type PluginAclClientV2 from '@nocobase/plugin-acl/client-v2';
|
|
6
6
|
import type { PermissionTabProps } from '@nocobase/plugin-acl/client-v2';
|
|
7
7
|
import React from 'react';
|
|
8
|
-
import {
|
|
8
|
+
import { registerGitWorkContexts } from './ai-context';
|
|
9
9
|
|
|
10
10
|
export class PluginGitManagerClient extends Plugin<Record<string, never>, Application> {
|
|
11
11
|
async load() {
|
|
12
12
|
const aiManager = this.app.pm.get<PluginAIClientV2>('ai')?.aiManager;
|
|
13
|
-
aiManager
|
|
14
|
-
aiManager?.registerWorkContext('git-merge-request', GitMergeRequestWorkContext);
|
|
15
|
-
aiManager?.registerWorkContext('git-commit', GitCommitWorkContext);
|
|
13
|
+
if (aiManager) await registerGitWorkContexts(this.app, aiManager);
|
|
16
14
|
this.app.pm.get<PluginAclClientV2>('acl')?.settingsUI.addPermissionsTab({
|
|
17
15
|
key: 'git-manager',
|
|
18
16
|
label: this.t('Git Manager'),
|
package/src/locale/en-US.json
CHANGED
|
@@ -392,5 +392,42 @@
|
|
|
392
392
|
"Refresh publication status before recovery": "Refresh publication status before recovery",
|
|
393
393
|
"Matching comment found; another publication attempt still owns the review": "Matching comment found; another publication attempt still owns the review",
|
|
394
394
|
"Review publication claim changed": "Review publication claim changed; refresh and check the current attempt",
|
|
395
|
-
"Review project reservation changed": "Review project reservation changed"
|
|
395
|
+
"Review project reservation changed": "Review project reservation changed",
|
|
396
|
+
"Git context is unavailable. Check your access and select it again.": "Git context is unavailable. Check your access and select it again.",
|
|
397
|
+
"Unable to load Git context. Check your access and try again.": "Unable to load Git context. Check your access and try again.",
|
|
398
|
+
"Search repositories": "Search repositories",
|
|
399
|
+
"No repositories available": "No repositories available",
|
|
400
|
+
"Load more repositories": "Load more repositories",
|
|
401
|
+
"Select a branch": "Select a branch",
|
|
402
|
+
"State": "State",
|
|
403
|
+
"opened": "Open",
|
|
404
|
+
"merged": "Merged",
|
|
405
|
+
"closed": "Closed",
|
|
406
|
+
"all": "All",
|
|
407
|
+
"Search loaded results": "Search loaded results",
|
|
408
|
+
"Select a commit": "Select a commit",
|
|
409
|
+
"Select a merge request": "Select a merge request",
|
|
410
|
+
"No results": "No results",
|
|
411
|
+
"Load more results": "Load more results",
|
|
412
|
+
"Cancel": "Cancel",
|
|
413
|
+
"Attach to chat": "Attach to chat",
|
|
414
|
+
"Loading": "Loading",
|
|
415
|
+
"Additional changed files were omitted.": "Additional changed files were omitted.",
|
|
416
|
+
"The diff was truncated to the configured limit.": "The diff was truncated to the configured limit.",
|
|
417
|
+
"Binary file contents are not included in the diff.": "Binary file contents are not included in the diff.",
|
|
418
|
+
"Additional changed files were omitted by the provider.": "Additional changed files were omitted by the provider.",
|
|
419
|
+
"The provider omitted patches for one or more files, including binary or large files.": "The provider omitted patches for one or more files, including binary or large files.",
|
|
420
|
+
"The provider omitted additional changed files or patches.": "The provider omitted additional changed files or patches.",
|
|
421
|
+
"Additional changed files or diff content were omitted.": "Additional changed files or diff content were omitted.",
|
|
422
|
+
"Repository": "Repository",
|
|
423
|
+
"Refresh": "Refresh",
|
|
424
|
+
"Installing Git via Cluster Manager...": "Installing Git via Cluster Manager...",
|
|
425
|
+
"Local Git operations will unlock automatically as soon as Cluster Manager finishes installing git on this node.": "Local Git operations will unlock automatically as soon as Cluster Manager finishes installing git on this node.",
|
|
426
|
+
"Git CLI is not installed on this node yet": "Git CLI is not installed on this node yet",
|
|
427
|
+
"Git is managed separately via Cluster Manager. Install git now to enable File Explorer, Commit History, Operations, and Clone.": "Git is managed separately via Cluster Manager. Install git now to enable File Explorer, Commit History, Operations, and Clone.",
|
|
428
|
+
"Install git in the app/worker container or set GIT_BINARY_PATH to use local repository features.": "Install git in the app/worker container or set GIT_BINARY_PATH to use local repository features.",
|
|
429
|
+
"Install Git via Cluster Manager": "Install Git via Cluster Manager",
|
|
430
|
+
"Open Cluster Package Installer": "Open Cluster Package Installer",
|
|
431
|
+
"Git installation dispatched via Cluster Manager": "Git installation dispatched via Cluster Manager",
|
|
432
|
+
"Failed to start Git installation via Cluster Manager": "Failed to start Git installation via Cluster Manager"
|
|
396
433
|
}
|
package/src/locale/vi-VN.json
CHANGED
|
@@ -380,5 +380,42 @@
|
|
|
380
380
|
"Refresh publication status before recovery": "Hãy làm mới trạng thái đăng trước khi khôi phục",
|
|
381
381
|
"Matching comment found; another publication attempt still owns the review": "Đã tìm thấy bình luận khớp; một lần đăng khác vẫn đang giữ lượt đánh giá",
|
|
382
382
|
"Review publication claim changed": "Lượt đăng đang giữ đã thay đổi; hãy làm mới và kiểm tra lượt hiện tại",
|
|
383
|
-
"Review project reservation changed": "Quyền giữ dự án cho lượt đánh giá đã thay đổi"
|
|
383
|
+
"Review project reservation changed": "Quyền giữ dự án cho lượt đánh giá đã thay đổi",
|
|
384
|
+
"Git context is unavailable. Check your access and select it again.": "Không thể đọc ngữ cảnh Git. Hãy kiểm tra quyền truy cập và chọn lại.",
|
|
385
|
+
"Unable to load Git context. Check your access and try again.": "Không thể tải dữ liệu Git. Hãy kiểm tra quyền truy cập và thử lại.",
|
|
386
|
+
"Search repositories": "Tìm repository",
|
|
387
|
+
"No repositories available": "Không có repository nào khả dụng",
|
|
388
|
+
"Load more repositories": "Tải thêm repository",
|
|
389
|
+
"Select a branch": "Chọn nhánh",
|
|
390
|
+
"State": "Trạng thái",
|
|
391
|
+
"opened": "Đang mở",
|
|
392
|
+
"merged": "Đã hợp nhất",
|
|
393
|
+
"closed": "Đã đóng",
|
|
394
|
+
"all": "Tất cả",
|
|
395
|
+
"Search loaded results": "Tìm trong các kết quả đã tải",
|
|
396
|
+
"Select a commit": "Chọn commit",
|
|
397
|
+
"Select a merge request": "Chọn merge request",
|
|
398
|
+
"No results": "Không có kết quả",
|
|
399
|
+
"Load more results": "Tải thêm kết quả",
|
|
400
|
+
"Cancel": "Hủy",
|
|
401
|
+
"Attach to chat": "Gắn vào chat",
|
|
402
|
+
"Loading": "Đang tải",
|
|
403
|
+
"Additional changed files were omitted.": "Một số tệp thay đổi khác đã được lược bỏ.",
|
|
404
|
+
"The diff was truncated to the configured limit.": "Nội dung diff đã được cắt theo giới hạn cấu hình.",
|
|
405
|
+
"Binary file contents are not included in the diff.": "Nội dung tệp nhị phân không có trong diff.",
|
|
406
|
+
"Additional changed files were omitted by the provider.": "Nhà cung cấp đã lược bỏ một số tệp thay đổi khác.",
|
|
407
|
+
"The provider omitted patches for one or more files, including binary or large files.": "Nhà cung cấp không trả patch cho một hoặc nhiều tệp, bao gồm tệp nhị phân hoặc tệp lớn.",
|
|
408
|
+
"The provider omitted additional changed files or patches.": "Nhà cung cấp đã lược bỏ một số tệp thay đổi hoặc patch khác.",
|
|
409
|
+
"Additional changed files or diff content were omitted.": "Một số tệp thay đổi hoặc nội dung diff khác đã được lược bỏ.",
|
|
410
|
+
"Repository": "Kho mã nguồn",
|
|
411
|
+
"Refresh": "Làm mới",
|
|
412
|
+
"Installing Git via Cluster Manager...": "Đang cài đặt Git qua Cluster Manager...",
|
|
413
|
+
"Local Git operations will unlock automatically as soon as Cluster Manager finishes installing git on this node.": "Các thao tác Git cục bộ sẽ tự động mở khóa ngay khi Cluster Manager cài xong git trên node này.",
|
|
414
|
+
"Git CLI is not installed on this node yet": "Node hiện tại chưa được cài đặt Git CLI",
|
|
415
|
+
"Git is managed separately via Cluster Manager. Install git now to enable File Explorer, Commit History, Operations, and Clone.": "Git được quản lý cài đặt riêng qua Cluster Manager. Hãy bấm cài đặt git để dùng Duyệt tệp, Lịch sử commit, Thao tác Git và Clone.",
|
|
416
|
+
"Install git in the app/worker container or set GIT_BINARY_PATH to use local repository features.": "Hãy cài git trong container app/worker hoặc cấu hình GIT_BINARY_PATH để dùng các tính năng kho cục bộ.",
|
|
417
|
+
"Install Git via Cluster Manager": "Cài đặt Git qua Cluster Manager",
|
|
418
|
+
"Open Cluster Package Installer": "Mở trình cài gói Cluster Manager",
|
|
419
|
+
"Git installation dispatched via Cluster Manager": "Đã gửi lệnh cài đặt Git qua Cluster Manager",
|
|
420
|
+
"Failed to start Git installation via Cluster Manager": "Không thể khởi chạy cài đặt Git qua Cluster Manager"
|
|
384
421
|
}
|
package/src/locale/zh-CN.json
CHANGED
|
@@ -146,5 +146,45 @@
|
|
|
146
146
|
"Refresh publication status before recovery": "恢复前请刷新发布状态",
|
|
147
147
|
"Matching comment found; another publication attempt still owns the review": "已找到匹配评论;另一个发布操作仍占用该审查",
|
|
148
148
|
"Review publication claim changed": "审查发布占用已更改;请刷新并检查当前操作",
|
|
149
|
-
"Review project reservation changed": "审查项目占用已更改"
|
|
149
|
+
"Review project reservation changed": "审查项目占用已更改",
|
|
150
|
+
"Git context is unavailable. Check your access and select it again.": "无法读取 Git 上下文。请检查访问权限并重新选择。",
|
|
151
|
+
"Unable to load Git context. Check your access and try again.": "无法加载 Git 数据。请检查访问权限后重试。",
|
|
152
|
+
"Search repositories": "搜索仓库",
|
|
153
|
+
"Select a repository": "选择仓库",
|
|
154
|
+
"Commit": "提交",
|
|
155
|
+
"Merge Request": "合并请求",
|
|
156
|
+
"No repositories available": "没有可用的仓库",
|
|
157
|
+
"Load more repositories": "加载更多仓库",
|
|
158
|
+
"Select a branch": "选择分支",
|
|
159
|
+
"State": "状态",
|
|
160
|
+
"opened": "开放",
|
|
161
|
+
"merged": "已合并",
|
|
162
|
+
"closed": "已关闭",
|
|
163
|
+
"all": "全部",
|
|
164
|
+
"Search loaded results": "搜索已加载的结果",
|
|
165
|
+
"Select a commit": "选择提交",
|
|
166
|
+
"Select a merge request": "选择合并请求",
|
|
167
|
+
"No results": "没有结果",
|
|
168
|
+
"Load more results": "加载更多结果",
|
|
169
|
+
"Cancel": "取消",
|
|
170
|
+
"Attach to chat": "附加到聊天",
|
|
171
|
+
"Loading": "正在加载",
|
|
172
|
+
"Additional changed files were omitted.": "已省略其他更改的文件。",
|
|
173
|
+
"The diff was truncated to the configured limit.": "差异内容已按配置的上限截断。",
|
|
174
|
+
"Binary file contents are not included in the diff.": "差异内容不包含二进制文件内容。",
|
|
175
|
+
"Additional changed files were omitted by the provider.": "提供商省略了其他更改的文件。",
|
|
176
|
+
"The provider omitted patches for one or more files, including binary or large files.": "提供商省略了一个或多个文件的补丁,包括二进制文件或大文件。",
|
|
177
|
+
"The provider omitted additional changed files or patches.": "提供商省略了其他更改的文件或补丁。",
|
|
178
|
+
"Additional changed files or diff content were omitted.": "已省略其他更改的文件或差异内容。",
|
|
179
|
+
"Repository": "仓库",
|
|
180
|
+
"Refresh": "刷新",
|
|
181
|
+
"Installing Git via Cluster Manager...": "正在通过集群管理器安装 Git...",
|
|
182
|
+
"Local Git operations will unlock automatically as soon as Cluster Manager finishes installing git on this node.": "集群管理器在此节点完成 git 安装后,本地 Git 操作将自动启用。",
|
|
183
|
+
"Git CLI is not installed on this node yet": "此节点尚未安装 Git CLI",
|
|
184
|
+
"Git is managed separately via Cluster Manager. Install git now to enable File Explorer, Commit History, Operations, and Clone.": "Git 通过集群管理器单独管理。立即安装 git 以启用文件浏览、提交历史、Git 操作与克隆功能。",
|
|
185
|
+
"Install git in the app/worker container or set GIT_BINARY_PATH to use local repository features.": "请在 app/worker 容器中安装 git 或设置 GIT_BINARY_PATH 以使用本地仓库功能。",
|
|
186
|
+
"Install Git via Cluster Manager": "通过集群管理器安装 Git",
|
|
187
|
+
"Open Cluster Package Installer": "打开集群包安装器",
|
|
188
|
+
"Git installation dispatched via Cluster Manager": "已通过集群管理器下发 Git 安装任务",
|
|
189
|
+
"Failed to start Git installation via Cluster Manager": "无法通过集群管理器启动 Git 安装"
|
|
150
190
|
}
|