Skip to content

Commit 23a063c

Browse files
committed
📦 new: add commit.js file for prompting commit message
1 parent e91b9a7 commit 23a063c

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

source/utils/commit.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import generatePrompt from "./openai.js";
2+
import execa from 'execa';
3+
import readline from "readline";
4+
5+
async function askForCommitMessage() {
6+
const prompt = await generatePrompt();
7+
8+
const rl = readline.createInterface({
9+
input: process.stdin,
10+
output: process.stdout,
11+
});
12+
13+
rl.question(`Suggested commit message: ${prompt}\nDo you want to proceed? (y/n) `, (answer) => {
14+
if (answer.toLowerCase() === "y") {
15+
execa("git", ["commit", "-m", prompt])
16+
.then(() => {
17+
console.log("Changes committed successfully!");
18+
})
19+
.catch((error) => {
20+
console.error("Failed to commit changes:", error);
21+
});
22+
} else {
23+
console.log("Changes not committed.");
24+
}
25+
26+
rl.close();
27+
});
28+
}
29+
30+
export default askForCommitMessage;

0 commit comments

Comments
 (0)