-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcommit.js
More file actions
60 lines (53 loc) · 1.26 KB
/
commit.js
File metadata and controls
60 lines (53 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import generatePrompt from './openai.js';
import {execa} from 'execa';
import readline from 'readline';
import React from 'react';
import {Box, render, Text, useApp} from 'ink';
import SelectInput from 'ink-select-input';
async function askForCommitMessage() {
const prompt = await generatePrompt();
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const SelectSuggestedCommit = () => {
const {exit} = useApp();
const handleSelect = item => {
if (item.value) {
execa('git', ['commit', '-m', prompt])
.then(() => {
console.log('Changes committed successfully!');
})
.catch(error => {
console.error('Failed to commit changes:', error);
});
} else {
console.log('Changes not committed.');
}
exit();
};
const items = [
{
label: 'No',
value: false,
},
{
label: 'Yes',
value: true,
},
];
return (
<Box flexDirection="column">
<Text>{`Suggested commit message: ${prompt}\nDo you want to proceed?`}</Text>
<SelectInput items={items} onSelect={handleSelect} />
</Box>
);
};
if (prompt) {
render(<SelectSuggestedCommit />);
} else {
console.log('No changes to commit...');
rl.close();
}
}
export default askForCommitMessage;