@andrebuzeli/git-mcp 7.2.4 → 7.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -4
- package/dist/config.js +6 -12
- package/dist/index.js +60 -65
- package/dist/providers/giteaProvider.js +3 -9
- package/dist/providers/githubProvider.js +3 -6
- package/dist/providers/providerManager.js +5 -12
- package/dist/resources/toolsGuide.js +2 -5
- package/dist/server.js +11 -17
- package/dist/tools/gitAnalytics.js +14 -21
- package/dist/tools/gitArchive.js +16 -23
- package/dist/tools/gitBackup.js +21 -28
- package/dist/tools/gitBranches.js +20 -27
- package/dist/tools/gitConfig.js +12 -19
- package/dist/tools/gitFiles.js +14 -21
- package/dist/tools/gitFix.js +12 -18
- package/dist/tools/gitFix.tool.js +3 -7
- package/dist/tools/gitHistory.js +18 -58
- package/dist/tools/gitIgnore.js +9 -46
- package/dist/tools/gitIssues.js +20 -24
- package/dist/tools/gitMonitor.js +14 -21
- package/dist/tools/gitPackages.js +12 -19
- package/dist/tools/gitPulls.js +18 -25
- package/dist/tools/gitRelease.js +24 -31
- package/dist/tools/gitRemote.js +19 -26
- package/dist/tools/gitReset.js +10 -17
- package/dist/tools/gitStash.js +6 -13
- package/dist/tools/gitSync.js +6 -13
- package/dist/tools/gitTags.js +18 -25
- package/dist/tools/gitUpdate.js +19 -59
- package/dist/tools/gitUpload.js +13 -53
- package/dist/tools/gitWorkflow.js +25 -32
- package/dist/types.js +1 -2
- package/dist/utils/errors.js +2 -7
- package/dist/utils/repoHelpers.js +9 -21
- package/dist/utils/safetyController.js +3 -6
- package/package.json +2 -1
package/dist/tools/gitIgnore.js
CHANGED
|
@@ -1,47 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.GitIgnoreTool = void 0;
|
|
37
|
-
const fs = __importStar(require("fs/promises"));
|
|
38
|
-
const path = __importStar(require("path"));
|
|
39
|
-
const errors_1 = require("../utils/errors");
|
|
1
|
+
import * as fs from 'fs/promises';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { MCPError } from '../utils/errors';
|
|
40
4
|
/**
|
|
41
5
|
* Git Ignore Tool - Manage .gitignore file
|
|
42
6
|
* Create, read, add, remove patterns, and ensure .gitignore exists
|
|
43
7
|
*/
|
|
44
|
-
class GitIgnoreTool {
|
|
8
|
+
export class GitIgnoreTool {
|
|
45
9
|
constructor() {
|
|
46
10
|
this.name = 'git-ignore';
|
|
47
11
|
this.description = 'Manage .gitignore file - create, add, remove, and update ignore patterns';
|
|
@@ -49,7 +13,7 @@ class GitIgnoreTool {
|
|
|
49
13
|
async handle(params, ctx) {
|
|
50
14
|
const projectPath = params.projectPath;
|
|
51
15
|
if (!projectPath) {
|
|
52
|
-
throw new
|
|
16
|
+
throw new MCPError('VALIDATION_ERROR', 'projectPath is required');
|
|
53
17
|
}
|
|
54
18
|
const action = params.action || 'read';
|
|
55
19
|
const gitignorePath = path.join(projectPath, '.gitignore');
|
|
@@ -129,7 +93,7 @@ class GitIgnoreTool {
|
|
|
129
93
|
case 'add': {
|
|
130
94
|
const patterns = params.patterns;
|
|
131
95
|
if (!patterns || !Array.isArray(patterns) || patterns.length === 0) {
|
|
132
|
-
throw new
|
|
96
|
+
throw new MCPError('VALIDATION_ERROR', 'patterns array is required for add action');
|
|
133
97
|
}
|
|
134
98
|
let content = '';
|
|
135
99
|
try {
|
|
@@ -168,7 +132,7 @@ class GitIgnoreTool {
|
|
|
168
132
|
case 'remove': {
|
|
169
133
|
const patterns = params.patterns;
|
|
170
134
|
if (!patterns || !Array.isArray(patterns) || patterns.length === 0) {
|
|
171
|
-
throw new
|
|
135
|
+
throw new MCPError('VALIDATION_ERROR', 'patterns array is required for remove action');
|
|
172
136
|
}
|
|
173
137
|
let content = '';
|
|
174
138
|
try {
|
|
@@ -203,7 +167,7 @@ class GitIgnoreTool {
|
|
|
203
167
|
case 'update': {
|
|
204
168
|
const content = params.content;
|
|
205
169
|
if (!content) {
|
|
206
|
-
throw new
|
|
170
|
+
throw new MCPError('VALIDATION_ERROR', 'content is required for update action');
|
|
207
171
|
}
|
|
208
172
|
await fs.writeFile(gitignorePath, content, 'utf-8');
|
|
209
173
|
return {
|
|
@@ -225,7 +189,7 @@ class GitIgnoreTool {
|
|
|
225
189
|
};
|
|
226
190
|
}
|
|
227
191
|
default:
|
|
228
|
-
throw new
|
|
192
|
+
throw new MCPError('VALIDATION_ERROR', `Unsupported action: ${action}`);
|
|
229
193
|
}
|
|
230
194
|
}
|
|
231
195
|
getTemplate(template) {
|
|
@@ -351,4 +315,3 @@ ENV/
|
|
|
351
315
|
return templates[template] || templates.default;
|
|
352
316
|
}
|
|
353
317
|
}
|
|
354
|
-
exports.GitIgnoreTool = GitIgnoreTool;
|
package/dist/tools/gitIssues.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const errors_1 = require("../utils/errors");
|
|
5
|
-
const repoHelpers_1 = require("../utils/repoHelpers");
|
|
6
|
-
class GitIssuesTool {
|
|
1
|
+
import { MCPError } from '../utils/errors';
|
|
2
|
+
import { getRepoInfo } from '../utils/repoHelpers';
|
|
3
|
+
export class GitIssuesTool {
|
|
7
4
|
constructor() {
|
|
8
5
|
this.name = 'git-issues';
|
|
9
6
|
this.description = 'Issue management for GitHub and Gitea - automatic dual-provider execution';
|
|
@@ -11,11 +8,11 @@ class GitIssuesTool {
|
|
|
11
8
|
async handle(params, ctx) {
|
|
12
9
|
const action = params.action;
|
|
13
10
|
if (!action)
|
|
14
|
-
throw new
|
|
11
|
+
throw new MCPError('VALIDATION_ERROR', 'action is required');
|
|
15
12
|
// Auto-extract repo info if projectPath is provided
|
|
16
13
|
let repo = params.repo;
|
|
17
14
|
if (!repo && params.projectPath) {
|
|
18
|
-
const repoInfo =
|
|
15
|
+
const repoInfo = getRepoInfo(params.projectPath);
|
|
19
16
|
repo = repoInfo.repoName;
|
|
20
17
|
}
|
|
21
18
|
// Each provider uses its own username from env
|
|
@@ -24,9 +21,9 @@ class GitIssuesTool {
|
|
|
24
21
|
switch (action) {
|
|
25
22
|
case 'create': {
|
|
26
23
|
if (!params.title)
|
|
27
|
-
throw new
|
|
24
|
+
throw new MCPError('VALIDATION_ERROR', 'title is required');
|
|
28
25
|
if (!repo)
|
|
29
|
-
throw new
|
|
26
|
+
throw new MCPError('VALIDATION_ERROR', 'repo is required (or provide projectPath)');
|
|
30
27
|
const results = { success: true, providers: {} };
|
|
31
28
|
// GitHub
|
|
32
29
|
if (ctx.providerManager.github && githubOwner) {
|
|
@@ -68,7 +65,7 @@ class GitIssuesTool {
|
|
|
68
65
|
}
|
|
69
66
|
case 'list': {
|
|
70
67
|
if (!repo)
|
|
71
|
-
throw new
|
|
68
|
+
throw new MCPError('VALIDATION_ERROR', 'repo is required (or provide projectPath)');
|
|
72
69
|
const results = { success: true, providers: {} };
|
|
73
70
|
// GitHub
|
|
74
71
|
if (ctx.providerManager.github && githubOwner) {
|
|
@@ -110,9 +107,9 @@ class GitIssuesTool {
|
|
|
110
107
|
case 'get': {
|
|
111
108
|
const issue_number = params.issue_number;
|
|
112
109
|
if (!issue_number)
|
|
113
|
-
throw new
|
|
110
|
+
throw new MCPError('VALIDATION_ERROR', 'issue_number is required');
|
|
114
111
|
if (!repo)
|
|
115
|
-
throw new
|
|
112
|
+
throw new MCPError('VALIDATION_ERROR', 'repo is required (or provide projectPath)');
|
|
116
113
|
const results = { success: true, providers: {} };
|
|
117
114
|
// GitHub
|
|
118
115
|
if (ctx.providerManager.github && githubOwner) {
|
|
@@ -146,9 +143,9 @@ class GitIssuesTool {
|
|
|
146
143
|
case 'update': {
|
|
147
144
|
const issue_number = params.issue_number;
|
|
148
145
|
if (!issue_number)
|
|
149
|
-
throw new
|
|
146
|
+
throw new MCPError('VALIDATION_ERROR', 'issue_number is required');
|
|
150
147
|
if (!repo)
|
|
151
|
-
throw new
|
|
148
|
+
throw new MCPError('VALIDATION_ERROR', 'repo is required (or provide projectPath)');
|
|
152
149
|
const results = { success: true, providers: {} };
|
|
153
150
|
// GitHub
|
|
154
151
|
if (ctx.providerManager.github && githubOwner) {
|
|
@@ -189,9 +186,9 @@ class GitIssuesTool {
|
|
|
189
186
|
case 'close': {
|
|
190
187
|
const issue_number = params.issue_number;
|
|
191
188
|
if (!issue_number)
|
|
192
|
-
throw new
|
|
189
|
+
throw new MCPError('VALIDATION_ERROR', 'issue_number is required');
|
|
193
190
|
if (!repo)
|
|
194
|
-
throw new
|
|
191
|
+
throw new MCPError('VALIDATION_ERROR', 'repo is required (or provide projectPath)');
|
|
195
192
|
const results = { success: true, providers: {} };
|
|
196
193
|
// GitHub
|
|
197
194
|
if (ctx.providerManager.github && githubOwner) {
|
|
@@ -227,11 +224,11 @@ class GitIssuesTool {
|
|
|
227
224
|
const issue_number = params.issue_number;
|
|
228
225
|
const comment_body = params.comment_body;
|
|
229
226
|
if (!issue_number)
|
|
230
|
-
throw new
|
|
227
|
+
throw new MCPError('VALIDATION_ERROR', 'issue_number is required');
|
|
231
228
|
if (!comment_body)
|
|
232
|
-
throw new
|
|
229
|
+
throw new MCPError('VALIDATION_ERROR', 'comment_body is required');
|
|
233
230
|
if (!repo)
|
|
234
|
-
throw new
|
|
231
|
+
throw new MCPError('VALIDATION_ERROR', 'repo is required (or provide projectPath)');
|
|
235
232
|
const results = { success: true, providers: {} };
|
|
236
233
|
// GitHub
|
|
237
234
|
if (ctx.providerManager.github && githubOwner) {
|
|
@@ -266,9 +263,9 @@ class GitIssuesTool {
|
|
|
266
263
|
case 'search': {
|
|
267
264
|
const query = params.query;
|
|
268
265
|
if (!query)
|
|
269
|
-
throw new
|
|
266
|
+
throw new MCPError('VALIDATION_ERROR', 'query is required');
|
|
270
267
|
if (!repo)
|
|
271
|
-
throw new
|
|
268
|
+
throw new MCPError('VALIDATION_ERROR', 'repo is required (or provide projectPath)');
|
|
272
269
|
const results = { success: true, providers: {} };
|
|
273
270
|
// GitHub
|
|
274
271
|
if (ctx.providerManager.github && githubOwner) {
|
|
@@ -291,8 +288,7 @@ class GitIssuesTool {
|
|
|
291
288
|
return results;
|
|
292
289
|
}
|
|
293
290
|
default:
|
|
294
|
-
throw new
|
|
291
|
+
throw new MCPError('VALIDATION_ERROR', `Unsupported action: ${action}`);
|
|
295
292
|
}
|
|
296
293
|
}
|
|
297
294
|
}
|
|
298
|
-
exports.GitIssuesTool = GitIssuesTool;
|
package/dist/tools/gitMonitor.js
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.GitMonitorTool = void 0;
|
|
7
|
-
const simple_git_1 = __importDefault(require("simple-git"));
|
|
8
|
-
const errors_1 = require("../utils/errors");
|
|
9
|
-
const repoHelpers_1 = require("../utils/repoHelpers");
|
|
10
|
-
const axios_1 = __importDefault(require("axios"));
|
|
11
|
-
class GitMonitorTool {
|
|
1
|
+
import simpleGit from 'simple-git';
|
|
2
|
+
import { MCPError } from '../utils/errors';
|
|
3
|
+
import { getRepoInfo } from '../utils/repoHelpers';
|
|
4
|
+
import axios from 'axios';
|
|
5
|
+
export class GitMonitorTool {
|
|
12
6
|
constructor() {
|
|
13
7
|
this.name = 'git-monitor';
|
|
14
8
|
this.description = 'Repository monitoring and status operations - automatic dual-provider execution for remote queries';
|
|
@@ -17,9 +11,9 @@ class GitMonitorTool {
|
|
|
17
11
|
const action = params.action;
|
|
18
12
|
const projectPath = params.projectPath;
|
|
19
13
|
if (!action || !projectPath) {
|
|
20
|
-
throw new
|
|
14
|
+
throw new MCPError('VALIDATION_ERROR', 'action and projectPath are required');
|
|
21
15
|
}
|
|
22
|
-
const git = (
|
|
16
|
+
const git = simpleGit({ baseDir: projectPath });
|
|
23
17
|
switch (action) {
|
|
24
18
|
case 'log': {
|
|
25
19
|
const options = {
|
|
@@ -41,7 +35,7 @@ class GitMonitorTool {
|
|
|
41
35
|
providers: {}
|
|
42
36
|
};
|
|
43
37
|
// Also query remote APIs
|
|
44
|
-
const repoInfo =
|
|
38
|
+
const repoInfo = getRepoInfo(projectPath);
|
|
45
39
|
const githubOwner = process.env.GITHUB_USERNAME;
|
|
46
40
|
const giteaOwner = process.env.GITEA_USERNAME;
|
|
47
41
|
// GitHub
|
|
@@ -73,7 +67,7 @@ class GitMonitorTool {
|
|
|
73
67
|
// Gitea
|
|
74
68
|
if (ctx.providerManager.giteaBaseUrl && giteaOwner) {
|
|
75
69
|
try {
|
|
76
|
-
const commits = await
|
|
70
|
+
const commits = await axios.get(`${ctx.providerManager.giteaBaseUrl}/api/v1/repos/${giteaOwner}/${repoInfo.repoName}/commits`, {
|
|
77
71
|
params: {
|
|
78
72
|
since: params.since,
|
|
79
73
|
until: params.until,
|
|
@@ -141,7 +135,7 @@ class GitMonitorTool {
|
|
|
141
135
|
providers: {}
|
|
142
136
|
};
|
|
143
137
|
// Also query remote APIs
|
|
144
|
-
const repoInfo =
|
|
138
|
+
const repoInfo = getRepoInfo(projectPath);
|
|
145
139
|
const githubOwner = process.env.GITHUB_USERNAME;
|
|
146
140
|
const giteaOwner = process.env.GITEA_USERNAME;
|
|
147
141
|
// GitHub
|
|
@@ -172,7 +166,7 @@ class GitMonitorTool {
|
|
|
172
166
|
// Gitea
|
|
173
167
|
if (ctx.providerManager.giteaBaseUrl && giteaOwner) {
|
|
174
168
|
try {
|
|
175
|
-
const commits = await
|
|
169
|
+
const commits = await axios.get(`${ctx.providerManager.giteaBaseUrl}/api/v1/repos/${giteaOwner}/${repoInfo.repoName}/commits`, {
|
|
176
170
|
params: {
|
|
177
171
|
sha: branch,
|
|
178
172
|
since: params.since,
|
|
@@ -220,7 +214,7 @@ class GitMonitorTool {
|
|
|
220
214
|
providers: {}
|
|
221
215
|
};
|
|
222
216
|
// Also query remote APIs
|
|
223
|
-
const repoInfo =
|
|
217
|
+
const repoInfo = getRepoInfo(projectPath);
|
|
224
218
|
const githubOwner = process.env.GITHUB_USERNAME;
|
|
225
219
|
const giteaOwner = process.env.GITEA_USERNAME;
|
|
226
220
|
// GitHub
|
|
@@ -247,7 +241,7 @@ class GitMonitorTool {
|
|
|
247
241
|
// Gitea
|
|
248
242
|
if (ctx.providerManager.giteaBaseUrl && giteaOwner) {
|
|
249
243
|
try {
|
|
250
|
-
const contributors = await
|
|
244
|
+
const contributors = await axios.get(`${ctx.providerManager.giteaBaseUrl}/api/v1/repos/${giteaOwner}/${repoInfo.repoName}/contributors`, { headers: { Authorization: `token ${ctx.providerManager.giteaToken}` } });
|
|
251
245
|
results.providers.gitea = {
|
|
252
246
|
success: true,
|
|
253
247
|
contributors: contributors.data.map((c) => ({
|
|
@@ -265,8 +259,7 @@ class GitMonitorTool {
|
|
|
265
259
|
return results;
|
|
266
260
|
}
|
|
267
261
|
default:
|
|
268
|
-
throw new
|
|
262
|
+
throw new MCPError('VALIDATION_ERROR', `Unsupported action: ${action}`);
|
|
269
263
|
}
|
|
270
264
|
}
|
|
271
265
|
}
|
|
272
|
-
exports.GitMonitorTool = GitMonitorTool;
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.GitPackagesTool = void 0;
|
|
7
|
-
const promises_1 = __importDefault(require("fs/promises"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const errors_1 = require("../utils/errors");
|
|
10
|
-
class GitPackagesTool {
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { MCPError } from '../utils/errors';
|
|
4
|
+
export class GitPackagesTool {
|
|
11
5
|
constructor() {
|
|
12
6
|
this.name = 'git-packages';
|
|
13
7
|
this.description = 'Package management operations';
|
|
@@ -16,15 +10,15 @@ class GitPackagesTool {
|
|
|
16
10
|
const action = params.action;
|
|
17
11
|
const projectPath = params.projectPath;
|
|
18
12
|
if (!action)
|
|
19
|
-
throw new
|
|
13
|
+
throw new MCPError('VALIDATION_ERROR', 'action is required');
|
|
20
14
|
switch (action) {
|
|
21
15
|
case 'list': {
|
|
22
16
|
if (!projectPath)
|
|
23
|
-
throw new
|
|
17
|
+
throw new MCPError('VALIDATION_ERROR', 'projectPath is required');
|
|
24
18
|
// Ler package.json
|
|
25
19
|
try {
|
|
26
|
-
const packageJsonPath =
|
|
27
|
-
const content = await
|
|
20
|
+
const packageJsonPath = path.join(projectPath, 'package.json');
|
|
21
|
+
const content = await fs.readFile(packageJsonPath, 'utf-8');
|
|
28
22
|
const pkg = JSON.parse(content);
|
|
29
23
|
return {
|
|
30
24
|
success: true,
|
|
@@ -36,13 +30,13 @@ class GitPackagesTool {
|
|
|
36
30
|
};
|
|
37
31
|
}
|
|
38
32
|
catch (error) {
|
|
39
|
-
throw new
|
|
33
|
+
throw new MCPError('FILE_ERROR', `Failed to read package.json: ${error.message}`);
|
|
40
34
|
}
|
|
41
35
|
}
|
|
42
36
|
case 'get': {
|
|
43
37
|
const packageName = params.packageName;
|
|
44
38
|
if (!packageName)
|
|
45
|
-
throw new
|
|
39
|
+
throw new MCPError('VALIDATION_ERROR', 'packageName is required');
|
|
46
40
|
return {
|
|
47
41
|
success: true,
|
|
48
42
|
message: `Package info for ${packageName}`,
|
|
@@ -54,10 +48,9 @@ class GitPackagesTool {
|
|
|
54
48
|
case 'delete':
|
|
55
49
|
case 'publish':
|
|
56
50
|
case 'download':
|
|
57
|
-
throw new
|
|
51
|
+
throw new MCPError('NOT_IMPLEMENTED', `Action ${action} not yet fully implemented`);
|
|
58
52
|
default:
|
|
59
|
-
throw new
|
|
53
|
+
throw new MCPError('VALIDATION_ERROR', `Unsupported action: ${action}`);
|
|
60
54
|
}
|
|
61
55
|
}
|
|
62
56
|
}
|
|
63
|
-
exports.GitPackagesTool = GitPackagesTool;
|
package/dist/tools/gitPulls.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.GitPullsTool = void 0;
|
|
7
|
-
const errors_1 = require("../utils/errors");
|
|
8
|
-
const axios_1 = __importDefault(require("axios"));
|
|
9
|
-
class GitPullsTool {
|
|
1
|
+
import { MCPError } from '../utils/errors';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
export class GitPullsTool {
|
|
10
4
|
constructor() {
|
|
11
5
|
this.name = 'git-pulls';
|
|
12
6
|
this.description = 'Pull request management for GitHub and Gitea - automatic dual-provider execution';
|
|
@@ -14,14 +8,14 @@ class GitPullsTool {
|
|
|
14
8
|
async handle(params, ctx) {
|
|
15
9
|
const action = params.action;
|
|
16
10
|
if (!action)
|
|
17
|
-
throw new
|
|
11
|
+
throw new MCPError('VALIDATION_ERROR', 'action is required');
|
|
18
12
|
const githubOwner = params.owner || process.env.GITHUB_USERNAME;
|
|
19
13
|
const giteaOwner = params.owner || process.env.GITEA_USERNAME;
|
|
20
14
|
const repo = params.repo;
|
|
21
15
|
switch (action) {
|
|
22
16
|
case 'create': {
|
|
23
17
|
if (!params.title || !params.head || !params.base) {
|
|
24
|
-
throw new
|
|
18
|
+
throw new MCPError('VALIDATION_ERROR', 'title, head, and base are required');
|
|
25
19
|
}
|
|
26
20
|
const results = { success: true, providers: {} };
|
|
27
21
|
// GitHub
|
|
@@ -44,7 +38,7 @@ class GitPullsTool {
|
|
|
44
38
|
// Gitea
|
|
45
39
|
if (ctx.providerManager.giteaBaseUrl) {
|
|
46
40
|
try {
|
|
47
|
-
const result = await
|
|
41
|
+
const result = await axios.post(`${ctx.providerManager.giteaBaseUrl}/api/v1/repos/${giteaOwner}/${repo}/pulls`, {
|
|
48
42
|
title: params.title,
|
|
49
43
|
head: params.head,
|
|
50
44
|
base: params.base,
|
|
@@ -79,7 +73,7 @@ class GitPullsTool {
|
|
|
79
73
|
// Gitea
|
|
80
74
|
if (ctx.providerManager.giteaBaseUrl) {
|
|
81
75
|
try {
|
|
82
|
-
const result = await
|
|
76
|
+
const result = await axios.get(`${ctx.providerManager.giteaBaseUrl}/api/v1/repos/${giteaOwner}/${repo}/pulls`, {
|
|
83
77
|
params: { state: params.state_filter || 'open' },
|
|
84
78
|
headers: { Authorization: `token ${ctx.providerManager.giteaToken}` }
|
|
85
79
|
});
|
|
@@ -94,7 +88,7 @@ class GitPullsTool {
|
|
|
94
88
|
case 'get': {
|
|
95
89
|
const pull_number = params.pull_number;
|
|
96
90
|
if (!pull_number)
|
|
97
|
-
throw new
|
|
91
|
+
throw new MCPError('VALIDATION_ERROR', 'pull_number is required');
|
|
98
92
|
const results = { success: true, providers: {} };
|
|
99
93
|
// GitHub
|
|
100
94
|
if (ctx.providerManager.github) {
|
|
@@ -113,7 +107,7 @@ class GitPullsTool {
|
|
|
113
107
|
// Gitea
|
|
114
108
|
if (ctx.providerManager.giteaBaseUrl) {
|
|
115
109
|
try {
|
|
116
|
-
const result = await
|
|
110
|
+
const result = await axios.get(`${ctx.providerManager.giteaBaseUrl}/api/v1/repos/${giteaOwner}/${repo}/pulls/${pull_number}`, { headers: { Authorization: `token ${ctx.providerManager.giteaToken}` } });
|
|
117
111
|
results.providers.gitea = { success: true, pull: result.data };
|
|
118
112
|
}
|
|
119
113
|
catch (err) {
|
|
@@ -125,7 +119,7 @@ class GitPullsTool {
|
|
|
125
119
|
case 'update': {
|
|
126
120
|
const pull_number = params.pull_number;
|
|
127
121
|
if (!pull_number)
|
|
128
|
-
throw new
|
|
122
|
+
throw new MCPError('VALIDATION_ERROR', 'pull_number is required');
|
|
129
123
|
const results = { success: true, providers: {} };
|
|
130
124
|
// GitHub
|
|
131
125
|
if (ctx.providerManager.github) {
|
|
@@ -147,7 +141,7 @@ class GitPullsTool {
|
|
|
147
141
|
// Gitea
|
|
148
142
|
if (ctx.providerManager.giteaBaseUrl) {
|
|
149
143
|
try {
|
|
150
|
-
const result = await
|
|
144
|
+
const result = await axios.patch(`${ctx.providerManager.giteaBaseUrl}/api/v1/repos/${giteaOwner}/${repo}/pulls/${pull_number}`, { title: params.title, body: params.body }, { headers: { Authorization: `token ${ctx.providerManager.giteaToken}` } });
|
|
151
145
|
results.providers.gitea = { success: true, pull: result.data };
|
|
152
146
|
}
|
|
153
147
|
catch (err) {
|
|
@@ -159,7 +153,7 @@ class GitPullsTool {
|
|
|
159
153
|
case 'merge': {
|
|
160
154
|
const pull_number = params.pull_number;
|
|
161
155
|
if (!pull_number)
|
|
162
|
-
throw new
|
|
156
|
+
throw new MCPError('VALIDATION_ERROR', 'pull_number is required');
|
|
163
157
|
const results = { success: true, providers: {} };
|
|
164
158
|
// GitHub
|
|
165
159
|
if (ctx.providerManager.github) {
|
|
@@ -181,7 +175,7 @@ class GitPullsTool {
|
|
|
181
175
|
// Gitea
|
|
182
176
|
if (ctx.providerManager.giteaBaseUrl) {
|
|
183
177
|
try {
|
|
184
|
-
const result = await
|
|
178
|
+
const result = await axios.post(`${ctx.providerManager.giteaBaseUrl}/api/v1/repos/${giteaOwner}/${repo}/pulls/${pull_number}/merge`, {
|
|
185
179
|
Do: params.merge_method || 'merge',
|
|
186
180
|
MergeTitleField: params.commit_title,
|
|
187
181
|
MergeMessageField: params.commit_message,
|
|
@@ -197,7 +191,7 @@ class GitPullsTool {
|
|
|
197
191
|
case 'close': {
|
|
198
192
|
const pull_number = params.pull_number;
|
|
199
193
|
if (!pull_number)
|
|
200
|
-
throw new
|
|
194
|
+
throw new MCPError('VALIDATION_ERROR', 'pull_number is required');
|
|
201
195
|
const results = { success: true, providers: {} };
|
|
202
196
|
// GitHub
|
|
203
197
|
if (ctx.providerManager.github) {
|
|
@@ -217,7 +211,7 @@ class GitPullsTool {
|
|
|
217
211
|
// Gitea
|
|
218
212
|
if (ctx.providerManager.giteaBaseUrl) {
|
|
219
213
|
try {
|
|
220
|
-
const result = await
|
|
214
|
+
const result = await axios.patch(`${ctx.providerManager.giteaBaseUrl}/api/v1/repos/${giteaOwner}/${repo}/pulls/${pull_number}`, { state: 'closed' }, { headers: { Authorization: `token ${ctx.providerManager.giteaToken}` } });
|
|
221
215
|
results.providers.gitea = { success: true, pull: result.data };
|
|
222
216
|
}
|
|
223
217
|
catch (err) {
|
|
@@ -230,7 +224,7 @@ class GitPullsTool {
|
|
|
230
224
|
const pull_number = params.pull_number;
|
|
231
225
|
const event = params.event;
|
|
232
226
|
if (!pull_number || !event) {
|
|
233
|
-
throw new
|
|
227
|
+
throw new MCPError('VALIDATION_ERROR', 'pull_number and event are required');
|
|
234
228
|
}
|
|
235
229
|
const results = { success: true, providers: {} };
|
|
236
230
|
// GitHub
|
|
@@ -258,7 +252,7 @@ class GitPullsTool {
|
|
|
258
252
|
case 'search': {
|
|
259
253
|
const query = params.query;
|
|
260
254
|
if (!query)
|
|
261
|
-
throw new
|
|
255
|
+
throw new MCPError('VALIDATION_ERROR', 'query is required');
|
|
262
256
|
const results = { success: true, providers: {} };
|
|
263
257
|
// GitHub
|
|
264
258
|
if (ctx.providerManager.github) {
|
|
@@ -281,8 +275,7 @@ class GitPullsTool {
|
|
|
281
275
|
return results;
|
|
282
276
|
}
|
|
283
277
|
default:
|
|
284
|
-
throw new
|
|
278
|
+
throw new MCPError('VALIDATION_ERROR', `Unsupported action: ${action}`);
|
|
285
279
|
}
|
|
286
280
|
}
|
|
287
281
|
}
|
|
288
|
-
exports.GitPullsTool = GitPullsTool;
|