diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 51fba40f..08698671 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -18,7 +18,8 @@ To get started, follow these steps: 1. Clone the project repository locally. 2. Install dependencies with `npm install`. 3. Run the project with `npm run dev`. -4. See [issues](https://github.com/di-sukharev/open-commit/issues) or [TODO.md](../TODO.md) to help the project. +4. Add your api key with `npm run dev -- config set OPENAI_API_KEY=''` +5. See [issues](https://github.com/di-sukharev/open-commit/issues) or [TODO.md](../TODO.md) to help the project. ## Commit message guidelines diff --git a/README.md b/README.md index 73d6d1c0..5da82678 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,13 @@ oc config set language=française The default language set is **English** All available languages are currently listed in the [i18n](https://github.com/di-sukharev/opencommit/tree/master/src/i18n) folder +### Push to git + +Pushing to git is on by default but if you would like to turn it off just use: +```sh +oc config set gitpush=false +``` + ### Git flags The `opencommit` or `oc` commands can be used in place of the `git commit -m "${generatedMessage}"` command. This means that any regular flags that are used with the `git commit` command will also be applied when using `opencommit` or `oc`. diff --git a/src/commands/commit.ts b/src/commands/commit.ts index 4ca9709a..563c79ff 100644 --- a/src/commands/commit.ts +++ b/src/commands/commit.ts @@ -21,12 +21,15 @@ import { } from '@clack/prompts'; import chalk from 'chalk'; import { trytm } from '../utils/trytm'; +import { getConfig } from './config'; const getGitRemotes = async () => { const { stdout } = await execa('git', ['remote']); return stdout.split('\n').filter((remote) => Boolean(remote.trim())); }; +const config = getConfig(); + const generateCommitMessageFromGitDiff = async ( diff: string, extraArgs: string[] @@ -79,12 +82,17 @@ ${chalk.grey('——————————————————')}` const remotes = await getGitRemotes(); + + // user isn't pushing, return early + if(config?.gitpush === false) return + 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`?' diff --git a/src/commands/config.ts b/src/commands/config.ts index 2349253d..fa27ab8d 100644 --- a/src/commands/config.ts +++ b/src/commands/config.ts @@ -13,7 +13,8 @@ export enum CONFIG_KEYS { OPENAI_BASE_PATH = 'OPENAI_BASE_PATH', description = 'description', emoji = 'emoji', - language = 'language' + language = 'language', + gitpush = 'gitpush' } export enum CONFIG_MODES { @@ -71,7 +72,14 @@ export const configValidators = { return value; }, - + [CONFIG_KEYS.gitpush](value: any) { + validateConfig( + CONFIG_KEYS.gitpush, + typeof value === 'boolean', + 'Must be true or false' + ); + return value; + }, [CONFIG_KEYS.language](value: any) { validateConfig( CONFIG_KEYS.language,