@andrebuzeli/git-mcp 5.5.2 → 5.8.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.
@@ -0,0 +1,342 @@
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.GitUploadTool = 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 Upload Tool - Envia projeto completo para GitHub e Gitea automaticamente
47
+ * Modo DUAL automático com rastreabilidade completa
48
+ */
49
+ class GitUploadTool {
50
+ constructor() {
51
+ this.name = 'git-upload';
52
+ this.description = 'Upload complete project to GitHub and Gitea with full traceability - automatic dual-provider execution';
53
+ }
54
+ async handle(params, ctx) {
55
+ const projectPath = params.projectPath;
56
+ if (!projectPath) {
57
+ throw new errors_1.MCPError('VALIDATION_ERROR', 'projectPath is required');
58
+ }
59
+ const repoName = params.repoName || path.basename(projectPath);
60
+ const description = params.description || `Project uploaded via git-upload at ${new Date().toISOString()}`;
61
+ const isPrivate = params.private !== undefined ? params.private : true;
62
+ const branch = params.branch || 'master';
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
+ repoName,
70
+ branch,
71
+ providers: {},
72
+ traceability: {
73
+ localChanges: {},
74
+ uploadSteps: [],
75
+ errors: [],
76
+ }
77
+ };
78
+ try {
79
+ // 1. Verificar status local
80
+ results.traceability.uploadSteps.push({
81
+ step: 1,
82
+ action: 'check_local_status',
83
+ timestamp: new Date().toISOString(),
84
+ });
85
+ const status = await git.status();
86
+ results.traceability.localChanges = {
87
+ modified: status.modified,
88
+ created: status.created,
89
+ deleted: status.deleted,
90
+ renamed: status.renamed,
91
+ staged: status.staged,
92
+ conflicted: status.conflicted,
93
+ isClean: status.isClean(),
94
+ };
95
+ // 2. Verificar se tem mudanças
96
+ if (!status.isClean()) {
97
+ results.traceability.uploadSteps.push({
98
+ step: 2,
99
+ action: 'stage_all_changes',
100
+ timestamp: new Date().toISOString(),
101
+ files: [...status.modified, ...status.created, ...status.deleted],
102
+ });
103
+ await git.add('.');
104
+ }
105
+ // 3. Commit com rastreabilidade
106
+ const commitMessage = params.commitMessage || `[git-upload] Upload project at ${new Date().toISOString()}`;
107
+ results.traceability.uploadSteps.push({
108
+ step: 3,
109
+ action: 'commit_changes',
110
+ timestamp: new Date().toISOString(),
111
+ message: commitMessage,
112
+ });
113
+ let commitResult;
114
+ try {
115
+ commitResult = await git.commit(commitMessage);
116
+ results.traceability.commit = {
117
+ hash: commitResult.commit,
118
+ summary: commitResult.summary,
119
+ branch: commitResult.branch,
120
+ author: commitResult.author,
121
+ };
122
+ }
123
+ catch (err) {
124
+ if (err.message.includes('nothing to commit')) {
125
+ results.traceability.commit = { message: 'No changes to commit' };
126
+ }
127
+ else {
128
+ throw err;
129
+ }
130
+ }
131
+ // 4. Criar repositórios remotos em ambos providers
132
+ // Nota: Cada provider precisa usar seu próprio username (Gitea é case-sensitive)
133
+ const githubOwner = params.owner || process.env.GITHUB_USERNAME;
134
+ const giteaOwner = params.owner || process.env.GITEA_USERNAME;
135
+ // GITHUB
136
+ if (ctx.providerManager.github) {
137
+ results.traceability.uploadSteps.push({
138
+ step: 4,
139
+ action: 'create_github_repo',
140
+ timestamp: new Date().toISOString(),
141
+ });
142
+ try {
143
+ // Verificar se repo já existe
144
+ let repoExists = false;
145
+ try {
146
+ await ctx.providerManager.github.rest.repos.get({ owner: githubOwner, repo: repoName });
147
+ repoExists = true;
148
+ }
149
+ catch { }
150
+ if (!repoExists) {
151
+ const createResult = await ctx.providerManager.github.rest.repos.createForAuthenticatedUser({
152
+ name: repoName,
153
+ description,
154
+ private: isPrivate,
155
+ auto_init: false,
156
+ });
157
+ results.providers.github = {
158
+ success: true,
159
+ created: true,
160
+ repo: createResult.data,
161
+ url: createResult.data.html_url,
162
+ clone_url: createResult.data.clone_url,
163
+ };
164
+ }
165
+ else {
166
+ results.providers.github = {
167
+ success: true,
168
+ created: false,
169
+ message: 'Repository already exists',
170
+ url: `https://github.com/${githubOwner}/${repoName}`,
171
+ };
172
+ }
173
+ // Adicionar remote se necessário
174
+ const remotes = await git.getRemotes(true);
175
+ const githubRemote = remotes.find(r => r.name === 'github');
176
+ if (!githubRemote) {
177
+ await git.addRemote('github', `https://github.com/${githubOwner}/${repoName}.git`);
178
+ results.traceability.uploadSteps.push({
179
+ step: 5,
180
+ action: 'add_github_remote',
181
+ timestamp: new Date().toISOString(),
182
+ remote: `https://github.com/${githubOwner}/${repoName}.git`,
183
+ });
184
+ }
185
+ // Push para GitHub
186
+ results.traceability.uploadSteps.push({
187
+ step: 6,
188
+ action: 'push_to_github',
189
+ timestamp: new Date().toISOString(),
190
+ branch,
191
+ });
192
+ try {
193
+ await git.push('github', branch, ['--set-upstream', '--force']);
194
+ results.providers.github.pushed = true;
195
+ results.providers.github.pushStatus = 'success';
196
+ }
197
+ catch (pushErr) {
198
+ results.providers.github.pushed = false;
199
+ results.providers.github.pushError = pushErr.message;
200
+ results.traceability.errors.push({
201
+ provider: 'github',
202
+ action: 'push',
203
+ error: pushErr.message,
204
+ timestamp: new Date().toISOString(),
205
+ });
206
+ }
207
+ }
208
+ catch (err) {
209
+ results.providers.github = {
210
+ success: false,
211
+ error: err.message,
212
+ timestamp: new Date().toISOString(),
213
+ };
214
+ results.traceability.errors.push({
215
+ provider: 'github',
216
+ action: 'upload',
217
+ error: err.message,
218
+ timestamp: new Date().toISOString(),
219
+ });
220
+ }
221
+ }
222
+ // GITEA
223
+ if (ctx.providerManager.giteaBaseUrl) {
224
+ results.traceability.uploadSteps.push({
225
+ step: 7,
226
+ action: 'create_gitea_repo',
227
+ timestamp: new Date().toISOString(),
228
+ });
229
+ try {
230
+ // Verificar se repo já existe
231
+ let repoExists = false;
232
+ try {
233
+ await axios_1.default.get(`${ctx.providerManager.giteaBaseUrl}/api/v1/repos/${giteaOwner}/${repoName}`, { headers: { Authorization: `token ${ctx.providerManager.giteaToken}` } });
234
+ repoExists = true;
235
+ }
236
+ catch { }
237
+ if (!repoExists) {
238
+ const createResult = await axios_1.default.post(`${ctx.providerManager.giteaBaseUrl}/api/v1/user/repos`, {
239
+ name: repoName,
240
+ description,
241
+ private: isPrivate,
242
+ auto_init: false,
243
+ }, { headers: { Authorization: `token ${ctx.providerManager.giteaToken}` } });
244
+ results.providers.gitea = {
245
+ success: true,
246
+ created: true,
247
+ repo: createResult.data,
248
+ url: createResult.data.html_url,
249
+ clone_url: createResult.data.clone_url,
250
+ };
251
+ }
252
+ else {
253
+ results.providers.gitea = {
254
+ success: true,
255
+ created: false,
256
+ message: 'Repository already exists',
257
+ url: `${ctx.providerManager.giteaBaseUrl}/${giteaOwner}/${repoName}`,
258
+ };
259
+ }
260
+ // Adicionar remote se necessário
261
+ const remotes = await git.getRemotes(true);
262
+ const giteaRemote = remotes.find(r => r.name === 'gitea');
263
+ if (!giteaRemote) {
264
+ const giteaUrl = `${ctx.providerManager.giteaBaseUrl}/${giteaOwner}/${repoName}.git`;
265
+ await git.addRemote('gitea', giteaUrl);
266
+ results.traceability.uploadSteps.push({
267
+ step: 8,
268
+ action: 'add_gitea_remote',
269
+ timestamp: new Date().toISOString(),
270
+ remote: giteaUrl,
271
+ });
272
+ }
273
+ // Push para Gitea
274
+ results.traceability.uploadSteps.push({
275
+ step: 9,
276
+ action: 'push_to_gitea',
277
+ timestamp: new Date().toISOString(),
278
+ branch,
279
+ });
280
+ try {
281
+ await git.push('gitea', branch, ['--set-upstream', '--force']);
282
+ results.providers.gitea.pushed = true;
283
+ results.providers.gitea.pushStatus = 'success';
284
+ }
285
+ catch (pushErr) {
286
+ results.providers.gitea.pushed = false;
287
+ results.providers.gitea.pushError = pushErr.message;
288
+ results.traceability.errors.push({
289
+ provider: 'gitea',
290
+ action: 'push',
291
+ error: pushErr.message,
292
+ timestamp: new Date().toISOString(),
293
+ });
294
+ }
295
+ }
296
+ catch (err) {
297
+ results.providers.gitea = {
298
+ success: false,
299
+ error: err.message,
300
+ timestamp: new Date().toISOString(),
301
+ };
302
+ results.traceability.errors.push({
303
+ provider: 'gitea',
304
+ action: 'upload',
305
+ error: err.message,
306
+ timestamp: new Date().toISOString(),
307
+ });
308
+ }
309
+ }
310
+ // 5. Salvar histórico local
311
+ await this.saveUploadHistory(projectPath, results);
312
+ return results;
313
+ }
314
+ catch (err) {
315
+ throw new errors_1.MCPError('UPLOAD_ERROR', `Failed to upload project: ${err.message}`);
316
+ }
317
+ }
318
+ async saveUploadHistory(projectPath, results) {
319
+ try {
320
+ const historyDir = path.join(projectPath, '.git-mcp-history');
321
+ await fs.mkdir(historyDir, { recursive: true });
322
+ const historyFile = path.join(historyDir, `upload-${Date.now()}.json`);
323
+ await fs.writeFile(historyFile, JSON.stringify(results, null, 2), 'utf-8');
324
+ // Também manter um log consolidado
325
+ const logFile = path.join(historyDir, 'upload-log.jsonl');
326
+ const logEntry = JSON.stringify({
327
+ timestamp: results.timestamp,
328
+ repoName: results.repoName,
329
+ branch: results.branch,
330
+ github: results.providers.github?.success || false,
331
+ gitea: results.providers.gitea?.success || false,
332
+ errors: results.traceability.errors.length,
333
+ }) + '\n';
334
+ await fs.appendFile(logFile, logEntry, 'utf-8');
335
+ }
336
+ catch (err) {
337
+ // Não falhar se não conseguir salvar histórico
338
+ console.warn('Failed to save upload history:', err);
339
+ }
340
+ }
341
+ }
342
+ exports.GitUploadTool = GitUploadTool;
@@ -2,68 +2,5 @@ import { Tool, MCPContext } from '../types';
2
2
  export declare class GitWorkflowTool implements Tool {
3
3
  name: string;
4
4
  description: string;
5
- handle(params: Record<string, any>, ctx: MCPContext): Promise<{
6
- success: boolean;
7
- path: any;
8
- status?: undefined;
9
- commit?: undefined;
10
- message?: undefined;
11
- backupPath?: undefined;
12
- repo?: undefined;
13
- repos?: undefined;
14
- } | {
15
- success: boolean;
16
- status: import("simple-git").StatusResult;
17
- path?: undefined;
18
- commit?: undefined;
19
- message?: undefined;
20
- backupPath?: undefined;
21
- repo?: undefined;
22
- repos?: undefined;
23
- } | {
24
- success: boolean;
25
- commit: import("simple-git").CommitResult;
26
- path?: undefined;
27
- status?: undefined;
28
- message?: undefined;
29
- backupPath?: undefined;
30
- repo?: undefined;
31
- repos?: undefined;
32
- } | {
33
- success: boolean;
34
- message: string;
35
- path?: undefined;
36
- status?: undefined;
37
- commit?: undefined;
38
- backupPath?: undefined;
39
- repo?: undefined;
40
- repos?: undefined;
41
- } | {
42
- success: boolean;
43
- backupPath: any;
44
- message: string;
45
- path?: undefined;
46
- status?: undefined;
47
- commit?: undefined;
48
- repo?: undefined;
49
- repos?: undefined;
50
- } | {
51
- success: boolean;
52
- repo: any;
53
- path?: undefined;
54
- status?: undefined;
55
- commit?: undefined;
56
- message?: undefined;
57
- backupPath?: undefined;
58
- repos?: undefined;
59
- } | {
60
- success: boolean;
61
- repos: any;
62
- path?: undefined;
63
- status?: undefined;
64
- commit?: undefined;
65
- message?: undefined;
66
- backupPath?: undefined;
67
- repo?: undefined;
68
- }>;
5
+ handle(params: Record<string, any>, ctx: MCPContext): Promise<any>;
69
6
  }