UNPKG

relaycode

Version:

A developer assistant that automates applying code changes from LLMs.

13 lines (9 loc) 2.9 kB
'use strict';var state=require('../core/state'),logger=require('../utils/logger'),shell=require('../utils/shell'),prompt=require('../utils/prompt'),formatters=require('../utils/formatters'),relaycodeCore=require('relaycode-core'),e=require('chalk');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var e__default=/*#__PURE__*/_interopDefault(e);const F=async(f={},i=process.cwd(),u)=>{const p=prompt.createConfirmationHandler(f,u);if(logger.logger.info("Looking for new transactions to commit..."),(await shell.executeShellCommand("git rev-parse --is-inside-work-tree",i)).exitCode!==0){logger.logger.error("This does not appear to be a git repository. Aborting commit.");return}const c=await shell.executeShellCommand("git log -1 --format=%ct",i),d=c.exitCode===0?parseInt(c.stdout,10)*1e3:0,m=(await state.readAllStateFiles(i)??[]).filter(t=>{const a=new Date(t.createdAt).getTime()>d,T=!t.gitCommittedAt;return (a||d===0)&&T}).sort((t,a)=>new Date(t.createdAt).getTime()-new Date(a.createdAt).getTime());if(m.length===0){logger.logger.info("No new transactions to commit since the last git commit.");return}const g=m.map(t=>relaycodeCore.normalizeGitCommitMsg(t.gitCommitMsg)).filter(t=>!!t);if(g.length===0){logger.logger.warn("No new transactions with git commit messages found.");return}const l=g.map(t=>t.trim()).filter(t=>t.length>0).join(` `);logger.logger.log("Found new transactions to commit:"),m.forEach(t=>{formatters.formatTransactionDetails(t).forEach(a=>logger.logger.log(a));});const C=l.split(` `).map(t=>` ${t}`).join(` `);if(!await p(` Do you want to run 'git add .' and commit with the following message? ${e__default.default.yellow(C)} (y/N)`)){logger.logger.info("Commit operation cancelled.");return}logger.logger.info(`Running ${e__default.default.magenta("'git add .'")}...`);const s=await shell.executeShellCommand("git add .",i);if(s.exitCode!==0){logger.logger.error(`${e__default.default.magenta("'git add .'")} failed with exit code ${e__default.default.red(s.exitCode)}.`),logger.logger.error(s.stderr);return}logger.logger.success(`${e__default.default.magenta("'git add .'")} completed successfully.`);const w=`git commit${l.split(` `).map(t=>` -m "${t.replace(/"/g,'\\"')}"`).join("")}`;logger.logger.info("Running commit command...");const n=await shell.executeShellCommand(w,i);if(n.exitCode!==0){logger.logger.error(`${e__default.default.magenta("'git commit'")} failed with exit code ${e__default.default.red(n.exitCode)}.`),logger.logger.error(n.stderr),n.stdout&&logger.logger.log(n.stdout),logger.logger.warn("You may need to resolve commit issues manually.");return}const h=m.map(t=>t.uuid);await state.markTransactionsAsGitCommitted(i,h),logger.logger.success("\u2705 Git commit successful!"),logger.logger.log(n.stdout);};exports.gitCommitCommand=F;//# sourceMappingURL=git-commit.cjs.map //# sourceMappingURL=git-commit.cjs.map