@mcp-apps/azure-devops-mcp-server
Version:
A Model Context Protocol (MCP) server for Azure DevOps integration
103 lines (101 loc) • 4.45 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.commitChangesTool = void 0;
const zod_1 = require("zod");
const child_process = __importStar(require("child_process"));
const util = __importStar(require("util"));
const execPromise = util.promisify(child_process.exec);
// Tool to commit changes
exports.commitChangesTool = {
name: "git-commit-changes",
description: `
Commits changes in a local Git repository.
This tool commits staged changes in the specified local Git repository
with the provided commit message.
Parameters:
- repositoryPath: The local path to the Git repository
Example: "C:\\projects\\my-repo" or "/home/user/projects/my-repo"
- message: The commit message
Example: "Fix login bug", "Add new feature"
- stageAll: Whether to stage all changes before committing (default: false)
Example: true, false
- allowEmpty: Whether to allow empty commits (default: false)
Example: true, false
`,
parameters: {
repositoryPath: zod_1.z.string().describe("Local path to the Git repository"),
message: zod_1.z.string().describe("Commit message"),
stageAll: zod_1.z.boolean().default(false).describe("Whether to stage all changes before committing"),
allowEmpty: zod_1.z.boolean().default(false).describe("Whether to allow empty commits"),
},
handler: async ({ repositoryPath, message, stageAll, allowEmpty }) => {
try {
// Stage all changes if requested
if (stageAll) {
await execPromise("git add -A", { cwd: repositoryPath });
}
// Build the commit command
let command = "commit";
if (allowEmpty) {
command += " --allow-empty";
}
command += ` -m "${message.replace(/"/g, '\\"')}"`;
// Execute the command
const { stdout, stderr } = await execPromise(`git ${command}`, { cwd: repositoryPath });
if (stderr && !stderr.includes("[") && !stderr.includes("file") && !stderr.includes("changed")) {
// Filter out normal Git commit output that goes to stderr
return {
content: [{ type: "text", text: `Warning during commit: ${stderr}` }],
};
}
const fullOutput = [stdout, stderr].filter(Boolean).join("\n");
return {
content: [{
type: "text",
text: `Changes committed successfully.\n\n${fullOutput}`
}],
};
}
catch (error) {
console.error("Error committing changes:", error);
const errorMessage = error instanceof Error ? error.message : String(error);
return {
content: [{ type: "text", text: `Error committing changes: ${errorMessage}` }],
};
}
}
};
//# sourceMappingURL=git-commit-changes.js.map