@fractary/core-mcp 0.1.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/LICENSE +21 -0
- package/README.md +272 -0
- package/dist/config.d.ts +40 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +112 -0
- package/dist/config.js.map +1 -0
- package/dist/handlers/docs.d.ts +58 -0
- package/dist/handlers/docs.d.ts.map +1 -0
- package/dist/handlers/docs.js +144 -0
- package/dist/handlers/docs.js.map +1 -0
- package/dist/handlers/file.d.ts +55 -0
- package/dist/handlers/file.d.ts.map +1 -0
- package/dist/handlers/file.js +153 -0
- package/dist/handlers/file.js.map +1 -0
- package/dist/handlers/helpers.d.ts +62 -0
- package/dist/handlers/helpers.d.ts.map +1 -0
- package/dist/handlers/helpers.js +100 -0
- package/dist/handlers/helpers.js.map +1 -0
- package/dist/handlers/index.d.ts +10 -0
- package/dist/handlers/index.d.ts.map +1 -0
- package/dist/handlers/index.js +184 -0
- package/dist/handlers/index.js.map +1 -0
- package/dist/handlers/logs.d.ts +48 -0
- package/dist/handlers/logs.d.ts.map +1 -0
- package/dist/handlers/logs.js +99 -0
- package/dist/handlers/logs.js.map +1 -0
- package/dist/handlers/repo.d.ts +158 -0
- package/dist/handlers/repo.d.ts.map +1 -0
- package/dist/handlers/repo.js +651 -0
- package/dist/handlers/repo.js.map +1 -0
- package/dist/handlers/security.d.ts +38 -0
- package/dist/handlers/security.d.ts.map +1 -0
- package/dist/handlers/security.js +79 -0
- package/dist/handlers/security.js.map +1 -0
- package/dist/handlers/spec.d.ts +39 -0
- package/dist/handlers/spec.d.ts.map +1 -0
- package/dist/handlers/spec.js +99 -0
- package/dist/handlers/spec.js.map +1 -0
- package/dist/handlers/work.d.ts +147 -0
- package/dist/handlers/work.d.ts.map +1 -0
- package/dist/handlers/work.js +373 -0
- package/dist/handlers/work.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +42 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/docs.d.ts +7 -0
- package/dist/tools/docs.d.ts.map +1 -0
- package/dist/tools/docs.js +160 -0
- package/dist/tools/docs.js.map +1 -0
- package/dist/tools/file.d.ts +7 -0
- package/dist/tools/file.d.ts.map +1 -0
- package/dist/tools/file.js +144 -0
- package/dist/tools/file.js.map +1 -0
- package/dist/tools/index.d.ts +9 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +18 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/logs.d.ts +7 -0
- package/dist/tools/logs.d.ts.map +1 -0
- package/dist/tools/logs.js +139 -0
- package/dist/tools/logs.js.map +1 -0
- package/dist/tools/repo.d.ts +7 -0
- package/dist/tools/repo.d.ts.map +1 -0
- package/dist/tools/repo.js +694 -0
- package/dist/tools/repo.js.map +1 -0
- package/dist/tools/spec.d.ts +7 -0
- package/dist/tools/spec.d.ts.map +1 -0
- package/dist/tools/spec.js +102 -0
- package/dist/tools/spec.js.map +1 -0
- package/dist/tools/work.d.ts +7 -0
- package/dist/tools/work.d.ts.map +1 -0
- package/dist/tools/work.js +384 -0
- package/dist/tools/work.js.map +1 -0
- package/dist/types.d.ts +28 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,651 @@
|
|
|
1
|
+
import { RepoManager } from '@fractary/core/repo';
|
|
2
|
+
import { successResult, errorResult, isValidBranchLocation, isValidBranchType, isValidCommitType, isValidPrState, isValidReviewAction, isValidMergeStrategy, isValidIssueState, validateRepoConfig } from './helpers.js';
|
|
3
|
+
/**
|
|
4
|
+
* NOTE: All handlers in this file validate config.repo before use
|
|
5
|
+
* Pattern: if (!validateRepoConfig(config)) { return errorResult(...) }
|
|
6
|
+
*/
|
|
7
|
+
// ============================================================================
|
|
8
|
+
// Repository Status
|
|
9
|
+
// ============================================================================
|
|
10
|
+
export async function handleRepoStatus(_params, config) {
|
|
11
|
+
try {
|
|
12
|
+
if (!validateRepoConfig(config)) {
|
|
13
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
14
|
+
}
|
|
15
|
+
const manager = new RepoManager(config.repo);
|
|
16
|
+
const status = await manager.getStatus();
|
|
17
|
+
return successResult(status);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
21
|
+
return errorResult(`Error getting status: ${message}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export async function handleRepoBranchCurrent(_params, config) {
|
|
25
|
+
try {
|
|
26
|
+
if (!validateRepoConfig(config)) {
|
|
27
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
28
|
+
}
|
|
29
|
+
const manager = new RepoManager(config.repo);
|
|
30
|
+
const branch = await manager.getCurrentBranch();
|
|
31
|
+
return successResult({ branch });
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
35
|
+
return errorResult(`Error getting current branch: ${message}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export async function handleRepoIsDirty(_params, config) {
|
|
39
|
+
try {
|
|
40
|
+
if (!validateRepoConfig(config)) {
|
|
41
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
42
|
+
}
|
|
43
|
+
const manager = new RepoManager(config.repo);
|
|
44
|
+
const dirty = await manager.isDirty();
|
|
45
|
+
return successResult({ dirty });
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
49
|
+
return errorResult(`Error checking if dirty: ${message}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export async function handleRepoDiff(params, config) {
|
|
53
|
+
try {
|
|
54
|
+
if (!validateRepoConfig(config)) {
|
|
55
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
56
|
+
}
|
|
57
|
+
const manager = new RepoManager(config.repo);
|
|
58
|
+
const diff = await manager.getDiff({
|
|
59
|
+
staged: params.staged,
|
|
60
|
+
base: params.base,
|
|
61
|
+
head: params.head,
|
|
62
|
+
});
|
|
63
|
+
return successResult({ diff });
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
67
|
+
return errorResult(`Error getting diff: ${message}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// ============================================================================
|
|
71
|
+
// Branch Operations
|
|
72
|
+
// ============================================================================
|
|
73
|
+
export async function handleRepoBranchCreate(params, config) {
|
|
74
|
+
try {
|
|
75
|
+
if (!validateRepoConfig(config)) {
|
|
76
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
77
|
+
}
|
|
78
|
+
const manager = new RepoManager(config.repo);
|
|
79
|
+
const branch = await manager.createBranch(params.name, {
|
|
80
|
+
baseBranch: params.base_branch,
|
|
81
|
+
fromProtected: params.from_protected,
|
|
82
|
+
});
|
|
83
|
+
return successResult(branch);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
87
|
+
return errorResult(`Error creating branch: ${message}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export async function handleRepoBranchDelete(params, config) {
|
|
91
|
+
try {
|
|
92
|
+
if (!validateRepoConfig(config)) {
|
|
93
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
94
|
+
}
|
|
95
|
+
if (params.location && !isValidBranchLocation(params.location)) {
|
|
96
|
+
return errorResult(`Invalid location: ${params.location}. Must be 'local', 'remote', or 'both'`);
|
|
97
|
+
}
|
|
98
|
+
const manager = new RepoManager(config.repo);
|
|
99
|
+
await manager.deleteBranch(params.name, {
|
|
100
|
+
force: params.force,
|
|
101
|
+
location: isValidBranchLocation(params.location) ? params.location : undefined,
|
|
102
|
+
});
|
|
103
|
+
return successResult({ deleted: true, branch: params.name });
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
107
|
+
return errorResult(`Error deleting branch: ${message}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export async function handleRepoBranchList(params, config) {
|
|
111
|
+
try {
|
|
112
|
+
if (!validateRepoConfig(config)) {
|
|
113
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
114
|
+
}
|
|
115
|
+
const manager = new RepoManager(config.repo);
|
|
116
|
+
const branches = await manager.listBranches({
|
|
117
|
+
pattern: params.pattern,
|
|
118
|
+
merged: params.merged,
|
|
119
|
+
limit: params.limit,
|
|
120
|
+
});
|
|
121
|
+
return successResult(branches);
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
125
|
+
return errorResult(`Error listing branches: ${message}`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
export async function handleRepoBranchGet(params, config) {
|
|
129
|
+
try {
|
|
130
|
+
if (!validateRepoConfig(config)) {
|
|
131
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
132
|
+
}
|
|
133
|
+
const manager = new RepoManager(config.repo);
|
|
134
|
+
const branch = await manager.getBranch(params.name);
|
|
135
|
+
if (!branch) {
|
|
136
|
+
return errorResult(`Branch not found: ${params.name}`);
|
|
137
|
+
}
|
|
138
|
+
return successResult(branch);
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
142
|
+
return errorResult(`Error getting branch: ${message}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
export async function handleRepoCheckout(params, config) {
|
|
146
|
+
try {
|
|
147
|
+
if (!validateRepoConfig(config)) {
|
|
148
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
149
|
+
}
|
|
150
|
+
const manager = new RepoManager(config.repo);
|
|
151
|
+
await manager.checkout(params.branch);
|
|
152
|
+
return successResult({ checked_out: params.branch });
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
156
|
+
return errorResult(`Error checking out branch: ${message}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
export async function handleRepoBranchNameGenerate(params, config) {
|
|
160
|
+
try {
|
|
161
|
+
if (!validateRepoConfig(config)) {
|
|
162
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
163
|
+
}
|
|
164
|
+
if (!isValidBranchType(params.type)) {
|
|
165
|
+
return errorResult(`Invalid type: ${params.type}. Must be 'feature', 'fix', 'chore', or 'docs'`);
|
|
166
|
+
}
|
|
167
|
+
const manager = new RepoManager(config.repo);
|
|
168
|
+
const name = await manager.generateBranchName({
|
|
169
|
+
type: params.type,
|
|
170
|
+
description: params.description,
|
|
171
|
+
workId: params.work_id,
|
|
172
|
+
});
|
|
173
|
+
return successResult({ name });
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
177
|
+
return errorResult(`Error generating branch name: ${message}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
// ============================================================================
|
|
181
|
+
// Staging
|
|
182
|
+
// ============================================================================
|
|
183
|
+
export async function handleRepoStage(params, config) {
|
|
184
|
+
try {
|
|
185
|
+
if (!validateRepoConfig(config)) {
|
|
186
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
187
|
+
}
|
|
188
|
+
const manager = new RepoManager(config.repo);
|
|
189
|
+
await manager.stage(params.patterns);
|
|
190
|
+
return successResult({ staged: params.patterns });
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
194
|
+
return errorResult(`Error staging files: ${message}`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
export async function handleRepoStageAll(_params, config) {
|
|
198
|
+
try {
|
|
199
|
+
if (!validateRepoConfig(config)) {
|
|
200
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
201
|
+
}
|
|
202
|
+
const manager = new RepoManager(config.repo);
|
|
203
|
+
await manager.stageAll();
|
|
204
|
+
return successResult({ staged_all: true });
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
208
|
+
return errorResult(`Error staging all files: ${message}`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
export async function handleRepoUnstage(params, config) {
|
|
212
|
+
try {
|
|
213
|
+
if (!validateRepoConfig(config)) {
|
|
214
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
215
|
+
}
|
|
216
|
+
const manager = new RepoManager(config.repo);
|
|
217
|
+
await manager.unstage(params.patterns);
|
|
218
|
+
return successResult({ unstaged: params.patterns });
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
222
|
+
return errorResult(`Error unstaging files: ${message}`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
// ============================================================================
|
|
226
|
+
// Commits
|
|
227
|
+
// ============================================================================
|
|
228
|
+
export async function handleRepoCommit(params, config) {
|
|
229
|
+
try {
|
|
230
|
+
if (!validateRepoConfig(config)) {
|
|
231
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
232
|
+
}
|
|
233
|
+
if (params.type && !isValidCommitType(params.type)) {
|
|
234
|
+
return errorResult(`Invalid type: ${params.type}. Must be 'feat', 'fix', 'docs', 'style', 'refactor', 'test', or 'chore'`);
|
|
235
|
+
}
|
|
236
|
+
const manager = new RepoManager(config.repo);
|
|
237
|
+
const commit = await manager.commit({
|
|
238
|
+
message: params.message,
|
|
239
|
+
type: isValidCommitType(params.type) ? params.type : undefined,
|
|
240
|
+
scope: params.scope,
|
|
241
|
+
body: params.body,
|
|
242
|
+
breaking: params.breaking,
|
|
243
|
+
workId: params.work_id,
|
|
244
|
+
});
|
|
245
|
+
return successResult(commit);
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
249
|
+
return errorResult(`Error creating commit: ${message}`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
export async function handleRepoCommitGet(params, config) {
|
|
253
|
+
try {
|
|
254
|
+
if (!validateRepoConfig(config)) {
|
|
255
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
256
|
+
}
|
|
257
|
+
const manager = new RepoManager(config.repo);
|
|
258
|
+
const commit = await manager.getCommit(params.ref);
|
|
259
|
+
return successResult(commit);
|
|
260
|
+
}
|
|
261
|
+
catch (error) {
|
|
262
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
263
|
+
return errorResult(`Error getting commit: ${message}`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
export async function handleRepoCommitList(params, config) {
|
|
267
|
+
try {
|
|
268
|
+
if (!validateRepoConfig(config)) {
|
|
269
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
270
|
+
}
|
|
271
|
+
const manager = new RepoManager(config.repo);
|
|
272
|
+
const commits = await manager.listCommits({
|
|
273
|
+
limit: params.limit,
|
|
274
|
+
branch: params.branch,
|
|
275
|
+
since: params.since,
|
|
276
|
+
until: params.until,
|
|
277
|
+
author: params.author,
|
|
278
|
+
});
|
|
279
|
+
return successResult(commits);
|
|
280
|
+
}
|
|
281
|
+
catch (error) {
|
|
282
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
283
|
+
return errorResult(`Error listing commits: ${message}`);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
// ============================================================================
|
|
287
|
+
// Push/Pull/Fetch
|
|
288
|
+
// ============================================================================
|
|
289
|
+
export async function handleRepoPush(params, config) {
|
|
290
|
+
try {
|
|
291
|
+
if (!validateRepoConfig(config)) {
|
|
292
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
293
|
+
}
|
|
294
|
+
const manager = new RepoManager(config.repo);
|
|
295
|
+
await manager.push({
|
|
296
|
+
branch: params.branch,
|
|
297
|
+
remote: params.remote,
|
|
298
|
+
force: params.force,
|
|
299
|
+
setUpstream: params.set_upstream,
|
|
300
|
+
});
|
|
301
|
+
return successResult({ pushed: true });
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
305
|
+
return errorResult(`Error pushing: ${message}`);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
export async function handleRepoPull(params, config) {
|
|
309
|
+
try {
|
|
310
|
+
if (!validateRepoConfig(config)) {
|
|
311
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
312
|
+
}
|
|
313
|
+
const manager = new RepoManager(config.repo);
|
|
314
|
+
await manager.pull({
|
|
315
|
+
branch: params.branch,
|
|
316
|
+
remote: params.remote,
|
|
317
|
+
rebase: params.rebase,
|
|
318
|
+
});
|
|
319
|
+
return successResult({ pulled: true });
|
|
320
|
+
}
|
|
321
|
+
catch (error) {
|
|
322
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
323
|
+
return errorResult(`Error pulling: ${message}`);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
export async function handleRepoFetch(params, config) {
|
|
327
|
+
try {
|
|
328
|
+
if (!validateRepoConfig(config)) {
|
|
329
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
330
|
+
}
|
|
331
|
+
const manager = new RepoManager(config.repo);
|
|
332
|
+
await manager.fetch(params.remote);
|
|
333
|
+
return successResult({ fetched: true });
|
|
334
|
+
}
|
|
335
|
+
catch (error) {
|
|
336
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
337
|
+
return errorResult(`Error fetching: ${message}`);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
// ============================================================================
|
|
341
|
+
// Pull Requests
|
|
342
|
+
// ============================================================================
|
|
343
|
+
export async function handleRepoPrCreate(params, config) {
|
|
344
|
+
try {
|
|
345
|
+
if (!validateRepoConfig(config)) {
|
|
346
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
347
|
+
}
|
|
348
|
+
const manager = new RepoManager(config.repo);
|
|
349
|
+
const pr = await manager.createPR({
|
|
350
|
+
title: params.title,
|
|
351
|
+
body: params.body,
|
|
352
|
+
base: params.base,
|
|
353
|
+
head: params.head,
|
|
354
|
+
draft: params.draft,
|
|
355
|
+
});
|
|
356
|
+
return successResult(pr);
|
|
357
|
+
}
|
|
358
|
+
catch (error) {
|
|
359
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
360
|
+
return errorResult(`Error creating PR: ${message}`);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
export async function handleRepoPrGet(params, config) {
|
|
364
|
+
try {
|
|
365
|
+
if (!validateRepoConfig(config)) {
|
|
366
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
367
|
+
}
|
|
368
|
+
const manager = new RepoManager(config.repo);
|
|
369
|
+
const pr = await manager.getPR(params.number);
|
|
370
|
+
return successResult(pr);
|
|
371
|
+
}
|
|
372
|
+
catch (error) {
|
|
373
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
374
|
+
return errorResult(`Error getting PR: ${message}`);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
export async function handleRepoPrUpdate(params, config) {
|
|
378
|
+
try {
|
|
379
|
+
if (!validateRepoConfig(config)) {
|
|
380
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
381
|
+
}
|
|
382
|
+
if (params.state && !isValidPrState(params.state)) {
|
|
383
|
+
return errorResult(`Invalid state: ${params.state}. Must be 'open' or 'closed'`);
|
|
384
|
+
}
|
|
385
|
+
const manager = new RepoManager(config.repo);
|
|
386
|
+
const pr = await manager.updatePR(params.number, {
|
|
387
|
+
title: params.title,
|
|
388
|
+
body: params.body,
|
|
389
|
+
state: isValidPrState(params.state) ? params.state : undefined,
|
|
390
|
+
});
|
|
391
|
+
return successResult(pr);
|
|
392
|
+
}
|
|
393
|
+
catch (error) {
|
|
394
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
395
|
+
return errorResult(`Error updating PR: ${message}`);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
export async function handleRepoPrComment(params, config) {
|
|
399
|
+
try {
|
|
400
|
+
if (!validateRepoConfig(config)) {
|
|
401
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
402
|
+
}
|
|
403
|
+
const manager = new RepoManager(config.repo);
|
|
404
|
+
await manager.addPRComment(params.number, params.body);
|
|
405
|
+
return successResult({ commented: true });
|
|
406
|
+
}
|
|
407
|
+
catch (error) {
|
|
408
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
409
|
+
return errorResult(`Error commenting on PR: ${message}`);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
export async function handleRepoPrReview(params, config) {
|
|
413
|
+
try {
|
|
414
|
+
if (!validateRepoConfig(config)) {
|
|
415
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
416
|
+
}
|
|
417
|
+
if (!isValidReviewAction(params.action)) {
|
|
418
|
+
return errorResult(`Invalid action: ${params.action}. Must be 'approve', 'request_changes', or 'comment'`);
|
|
419
|
+
}
|
|
420
|
+
const manager = new RepoManager(config.repo);
|
|
421
|
+
await manager.reviewPR(params.number, {
|
|
422
|
+
action: params.action,
|
|
423
|
+
comment: params.comment,
|
|
424
|
+
});
|
|
425
|
+
return successResult({ reviewed: true });
|
|
426
|
+
}
|
|
427
|
+
catch (error) {
|
|
428
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
429
|
+
return errorResult(`Error reviewing PR: ${message}`);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
export async function handleRepoPrRequestReview(params, config) {
|
|
433
|
+
try {
|
|
434
|
+
if (!validateRepoConfig(config)) {
|
|
435
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
436
|
+
}
|
|
437
|
+
const manager = new RepoManager(config.repo);
|
|
438
|
+
await manager.requestReview(params.number, params.reviewers);
|
|
439
|
+
return successResult({ requested: true });
|
|
440
|
+
}
|
|
441
|
+
catch (error) {
|
|
442
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
443
|
+
return errorResult(`Error requesting review: ${message}`);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
export async function handleRepoPrApprove(params, config) {
|
|
447
|
+
try {
|
|
448
|
+
if (!validateRepoConfig(config)) {
|
|
449
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
450
|
+
}
|
|
451
|
+
const manager = new RepoManager(config.repo);
|
|
452
|
+
await manager.approvePR(params.number, params.comment);
|
|
453
|
+
return successResult({ approved: true });
|
|
454
|
+
}
|
|
455
|
+
catch (error) {
|
|
456
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
457
|
+
return errorResult(`Error approving PR: ${message}`);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
export async function handleRepoPrMerge(params, config) {
|
|
461
|
+
try {
|
|
462
|
+
if (!validateRepoConfig(config)) {
|
|
463
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
464
|
+
}
|
|
465
|
+
if (params.strategy && !isValidMergeStrategy(params.strategy)) {
|
|
466
|
+
return errorResult(`Invalid strategy: ${params.strategy}. Must be 'merge', 'squash', or 'rebase'`);
|
|
467
|
+
}
|
|
468
|
+
const manager = new RepoManager(config.repo);
|
|
469
|
+
const pr = await manager.mergePR(params.number, {
|
|
470
|
+
strategy: isValidMergeStrategy(params.strategy) ? params.strategy : undefined,
|
|
471
|
+
deleteBranch: params.delete_branch,
|
|
472
|
+
});
|
|
473
|
+
return successResult(pr);
|
|
474
|
+
}
|
|
475
|
+
catch (error) {
|
|
476
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
477
|
+
return errorResult(`Error merging PR: ${message}`);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
export async function handleRepoPrList(params, config) {
|
|
481
|
+
try {
|
|
482
|
+
if (!validateRepoConfig(config)) {
|
|
483
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
484
|
+
}
|
|
485
|
+
if (params.state && !isValidIssueState(params.state)) {
|
|
486
|
+
return errorResult(`Invalid state: ${params.state}. Must be 'open', 'closed', or 'all'`);
|
|
487
|
+
}
|
|
488
|
+
const manager = new RepoManager(config.repo);
|
|
489
|
+
const prs = await manager.listPRs({
|
|
490
|
+
state: isValidIssueState(params.state) ? params.state : undefined,
|
|
491
|
+
author: params.author,
|
|
492
|
+
limit: params.limit,
|
|
493
|
+
});
|
|
494
|
+
return successResult(prs);
|
|
495
|
+
}
|
|
496
|
+
catch (error) {
|
|
497
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
498
|
+
return errorResult(`Error listing PRs: ${message}`);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
// ============================================================================
|
|
502
|
+
// Tags
|
|
503
|
+
// ============================================================================
|
|
504
|
+
export async function handleRepoTagCreate(params, config) {
|
|
505
|
+
try {
|
|
506
|
+
if (!validateRepoConfig(config)) {
|
|
507
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
508
|
+
}
|
|
509
|
+
const manager = new RepoManager(config.repo);
|
|
510
|
+
await manager.createTag(params.name, {
|
|
511
|
+
name: params.name,
|
|
512
|
+
message: params.message,
|
|
513
|
+
sha: params.sha,
|
|
514
|
+
commit: params.commit,
|
|
515
|
+
sign: params.sign,
|
|
516
|
+
force: params.force,
|
|
517
|
+
});
|
|
518
|
+
return successResult({ tag: params.name, created: true });
|
|
519
|
+
}
|
|
520
|
+
catch (error) {
|
|
521
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
522
|
+
return errorResult(`Error creating tag: ${message}`);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
export async function handleRepoTagDelete(params, config) {
|
|
526
|
+
try {
|
|
527
|
+
if (!validateRepoConfig(config)) {
|
|
528
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
529
|
+
}
|
|
530
|
+
const manager = new RepoManager(config.repo);
|
|
531
|
+
await manager.deleteTag(params.name);
|
|
532
|
+
return successResult({ tag: params.name, deleted: true });
|
|
533
|
+
}
|
|
534
|
+
catch (error) {
|
|
535
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
536
|
+
return errorResult(`Error deleting tag: ${message}`);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
export async function handleRepoTagPush(params, config) {
|
|
540
|
+
try {
|
|
541
|
+
if (!validateRepoConfig(config)) {
|
|
542
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
543
|
+
}
|
|
544
|
+
const manager = new RepoManager(config.repo);
|
|
545
|
+
await manager.pushTag(params.name, params.remote);
|
|
546
|
+
return successResult({ tag: params.name, pushed: true });
|
|
547
|
+
}
|
|
548
|
+
catch (error) {
|
|
549
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
550
|
+
return errorResult(`Error pushing tag: ${message}`);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
export async function handleRepoTagList(params, config) {
|
|
554
|
+
try {
|
|
555
|
+
if (!validateRepoConfig(config)) {
|
|
556
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
557
|
+
}
|
|
558
|
+
const manager = new RepoManager(config.repo);
|
|
559
|
+
const tags = await manager.listTags({
|
|
560
|
+
pattern: params.pattern,
|
|
561
|
+
latest: params.latest,
|
|
562
|
+
});
|
|
563
|
+
return successResult(tags);
|
|
564
|
+
}
|
|
565
|
+
catch (error) {
|
|
566
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
567
|
+
return errorResult(`Error listing tags: ${message}`);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
// ============================================================================
|
|
571
|
+
// Worktrees
|
|
572
|
+
// ============================================================================
|
|
573
|
+
export async function handleRepoWorktreeCreate(params, config) {
|
|
574
|
+
try {
|
|
575
|
+
if (!validateRepoConfig(config)) {
|
|
576
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
577
|
+
}
|
|
578
|
+
const manager = new RepoManager(config.repo);
|
|
579
|
+
const worktree = await manager.createWorktree({
|
|
580
|
+
path: params.path,
|
|
581
|
+
branch: params.branch,
|
|
582
|
+
baseBranch: params.base_branch,
|
|
583
|
+
});
|
|
584
|
+
return successResult(worktree);
|
|
585
|
+
}
|
|
586
|
+
catch (error) {
|
|
587
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
588
|
+
return errorResult(`Error creating worktree: ${message}`);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
export async function handleRepoWorktreeList(_params, config) {
|
|
592
|
+
try {
|
|
593
|
+
if (!validateRepoConfig(config)) {
|
|
594
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
595
|
+
}
|
|
596
|
+
const manager = new RepoManager(config.repo);
|
|
597
|
+
const worktrees = await manager.listWorktrees();
|
|
598
|
+
return successResult(worktrees);
|
|
599
|
+
}
|
|
600
|
+
catch (error) {
|
|
601
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
602
|
+
return errorResult(`Error listing worktrees: ${message}`);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
export async function handleRepoWorktreeRemove(params, config) {
|
|
606
|
+
try {
|
|
607
|
+
if (!validateRepoConfig(config)) {
|
|
608
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
609
|
+
}
|
|
610
|
+
const manager = new RepoManager(config.repo);
|
|
611
|
+
await manager.removeWorktree(params.path, params.force);
|
|
612
|
+
return successResult({ path: params.path, removed: true });
|
|
613
|
+
}
|
|
614
|
+
catch (error) {
|
|
615
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
616
|
+
return errorResult(`Error removing worktree: ${message}`);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
export async function handleRepoWorktreePrune(_params, config) {
|
|
620
|
+
try {
|
|
621
|
+
if (!validateRepoConfig(config)) {
|
|
622
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
623
|
+
}
|
|
624
|
+
const manager = new RepoManager(config.repo);
|
|
625
|
+
await manager.pruneWorktrees();
|
|
626
|
+
return successResult({ pruned: true });
|
|
627
|
+
}
|
|
628
|
+
catch (error) {
|
|
629
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
630
|
+
return errorResult(`Error pruning worktrees: ${message}`);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
export async function handleRepoWorktreeCleanup(params, config) {
|
|
634
|
+
try {
|
|
635
|
+
if (!validateRepoConfig(config)) {
|
|
636
|
+
return errorResult('Repository configuration is missing or incomplete. Please configure repo.platform and repo.token.');
|
|
637
|
+
}
|
|
638
|
+
const manager = new RepoManager(config.repo);
|
|
639
|
+
const result = await manager.cleanupWorktrees({
|
|
640
|
+
merged: params.merged,
|
|
641
|
+
force: params.force,
|
|
642
|
+
deleteBranch: params.delete_branch,
|
|
643
|
+
});
|
|
644
|
+
return successResult(result);
|
|
645
|
+
}
|
|
646
|
+
catch (error) {
|
|
647
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
648
|
+
return errorResult(`Error cleaning up worktrees: ${message}`);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
//# sourceMappingURL=repo.js.map
|