@andrebuzeli/git-mcp 5.5.2 → 5.8.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/README.md +69 -6
- package/dist/index.js +178 -17
- package/dist/resources/toolsGuide.d.ts +12 -0
- package/dist/resources/toolsGuide.js +1491 -0
- package/dist/server.d.ts +2 -1
- package/dist/server.js +33 -0
- package/dist/tools/gitBranches.d.ts +2 -2
- package/dist/tools/gitBranches.js +2 -1
- package/dist/tools/gitFiles.d.ts +6 -0
- package/dist/tools/gitFiles.js +10 -8
- package/dist/tools/gitHistory.d.ts +17 -0
- package/dist/tools/gitHistory.js +365 -0
- package/dist/tools/gitIssues.d.ts +1 -16
- package/dist/tools/gitIssues.js +208 -122
- package/dist/tools/gitPulls.d.ts +1 -69
- package/dist/tools/gitPulls.js +225 -127
- package/dist/tools/gitRelease.d.ts +1 -29
- package/dist/tools/gitRelease.js +277 -55
- package/dist/tools/gitUpdate.d.ts +14 -0
- package/dist/tools/gitUpdate.js +374 -0
- package/dist/tools/gitUpload.d.ts +11 -0
- package/dist/tools/gitUpload.js +342 -0
- package/dist/tools/gitWorkflow.d.ts +1 -64
- package/dist/tools/gitWorkflow.js +224 -50
- package/dist/types.d.ts +7 -0
- package/package.json +2 -2
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.GitUpdateTool = void 0;
|
|
40
|
+
const simple_git_1 = __importDefault(require("simple-git"));
|
|
41
|
+
const errors_1 = require("../utils/errors");
|
|
42
|
+
const axios_1 = __importDefault(require("axios"));
|
|
43
|
+
const fs = __importStar(require("fs/promises"));
|
|
44
|
+
const path = __importStar(require("path"));
|
|
45
|
+
/**
|
|
46
|
+
* Git Update Tool - Atualiza projeto completo em GitHub e Gitea automaticamente
|
|
47
|
+
* Modo DUAL automático com rastreabilidade completa
|
|
48
|
+
* Inclui: add, commit, push, sync, history tracking
|
|
49
|
+
*/
|
|
50
|
+
class GitUpdateTool {
|
|
51
|
+
constructor() {
|
|
52
|
+
this.name = 'git-update';
|
|
53
|
+
this.description = 'Complete project update workflow (add, commit, push) to GitHub and Gitea with full traceability - automatic dual-provider execution';
|
|
54
|
+
}
|
|
55
|
+
async handle(params, ctx) {
|
|
56
|
+
const projectPath = params.projectPath;
|
|
57
|
+
if (!projectPath) {
|
|
58
|
+
throw new errors_1.MCPError('VALIDATION_ERROR', 'projectPath is required');
|
|
59
|
+
}
|
|
60
|
+
const commitMessage = params.message || params.commitMessage || `[git-update] Update at ${new Date().toISOString()}`;
|
|
61
|
+
const branch = params.branch || 'master';
|
|
62
|
+
const files = params.files || ['.'];
|
|
63
|
+
const git = (0, simple_git_1.default)({ baseDir: projectPath });
|
|
64
|
+
// Resultado com rastreabilidade completa
|
|
65
|
+
const results = {
|
|
66
|
+
success: true,
|
|
67
|
+
timestamp: new Date().toISOString(),
|
|
68
|
+
projectPath,
|
|
69
|
+
branch,
|
|
70
|
+
commitMessage,
|
|
71
|
+
providers: {},
|
|
72
|
+
traceability: {
|
|
73
|
+
preUpdateStatus: {},
|
|
74
|
+
changedFiles: [],
|
|
75
|
+
updateSteps: [],
|
|
76
|
+
syncStatus: {},
|
|
77
|
+
errors: [],
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
try {
|
|
81
|
+
// 1. Status PRÉ-UPDATE
|
|
82
|
+
results.traceability.updateSteps.push({
|
|
83
|
+
step: 1,
|
|
84
|
+
action: 'check_pre_update_status',
|
|
85
|
+
timestamp: new Date().toISOString(),
|
|
86
|
+
});
|
|
87
|
+
const preStatus = await git.status();
|
|
88
|
+
results.traceability.preUpdateStatus = {
|
|
89
|
+
branch: preStatus.current,
|
|
90
|
+
ahead: preStatus.ahead,
|
|
91
|
+
behind: preStatus.behind,
|
|
92
|
+
modified: preStatus.modified,
|
|
93
|
+
created: preStatus.created,
|
|
94
|
+
deleted: preStatus.deleted,
|
|
95
|
+
renamed: preStatus.renamed,
|
|
96
|
+
staged: preStatus.staged,
|
|
97
|
+
conflicted: preStatus.conflicted,
|
|
98
|
+
isClean: preStatus.isClean(),
|
|
99
|
+
};
|
|
100
|
+
// 2. Detectar arquivos alterados com diff
|
|
101
|
+
results.traceability.updateSteps.push({
|
|
102
|
+
step: 2,
|
|
103
|
+
action: 'detect_changes',
|
|
104
|
+
timestamp: new Date().toISOString(),
|
|
105
|
+
});
|
|
106
|
+
const diff = await git.diff(['--name-status']);
|
|
107
|
+
const diffLines = diff.split('\n').filter(l => l.trim());
|
|
108
|
+
results.traceability.changedFiles = diffLines.map(line => {
|
|
109
|
+
const [status, ...fileParts] = line.split('\t');
|
|
110
|
+
return {
|
|
111
|
+
status: status.trim(),
|
|
112
|
+
file: fileParts.join('\t').trim(),
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
// 3. Add files
|
|
116
|
+
results.traceability.updateSteps.push({
|
|
117
|
+
step: 3,
|
|
118
|
+
action: 'stage_changes',
|
|
119
|
+
timestamp: new Date().toISOString(),
|
|
120
|
+
files,
|
|
121
|
+
});
|
|
122
|
+
await git.add(files);
|
|
123
|
+
// 4. Commit
|
|
124
|
+
results.traceability.updateSteps.push({
|
|
125
|
+
step: 4,
|
|
126
|
+
action: 'commit',
|
|
127
|
+
timestamp: new Date().toISOString(),
|
|
128
|
+
message: commitMessage,
|
|
129
|
+
});
|
|
130
|
+
let commitResult;
|
|
131
|
+
try {
|
|
132
|
+
commitResult = await git.commit(commitMessage);
|
|
133
|
+
results.traceability.commit = {
|
|
134
|
+
hash: commitResult.commit,
|
|
135
|
+
summary: commitResult.summary,
|
|
136
|
+
branch: commitResult.branch,
|
|
137
|
+
author: commitResult.author,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
catch (err) {
|
|
141
|
+
if (err.message.includes('nothing to commit')) {
|
|
142
|
+
results.traceability.commit = { message: 'No changes to commit' };
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
throw err;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// 5. Get remotes
|
|
149
|
+
const remotes = await git.getRemotes(true);
|
|
150
|
+
const githubRemote = remotes.find(r => r.name === 'github' || r.name === 'origin');
|
|
151
|
+
const giteaRemote = remotes.find(r => r.name === 'gitea');
|
|
152
|
+
// 6. Push to GITHUB
|
|
153
|
+
if (githubRemote && ctx.providerManager.github) {
|
|
154
|
+
results.traceability.updateSteps.push({
|
|
155
|
+
step: 5,
|
|
156
|
+
action: 'push_to_github',
|
|
157
|
+
timestamp: new Date().toISOString(),
|
|
158
|
+
remote: githubRemote.name,
|
|
159
|
+
branch,
|
|
160
|
+
});
|
|
161
|
+
try {
|
|
162
|
+
const pushResult = await git.push(githubRemote.name, branch);
|
|
163
|
+
results.providers.github = {
|
|
164
|
+
success: true,
|
|
165
|
+
remote: githubRemote.name,
|
|
166
|
+
url: githubRemote.refs.push,
|
|
167
|
+
pushed: true,
|
|
168
|
+
pushResult: {
|
|
169
|
+
remoteMessages: pushResult.remoteMessages?.all || [],
|
|
170
|
+
update: pushResult.update,
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
// Verificar commit no GitHub via API
|
|
174
|
+
try {
|
|
175
|
+
if (results.traceability.commit?.hash) {
|
|
176
|
+
const githubOwner = params.owner || process.env.GITHUB_USERNAME;
|
|
177
|
+
const repo = path.basename(projectPath);
|
|
178
|
+
const commitInfo = await ctx.providerManager.github.rest.repos.getCommit({
|
|
179
|
+
owner: githubOwner,
|
|
180
|
+
repo,
|
|
181
|
+
ref: results.traceability.commit.hash,
|
|
182
|
+
});
|
|
183
|
+
results.providers.github.commitVerified = true;
|
|
184
|
+
results.providers.github.commitUrl = commitInfo.data.html_url;
|
|
185
|
+
results.providers.github.stats = commitInfo.data.stats;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
catch { }
|
|
189
|
+
}
|
|
190
|
+
catch (err) {
|
|
191
|
+
results.providers.github = {
|
|
192
|
+
success: false,
|
|
193
|
+
error: err.message,
|
|
194
|
+
remote: githubRemote.name,
|
|
195
|
+
};
|
|
196
|
+
results.traceability.errors.push({
|
|
197
|
+
provider: 'github',
|
|
198
|
+
action: 'push',
|
|
199
|
+
error: err.message,
|
|
200
|
+
timestamp: new Date().toISOString(),
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
// 7. Push to GITEA
|
|
205
|
+
if (giteaRemote && ctx.providerManager.giteaBaseUrl) {
|
|
206
|
+
results.traceability.updateSteps.push({
|
|
207
|
+
step: 6,
|
|
208
|
+
action: 'push_to_gitea',
|
|
209
|
+
timestamp: new Date().toISOString(),
|
|
210
|
+
remote: giteaRemote.name,
|
|
211
|
+
branch,
|
|
212
|
+
});
|
|
213
|
+
try {
|
|
214
|
+
const pushResult = await git.push(giteaRemote.name, branch);
|
|
215
|
+
results.providers.gitea = {
|
|
216
|
+
success: true,
|
|
217
|
+
remote: giteaRemote.name,
|
|
218
|
+
url: giteaRemote.refs.push,
|
|
219
|
+
pushed: true,
|
|
220
|
+
pushResult: {
|
|
221
|
+
remoteMessages: pushResult.remoteMessages?.all || [],
|
|
222
|
+
update: pushResult.update,
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
// Verificar commit no Gitea via API
|
|
226
|
+
try {
|
|
227
|
+
if (results.traceability.commit?.hash) {
|
|
228
|
+
const giteaOwner = params.owner || process.env.GITEA_USERNAME;
|
|
229
|
+
const repo = path.basename(projectPath);
|
|
230
|
+
const commitInfo = await axios_1.default.get(`${ctx.providerManager.giteaBaseUrl}/api/v1/repos/${giteaOwner}/${repo}/git/commits/${results.traceability.commit.hash}`, { headers: { Authorization: `token ${ctx.providerManager.giteaToken}` } });
|
|
231
|
+
results.providers.gitea.commitVerified = true;
|
|
232
|
+
results.providers.gitea.commitUrl = commitInfo.data.html_url;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
catch { }
|
|
236
|
+
}
|
|
237
|
+
catch (err) {
|
|
238
|
+
results.providers.gitea = {
|
|
239
|
+
success: false,
|
|
240
|
+
error: err.message,
|
|
241
|
+
remote: giteaRemote.name,
|
|
242
|
+
};
|
|
243
|
+
results.traceability.errors.push({
|
|
244
|
+
provider: 'gitea',
|
|
245
|
+
action: 'push',
|
|
246
|
+
error: err.message,
|
|
247
|
+
timestamp: new Date().toISOString(),
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
// 8. Status PÓS-UPDATE
|
|
252
|
+
results.traceability.updateSteps.push({
|
|
253
|
+
step: 7,
|
|
254
|
+
action: 'check_post_update_status',
|
|
255
|
+
timestamp: new Date().toISOString(),
|
|
256
|
+
});
|
|
257
|
+
const postStatus = await git.status();
|
|
258
|
+
results.traceability.postUpdateStatus = {
|
|
259
|
+
branch: postStatus.current,
|
|
260
|
+
ahead: postStatus.ahead,
|
|
261
|
+
behind: postStatus.behind,
|
|
262
|
+
isClean: postStatus.isClean(),
|
|
263
|
+
tracking: postStatus.tracking,
|
|
264
|
+
};
|
|
265
|
+
// 9. Salvar histórico local
|
|
266
|
+
await this.saveUpdateHistory(projectPath, results);
|
|
267
|
+
// 10. Criar histórico remoto via git-history
|
|
268
|
+
await this.createRemoteHistory(ctx, projectPath, results, params);
|
|
269
|
+
return results;
|
|
270
|
+
}
|
|
271
|
+
catch (err) {
|
|
272
|
+
throw new errors_1.MCPError('UPDATE_ERROR', `Failed to update project: ${err.message}`);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
async saveUpdateHistory(projectPath, results) {
|
|
276
|
+
try {
|
|
277
|
+
const historyDir = path.join(projectPath, '.git-mcp-history');
|
|
278
|
+
await fs.mkdir(historyDir, { recursive: true });
|
|
279
|
+
const historyFile = path.join(historyDir, `update-${Date.now()}.json`);
|
|
280
|
+
await fs.writeFile(historyFile, JSON.stringify(results, null, 2), 'utf-8');
|
|
281
|
+
// Log consolidado
|
|
282
|
+
const logFile = path.join(historyDir, 'update-log.jsonl');
|
|
283
|
+
const logEntry = JSON.stringify({
|
|
284
|
+
timestamp: results.timestamp,
|
|
285
|
+
branch: results.branch,
|
|
286
|
+
commit: results.traceability.commit?.hash || 'none',
|
|
287
|
+
filesChanged: results.traceability.changedFiles.length,
|
|
288
|
+
github: results.providers.github?.success || false,
|
|
289
|
+
gitea: results.providers.gitea?.success || false,
|
|
290
|
+
errors: results.traceability.errors.length,
|
|
291
|
+
}) + '\n';
|
|
292
|
+
await fs.appendFile(logFile, logEntry, 'utf-8');
|
|
293
|
+
}
|
|
294
|
+
catch (err) {
|
|
295
|
+
console.warn('Failed to save update history:', err);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
async createRemoteHistory(ctx, projectPath, results, params) {
|
|
299
|
+
// Criar issue de histórico em ambos providers
|
|
300
|
+
const githubOwner = params.owner || process.env.GITHUB_USERNAME;
|
|
301
|
+
const giteaOwner = params.owner || process.env.GITEA_USERNAME;
|
|
302
|
+
// Pegar nome do repo dos remotes do Git ao invés do nome da pasta
|
|
303
|
+
const git = (0, simple_git_1.default)(projectPath);
|
|
304
|
+
const remotes = await git.getRemotes(true);
|
|
305
|
+
let repoName = path.basename(projectPath).replace(/\s+/g, '-'); // fallback
|
|
306
|
+
if (remotes.length > 0) {
|
|
307
|
+
const githubRemote = remotes.find(r => r.name === 'github') || remotes.find(r => r.name === 'origin') || remotes[0];
|
|
308
|
+
const match = githubRemote.refs.push?.match(/\/([^\/]+?)(\.git)?$/);
|
|
309
|
+
if (match)
|
|
310
|
+
repoName = match[1];
|
|
311
|
+
}
|
|
312
|
+
const historyBody = this.formatHistoryIssue(results);
|
|
313
|
+
const historyTitle = `[git-history] Update ${results.timestamp}`;
|
|
314
|
+
// GitHub
|
|
315
|
+
if (ctx.providerManager.github && results.providers.github?.success) {
|
|
316
|
+
try {
|
|
317
|
+
await ctx.providerManager.github.rest.issues.create({
|
|
318
|
+
owner: githubOwner,
|
|
319
|
+
repo: repoName,
|
|
320
|
+
title: historyTitle,
|
|
321
|
+
body: historyBody,
|
|
322
|
+
labels: ['git-history', 'automated'],
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
catch (err) {
|
|
326
|
+
console.warn('Failed to create GitHub history issue:', err);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
// Gitea
|
|
330
|
+
if (ctx.providerManager.giteaBaseUrl && results.providers.gitea?.success) {
|
|
331
|
+
try {
|
|
332
|
+
await axios_1.default.post(`${ctx.providerManager.giteaBaseUrl}/api/v1/repos/${giteaOwner}/${repoName}/issues`, {
|
|
333
|
+
title: historyTitle,
|
|
334
|
+
body: historyBody,
|
|
335
|
+
labels: [1], // Assumindo label ID 1 para git-history
|
|
336
|
+
}, { headers: { Authorization: `token ${ctx.providerManager.giteaToken}` } });
|
|
337
|
+
}
|
|
338
|
+
catch (err) {
|
|
339
|
+
console.warn('Failed to create Gitea history issue:', err);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
formatHistoryIssue(results) {
|
|
344
|
+
return `
|
|
345
|
+
## 📋 Git Update History
|
|
346
|
+
|
|
347
|
+
**Timestamp:** ${results.timestamp}
|
|
348
|
+
**Branch:** ${results.branch}
|
|
349
|
+
**Commit:** ${results.traceability.commit?.hash || 'N/A'}
|
|
350
|
+
|
|
351
|
+
### 📝 Changes Summary
|
|
352
|
+
${results.traceability.commit?.summary || 'No commit made'}
|
|
353
|
+
|
|
354
|
+
**Files Changed:** ${results.traceability.changedFiles.length}
|
|
355
|
+
**Insertions:** ${results.traceability.commit?.inserted || 0}
|
|
356
|
+
**Deletions:** ${results.traceability.commit?.deleted || 0}
|
|
357
|
+
|
|
358
|
+
### 📁 Changed Files
|
|
359
|
+
${results.traceability.changedFiles.map((f) => `- [${f.status}] ${f.file}`).join('\n') || 'No files changed'}
|
|
360
|
+
|
|
361
|
+
### 🔄 Provider Status
|
|
362
|
+
- **GitHub:** ${results.providers.github?.success ? '✅ Success' : '❌ Failed'}
|
|
363
|
+
- **Gitea:** ${results.providers.gitea?.success ? '✅ Success' : '❌ Failed'}
|
|
364
|
+
|
|
365
|
+
### 🔗 Links
|
|
366
|
+
${results.providers.github?.commitUrl ? `- GitHub: ${results.providers.github.commitUrl}` : ''}
|
|
367
|
+
${results.providers.gitea?.commitUrl ? `- Gitea: ${results.providers.gitea.commitUrl}` : ''}
|
|
368
|
+
|
|
369
|
+
---
|
|
370
|
+
*Generated by git-mcp git-update tool*
|
|
371
|
+
`;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
exports.GitUpdateTool = GitUpdateTool;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Tool, MCPContext } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Git Upload Tool - Envia projeto completo para GitHub e Gitea automaticamente
|
|
4
|
+
* Modo DUAL automático com rastreabilidade completa
|
|
5
|
+
*/
|
|
6
|
+
export declare class GitUploadTool implements Tool {
|
|
7
|
+
name: string;
|
|
8
|
+
description: string;
|
|
9
|
+
handle(params: Record<string, any>, ctx: MCPContext): Promise<any>;
|
|
10
|
+
private saveUploadHistory;
|
|
11
|
+
}
|