diff --git a/README.md b/README.md index 21470d9..40ef0a2 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@

Auto-generate meaningful commits in 1 second

Killing lame commits with AI 🤯🔫

Current version -

🪩 Winner of GitHub 2023 HACKATHON +

🪩 Winner of GitHub 2023 HACKATHON

@@ -34,68 +34,11 @@ You can use OpenCommit by simply running it via the CLI like this `oco`. 2 secon 3. Set the key to OpenCommit config: ```sh - opencommit config set OCO_OPENAI_API_KEY= + oco config set OCO_OPENAI_API_KEY= ``` Your API key is stored locally in the `~/.opencommit` config file. -## Setup OpenCommit as a GitHub Action 🔥 - -OpenCommit is now available as a GitHub Action which automatically improves all new commits messages when you push to remote! - -This is great if you want to make sure all of the commits in all of your repository branches are meaningful and not lame like `fix1` or `done2`. - -Create a file `.github/workflows/opencommit.yml` with the contents below: - -```yml -name: 'OpenCommit Action' - -on: - push: - # this list of branches is often enough, - # but you may still ignore other public branches - branches-ignore: [main master dev development release] - -jobs: - opencommit: - timeout-minutes: 10 - name: OpenCommit - runs-on: ubuntu-latest - permissions: write-all - steps: - - name: Setup Node.js Environment - uses: actions/setup-node@v2 - with: - node-version: '16' - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - uses: di-sukharev/opencommit@github-action-v1.0.4 - with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - env: - # set openAI api key in repo actions secrets, - # for openAI keys go to: https://platform.openai.com/account/api-keys - # for repo secret go to: /settings/secrets/actions - OCO_OPENAI_API_KEY: ${{ secrets.OCO_OPENAI_API_KEY }} - - # customization - OCO_OPENAI_MAX_TOKENS: 500 - OCO_OPENAI_BASE_PATH: '' - OCO_DESCRIPTION: false - OCO_EMOJI: false - OCO_MODEL: gpt-3.5-turbo - OCO_LANGUAGE: en - OCO_PROMPT_MODULE: conventional-commit -``` - -That is it. Now when you push to any branch in your repo — all NEW commits are being improved by your never-tired AI. - -Make sure you exclude public collaboration branches (`main`, `dev`, `etc`) in `branches-ignore`, so OpenCommit does not rebase commits there while improving the messages. - -Interactive rebase (`rebase -i`) changes commits' SHA, so the commit history in remote becomes different from your local branch history. This is okay if you work on the branch alone, but may be inconvenient for other collaborators. - ## Usage You can call OpenCommit directly to generate a commit message for your staged changes: @@ -122,12 +65,12 @@ Create a `.env` file and add OpenCommit config variables there like this: OCO_OPENAI_API_KEY= OCO_OPENAI_MAX_TOKENS= OCO_OPENAI_BASE_PATH= -OCO_DESCRIPTION= -OCO_EMOJI= -OCO_MODEL= +OCO_DESCRIPTION= +OCO_EMOJI= +OCO_MODEL= OCO_LANGUAGE= -OCO_MESSAGE_TEMPLATE_PLACEHOLDER= -OCO_PROMPT_MODULE= +OCO_MESSAGE_TEMPLATE_PLACEHOLDER= +OCO_PROMPT_MODULE= ``` ### Global config for all repos @@ -233,7 +176,7 @@ This allows you to ensure that the configuration is set up as desired. Additionally, the integration creates a file named `.opencommit-commitlint` which contains the prompts used for the local `@commitlint` configuration. You can modify this file to fine-tune the example commit message generated by OpenAI. This gives you the flexibility to make adjustments based on your preferences or project guidelines. -Additionally, OpenCommit generates a file named `.opencommit-commitlint` in your project directory which contains the prompts used for the local `@commitlint` configuration. You can modify this file to fine-tune the example commit message generated by OpenAI. If the local `@commitlint` configuration changes, this file will be updated the next time OpenCommit is run. +OpenCommit generates a file named `.opencommit-commitlint` in your project directory which contains the prompts used for the local `@commitlint` configuration. You can modify this file to fine-tune the example commit message generated by OpenAI. If the local `@commitlint` configuration changes, this file will be updated the next time OpenCommit is run. This offers you greater control over the generated commit messages, allowing for customization that aligns with your project's conventions. @@ -251,10 +194,10 @@ is translated to : git commit -m "${generatedMessage}" --no-verify ``` -To include a message in the generated message, you can utilize the template function! For instance: +To include a message in the generated message, you can utilize the template function, for instance: ```sh -oco '$msg #205’ +oco '#205: $msg’ ``` > opencommit examines placeholders in the parameters, allowing you to append additional information before and after the placeholders, such as the relevant Issue or Pull Request. Similarly, you have the option to customize the OCO_MESSAGE_TEMPLATE_PLACEHOLDER configuration item, for example, simplifying it to $m!" @@ -268,12 +211,14 @@ The `OCO_MESSAGE_TEMPLATE_PLACEHOLDER` feature in the `opencommit` tool allows u #### Implementation Details In our codebase, the implementation of this feature can be found in the following segment: + ```javascript commitMessage = messageTemplate.replace( - config?.OCO_MESSAGE_TEMPLATE_PLACEHOLDER, - commitMessage + config?.OCO_MESSAGE_TEMPLATE_PLACEHOLDER, + commitMessage ); ``` + This line is responsible for replacing the placeholder in the `messageTemplate` with the actual `commitMessage`. #### Usage @@ -322,6 +267,63 @@ git commit Or follow the process of your IDE Source Control feature, when it calls `git commit` command — OpenCommit will integrate into the flow. +## Setup OpenCommit as a GitHub Action (BETA) 🔥 + +OpenCommit is now available as a GitHub Action which automatically improves all new commits messages when you push to remote! + +This is great if you want to make sure all of the commits in all of your repository branches are meaningful and not lame like `fix1` or `done2`. + +Create a file `.github/workflows/opencommit.yml` with the contents below: + +```yml +name: 'OpenCommit Action' + +on: + push: + # this list of branches is often enough, + # but you may still ignore other public branches + branches-ignore: [main master dev development release] + +jobs: + opencommit: + timeout-minutes: 10 + name: OpenCommit + runs-on: ubuntu-latest + permissions: write-all + steps: + - name: Setup Node.js Environment + uses: actions/setup-node@v2 + with: + node-version: '16' + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: di-sukharev/opencommit@github-action-v1.0.4 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + env: + # set openAI api key in repo actions secrets, + # for openAI keys go to: https://platform.openai.com/account/api-keys + # for repo secret go to: /settings/secrets/actions + OCO_OPENAI_API_KEY: ${{ secrets.OCO_OPENAI_API_KEY }} + + # customization + OCO_OPENAI_MAX_TOKENS: 500 + OCO_OPENAI_BASE_PATH: '' + OCO_DESCRIPTION: false + OCO_EMOJI: false + OCO_MODEL: gpt-3.5-turbo-16k + OCO_LANGUAGE: en + OCO_PROMPT_MODULE: conventional-commit +``` + +That is it. Now when you push to any branch in your repo — all NEW commits are being improved by your never-tired AI. + +Make sure you exclude public collaboration branches (`main`, `dev`, `etc`) in `branches-ignore`, so OpenCommit does not rebase commits there while improving the messages. + +Interactive rebase (`rebase -i`) changes commits' SHA, so the commit history in remote becomes different from your local branch history. This is okay if you work on the branch alone, but may be inconvenient for other collaborators. + ## Payments You pay for your requests to OpenAI API. OpenCommit uses ChatGPT (3.5-turbo) official model, which is ~15x times cheaper than GPT-4. diff --git a/out/cli.cjs b/out/cli.cjs index 34aa612..1489218 100755 --- a/out/cli.cjs +++ b/out/cli.cjs @@ -16425,8 +16425,8 @@ var package_default = { start: "node ./out/cli.cjs", dev: "ts-node ./src/cli.ts", build: "rimraf out && node esbuild.config.js", - deploy: "npm run build:push && npm version patch && git push --tags && git push && npm publish --tag latest", "build:push": "npm run build && git add . && git commit -m 'build' && git push", + deploy: "npm run build:push && npm version patch && git push --tags && git push && npm publish --tag latest", lint: "eslint src --ext ts && tsc --noEmit", format: "prettier --write src" }, @@ -21548,7 +21548,7 @@ var configValidators = { "gpt-3.5-turbo-16k", "gpt-3.5-turbo-0613" ].includes(value), - `${value} is not supported yet, use 'gpt-4', 'gpt-3.5-turbo-0613', 'gpt-3.5-turbo-0613' or 'gpt-3.5-turbo' (default)` + `${value} is not supported yet, use 'gpt-4', 'gpt-3.5-turbo-16k' (default), 'gpt-3.5-turbo-0613' or 'gpt-3.5-turbo'` ); return value; }, @@ -22306,12 +22306,12 @@ var checkMessageTemplate = (extraArgs2) => { return false; }; var generateCommitMessageFromGitDiff = async (diff, extraArgs2) => { - const messageTemplate = checkMessageTemplate(extraArgs2); await assertGitRepo(); const commitSpinner = le(); commitSpinner.start("Generating the commit message"); try { let commitMessage = await generateCommitMessageByDiff(diff); + const messageTemplate = checkMessageTemplate(extraArgs2); if (typeof messageTemplate === "string") { commitMessage = messageTemplate.replace( config7?.OCO_MESSAGE_TEMPLATE_PLACEHOLDER, @@ -22320,7 +22320,7 @@ var generateCommitMessageFromGitDiff = async (diff, extraArgs2) => { } commitSpinner.stop("\u{1F4DD} Commit message generated"); ce( - `Commit message: + `Generated commit message: ${source_default.grey("\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014")} ${commitMessage} ${source_default.grey("\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014")}` @@ -22350,7 +22350,7 @@ ${source_default.grey("\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2 }); if (isPushConfirmedByUser && !eD2(isPushConfirmedByUser)) { const pushSpinner = le(); - pushSpinner.start(`Running \`git push ${remotes[0]}\``); + pushSpinner.start(`Running 'git push ${remotes[0]}'`); const { stdout: stdout2 } = await execa("git", [ "push", "--verbose", @@ -22372,7 +22372,7 @@ ${source_default.grey("\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2 }); if (!eD2(selectedRemote)) { const pushSpinner = le(); - pushSpinner.start(`Running \`git push ${selectedRemote}\``); + pushSpinner.start(`Running 'git push ${selectedRemote}'`); const { stdout: stdout2 } = await execa("git", ["push", selectedRemote]); pushSpinner.stop( `${source_default.green( diff --git a/out/github-action.cjs b/out/github-action.cjs index 5ca92e1..e188681 100644 --- a/out/github-action.cjs +++ b/out/github-action.cjs @@ -27971,7 +27971,7 @@ var configValidators = { "gpt-3.5-turbo-16k", "gpt-3.5-turbo-0613" ].includes(value), - `${value} is not supported yet, use 'gpt-4', 'gpt-3.5-turbo-0613', 'gpt-3.5-turbo-0613' or 'gpt-3.5-turbo' (default)` + `${value} is not supported yet, use 'gpt-4', 'gpt-3.5-turbo-16k' (default), 'gpt-3.5-turbo-0613' or 'gpt-3.5-turbo'` ); return value; }, diff --git a/src/commands/commit.ts b/src/commands/commit.ts index 688b6c4..10ce123 100644 --- a/src/commands/commit.ts +++ b/src/commands/commit.ts @@ -42,24 +42,28 @@ const generateCommitMessageFromGitDiff = async ( diff: string, extraArgs: string[] ): Promise => { - const messageTemplate = checkMessageTemplate(extraArgs); await assertGitRepo(); - const commitSpinner = spinner(); commitSpinner.start('Generating the commit message'); + try { let commitMessage = await generateCommitMessageByDiff(diff); - if (typeof messageTemplate === 'string') { + const messageTemplate = checkMessageTemplate(extraArgs); + if ( + config?.OCO_MESSAGE_TEMPLATE_PLACEHOLDER && + typeof messageTemplate === 'string' + ) { commitMessage = messageTemplate.replace( config?.OCO_MESSAGE_TEMPLATE_PLACEHOLDER, commitMessage ); } + commitSpinner.stop('📝 Commit message generated'); outro( - `Commit message: + `Generated commit message: ${chalk.grey('——————————————————')} ${commitMessage} ${chalk.grey('——————————————————')}` @@ -97,7 +101,7 @@ ${chalk.grey('——————————————————')}` if (isPushConfirmedByUser && !isCancel(isPushConfirmedByUser)) { const pushSpinner = spinner(); - pushSpinner.start(`Running \`git push ${remotes[0]}\``); + pushSpinner.start(`Running 'git push ${remotes[0]}'`); const { stdout } = await execa('git', [ 'push', @@ -125,7 +129,7 @@ ${chalk.grey('——————————————————')}` if (!isCancel(selectedRemote)) { const pushSpinner = spinner(); - pushSpinner.start(`Running \`git push ${selectedRemote}\``); + pushSpinner.start(`Running 'git push ${selectedRemote}'`); const { stdout } = await execa('git', ['push', selectedRemote]); diff --git a/src/commands/config.ts b/src/commands/config.ts index b580d73..ca3bf1a 100644 --- a/src/commands/config.ts +++ b/src/commands/config.ts @@ -129,7 +129,7 @@ export const configValidators = { 'gpt-3.5-turbo-16k', 'gpt-3.5-turbo-0613' ].includes(value), - `${value} is not supported yet, use 'gpt-4', 'gpt-3.5-turbo-0613', 'gpt-3.5-turbo-0613' or 'gpt-3.5-turbo' (default)` + `${value} is not supported yet, use 'gpt-4', 'gpt-3.5-turbo-16k' (default), 'gpt-3.5-turbo-0613' or 'gpt-3.5-turbo'` ); return value; }, @@ -192,7 +192,8 @@ export const getConfig = (): ConfigType | null => { try { const validator = configValidators[configKey as CONFIG_KEYS]; const validValue = validator( - config[configKey] ?? configFromEnv[configKey as CONFIG_KEYS], config + config[configKey] ?? configFromEnv[configKey as CONFIG_KEYS], + config ); config[configKey] = validValue;