Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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='<your_key>'`
5. See [issues](https://github.com/di-sukharev/open-commit/issues) or [TODO.md](../TODO.md) to help the project.

## Commit message guidelines

Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
8 changes: 8 additions & 0 deletions src/commands/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down Expand Up @@ -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`?'
Expand Down
12 changes: 10 additions & 2 deletions src/commands/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down