@andrebuzeli/git-mcp 5.4.0 → 5.4.2

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.
Files changed (49) hide show
  1. package/dist/tools/git-analytics.d.ts.map +1 -1
  2. package/dist/tools/git-analytics.js +11 -1
  3. package/dist/tools/git-analytics.js.map +1 -1
  4. package/dist/tools/git-issues.d.ts +12 -0
  5. package/dist/tools/git-issues.d.ts.map +1 -1
  6. package/dist/tools/git-issues.js +40 -13
  7. package/dist/tools/git-issues.js.map +1 -1
  8. package/dist/tools/git-pulls.d.ts +12 -0
  9. package/dist/tools/git-pulls.d.ts.map +1 -1
  10. package/dist/tools/git-pulls.js +40 -13
  11. package/dist/tools/git-pulls.js.map +1 -1
  12. package/dist/tools/git-tags.js +1 -1
  13. package/dist/tools/git-tags.js.map +1 -1
  14. package/dist/utils/parameter-validator.d.ts.map +1 -1
  15. package/dist/utils/parameter-validator.js +7 -3
  16. package/dist/utils/parameter-validator.js.map +1 -1
  17. package/package.json +10 -12
  18. package/dist/__tests__/setup.d.ts +0 -10
  19. package/dist/__tests__/setup.d.ts.map +0 -1
  20. package/dist/__tests__/setup.js +0 -105
  21. package/dist/__tests__/setup.js.map +0 -1
  22. package/dist/tools/git-automations.d.ts +0 -257
  23. package/dist/tools/git-automations.d.ts.map +0 -1
  24. package/dist/tools/git-automations.js +0 -878
  25. package/dist/tools/git-automations.js.map +0 -1
  26. package/dist/tools/git-bisect.d.ts +0 -158
  27. package/dist/tools/git-bisect.d.ts.map +0 -1
  28. package/dist/tools/git-bisect.js +0 -571
  29. package/dist/tools/git-bisect.js.map +0 -1
  30. package/dist/tools/git-changelog.d.ts +0 -253
  31. package/dist/tools/git-changelog.d.ts.map +0 -1
  32. package/dist/tools/git-changelog.js +0 -728
  33. package/dist/tools/git-changelog.js.map +0 -1
  34. package/dist/tools/git-cherry-pick.d.ts +0 -150
  35. package/dist/tools/git-cherry-pick.d.ts.map +0 -1
  36. package/dist/tools/git-cherry-pick.js +0 -455
  37. package/dist/tools/git-cherry-pick.js.map +0 -1
  38. package/dist/tools/git-dependencies.d.ts +0 -233
  39. package/dist/tools/git-dependencies.d.ts.map +0 -1
  40. package/dist/tools/git-dependencies.js +0 -761
  41. package/dist/tools/git-dependencies.js.map +0 -1
  42. package/dist/tools/git-hooks.d.ts +0 -146
  43. package/dist/tools/git-hooks.d.ts.map +0 -1
  44. package/dist/tools/git-hooks.js +0 -634
  45. package/dist/tools/git-hooks.js.map +0 -1
  46. package/dist/tools/git-stats-personal.d.ts +0 -210
  47. package/dist/tools/git-stats-personal.d.ts.map +0 -1
  48. package/dist/tools/git-stats-personal.js +0 -718
  49. package/dist/tools/git-stats-personal.js.map +0 -1
@@ -1,878 +0,0 @@
1
- "use strict";
2
- /**
3
- * Git Automations Tool
4
- *
5
- * Custom automation tool providing comprehensive Git workflow automation.
6
- * Supports creating, managing, and executing custom Git workflows and sequences.
7
- *
8
- * Operations: create, list, run, update, delete, schedule, enable, disable
9
- */
10
- var __importDefault = (this && this.__importDefault) || function (mod) {
11
- return (mod && mod.__esModule) ? mod : { "default": mod };
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.GitAutomationsTool = void 0;
15
- const git_command_executor_js_1 = require("../utils/git-command-executor.js");
16
- const parameter_validator_js_1 = require("../utils/parameter-validator.js");
17
- const operation_error_handler_js_1 = require("../utils/operation-error-handler.js");
18
- const fs_1 = __importDefault(require("fs"));
19
- const path_1 = __importDefault(require("path"));
20
- class GitAutomationsTool {
21
- gitExecutor;
22
- automationsPath;
23
- // Built-in automation templates
24
- templates = {
25
- 'release-workflow': {
26
- name: 'Release Workflow',
27
- description: 'Automated release workflow with versioning and tagging',
28
- commands: [
29
- 'npm version patch',
30
- 'git push origin --follow-tags',
31
- 'npm publish'
32
- ],
33
- trigger: 'manual',
34
- category: 'release'
35
- },
36
- 'dependency-update': {
37
- name: 'Dependency Update',
38
- description: 'Update dependencies and create PR',
39
- commands: [
40
- 'npm update',
41
- 'npm audit fix',
42
- 'git add package*.json',
43
- 'git commit -m "chore: update dependencies"',
44
- 'git push origin HEAD'
45
- ],
46
- trigger: 'schedule',
47
- schedule: '0 0 * * 0', // Weekly
48
- category: 'maintenance'
49
- },
50
- 'code-quality': {
51
- name: 'Code Quality Check',
52
- description: 'Run linting, testing, and formatting',
53
- commands: [
54
- 'npm run lint',
55
- 'npm run test',
56
- 'npm run format'
57
- ],
58
- trigger: 'pre-commit',
59
- category: 'quality'
60
- },
61
- 'deployment': {
62
- name: 'Deployment Workflow',
63
- description: 'Build and deploy application',
64
- commands: [
65
- 'npm run build',
66
- 'npm run test',
67
- 'npm run deploy'
68
- ],
69
- trigger: 'post-merge',
70
- conditions: { branch: 'main' },
71
- category: 'deployment'
72
- },
73
- 'backup': {
74
- name: 'Repository Backup',
75
- description: 'Create repository backup',
76
- commands: [
77
- 'git bundle create backup-$(date +%Y%m%d).bundle --all',
78
- 'tar -czf backup-$(date +%Y%m%d).tar.gz .git'
79
- ],
80
- trigger: 'schedule',
81
- schedule: '0 2 * * *', // Daily at 2 AM
82
- category: 'backup'
83
- }
84
- };
85
- constructor() {
86
- this.gitExecutor = new git_command_executor_js_1.GitCommandExecutor();
87
- this.automationsPath = path_1.default.join(process.cwd(), '.git-automations');
88
- }
89
- /**
90
- * Execute git-automations operation
91
- */
92
- async execute(params) {
93
- const startTime = Date.now();
94
- try {
95
- // Validate basic parameters
96
- const validation = parameter_validator_js_1.ParameterValidator.validateToolParams('git-automations', params);
97
- if (!validation.isValid) {
98
- return operation_error_handler_js_1.OperationErrorHandler.createToolError('VALIDATION_ERROR', `Parameter validation failed: ${validation.errors.join(', ')}`, params.action, { validationErrors: validation.errors }, validation.suggestions);
99
- }
100
- // Validate operation-specific parameters
101
- const operationValidation = parameter_validator_js_1.ParameterValidator.validateOperationParams('git-automations', params.action, params);
102
- if (!operationValidation.isValid) {
103
- return operation_error_handler_js_1.OperationErrorHandler.createToolError('VALIDATION_ERROR', `Operation validation failed: ${operationValidation.errors.join(', ')}`, params.action, { validationErrors: operationValidation.errors }, operationValidation.suggestions);
104
- }
105
- // Ensure automations directory exists
106
- this.ensureAutomationsDirectory();
107
- // Route to appropriate handler
108
- switch (params.action) {
109
- case 'create':
110
- return await this.handleCreate(params, startTime);
111
- case 'list':
112
- return await this.handleList(params, startTime);
113
- case 'run':
114
- return await this.handleRun(params, startTime);
115
- case 'update':
116
- return await this.handleUpdate(params, startTime);
117
- case 'delete':
118
- return await this.handleDelete(params, startTime);
119
- case 'schedule':
120
- return await this.handleSchedule(params, startTime);
121
- case 'enable':
122
- return await this.handleEnable(params, startTime);
123
- case 'disable':
124
- return await this.handleDisable(params, startTime);
125
- default:
126
- return operation_error_handler_js_1.OperationErrorHandler.createToolError('INVALID_ACTION', `Unknown action: ${params.action}`, params.action, { supportedActions: ['create', 'list', 'run', 'update', 'delete', 'schedule', 'enable', 'disable'] }, ['Use one of the supported actions']);
127
- }
128
- }
129
- catch (error) {
130
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
131
- return operation_error_handler_js_1.OperationErrorHandler.createToolError('EXECUTION_ERROR', `Failed to execute ${params.action}: ${errorMessage}`, params.action, { error: errorMessage }, ['Check the error details and try again']);
132
- }
133
- }
134
- /**
135
- * Create automation
136
- */
137
- async handleCreate(params, startTime) {
138
- try {
139
- if (!params.name) {
140
- return operation_error_handler_js_1.OperationErrorHandler.createToolError('MISSING_NAME', 'Name is required for creating automation', params.action, { name: params.name }, ['Provide name parameter']);
141
- }
142
- // Check if automation already exists
143
- const existingAutomation = this.getAutomation(params.name);
144
- if (existingAutomation) {
145
- return operation_error_handler_js_1.OperationErrorHandler.createToolError('AUTOMATION_EXISTS', `Automation '${params.name}' already exists`, params.action, { name: params.name }, ['Use update action to modify existing automation', 'Use different name']);
146
- }
147
- const automation = this.createAutomationDefinition(params);
148
- this.saveAutomation(automation);
149
- const executionTime = Date.now() - startTime;
150
- return {
151
- success: true,
152
- data: {
153
- automation: {
154
- id: automation.id,
155
- name: automation.name,
156
- trigger: automation.trigger,
157
- enabled: automation.enabled,
158
- commands: automation.commands.length,
159
- created: automation.created
160
- },
161
- message: `Automation '${params.name}' created successfully`,
162
- executionTime
163
- }
164
- };
165
- }
166
- catch (error) {
167
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
168
- return operation_error_handler_js_1.OperationErrorHandler.createToolError('CREATE_ERROR', `Failed to create automation: ${errorMessage}`, params.action, { name: params.name, error: errorMessage }, ['Check automation definition', 'Verify permissions']);
169
- }
170
- }
171
- /**
172
- * List automations
173
- */
174
- async handleList(params, startTime) {
175
- try {
176
- const automations = this.getAllAutomations();
177
- // Apply filters
178
- let filteredAutomations = automations;
179
- if (params.filter) {
180
- filteredAutomations = automations.filter(automation => automation.name.includes(params.filter) ||
181
- automation.description?.includes(params.filter));
182
- }
183
- if (params.category) {
184
- filteredAutomations = filteredAutomations.filter(automation => automation.category === params.category);
185
- }
186
- const executionTime = Date.now() - startTime;
187
- return {
188
- success: true,
189
- data: {
190
- automations: filteredAutomations.map(automation => ({
191
- id: automation.id,
192
- name: automation.name,
193
- description: automation.description,
194
- trigger: automation.trigger,
195
- enabled: automation.enabled,
196
- category: automation.category,
197
- commands: automation.commands.length,
198
- created: automation.created,
199
- lastRun: automation.lastRun
200
- })),
201
- count: filteredAutomations.length,
202
- message: `Found ${filteredAutomations.length} automations`,
203
- executionTime
204
- }
205
- };
206
- }
207
- catch (error) {
208
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
209
- return operation_error_handler_js_1.OperationErrorHandler.createToolError('LIST_ERROR', `Failed to list automations: ${errorMessage}`, params.action, { error: errorMessage }, ['Check automations directory permissions']);
210
- }
211
- }
212
- /**
213
- * Run automation
214
- */
215
- async handleRun(params, startTime) {
216
- try {
217
- if (!params.name && !params.id) {
218
- return operation_error_handler_js_1.OperationErrorHandler.createToolError('MISSING_IDENTIFIER', 'Either name or id is required for running automation', params.action, { name: params.name, id: params.id }, ['Provide name or id parameter']);
219
- }
220
- const automation = params.name ? this.getAutomation(params.name) : this.getAutomationById(params.id);
221
- if (!automation) {
222
- return operation_error_handler_js_1.OperationErrorHandler.createToolError('AUTOMATION_NOT_FOUND', `Automation not found: ${params.name || params.id}`, params.action, { name: params.name, id: params.id }, ['Check automation name/id', 'Use list action to see available automations']);
223
- }
224
- if (!automation.enabled) {
225
- return operation_error_handler_js_1.OperationErrorHandler.createToolError('AUTOMATION_DISABLED', `Automation '${automation.name}' is disabled`, params.action, { name: automation.name }, ['Enable the automation first', 'Use enable action']);
226
- }
227
- const result = await this.executeAutomation(automation, params);
228
- const executionTime = Date.now() - startTime;
229
- return {
230
- success: result.success,
231
- data: {
232
- automation: {
233
- id: automation.id,
234
- name: automation.name,
235
- execution: result
236
- },
237
- message: `Automation '${automation.name}' ${result.success ? 'executed successfully' : 'execution failed'}`,
238
- executionTime
239
- }
240
- };
241
- }
242
- catch (error) {
243
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
244
- return operation_error_handler_js_1.OperationErrorHandler.createToolError('RUN_ERROR', `Failed to run automation: ${errorMessage}`, params.action, { name: params.name, id: params.id, error: errorMessage }, ['Check automation definition', 'Verify commands are valid']);
245
- }
246
- }
247
- /**
248
- * Update automation
249
- */
250
- async handleUpdate(params, startTime) {
251
- try {
252
- if (!params.name && !params.id) {
253
- return operation_error_handler_js_1.OperationErrorHandler.createToolError('MISSING_IDENTIFIER', 'Either name or id is required for updating automation', params.action, { name: params.name, id: params.id }, ['Provide name or id parameter']);
254
- }
255
- const existingAutomation = params.name ? this.getAutomation(params.name) : this.getAutomationById(params.id);
256
- if (!existingAutomation) {
257
- return operation_error_handler_js_1.OperationErrorHandler.createToolError('AUTOMATION_NOT_FOUND', `Automation not found: ${params.name || params.id}`, params.action, { name: params.name, id: params.id }, ['Check automation name/id', 'Use list action to see available automations']);
258
- }
259
- const updatedAutomation = this.updateAutomationDefinition(existingAutomation, params);
260
- this.saveAutomation(updatedAutomation);
261
- const executionTime = Date.now() - startTime;
262
- return {
263
- success: true,
264
- data: {
265
- automation: {
266
- id: updatedAutomation.id,
267
- name: updatedAutomation.name,
268
- trigger: updatedAutomation.trigger,
269
- enabled: updatedAutomation.enabled,
270
- commands: updatedAutomation.commands.length,
271
- updated: updatedAutomation.updated
272
- },
273
- message: `Automation '${updatedAutomation.name}' updated successfully`,
274
- executionTime
275
- }
276
- };
277
- }
278
- catch (error) {
279
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
280
- return operation_error_handler_js_1.OperationErrorHandler.createToolError('UPDATE_ERROR', `Failed to update automation: ${errorMessage}`, params.action, { name: params.name, id: params.id, error: errorMessage }, ['Check automation definition', 'Verify permissions']);
281
- }
282
- }
283
- /**
284
- * Delete automation
285
- */
286
- async handleDelete(params, startTime) {
287
- try {
288
- if (!params.name && !params.id) {
289
- return operation_error_handler_js_1.OperationErrorHandler.createToolError('MISSING_IDENTIFIER', 'Either name or id is required for deleting automation', params.action, { name: params.name, id: params.id }, ['Provide name or id parameter']);
290
- }
291
- const automation = params.name ? this.getAutomation(params.name) : this.getAutomationById(params.id);
292
- if (!automation) {
293
- return operation_error_handler_js_1.OperationErrorHandler.createToolError('AUTOMATION_NOT_FOUND', `Automation not found: ${params.name || params.id}`, params.action, { name: params.name, id: params.id }, ['Check automation name/id', 'Use list action to see available automations']);
294
- }
295
- this.deleteAutomation(automation.id);
296
- const executionTime = Date.now() - startTime;
297
- return {
298
- success: true,
299
- data: {
300
- automation: {
301
- id: automation.id,
302
- name: automation.name,
303
- deleted: true
304
- },
305
- message: `Automation '${automation.name}' deleted successfully`,
306
- executionTime
307
- }
308
- };
309
- }
310
- catch (error) {
311
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
312
- return operation_error_handler_js_1.OperationErrorHandler.createToolError('DELETE_ERROR', `Failed to delete automation: ${errorMessage}`, params.action, { name: params.name, id: params.id, error: errorMessage }, ['Check automation exists', 'Verify permissions']);
313
- }
314
- }
315
- /**
316
- * Schedule automation
317
- */
318
- async handleSchedule(params, startTime) {
319
- try {
320
- if (!params.name && !params.id) {
321
- return operation_error_handler_js_1.OperationErrorHandler.createToolError('MISSING_IDENTIFIER', 'Either name or id is required for scheduling automation', params.action, { name: params.name, id: params.id }, ['Provide name or id parameter']);
322
- }
323
- const automation = params.name ? this.getAutomation(params.name) : this.getAutomationById(params.id);
324
- if (!automation) {
325
- return operation_error_handler_js_1.OperationErrorHandler.createToolError('AUTOMATION_NOT_FOUND', `Automation not found: ${params.name || params.id}`, params.action, { name: params.name, id: params.id }, ['Check automation name/id', 'Use list action to see available automations']);
326
- }
327
- // Update automation with schedule
328
- automation.schedule = params.schedule;
329
- automation.trigger = 'schedule';
330
- this.saveAutomation(automation);
331
- const executionTime = Date.now() - startTime;
332
- return {
333
- success: true,
334
- data: {
335
- automation: {
336
- id: automation.id,
337
- name: automation.name,
338
- schedule: automation.schedule,
339
- trigger: automation.trigger
340
- },
341
- message: `Automation '${automation.name}' scheduled successfully`,
342
- executionTime
343
- }
344
- };
345
- }
346
- catch (error) {
347
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
348
- return operation_error_handler_js_1.OperationErrorHandler.createToolError('SCHEDULE_ERROR', `Failed to schedule automation: ${errorMessage}`, params.action, { name: params.name, id: params.id, error: errorMessage }, ['Check schedule format', 'Verify automation exists']);
349
- }
350
- }
351
- /**
352
- * Enable automation
353
- */
354
- async handleEnable(params, startTime) {
355
- try {
356
- if (!params.name && !params.id) {
357
- return operation_error_handler_js_1.OperationErrorHandler.createToolError('MISSING_IDENTIFIER', 'Either name or id is required for enabling automation', params.action, { name: params.name, id: params.id }, ['Provide name or id parameter']);
358
- }
359
- const automation = params.name ? this.getAutomation(params.name) : this.getAutomationById(params.id);
360
- if (!automation) {
361
- return operation_error_handler_js_1.OperationErrorHandler.createToolError('AUTOMATION_NOT_FOUND', `Automation not found: ${params.name || params.id}`, params.action, { name: params.name, id: params.id }, ['Check automation name/id', 'Use list action to see available automations']);
362
- }
363
- automation.enabled = true;
364
- this.saveAutomation(automation);
365
- const executionTime = Date.now() - startTime;
366
- return {
367
- success: true,
368
- data: {
369
- automation: {
370
- id: automation.id,
371
- name: automation.name,
372
- enabled: automation.enabled
373
- },
374
- message: `Automation '${automation.name}' enabled successfully`,
375
- executionTime
376
- }
377
- };
378
- }
379
- catch (error) {
380
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
381
- return operation_error_handler_js_1.OperationErrorHandler.createToolError('ENABLE_ERROR', `Failed to enable automation: ${errorMessage}`, params.action, { name: params.name, id: params.id, error: errorMessage }, ['Check automation exists', 'Verify permissions']);
382
- }
383
- }
384
- /**
385
- * Disable automation
386
- */
387
- async handleDisable(params, startTime) {
388
- try {
389
- if (!params.name && !params.id) {
390
- return operation_error_handler_js_1.OperationErrorHandler.createToolError('MISSING_IDENTIFIER', 'Either name or id is required for disabling automation', params.action, { name: params.name, id: params.id }, ['Provide name or id parameter']);
391
- }
392
- const automation = params.name ? this.getAutomation(params.name) : this.getAutomationById(params.id);
393
- if (!automation) {
394
- return operation_error_handler_js_1.OperationErrorHandler.createToolError('AUTOMATION_NOT_FOUND', `Automation not found: ${params.name || params.id}`, params.action, { name: params.name, id: params.id }, ['Check automation name/id', 'Use list action to see available automations']);
395
- }
396
- automation.enabled = false;
397
- this.saveAutomation(automation);
398
- const executionTime = Date.now() - startTime;
399
- return {
400
- success: true,
401
- data: {
402
- automation: {
403
- id: automation.id,
404
- name: automation.name,
405
- enabled: automation.enabled
406
- },
407
- message: `Automation '${automation.name}' disabled successfully`,
408
- executionTime
409
- }
410
- };
411
- }
412
- catch (error) {
413
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
414
- return operation_error_handler_js_1.OperationErrorHandler.createToolError('DISABLE_ERROR', `Failed to disable automation: ${errorMessage}`, params.action, { name: params.name, id: params.id, error: errorMessage }, ['Check automation exists', 'Verify permissions']);
415
- }
416
- }
417
- /**
418
- * Ensure automations directory exists
419
- */
420
- ensureAutomationsDirectory() {
421
- if (!fs_1.default.existsSync(this.automationsPath)) {
422
- fs_1.default.mkdirSync(this.automationsPath, { recursive: true });
423
- }
424
- }
425
- /**
426
- * Create automation definition
427
- */
428
- createAutomationDefinition(params) {
429
- const id = params.id || this.generateId();
430
- const now = new Date().toISOString();
431
- return {
432
- id,
433
- name: params.name,
434
- description: this.getAutomationDescription(params),
435
- commands: params.commands || [],
436
- script: params.script || '',
437
- trigger: params.trigger || 'manual',
438
- schedule: params.schedule,
439
- conditions: params.conditions || {},
440
- parallel: params.parallel || false,
441
- continueOnError: params.continueOnError || false,
442
- timeout: params.timeout || 300,
443
- retries: params.retries || 0,
444
- workingDirectory: params.workingDirectory,
445
- environment: params.environment || {},
446
- context: params.context || {},
447
- createBranch: params.createBranch || false,
448
- autoCommit: params.autoCommit || false,
449
- createPR: params.createPR || false,
450
- enabled: params.enabled !== false,
451
- category: params.category || 'custom',
452
- created: now,
453
- updated: now,
454
- lastRun: null
455
- };
456
- }
457
- /**
458
- * Update automation definition
459
- */
460
- updateAutomationDefinition(existing, params) {
461
- const updated = { ...existing };
462
- if (params.commands)
463
- updated.commands = params.commands;
464
- if (params.script)
465
- updated.script = params.script;
466
- if (params.trigger)
467
- updated.trigger = params.trigger;
468
- if (params.schedule !== undefined)
469
- updated.schedule = params.schedule;
470
- if (params.conditions)
471
- updated.conditions = params.conditions;
472
- if (params.parallel !== undefined)
473
- updated.parallel = params.parallel;
474
- if (params.continueOnError !== undefined)
475
- updated.continueOnError = params.continueOnError;
476
- if (params.timeout !== undefined)
477
- updated.timeout = params.timeout;
478
- if (params.retries !== undefined)
479
- updated.retries = params.retries;
480
- if (params.workingDirectory)
481
- updated.workingDirectory = params.workingDirectory;
482
- if (params.environment)
483
- updated.environment = { ...updated.environment, ...params.environment };
484
- if (params.context)
485
- updated.context = { ...updated.context, ...params.context };
486
- if (params.createBranch !== undefined)
487
- updated.createBranch = params.createBranch;
488
- if (params.autoCommit !== undefined)
489
- updated.autoCommit = params.autoCommit;
490
- if (params.createPR !== undefined)
491
- updated.createPR = params.createPR;
492
- if (params.enabled !== undefined)
493
- updated.enabled = params.enabled;
494
- if (params.category)
495
- updated.category = params.category;
496
- updated.updated = new Date().toISOString();
497
- return updated;
498
- }
499
- /**
500
- * Execute automation
501
- */
502
- async executeAutomation(automation, params) {
503
- const startTime = Date.now();
504
- const results = [];
505
- let success = true;
506
- let error = null;
507
- try {
508
- // Create branch if requested
509
- let branchName = '';
510
- if (automation.createBranch && !params.dryRun) {
511
- branchName = `automation-${automation.name}-${Date.now()}`;
512
- await this.createBranch(branchName, params.projectPath);
513
- }
514
- // Set working directory
515
- const workingDir = automation.workingDirectory || params.projectPath;
516
- // Execute commands
517
- if (automation.commands && automation.commands.length > 0) {
518
- for (let i = 0; i < automation.commands.length; i++) {
519
- const command = automation.commands[i];
520
- try {
521
- const result = await this.gitExecutor.executeGitCommand(command, workingDir);
522
- results.push({
523
- command,
524
- success: result.success,
525
- output: result.stdout,
526
- error: result.stderr,
527
- exitCode: result.exitCode
528
- });
529
- if (!result.success && !automation.continueOnError) {
530
- success = false;
531
- error = result.stderr || 'Command failed';
532
- break;
533
- }
534
- }
535
- catch (cmdError) {
536
- results.push({
537
- command,
538
- success: false,
539
- output: '',
540
- error: cmdError instanceof Error ? cmdError.message : 'Unknown error',
541
- exitCode: 1
542
- });
543
- if (!automation.continueOnError) {
544
- success = false;
545
- error = cmdError instanceof Error ? cmdError.message : 'Unknown error';
546
- break;
547
- }
548
- }
549
- }
550
- }
551
- // Execute script if provided
552
- if (automation.script && !error) {
553
- try {
554
- const scriptResult = await this.executeScript(automation.script, workingDir);
555
- results.push({
556
- command: 'custom-script',
557
- success: scriptResult.success,
558
- output: scriptResult.stdout,
559
- error: scriptResult.stderr,
560
- exitCode: scriptResult.exitCode
561
- });
562
- if (!scriptResult.success && !automation.continueOnError) {
563
- success = false;
564
- error = scriptResult.stderr || 'Script failed';
565
- }
566
- }
567
- catch (scriptError) {
568
- results.push({
569
- command: 'custom-script',
570
- success: false,
571
- output: '',
572
- error: scriptError instanceof Error ? scriptError.message : 'Unknown error',
573
- exitCode: 1
574
- });
575
- if (!automation.continueOnError) {
576
- success = false;
577
- error = scriptError instanceof Error ? scriptError.message : 'Unknown error';
578
- }
579
- }
580
- }
581
- // Auto-commit if requested and successful
582
- if (success && automation.autoCommit && !params.dryRun) {
583
- try {
584
- await this.autoCommit(automation.name, params.projectPath);
585
- }
586
- catch (commitError) {
587
- error = commitError instanceof Error ? commitError.message : 'Auto-commit failed';
588
- success = false;
589
- }
590
- }
591
- // Update automation with last run info
592
- automation.lastRun = {
593
- timestamp: new Date().toISOString(),
594
- success,
595
- error,
596
- duration: Date.now() - startTime,
597
- results
598
- };
599
- this.saveAutomation(automation);
600
- return {
601
- success,
602
- error,
603
- results,
604
- duration: Date.now() - startTime,
605
- branchName
606
- };
607
- }
608
- catch (execError) {
609
- return {
610
- success: false,
611
- error: execError instanceof Error ? execError.message : 'Unknown error',
612
- results,
613
- duration: Date.now() - startTime
614
- };
615
- }
616
- }
617
- /**
618
- * Execute custom script
619
- */
620
- async executeScript(script, workingDir) {
621
- // Write script to temporary file
622
- const scriptPath = path_1.default.join(workingDir, 'temp-script.sh');
623
- fs_1.default.writeFileSync(scriptPath, script, 'utf8');
624
- fs_1.default.chmodSync(scriptPath, '755');
625
- try {
626
- const result = await this.gitExecutor.executeGitCommand('./temp-script.sh', [], workingDir);
627
- return result;
628
- }
629
- finally {
630
- // Clean up script file
631
- if (fs_1.default.existsSync(scriptPath)) {
632
- fs_1.default.unlinkSync(scriptPath);
633
- }
634
- }
635
- }
636
- /**
637
- * Create branch for automation
638
- */
639
- async createBranch(branchName, projectPath) {
640
- const result = await this.gitExecutor.executeGitCommand('git', ['checkout', '-b', branchName], projectPath);
641
- if (!result.success) {
642
- throw new Error(`Failed to create branch: ${result.stderr}`);
643
- }
644
- }
645
- /**
646
- * Auto-commit changes
647
- */
648
- async autoCommit(automationName, projectPath) {
649
- // Add all changes
650
- await this.gitExecutor.executeGitCommand('git', ['add', '.'], projectPath);
651
- // Commit with automation name
652
- const commitMessage = `chore: automated changes by ${automationName}`;
653
- const result = await this.gitExecutor.executeGitCommand('git', ['commit', '-m', commitMessage], projectPath);
654
- if (!result.success) {
655
- throw new Error(`Failed to auto-commit: ${result.stderr}`);
656
- }
657
- }
658
- /**
659
- * Save automation to file
660
- */
661
- saveAutomation(automation) {
662
- const filePath = path_1.default.join(this.automationsPath, `${automation.id}.json`);
663
- fs_1.default.writeFileSync(filePath, JSON.stringify(automation, null, 2), 'utf8');
664
- }
665
- /**
666
- * Get automation by name
667
- */
668
- getAutomation(name) {
669
- const automations = this.getAllAutomations();
670
- return automations.find(a => a.name === name) || null;
671
- }
672
- /**
673
- * Get automation by ID
674
- */
675
- getAutomationById(id) {
676
- const filePath = path_1.default.join(this.automationsPath, `${id}.json`);
677
- if (!fs_1.default.existsSync(filePath)) {
678
- return null;
679
- }
680
- try {
681
- const content = fs_1.default.readFileSync(filePath, 'utf8');
682
- return JSON.parse(content);
683
- }
684
- catch {
685
- return null;
686
- }
687
- }
688
- /**
689
- * Get all automations
690
- */
691
- getAllAutomations() {
692
- if (!fs_1.default.existsSync(this.automationsPath)) {
693
- return [];
694
- }
695
- const files = fs_1.default.readdirSync(this.automationsPath);
696
- const automations = [];
697
- for (const file of files) {
698
- if (file.endsWith('.json')) {
699
- const filePath = path_1.default.join(this.automationsPath, file);
700
- try {
701
- const content = fs_1.default.readFileSync(filePath, 'utf8');
702
- const automation = JSON.parse(content);
703
- automations.push(automation);
704
- }
705
- catch {
706
- // Skip invalid files
707
- }
708
- }
709
- }
710
- return automations;
711
- }
712
- /**
713
- * Delete automation
714
- */
715
- deleteAutomation(id) {
716
- const filePath = path_1.default.join(this.automationsPath, `${id}.json`);
717
- if (fs_1.default.existsSync(filePath)) {
718
- fs_1.default.unlinkSync(filePath);
719
- }
720
- }
721
- /**
722
- * Generate unique ID
723
- */
724
- generateId() {
725
- return `automation-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
726
- }
727
- /**
728
- * Get automation description
729
- */
730
- getAutomationDescription(params) {
731
- if (params.description) {
732
- return params.description;
733
- }
734
- // Generate description based on commands
735
- if (params.commands && params.commands.length > 0) {
736
- return `Automation with ${params.commands.length} commands`;
737
- }
738
- if (params.script) {
739
- return 'Custom script automation';
740
- }
741
- return 'Custom automation';
742
- }
743
- /**
744
- * Get tool schema for MCP registration
745
- */
746
- static getToolSchema() {
747
- return {
748
- name: 'git-automations',
749
- description: 'Custom workflow automation tool. Create and manage automated Git workflows with triggers, scheduling, and execution monitoring.',
750
- inputSchema: {
751
- type: 'object',
752
- properties: {
753
- "action": {
754
- "type": "string",
755
- "enum": [
756
- "create",
757
- "list",
758
- "run",
759
- "update",
760
- "delete",
761
- "schedule",
762
- "enable",
763
- "disable"
764
- ],
765
- "description": "The operation to perform"
766
- },
767
- "projectPath": {
768
- "type": "string",
769
- "description": "Path to the Git repository"
770
- },
771
- "name": {
772
- "type": "string",
773
- "description": "name parameter"
774
- },
775
- "id": {
776
- "type": "string",
777
- "description": "id parameter"
778
- },
779
- "commands": {
780
- "type": "array",
781
- "items": {
782
- "type": "string"
783
- },
784
- "description": "commands parameter"
785
- },
786
- "script": {
787
- "type": "string",
788
- "description": "script parameter"
789
- },
790
- "workflow": {
791
- "type": "object",
792
- "description": "workflow parameter"
793
- },
794
- "trigger": {
795
- "type": "string",
796
- "description": "trigger parameter"
797
- },
798
- "schedule": {
799
- "type": "string",
800
- "description": "schedule parameter"
801
- },
802
- "conditions": {
803
- "type": "object",
804
- "description": "conditions parameter"
805
- },
806
- "parallel": {
807
- "type": "string",
808
- "description": "parallel parameter"
809
- },
810
- "continueOnError": {
811
- "type": "string",
812
- "description": "continueOnError parameter"
813
- },
814
- "timeout": {
815
- "type": "string",
816
- "description": "timeout parameter"
817
- },
818
- "retries": {
819
- "type": "string",
820
- "description": "retries parameter"
821
- },
822
- "workingDirectory": {
823
- "type": "string",
824
- "description": "workingDirectory parameter"
825
- },
826
- "environment": {
827
- "type": "object",
828
- "description": "environment parameter"
829
- },
830
- "context": {
831
- "type": "object",
832
- "description": "context parameter"
833
- },
834
- "createBranch": {
835
- "type": "string",
836
- "description": "createBranch parameter"
837
- },
838
- "autoCommit": {
839
- "type": "string",
840
- "description": "autoCommit parameter"
841
- },
842
- "createPR": {
843
- "type": "string",
844
- "description": "createPR parameter"
845
- },
846
- "enabled": {
847
- "type": "string",
848
- "description": "enabled parameter"
849
- },
850
- "dryRun": {
851
- "type": "string",
852
- "description": "dryRun parameter"
853
- },
854
- "verbose": {
855
- "type": "string",
856
- "description": "verbose parameter"
857
- },
858
- "filter": {
859
- "type": "string",
860
- "description": "filter parameter"
861
- },
862
- "category": {
863
- "type": "string",
864
- "description": "category parameter"
865
- }
866
- },
867
- required: ['action', 'projectPath'],
868
- additionalProperties: false
869
- },
870
- errorCodes: {
871
- 'VALIDATION_ERROR': 'Parameter validation failed',
872
- 'EXECUTION_ERROR': 'Tool execution failed'
873
- }
874
- };
875
- }
876
- }
877
- exports.GitAutomationsTool = GitAutomationsTool;
878
- //# sourceMappingURL=git-automations.js.map