@andrebuzeli/git-mcp 10.0.8 → 11.0.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 +34 -428
- package/bin/git-mcp.js +21 -0
- package/docs/TOOLS.md +110 -0
- package/mcp.json.template +12 -0
- package/package.json +9 -76
- package/src/local/git.js +14 -0
- package/src/providers/gitea.js +13 -0
- package/src/providers/github.js +13 -0
- package/src/server.js +63 -0
- package/src/tools/git-actions.js +19 -0
- package/src/tools/git-activity.js +28 -0
- package/src/tools/git-admin.js +20 -0
- package/src/tools/git-checks.js +14 -0
- package/src/tools/git-commits.js +34 -0
- package/src/tools/git-contents.js +30 -0
- package/src/tools/git-deployments.js +21 -0
- package/src/tools/git-gists.js +15 -0
- package/src/tools/git-gitdata.js +19 -0
- package/src/tools/git-issues-prs.js +44 -0
- package/src/tools/git-issues.js +12 -0
- package/src/tools/git-local.js +66 -0
- package/src/tools/git-meta.js +19 -0
- package/src/tools/git-misc.js +21 -0
- package/src/tools/git-orgs.js +26 -0
- package/src/tools/git-packages.js +12 -0
- package/src/tools/git-raw.js +14 -0
- package/src/tools/git-releases.js +17 -0
- package/src/tools/git-remote.js +29 -0
- package/src/tools/git-repos.js +60 -0
- package/src/tools/git-search.js +18 -0
- package/src/tools/git-sync.js +40 -0
- package/src/tools/git-user.js +26 -0
- package/src/tools/schema.js +3 -0
- package/src/utils/fs.js +29 -0
- package/src/utils/project.js +7 -0
- package/tests/errors.js +26 -0
- package/tests/full_suite.js +98 -0
- package/tests/run.js +50 -0
- package/LICENSE +0 -21
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -224
- package/dist/prompts/gitPrompts.d.ts +0 -93
- package/dist/prompts/gitPrompts.js +0 -177
- package/dist/providers/giteaProvider.d.ts +0 -3
- package/dist/providers/giteaProvider.js +0 -6
- package/dist/providers/githubProvider.d.ts +0 -2
- package/dist/providers/githubProvider.js +0 -4
- package/dist/providers/providerManager.d.ts +0 -11
- package/dist/providers/providerManager.js +0 -49
- package/dist/resources/toolsGuide.d.ts +0 -12
- package/dist/resources/toolsGuide.js +0 -1713
- package/dist/scripts/test_e2e.d.ts +0 -1
- package/dist/scripts/test_e2e.js +0 -199
- package/dist/scripts/test_exhaustive.d.ts +0 -1
- package/dist/scripts/test_exhaustive.js +0 -275
- package/dist/scripts/verify_setup.d.ts +0 -1
- package/dist/scripts/verify_setup.js +0 -61
- package/dist/server.d.ts +0 -9
- package/dist/server.js +0 -73
- package/dist/tools/gitAnalytics.d.ts +0 -35
- package/dist/tools/gitAnalytics.js +0 -220
- package/dist/tools/gitArchive.d.ts +0 -119
- package/dist/tools/gitArchive.js +0 -150
- package/dist/tools/gitBackup.d.ts +0 -116
- package/dist/tools/gitBackup.js +0 -156
- package/dist/tools/gitBranches.d.ts +0 -54
- package/dist/tools/gitBranches.js +0 -282
- package/dist/tools/gitChangelog.d.ts +0 -37
- package/dist/tools/gitChangelog.js +0 -67
- package/dist/tools/gitConfig.d.ts +0 -97
- package/dist/tools/gitConfig.js +0 -125
- package/dist/tools/gitFiles.d.ts +0 -129
- package/dist/tools/gitFiles.js +0 -213
- package/dist/tools/gitFix.d.ts +0 -4
- package/dist/tools/gitFix.js +0 -159
- package/dist/tools/gitFix.tool.d.ts +0 -31
- package/dist/tools/gitFix.tool.js +0 -92
- package/dist/tools/gitHistory.d.ts +0 -41
- package/dist/tools/gitHistory.js +0 -349
- package/dist/tools/gitIgnore.d.ts +0 -214
- package/dist/tools/gitIgnore.js +0 -338
- package/dist/tools/gitIssues.d.ts +0 -80
- package/dist/tools/gitIssues.js +0 -363
- package/dist/tools/gitLog.d.ts +0 -30
- package/dist/tools/gitLog.js +0 -46
- package/dist/tools/gitMonitor.d.ts +0 -30
- package/dist/tools/gitMonitor.js +0 -284
- package/dist/tools/gitPackages.d.ts +0 -180
- package/dist/tools/gitPackages.js +0 -214
- package/dist/tools/gitPulls.d.ts +0 -66
- package/dist/tools/gitPulls.js +0 -347
- package/dist/tools/gitPush.d.ts +0 -40
- package/dist/tools/gitPush.js +0 -59
- package/dist/tools/gitRelease.d.ts +0 -49
- package/dist/tools/gitRelease.js +0 -359
- package/dist/tools/gitRemote.d.ts +0 -47
- package/dist/tools/gitRemote.js +0 -111
- package/dist/tools/gitReset.d.ts +0 -57
- package/dist/tools/gitReset.js +0 -79
- package/dist/tools/gitStash.d.ts +0 -61
- package/dist/tools/gitStash.js +0 -80
- package/dist/tools/gitSync.d.ts +0 -34
- package/dist/tools/gitSync.js +0 -182
- package/dist/tools/gitTags.d.ts +0 -45
- package/dist/tools/gitTags.js +0 -251
- package/dist/tools/gitUpdate.d.ts +0 -60
- package/dist/tools/gitUpdate.js +0 -474
- package/dist/tools/gitUpload.d.ts +0 -35
- package/dist/tools/gitUpload.js +0 -385
- package/dist/tools/gitWorkflow.d.ts +0 -117
- package/dist/tools/gitWorkflow.js +0 -472
- package/dist/types.d.ts +0 -20
- package/dist/types.js +0 -1
- package/dist/utils/agentHelpers.d.ts +0 -11
- package/dist/utils/agentHelpers.js +0 -41
- package/dist/utils/apiHelpers.d.ts +0 -29
- package/dist/utils/apiHelpers.js +0 -125
- package/dist/utils/cache.d.ts +0 -96
- package/dist/utils/cache.js +0 -208
- package/dist/utils/contextDetector.d.ts +0 -0
- package/dist/utils/contextDetector.js +0 -1
- package/dist/utils/errors.d.ts +0 -13
- package/dist/utils/errors.js +0 -17
- package/dist/utils/gitAdapter.d.ts +0 -224
- package/dist/utils/gitAdapter.js +0 -1152
- package/dist/utils/logger.d.ts +0 -45
- package/dist/utils/logger.js +0 -140
- package/dist/utils/rateLimiter.d.ts +0 -113
- package/dist/utils/rateLimiter.js +0 -257
- package/dist/utils/repoHelpers.d.ts +0 -44
- package/dist/utils/repoHelpers.js +0 -122
- package/dist/utils/safetyController.d.ts +0 -1
- package/dist/utils/safetyController.js +0 -12
- package/dist/utils/validation.d.ts +0 -115
- package/dist/utils/validation.js +0 -270
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { Tool, MCPContext } from '../types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Git Update Tool - Atualiza projeto completo em GitHub e Gitea automaticamente
|
|
4
|
-
* Modo DUAL automático com rastreabilidade completa
|
|
5
|
-
* Inclui: add, commit, push, sync, history tracking
|
|
6
|
-
*/
|
|
7
|
-
export declare class GitUpdateTool implements Tool {
|
|
8
|
-
name: string;
|
|
9
|
-
description: string;
|
|
10
|
-
inputSchema: {
|
|
11
|
-
type: "object";
|
|
12
|
-
properties: {
|
|
13
|
-
projectPath: {
|
|
14
|
-
type: string;
|
|
15
|
-
description: string;
|
|
16
|
-
};
|
|
17
|
-
private: {
|
|
18
|
-
type: string;
|
|
19
|
-
description: string;
|
|
20
|
-
};
|
|
21
|
-
owner: {
|
|
22
|
-
type: string;
|
|
23
|
-
description: string;
|
|
24
|
-
};
|
|
25
|
-
message: {
|
|
26
|
-
type: string;
|
|
27
|
-
description: string;
|
|
28
|
-
};
|
|
29
|
-
commitMessage: {
|
|
30
|
-
type: string;
|
|
31
|
-
description: string;
|
|
32
|
-
};
|
|
33
|
-
branch: {
|
|
34
|
-
type: string;
|
|
35
|
-
description: string;
|
|
36
|
-
};
|
|
37
|
-
files: {
|
|
38
|
-
type: string;
|
|
39
|
-
items: {
|
|
40
|
-
type: string;
|
|
41
|
-
};
|
|
42
|
-
description: string;
|
|
43
|
-
};
|
|
44
|
-
repoName: {
|
|
45
|
-
type: string;
|
|
46
|
-
description: string;
|
|
47
|
-
};
|
|
48
|
-
description: {
|
|
49
|
-
type: string;
|
|
50
|
-
description: string;
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
required: string[];
|
|
54
|
-
additionalProperties: boolean;
|
|
55
|
-
};
|
|
56
|
-
handle(params: Record<string, any>, ctx: MCPContext): Promise<any>;
|
|
57
|
-
private saveUpdateHistory;
|
|
58
|
-
private createRemoteHistory;
|
|
59
|
-
private formatHistoryIssue;
|
|
60
|
-
}
|
package/dist/tools/gitUpdate.js
DELETED
|
@@ -1,474 +0,0 @@
|
|
|
1
|
-
import { MCPError } from '../utils/errors.js';
|
|
2
|
-
import axios from 'axios';
|
|
3
|
-
import * as fs from 'fs/promises';
|
|
4
|
-
import * as path from 'path';
|
|
5
|
-
import { getRepoNameFromPath } from '../utils/repoHelpers.js';
|
|
6
|
-
/**
|
|
7
|
-
* Git Update Tool - Atualiza projeto completo em GitHub e Gitea automaticamente
|
|
8
|
-
* Modo DUAL automático com rastreabilidade completa
|
|
9
|
-
* Inclui: add, commit, push, sync, history tracking
|
|
10
|
-
*/
|
|
11
|
-
export class GitUpdateTool {
|
|
12
|
-
constructor() {
|
|
13
|
-
this.name = 'git-update';
|
|
14
|
-
this.description = 'Complete project update workflow (add, commit, push) to GitHub and Gitea with full traceability - automatic dual-provider execution';
|
|
15
|
-
this.inputSchema = {
|
|
16
|
-
type: "object",
|
|
17
|
-
properties: {
|
|
18
|
-
projectPath: {
|
|
19
|
-
type: "string",
|
|
20
|
-
description: "The absolute path to the Git repository directory on the local filesystem. This should be the root directory containing the .git folder. For example: '/home/user/my-project' on Linux/Mac or 'C:\\Users\\user\\my-project' on Windows."
|
|
21
|
-
},
|
|
22
|
-
private: {
|
|
23
|
-
type: "boolean",
|
|
24
|
-
description: "Make repository private when auto-creating (optional, default: true)"
|
|
25
|
-
},
|
|
26
|
-
owner: {
|
|
27
|
-
type: "string",
|
|
28
|
-
description: "Repository owner for providers (optional, uses env vars)"
|
|
29
|
-
},
|
|
30
|
-
message: {
|
|
31
|
-
type: "string",
|
|
32
|
-
description: "Commit message"
|
|
33
|
-
},
|
|
34
|
-
commitMessage: {
|
|
35
|
-
type: "string",
|
|
36
|
-
description: "Commit message (alias)"
|
|
37
|
-
},
|
|
38
|
-
branch: {
|
|
39
|
-
type: "string",
|
|
40
|
-
description: "Branch name"
|
|
41
|
-
},
|
|
42
|
-
files: {
|
|
43
|
-
type: "array",
|
|
44
|
-
items: { type: "string" },
|
|
45
|
-
description: "Files to add"
|
|
46
|
-
},
|
|
47
|
-
repoName: {
|
|
48
|
-
type: "string",
|
|
49
|
-
description: "Repository name"
|
|
50
|
-
},
|
|
51
|
-
description: {
|
|
52
|
-
type: "string",
|
|
53
|
-
description: "Repository description"
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
required: ["projectPath"],
|
|
57
|
-
additionalProperties: true
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
async handle(params, ctx) {
|
|
61
|
-
const projectPath = params.projectPath;
|
|
62
|
-
if (!projectPath) {
|
|
63
|
-
throw new MCPError('VALIDATION_ERROR', 'projectPath is required');
|
|
64
|
-
}
|
|
65
|
-
if (!ctx.gitAdapter) {
|
|
66
|
-
throw new MCPError('INTERNAL_ERROR', 'Git adapter not available');
|
|
67
|
-
}
|
|
68
|
-
const commitMessage = params.message || params.commitMessage || `[git-update] Update at ${new Date().toISOString()}`;
|
|
69
|
-
const branch = params.branch || 'master';
|
|
70
|
-
const files = params.files || ['.'];
|
|
71
|
-
// Resultado com rastreabilidade completa
|
|
72
|
-
const results = {
|
|
73
|
-
success: true,
|
|
74
|
-
timestamp: new Date().toISOString(),
|
|
75
|
-
projectPath,
|
|
76
|
-
branch,
|
|
77
|
-
commitMessage,
|
|
78
|
-
providers: {},
|
|
79
|
-
traceability: {
|
|
80
|
-
preUpdateStatus: {},
|
|
81
|
-
changedFiles: [],
|
|
82
|
-
updateSteps: [],
|
|
83
|
-
syncStatus: {},
|
|
84
|
-
errors: [],
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
try {
|
|
88
|
-
// 1. Status PRÉ-UPDATE
|
|
89
|
-
results.traceability.updateSteps.push({
|
|
90
|
-
step: 1,
|
|
91
|
-
action: 'check_pre_update_status',
|
|
92
|
-
timestamp: new Date().toISOString(),
|
|
93
|
-
});
|
|
94
|
-
const preStatus = await ctx.gitAdapter.status(projectPath);
|
|
95
|
-
results.traceability.preUpdateStatus = {
|
|
96
|
-
branch: preStatus.current,
|
|
97
|
-
ahead: preStatus.ahead,
|
|
98
|
-
behind: preStatus.behind,
|
|
99
|
-
modified: preStatus.modified,
|
|
100
|
-
created: preStatus.created,
|
|
101
|
-
deleted: preStatus.deleted,
|
|
102
|
-
renamed: preStatus.renamed,
|
|
103
|
-
staged: preStatus.staged,
|
|
104
|
-
conflicted: preStatus.conflicted,
|
|
105
|
-
isClean: preStatus.isClean,
|
|
106
|
-
};
|
|
107
|
-
// 2. Detectar arquivos alterados com diff
|
|
108
|
-
results.traceability.updateSteps.push({
|
|
109
|
-
step: 2,
|
|
110
|
-
action: 'detect_changes',
|
|
111
|
-
timestamp: new Date().toISOString(),
|
|
112
|
-
});
|
|
113
|
-
// Isomorphic git diff is basic, so we rely on status for changed files list
|
|
114
|
-
results.traceability.changedFiles = preStatus.files.map(f => ({
|
|
115
|
-
status: f.working_dir,
|
|
116
|
-
file: f.path
|
|
117
|
-
}));
|
|
118
|
-
// 3. Add files
|
|
119
|
-
results.traceability.updateSteps.push({
|
|
120
|
-
step: 3,
|
|
121
|
-
action: 'stage_changes',
|
|
122
|
-
timestamp: new Date().toISOString(),
|
|
123
|
-
files,
|
|
124
|
-
});
|
|
125
|
-
await ctx.gitAdapter.add(projectPath, files);
|
|
126
|
-
// 4. Commit
|
|
127
|
-
results.traceability.updateSteps.push({
|
|
128
|
-
step: 4,
|
|
129
|
-
action: 'commit',
|
|
130
|
-
timestamp: new Date().toISOString(),
|
|
131
|
-
message: commitMessage,
|
|
132
|
-
});
|
|
133
|
-
let commitResult;
|
|
134
|
-
try {
|
|
135
|
-
const sha = await ctx.gitAdapter.commit(projectPath, commitMessage);
|
|
136
|
-
commitResult = {
|
|
137
|
-
commit: sha,
|
|
138
|
-
summary: { changes: 0, insertions: 0, deletions: 0 }, // Basic adapter doesn't return stats yet
|
|
139
|
-
branch: await ctx.gitAdapter.getCurrentBranch(projectPath),
|
|
140
|
-
author: { name: 'unknown', email: 'unknown' } // We could fetch this if needed
|
|
141
|
-
};
|
|
142
|
-
results.traceability.commit = {
|
|
143
|
-
hash: commitResult.commit,
|
|
144
|
-
summary: commitResult.summary,
|
|
145
|
-
branch: commitResult.branch,
|
|
146
|
-
author: commitResult.author,
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
catch (err) {
|
|
150
|
-
if (err.message.includes('nothing to commit') || (preStatus.isClean && files[0] === '.')) {
|
|
151
|
-
results.traceability.commit = { message: 'No changes to commit' };
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
throw err;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
// 5. Get remotes and ensure repos exist
|
|
158
|
-
const remotes = await ctx.gitAdapter.listRemotes(projectPath);
|
|
159
|
-
let githubRemote = remotes.find(r => r.name === 'github' || r.name === 'origin');
|
|
160
|
-
let giteaRemote = remotes.find(r => r.name === 'gitea');
|
|
161
|
-
// Auto-create repos if they don't exist
|
|
162
|
-
const repoName = params.repoName || getRepoNameFromPath(projectPath);
|
|
163
|
-
const description = params.description || `Project updated via git-update at ${new Date().toISOString()}`;
|
|
164
|
-
const isPrivate = params.private !== undefined ? params.private : true;
|
|
165
|
-
const githubOwner = params.owner || process.env.GITHUB_USERNAME;
|
|
166
|
-
const giteaOwner = process.env.GITEA_USERNAME;
|
|
167
|
-
// 5a. Ensure GitHub repo exists
|
|
168
|
-
if (ctx.providerManager.github && !githubRemote) {
|
|
169
|
-
results.traceability.updateSteps.push({
|
|
170
|
-
step: 5,
|
|
171
|
-
action: 'ensure_github_repo',
|
|
172
|
-
timestamp: new Date().toISOString(),
|
|
173
|
-
});
|
|
174
|
-
try {
|
|
175
|
-
// Try to get repo, create if doesn't exist
|
|
176
|
-
let repoExists = false;
|
|
177
|
-
try {
|
|
178
|
-
await ctx.providerManager.github.rest.repos.get({
|
|
179
|
-
owner: githubOwner,
|
|
180
|
-
repo: repoName
|
|
181
|
-
});
|
|
182
|
-
repoExists = true;
|
|
183
|
-
}
|
|
184
|
-
catch { }
|
|
185
|
-
if (!repoExists) {
|
|
186
|
-
await ctx.providerManager.github.rest.repos.createForAuthenticatedUser({
|
|
187
|
-
name: repoName,
|
|
188
|
-
description,
|
|
189
|
-
private: isPrivate,
|
|
190
|
-
auto_init: false,
|
|
191
|
-
});
|
|
192
|
-
results.traceability.updateSteps.push({
|
|
193
|
-
step: 5.1,
|
|
194
|
-
action: 'created_github_repo',
|
|
195
|
-
timestamp: new Date().toISOString(),
|
|
196
|
-
repo: repoName,
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
// Add remote
|
|
200
|
-
const url = `https://github.com/${githubOwner}/${repoName}.git`;
|
|
201
|
-
await ctx.gitAdapter.addRemote(projectPath, 'github', url);
|
|
202
|
-
githubRemote = { name: 'github', remote: 'github', url, fetch: url };
|
|
203
|
-
}
|
|
204
|
-
catch (err) {
|
|
205
|
-
results.traceability.errors.push({
|
|
206
|
-
provider: 'github',
|
|
207
|
-
action: 'ensure_repo',
|
|
208
|
-
error: err.message,
|
|
209
|
-
timestamp: new Date().toISOString(),
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
// 5b. Ensure Gitea repo exists
|
|
214
|
-
if (ctx.providerManager.giteaBaseUrl && !giteaRemote) {
|
|
215
|
-
results.traceability.updateSteps.push({
|
|
216
|
-
step: 5.5,
|
|
217
|
-
action: 'ensure_gitea_repo',
|
|
218
|
-
timestamp: new Date().toISOString(),
|
|
219
|
-
});
|
|
220
|
-
try {
|
|
221
|
-
// Try to get repo, create if doesn't exist
|
|
222
|
-
let repoExists = false;
|
|
223
|
-
try {
|
|
224
|
-
await axios.get(`${ctx.providerManager.giteaBaseUrl}/api/v1/repos/${giteaOwner}/${repoName}`, { headers: { Authorization: `token ${ctx.providerManager.giteaToken}` } });
|
|
225
|
-
repoExists = true;
|
|
226
|
-
}
|
|
227
|
-
catch { }
|
|
228
|
-
if (!repoExists) {
|
|
229
|
-
await axios.post(`${ctx.providerManager.giteaBaseUrl}/api/v1/user/repos`, {
|
|
230
|
-
name: repoName,
|
|
231
|
-
description,
|
|
232
|
-
private: isPrivate,
|
|
233
|
-
auto_init: false,
|
|
234
|
-
}, { headers: { Authorization: `token ${ctx.providerManager.giteaToken}` } });
|
|
235
|
-
results.traceability.updateSteps.push({
|
|
236
|
-
step: 5.6,
|
|
237
|
-
action: 'created_gitea_repo',
|
|
238
|
-
timestamp: new Date().toISOString(),
|
|
239
|
-
repo: repoName,
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
// Add remote
|
|
243
|
-
const url = `${ctx.providerManager.giteaBaseUrl}/${giteaOwner}/${repoName}.git`;
|
|
244
|
-
await ctx.gitAdapter.addRemote(projectPath, 'gitea', url);
|
|
245
|
-
giteaRemote = { name: 'gitea', remote: 'gitea', url, fetch: url };
|
|
246
|
-
}
|
|
247
|
-
catch (err) {
|
|
248
|
-
results.traceability.errors.push({
|
|
249
|
-
provider: 'gitea',
|
|
250
|
-
action: 'ensure_repo',
|
|
251
|
-
error: err.message,
|
|
252
|
-
timestamp: new Date().toISOString(),
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
// 6. Push to GITHUB
|
|
257
|
-
if (githubRemote && ctx.providerManager.github) {
|
|
258
|
-
results.traceability.updateSteps.push({
|
|
259
|
-
step: 6,
|
|
260
|
-
action: 'push_to_github',
|
|
261
|
-
timestamp: new Date().toISOString(),
|
|
262
|
-
remote: githubRemote.name,
|
|
263
|
-
branch,
|
|
264
|
-
});
|
|
265
|
-
try {
|
|
266
|
-
await ctx.gitAdapter.push(projectPath, githubRemote.name, branch);
|
|
267
|
-
results.providers.github = {
|
|
268
|
-
success: true,
|
|
269
|
-
remote: githubRemote.name,
|
|
270
|
-
url: githubRemote.url,
|
|
271
|
-
pushed: true,
|
|
272
|
-
pushResult: {
|
|
273
|
-
message: 'Push successful'
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
// Verificar commit no GitHub via API
|
|
277
|
-
try {
|
|
278
|
-
if (results.traceability.commit?.hash) {
|
|
279
|
-
const githubOwner = params.owner || process.env.GITHUB_USERNAME;
|
|
280
|
-
const repo = getRepoNameFromPath(projectPath);
|
|
281
|
-
const commitInfo = await ctx.providerManager.github.rest.repos.getCommit({
|
|
282
|
-
owner: githubOwner,
|
|
283
|
-
repo,
|
|
284
|
-
ref: results.traceability.commit.hash,
|
|
285
|
-
});
|
|
286
|
-
results.providers.github.commitVerified = true;
|
|
287
|
-
results.providers.github.commitUrl = commitInfo.data.html_url;
|
|
288
|
-
results.providers.github.stats = commitInfo.data.stats;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
catch { }
|
|
292
|
-
}
|
|
293
|
-
catch (err) {
|
|
294
|
-
results.providers.github = {
|
|
295
|
-
success: false,
|
|
296
|
-
error: err.message,
|
|
297
|
-
remote: githubRemote.name,
|
|
298
|
-
};
|
|
299
|
-
results.traceability.errors.push({
|
|
300
|
-
provider: 'github',
|
|
301
|
-
action: 'push',
|
|
302
|
-
error: err.message,
|
|
303
|
-
timestamp: new Date().toISOString(),
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
// 7. Push to GITEA
|
|
308
|
-
if (giteaRemote && ctx.providerManager.giteaBaseUrl) {
|
|
309
|
-
results.traceability.updateSteps.push({
|
|
310
|
-
step: 7,
|
|
311
|
-
action: 'push_to_gitea',
|
|
312
|
-
timestamp: new Date().toISOString(),
|
|
313
|
-
remote: giteaRemote.name,
|
|
314
|
-
branch,
|
|
315
|
-
});
|
|
316
|
-
try {
|
|
317
|
-
await ctx.gitAdapter.push(projectPath, giteaRemote.name, branch);
|
|
318
|
-
results.providers.gitea = {
|
|
319
|
-
success: true,
|
|
320
|
-
remote: giteaRemote.name,
|
|
321
|
-
url: giteaRemote.url,
|
|
322
|
-
pushed: true,
|
|
323
|
-
pushResult: {
|
|
324
|
-
message: 'Push successful'
|
|
325
|
-
}
|
|
326
|
-
};
|
|
327
|
-
// Verificar commit no Gitea via API
|
|
328
|
-
try {
|
|
329
|
-
if (results.traceability.commit?.hash) {
|
|
330
|
-
const giteaOwner = params.owner || process.env.GITEA_USERNAME;
|
|
331
|
-
const repo = getRepoNameFromPath(projectPath);
|
|
332
|
-
const commitInfo = await axios.get(`${ctx.providerManager.giteaBaseUrl}/api/v1/repos/${giteaOwner}/${repo}/git/commits/${results.traceability.commit.hash}`, { headers: { Authorization: `token ${ctx.providerManager.giteaToken}` } });
|
|
333
|
-
results.providers.gitea.commitVerified = true;
|
|
334
|
-
results.providers.gitea.commitUrl = commitInfo.data.html_url;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
catch { }
|
|
338
|
-
}
|
|
339
|
-
catch (err) {
|
|
340
|
-
results.providers.gitea = {
|
|
341
|
-
success: false,
|
|
342
|
-
error: err.message,
|
|
343
|
-
remote: giteaRemote.name,
|
|
344
|
-
};
|
|
345
|
-
results.traceability.errors.push({
|
|
346
|
-
provider: 'gitea',
|
|
347
|
-
action: 'push',
|
|
348
|
-
error: err.message,
|
|
349
|
-
timestamp: new Date().toISOString(),
|
|
350
|
-
});
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
// 8. Status PÓS-UPDATE
|
|
354
|
-
results.traceability.updateSteps.push({
|
|
355
|
-
step: 7,
|
|
356
|
-
action: 'check_post_update_status',
|
|
357
|
-
timestamp: new Date().toISOString(),
|
|
358
|
-
});
|
|
359
|
-
const postStatus = await ctx.gitAdapter.status(projectPath);
|
|
360
|
-
results.traceability.postUpdateStatus = {
|
|
361
|
-
branch: postStatus.current,
|
|
362
|
-
ahead: postStatus.ahead,
|
|
363
|
-
behind: postStatus.behind,
|
|
364
|
-
isClean: postStatus.isClean,
|
|
365
|
-
tracking: postStatus.tracking,
|
|
366
|
-
};
|
|
367
|
-
// 9. Salvar histórico local
|
|
368
|
-
await this.saveUpdateHistory(projectPath, results);
|
|
369
|
-
// 10. Criar histórico remoto via git-history
|
|
370
|
-
await this.createRemoteHistory(ctx, projectPath, results, params);
|
|
371
|
-
return results;
|
|
372
|
-
}
|
|
373
|
-
catch (err) {
|
|
374
|
-
throw new MCPError('UPDATE_ERROR', `Failed to update project: ${err.message}`);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
async saveUpdateHistory(projectPath, results) {
|
|
378
|
-
try {
|
|
379
|
-
const historyDir = path.join(projectPath, '.git-mcp-history');
|
|
380
|
-
await fs.mkdir(historyDir, { recursive: true });
|
|
381
|
-
const historyFile = path.join(historyDir, `update-${Date.now()}.json`);
|
|
382
|
-
await fs.writeFile(historyFile, JSON.stringify(results, null, 2), 'utf-8');
|
|
383
|
-
// Log consolidado
|
|
384
|
-
const logFile = path.join(historyDir, 'update-log.jsonl');
|
|
385
|
-
const logEntry = JSON.stringify({
|
|
386
|
-
timestamp: results.timestamp,
|
|
387
|
-
branch: results.branch,
|
|
388
|
-
commit: results.traceability.commit?.hash || 'none',
|
|
389
|
-
filesChanged: results.traceability.changedFiles.length,
|
|
390
|
-
github: results.providers.github?.success || false,
|
|
391
|
-
gitea: results.providers.gitea?.success || false,
|
|
392
|
-
errors: results.traceability.errors.length,
|
|
393
|
-
}) + '\n';
|
|
394
|
-
await fs.appendFile(logFile, logEntry, 'utf-8');
|
|
395
|
-
}
|
|
396
|
-
catch (err) {
|
|
397
|
-
console.warn('Failed to save update history:', err);
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
async createRemoteHistory(ctx, projectPath, results, params) {
|
|
401
|
-
// Criar issue de histórico em ambos providers
|
|
402
|
-
const githubOwner = params.owner || process.env.GITHUB_USERNAME;
|
|
403
|
-
const giteaOwner = params.owner || process.env.GITEA_USERNAME;
|
|
404
|
-
// Pegar nome do repo dos remotes do Git ao invés do nome da pasta
|
|
405
|
-
const remotes = await ctx.gitAdapter.listRemotes(projectPath);
|
|
406
|
-
let repoName = getRepoNameFromPath(projectPath); // fallback
|
|
407
|
-
if (remotes.length > 0) {
|
|
408
|
-
const githubRemote = remotes.find(r => r.name === 'github') || remotes.find(r => r.name === 'origin') || remotes[0];
|
|
409
|
-
const match = githubRemote.fetch?.match(/\/([^\/]+?)(\.git)?$/);
|
|
410
|
-
if (match)
|
|
411
|
-
repoName = match[1];
|
|
412
|
-
}
|
|
413
|
-
const historyBody = this.formatHistoryIssue(results);
|
|
414
|
-
const historyTitle = `[git-history] Update ${results.timestamp}`;
|
|
415
|
-
// GitHub
|
|
416
|
-
if (ctx.providerManager.github && results.providers.github?.success) {
|
|
417
|
-
try {
|
|
418
|
-
await ctx.providerManager.github.rest.issues.create({
|
|
419
|
-
owner: githubOwner,
|
|
420
|
-
repo: repoName,
|
|
421
|
-
title: historyTitle,
|
|
422
|
-
body: historyBody,
|
|
423
|
-
labels: ['git-history', 'automated'],
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
catch (err) {
|
|
427
|
-
console.warn('Failed to create GitHub history issue:', err);
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
// Gitea
|
|
431
|
-
if (ctx.providerManager.giteaBaseUrl && results.providers.gitea?.success) {
|
|
432
|
-
try {
|
|
433
|
-
await axios.post(`${ctx.providerManager.giteaBaseUrl}/api/v1/repos/${giteaOwner}/${repoName}/issues`, {
|
|
434
|
-
title: historyTitle,
|
|
435
|
-
body: historyBody,
|
|
436
|
-
labels: [1], // Assumindo label ID 1 para git-history
|
|
437
|
-
}, { headers: { Authorization: `token ${ctx.providerManager.giteaToken}` } });
|
|
438
|
-
}
|
|
439
|
-
catch (err) {
|
|
440
|
-
console.warn('Failed to create Gitea history issue:', err);
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
formatHistoryIssue(results) {
|
|
445
|
-
return `
|
|
446
|
-
## 📋 Git Update History
|
|
447
|
-
|
|
448
|
-
**Timestamp:** ${results.timestamp}
|
|
449
|
-
**Branch:** ${results.branch}
|
|
450
|
-
**Commit:** ${results.traceability.commit?.hash || 'N/A'}
|
|
451
|
-
|
|
452
|
-
### 📝 Changes Summary
|
|
453
|
-
${results.traceability.commit?.summary || 'No commit made'}
|
|
454
|
-
|
|
455
|
-
**Files Changed:** ${results.traceability.changedFiles.length}
|
|
456
|
-
**Insertions:** ${results.traceability.commit?.inserted || 0}
|
|
457
|
-
**Deletions:** ${results.traceability.commit?.deleted || 0}
|
|
458
|
-
|
|
459
|
-
### 📁 Changed Files
|
|
460
|
-
${results.traceability.changedFiles.map((f) => `- [${f.status}] ${f.file}`).join('\n') || 'No files changed'}
|
|
461
|
-
|
|
462
|
-
### 🔄 Provider Status
|
|
463
|
-
- **GitHub:** ${results.providers.github?.success ? '✅ Success' : '❌ Failed'}
|
|
464
|
-
- **Gitea:** ${results.providers.gitea?.success ? '✅ Success' : '❌ Failed'}
|
|
465
|
-
|
|
466
|
-
### 🔗 Links
|
|
467
|
-
${results.providers.github?.commitUrl ? `- GitHub: ${results.providers.github.commitUrl}` : ''}
|
|
468
|
-
${results.providers.gitea?.commitUrl ? `- Gitea: ${results.providers.gitea.commitUrl}` : ''}
|
|
469
|
-
|
|
470
|
-
---
|
|
471
|
-
*Generated by git-mcp git-update tool*
|
|
472
|
-
`;
|
|
473
|
-
}
|
|
474
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { Tool, MCPContext } from '../types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Git Upload Tool - Envia projeto completo para GitHub e Gitea automaticamente
|
|
4
|
-
* Modo DUAL automático com rastreabilidade completa
|
|
5
|
-
* VERSÃO SEGURA: Remove tokens das URLs e usa autenticação segura
|
|
6
|
-
*/
|
|
7
|
-
export declare class GitUploadTool implements Tool {
|
|
8
|
-
name: string;
|
|
9
|
-
description: string;
|
|
10
|
-
inputSchema: {
|
|
11
|
-
type: "object";
|
|
12
|
-
properties: {
|
|
13
|
-
projectPath: {
|
|
14
|
-
type: string;
|
|
15
|
-
description: string;
|
|
16
|
-
};
|
|
17
|
-
description: {
|
|
18
|
-
type: string;
|
|
19
|
-
description: string;
|
|
20
|
-
};
|
|
21
|
-
private: {
|
|
22
|
-
type: string;
|
|
23
|
-
description: string;
|
|
24
|
-
};
|
|
25
|
-
repoName: {
|
|
26
|
-
type: string;
|
|
27
|
-
description: string;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
required: string[];
|
|
31
|
-
additionalProperties: boolean;
|
|
32
|
-
};
|
|
33
|
-
handle(params: Record<string, any>, ctx: MCPContext): Promise<any>;
|
|
34
|
-
private saveUploadHistory;
|
|
35
|
-
}
|