cloving 0.3.18 → 0.3.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2 -0
- package/dist/managers/CommitManager.js +38 -18
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -62,6 +62,7 @@ program
|
|
|
62
62
|
.description('Alias for cloving generate commit')
|
|
63
63
|
.option('-s, --silent', 'Run the command without asking for confirmation of submitting prompts')
|
|
64
64
|
.option('-m, --model <model>', 'Select the model to use (e.g., openai, claude, ollama, ollama:llama3, claude:claude-3-5-sonnet-20240620)')
|
|
65
|
+
.option('-a, --autoAccept', 'Automatically accept the generated commit message without editing')
|
|
65
66
|
.action(commit_1.default);
|
|
66
67
|
// Generate commands
|
|
67
68
|
const generate = program
|
|
@@ -96,6 +97,7 @@ generate
|
|
|
96
97
|
.option('-t, --temperature <temperature>', 'Temperature for the model (default 0.2)')
|
|
97
98
|
.option('-s, --silent', 'Run the command without asking for confirmation of submitting prompts')
|
|
98
99
|
.option('-m, --model <model>', 'Select the model to use (e.g., openai, claude, ollama, ollama:llama3, claude:claude-3-5-sonnet-20240620)')
|
|
100
|
+
.option('-a, --autoAccept', 'Automatically accept the generated commit message without editing')
|
|
99
101
|
.action(commit_1.default);
|
|
100
102
|
generate
|
|
101
103
|
.command('context')
|
|
@@ -13,8 +13,15 @@ const cloving_gpt_1 = __importDefault(require("../cloving_gpt"));
|
|
|
13
13
|
class CommitManager {
|
|
14
14
|
constructor(options) {
|
|
15
15
|
options.silent = (0, config_utils_1.getConfig)(options).globalSilent || false;
|
|
16
|
+
this.autoAccept = options.autoAccept || false;
|
|
16
17
|
this.gpt = new cloving_gpt_1.default(options);
|
|
17
18
|
}
|
|
19
|
+
cleanCommitMessage(message) {
|
|
20
|
+
// Remove markdown code block formatting if present, including any text before and after
|
|
21
|
+
const codeBlockRegex = /.*?```.*\n(.*?)\n```.*/m;
|
|
22
|
+
const match = message.match(codeBlockRegex);
|
|
23
|
+
return match ? match[1].trim() : message.trim();
|
|
24
|
+
}
|
|
18
25
|
async generateCommit() {
|
|
19
26
|
try {
|
|
20
27
|
// Get the git diff
|
|
@@ -28,26 +35,39 @@ class CommitManager {
|
|
|
28
35
|
const prompt = (0, git_utils_1.generateCommitMessagePrompt)(diff);
|
|
29
36
|
// Instantiate ClovingGPT and get the commit message
|
|
30
37
|
const rawCommitMessage = await this.gpt.generateText({ prompt });
|
|
31
|
-
// Clean the commit message using extractMarkdown
|
|
32
|
-
const commitMessage = (0, string_utils_1.extractMarkdown)(rawCommitMessage);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
// Clean the commit message using extractMarkdown and remove code blocks
|
|
39
|
+
const commitMessage = this.cleanCommitMessage((0, string_utils_1.extractMarkdown)(rawCommitMessage));
|
|
40
|
+
if (this.autoAccept) {
|
|
41
|
+
// Directly commit with the generated message without opening an editor
|
|
42
|
+
try {
|
|
43
|
+
(0, child_process_1.execFileSync)('git', ['commit', '-a', '-m', commitMessage], {
|
|
44
|
+
stdio: 'inherit',
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
catch (commitError) {
|
|
48
|
+
console.log('Commit failed:', commitError.message);
|
|
49
|
+
}
|
|
41
50
|
}
|
|
42
|
-
|
|
43
|
-
//
|
|
44
|
-
|
|
51
|
+
else {
|
|
52
|
+
// Write the commit message to a temporary file
|
|
53
|
+
const tempCommitFilePath = path_1.default.join('.git', 'SUGGESTED_COMMIT_EDITMSG');
|
|
54
|
+
fs_1.default.writeFileSync(tempCommitFilePath, commitMessage);
|
|
55
|
+
// Commit the changes using the generated commit message
|
|
56
|
+
try {
|
|
57
|
+
(0, child_process_1.execFileSync)('git', ['commit', '-a', '--edit', '--file', tempCommitFilePath], {
|
|
58
|
+
stdio: 'inherit',
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
catch (commitError) {
|
|
62
|
+
// If commit is canceled (non-zero exit), handle it here
|
|
63
|
+
console.log('Commit was canceled or failed.');
|
|
64
|
+
}
|
|
65
|
+
// Remove the temporary file using fs
|
|
66
|
+
fs_1.default.unlink(tempCommitFilePath, (err) => {
|
|
67
|
+
if (err)
|
|
68
|
+
throw err;
|
|
69
|
+
});
|
|
45
70
|
}
|
|
46
|
-
// Remove the temporary file using fs
|
|
47
|
-
fs_1.default.unlink(tempCommitFilePath, (err) => {
|
|
48
|
-
if (err)
|
|
49
|
-
throw err;
|
|
50
|
-
});
|
|
51
71
|
}
|
|
52
72
|
catch (err) {
|
|
53
73
|
const error = err;
|
package/dist/package.json
CHANGED