autoagent-cli
Version:
Run autonomous AI agents using Claude or Gemini for task execution
40 lines (39 loc) • 1.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GitCommitHook = void 0;
const git_js_1 = require("../utils/git.js");
class GitCommitHook {
async execute(data, config) {
const hasChanges = await (0, git_js_1.hasChangesToCommit)();
if (!hasChanges) {
return {
blocked: false,
output: 'No changes to commit.',
};
}
await (0, git_js_1.stageAllChanges)();
const message = this.interpolateMessage(config.message ?? 'feat: Auto-commit by AutoAgent', data);
const commitResult = await (0, git_js_1.createCommit)({
message,
noVerify: config.noVerify ?? false,
});
if (commitResult.success) {
return {
blocked: false,
output: `Commit created: ${commitResult.commitHash}`,
};
}
else {
return {
blocked: false,
output: `Failed to create commit: ${commitResult.error}`,
};
}
}
interpolateMessage(template, data) {
return template
.replace(/{{issueNumber}}/g, String(data.issueNumber ?? ''))
.replace(/{{issueTitle}}/g, String(data.issueTitle ?? ''));
}
}
exports.GitCommitHook = GitCommitHook;