mirror of
https://github.com/di-sukharev/opencommit.git
synced 2026-01-13 07:38:01 -05:00
Compare commits
4 Commits
revert-70-
...
v2.0.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83abd5ffd6 | ||
|
|
42c26cbaaa | ||
|
|
51613c2aea | ||
|
|
f04757f8af |
@@ -1,5 +1,4 @@
|
||||
{
|
||||
"trailingComma": "none",
|
||||
"singleQuote": true,
|
||||
"semi": true
|
||||
"singleQuote": true
|
||||
}
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "opencommit",
|
||||
"version": "2.0.1",
|
||||
"version": "2.0.2",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "opencommit",
|
||||
"version": "2.0.1",
|
||||
"version": "2.0.2",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@clack/prompts": "^0.6.1",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "opencommit",
|
||||
"version": "2.0.1",
|
||||
"version": "2.0.2",
|
||||
"description": "GPT CLI to auto-generate impressive commits in 1 second. Killing lame commits with AI 🤯🔫",
|
||||
"keywords": [
|
||||
"git",
|
||||
|
||||
@@ -29,6 +29,8 @@ if (!apiKey && command !== 'config' && mode !== CONFIG_MODES.set) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const MODEL = config?.model || 'gpt-3.5-turbo';
|
||||
|
||||
class OpenAi {
|
||||
private openAiApiConfiguration = new OpenAiApiConfiguration({
|
||||
apiKey: apiKey
|
||||
@@ -47,7 +49,7 @@ class OpenAi {
|
||||
): Promise<string | undefined> => {
|
||||
try {
|
||||
const { data } = await this.openAI.createChatCompletion({
|
||||
model: 'gpt-3.5-turbo',
|
||||
model: MODEL,
|
||||
messages,
|
||||
temperature: 0,
|
||||
top_p: 0.1,
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { execa } from 'execa';
|
||||
import fs from 'fs';
|
||||
import os from 'os';
|
||||
import {
|
||||
GenerateCommitMessageErrorEnum,
|
||||
generateCommitMessageWithChatCompletion
|
||||
@@ -19,7 +17,7 @@ import {
|
||||
isCancel,
|
||||
intro,
|
||||
multiselect,
|
||||
select,
|
||||
select
|
||||
} from '@clack/prompts';
|
||||
import chalk from 'chalk';
|
||||
import { trytm } from '../utils/trytm';
|
||||
@@ -62,142 +60,79 @@ ${chalk.grey('——————————————————')}
|
||||
${commitMessage}
|
||||
${chalk.grey('——————————————————')}`
|
||||
);
|
||||
|
||||
const promptUserConfirm = async(commitText: string ) => {
|
||||
|
||||
const isCommitConfirmedByUser = await select({
|
||||
message: 'Confirm the commit message',
|
||||
options: [
|
||||
{value: "yes", label: "Yes"},
|
||||
{value: "no", label: "No"},
|
||||
{value: "edit", label: "Edit"}
|
||||
]
|
||||
|
||||
});
|
||||
const isCommitConfirmedByUser = await confirm({
|
||||
message: 'Confirm the commit message?'
|
||||
});
|
||||
|
||||
if (isCommitConfirmedByUser == "yes" && !isCancel(isCommitConfirmedByUser)) {
|
||||
const { stdout } = await execa('git', [
|
||||
'commit',
|
||||
'-m',
|
||||
commitText,
|
||||
...extraArgs
|
||||
]);
|
||||
if (isCommitConfirmedByUser && !isCancel(isCommitConfirmedByUser)) {
|
||||
const { stdout } = await execa('git', [
|
||||
'commit',
|
||||
'-m',
|
||||
commitMessage,
|
||||
...extraArgs
|
||||
]);
|
||||
|
||||
outro(`${chalk.green('✔')} successfully committed`);
|
||||
outro(`${chalk.green('✔')} successfully committed`);
|
||||
|
||||
outro(stdout);
|
||||
|
||||
const remotes = await getGitRemotes();
|
||||
outro(stdout);
|
||||
|
||||
const remotes = await getGitRemotes();
|
||||
|
||||
if (!remotes.length) {
|
||||
const { stdout } = await execa('git', ['push']);
|
||||
if (stdout) outro(stdout);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if (remotes.length === 1) {
|
||||
const isPushConfirmedByUser = await confirm({
|
||||
message: 'Do you want to run `git push`?'
|
||||
});
|
||||
|
||||
if (isPushConfirmedByUser && !isCancel(isPushConfirmedByUser)) {
|
||||
const pushSpinner = spinner();
|
||||
|
||||
pushSpinner.start(`Running \`git push ${remotes[0]}\``);
|
||||
|
||||
const { stdout } = await execa('git', [
|
||||
'push',
|
||||
'--verbose',
|
||||
remotes[0]
|
||||
]);
|
||||
|
||||
pushSpinner.stop(
|
||||
`${chalk.green('✔')} successfully pushed all commits to ${remotes[0]}`
|
||||
);
|
||||
|
||||
if (!remotes.length) {
|
||||
const { stdout } = await execa('git', ['push']);
|
||||
if (stdout) outro(stdout);
|
||||
} else {
|
||||
outro('`git push` aborted');
|
||||
process.exit(0);
|
||||
}
|
||||
} else {
|
||||
const selectedRemote = (await select({
|
||||
message: 'Choose a remote to push to',
|
||||
options: remotes.map((remote) => ({ value: remote, label: remote }))
|
||||
})) as string;
|
||||
|
||||
if (remotes.length === 1) {
|
||||
const isPushConfirmedByUser = await confirm({
|
||||
message: 'Do you want to run `git push`?'
|
||||
});
|
||||
if (!isCancel(selectedRemote)) {
|
||||
const pushSpinner = spinner();
|
||||
|
||||
if (isPushConfirmedByUser && !isCancel(isPushConfirmedByUser)) {
|
||||
const pushSpinner = spinner();
|
||||
pushSpinner.start(`Running \`git push ${selectedRemote}\``);
|
||||
|
||||
pushSpinner.start(`Running \`git push ${remotes[0]}\``);
|
||||
const { stdout } = await execa('git', ['push', selectedRemote]);
|
||||
|
||||
const { stdout } = await execa('git', [
|
||||
'push',
|
||||
'--verbose',
|
||||
remotes[0]
|
||||
]);
|
||||
pushSpinner.stop(
|
||||
`${chalk.green(
|
||||
'✔'
|
||||
)} successfully pushed all commits to ${selectedRemote}`
|
||||
);
|
||||
|
||||
pushSpinner.stop(
|
||||
`${chalk.green('✔')} successfully pushed all commits to ${remotes[0]}`
|
||||
);
|
||||
|
||||
if (stdout) outro(stdout);
|
||||
} else {
|
||||
const selectedRemote = (await select({
|
||||
message: 'Choose a remote to push to',
|
||||
options: remotes.map((remote) => ({ value: remote, label: remote }))
|
||||
})) as string;
|
||||
|
||||
if (!isCancel(selectedRemote)) {
|
||||
const pushSpinner = spinner();
|
||||
pushSpinner.start(`Running \`git push ${selectedRemote}\``);
|
||||
const { stdout } = await execa('git', ['push', selectedRemote]);
|
||||
pushSpinner.stop(
|
||||
`${chalk.green(
|
||||
'✔'
|
||||
)} successfully pushed all commits to ${selectedRemote}`
|
||||
);
|
||||
|
||||
if (stdout) outro(stdout);
|
||||
} else {
|
||||
outro('`git push` aborted');
|
||||
process.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (isCommitConfirmedByUser == "edit" && !isCancel(isCommitConfirmedByUser)) {
|
||||
|
||||
let defaultEditor = process.env.EDITOR || (process.platform === 'win32' ? 'notepad.exe' : 'vi');
|
||||
let defaultOpenCommand
|
||||
let linuxTermFlag = ''
|
||||
|
||||
switch (os.platform()) {
|
||||
case 'darwin':
|
||||
defaultOpenCommand = 'open'
|
||||
break
|
||||
case 'win32':
|
||||
defaultOpenCommand = 'start'
|
||||
break
|
||||
case 'linux':
|
||||
if (
|
||||
defaultEditor == 'vi' ||
|
||||
defaultEditor == 'vim' ||
|
||||
defaultEditor == 'nvim' ||
|
||||
defaultEditor == 'nano' ||
|
||||
defaultEditor == 'micro' ||
|
||||
defaultEditor == 'emacs'
|
||||
) {
|
||||
defaultOpenCommand = 'x-terminal-emulator'
|
||||
linuxTermFlag = '-e'
|
||||
break
|
||||
} else {
|
||||
defaultOpenCommand = 'xdg-open'
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
fs.writeFileSync('tmp_commit.txt', commitText);
|
||||
|
||||
outro('🙏 Please close the file when you are done editing it.')
|
||||
|
||||
const { } = await execa(`${defaultOpenCommand}`, [linuxTermFlag, defaultEditor, 'tmp_commit.txt']);
|
||||
|
||||
process.stdin.resume();
|
||||
|
||||
const updatedCommitMessage = fs.readFileSync('tmp_commit.txt', 'utf-8');
|
||||
const updatedCommitMessageTrimmed = updatedCommitMessage.trim()
|
||||
|
||||
fs.unlinkSync('tmp_commit.txt');
|
||||
|
||||
outro(
|
||||
`Commit message:
|
||||
${chalk.grey('——————————————————')}
|
||||
${updatedCommitMessageTrimmed}
|
||||
${chalk.grey('——————————————————')}`
|
||||
)
|
||||
|
||||
await promptUserConfirm(updatedCommitMessage)
|
||||
|
||||
} else if (isCommitConfirmedByUser == "no" && !isCancel(isCommitConfirmedByUser)) {
|
||||
outro(`👋 exiting`);
|
||||
}
|
||||
if (stdout) outro(stdout);
|
||||
} else outro(`${chalk.gray('✖')} process cancelled`);
|
||||
}
|
||||
}
|
||||
|
||||
await promptUserConfirm(commitMessage)
|
||||
};
|
||||
|
||||
export async function commit(
|
||||
|
||||
@@ -13,6 +13,7 @@ export enum CONFIG_KEYS {
|
||||
OPENAI_BASE_PATH = 'OPENAI_BASE_PATH',
|
||||
description = 'description',
|
||||
emoji = 'emoji',
|
||||
model = 'model',
|
||||
language = 'language'
|
||||
}
|
||||
|
||||
@@ -88,6 +89,15 @@ export const configValidators = {
|
||||
`${value} is not supported yet`
|
||||
);
|
||||
return value;
|
||||
},
|
||||
|
||||
[CONFIG_KEYS.model](value: any) {
|
||||
validateConfig(
|
||||
CONFIG_KEYS.OPENAI_BASE_PATH,
|
||||
value === 'gpt-3.5-turbo' || value === 'gpt-4',
|
||||
`${value} is not supported yet, use 'gpt-4' or 'gpt-3.5-turbo' (default)`
|
||||
);
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ const INIT_MESSAGES_PROMPT: Array<ChatCompletionRequestMessage> = [
|
||||
{
|
||||
role: ChatCompletionRequestMessageRoleEnum.System,
|
||||
// prettier-ignore
|
||||
content: `You are to act as the author of a commit message in git. Your mission is to create clean and comprehensive commit messages in the conventional commit convention and explain why a change was done. I'll send you an output of 'git diff --staged' command, and you convert it into a commit message.
|
||||
content: `You are to act as the author of a commit message in git. Your mission is to create clean and comprehensive commit messages in the conventional commit convention and explain WHAT were the changes and WHY the changes were done. I'll send you an output of 'git diff --staged' command, and you convert it into a commit message.
|
||||
${config?.emoji? 'Use GitMoji convention to preface the commit.': 'Do not preface the commit with anything.'}
|
||||
${config?.description ? 'Add a short description of WHY the changes are done after the commit message. Don\'t start it with "This commit", just describe the changes.': "Don't add any descriptions to the commit, only commit message."}
|
||||
Use the present tense. Lines must not be longer than 74 characters. Use ${translation.localLanguage} to answer.`
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"localLanguage": "english",
|
||||
"commitFix": "fix(server.ts): change port variable case from lowercase port to uppercase PORT",
|
||||
"commitFeat": "feat(server.ts): add support for process.env.PORT environment variable",
|
||||
"commitFix": "fix(server.ts): change port variable case from lowercase port to uppercase PORT to improve semantics",
|
||||
"commitFeat": "feat(server.ts): add support for process.env.PORT environment variable to be able to run app on a configurable port",
|
||||
"commitDescription": "The port variable is now named PORT, which improves consistency with the naming conventions as PORT is a constant. Support for an environment variable allows the application to be more flexible as it can now run on any available port specified via the process.env.PORT environment variable."
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user