Giter Site home page Giter Site logo

dvakatsiienko / opencommit Goto Github PK

View Code? Open in Web Editor NEW

This project forked from di-sukharev/opencommit

0.0 0.0 0.0 2.73 MB

Auto-generate impressive commits with AI in 1 second 🤯🔫

Home Page: https://www.npmjs.com/package/opencommit

License: MIT License

JavaScript 99.04% TypeScript 0.96%

opencommit's Introduction

OpenCommit logo

OpenCommit

Follow the bird

Auto-generate meaningful commits in 1 second

Killing lame commits with AI 🤯🔫

Current version

OpenCommit example

All the commits in this repo are done with OpenCommit — look into the commits to see how OpenCommit works. Emoji and long commit description text is configurable.

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 repository branches are meaningful and not lame like fix1 or done2.

Create a file .github/workflows/opencommit.yml with contents below:

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/[email protected]
        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: <your_repo_url>/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

That is it. Now when you push to any branch in your repo — all NEW commits are being improved by never-tired-AI.

Make sure you exclude public collaboration branches (main, dev, etc) in branches-ignore, so OpenCommit does not rebase commits there when improving the messages.

Interactive rebase (rebase -i) changes commit SHA, so commit history in remote becomes different with your local branch history. It's ok when you work on the branch alone, but may be inconvenient for other collaborators.

Setup OpenCommit as a CLI

You can use OpenCommit by simply running it via CLI like this oco. 2 seconds and your staged changes are committed with a meaningful message.

  1. Install OpenCommit globally to use in any repository:

    npm install -g opencommit
  2. Get your API key from OpenAI. Make sure you add payment details, so API works.

  3. Set the key to OpenCommit config:

    opencommit config set OCO_OPENAI_API_KEY=<your_api_key>

    Your api key is stored locally in ~/.opencommit config file.

Usage

You can call OpenCommit directly to generate a commit message for your staged changes:

git add <files...>
opencommit

You can also use the oco shortcut:

git add <files...>
oc

Configuration

Local per repo configuration

Create an .env file and add OpenCommit config variables there like this:

OCO_OPENAI_API_KEY=<your openAI API token>
OCO_OPENAI_MAX_TOKENS=<max response tokens from openAI API>
OCO_OPENAI_BASE_PATH=<may be used to set proxy path to openAI api>
OCO_DESCRIPTION=<postface a message with ~3 sentences description>
OCO_EMOJI=<add GitMoji>
OCO_MODEL=<either gpt-3.5-turbo or gpt-4>
OCO_LANGUAGE=<locale, scroll to the bottom to see options>

Global config for all repos

Local config still has more priority as Global config, but you may set OCO_MODEL and OCO_LOCALE globally and set local configs for OCO_EMOJI and OCO_DESCRIPTION per repo which is more convenient.

Simply run any of the variable above like this:

oco config set OCO_OPENAI_API_KEY=gpt-4

Configure GitMoji to preface a message.

oco config set OCO_EMOJI=true

To remove preface emoji:

oco config set OCO_EMOJI=false

Switch to GPT-4

By default OpenCommit uses GPT-3.5-turbo (ChatGPT).

You may switch to GPT-4 which performs better, but costs ~x15 times more 🤠

oco config set OCO_MODEL=gpt-4

Make sure you do lowercase gpt-4 and you have API access to the 4th model. Even if you have ChatGPT+ it doesn't necessarily mean that you have API access to GPT-4.

Locale configuration

To globally specify the language used to generate commit messages:

# de, German ,Deutsch
oco config set OCO_LANGUAGE=de
oco config set OCO_LANGUAGE=German
oco config set OCO_LANGUAGE=Deutsch

# fr, French, française
oco config set OCO_LANGUAGE=fr
oco config set OCO_LANGUAGE=French
oco config set OCO_LANGUAGE=française

The default language set is English All available languages are currently listed in the i18n folder

Git flags

The opencommit or oco 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 oco.

oco --no-verify

is translated to :

git commit -m "${generatedMessage}" --no-verify

Ignore files

You can ignore files from submission to OpenAI by creating a .opencommitignore file. For example:

path/to/large-asset.zip
**/*.jpg

This is useful for preventing opencommit from uploading artifacts and large files.

By default, opencommit ignores files matching: *-lock.* and *.lock

Git hook (KILLER FEATURE)

You can set OpenCommit as Git prepare-commit-msg hook. Hook integrates with you IDE Source Control and allows you edit the message before commit.

To set the hook:

oco hook set

To unset the hook:

oco hook unset

To use the hook:

git add <files...>
git commit

Or follow the process of your IDE Source Control feature, when it calls git commit command — OpenCommit will integrate into the flow.

Payments

You pay for your own requests to OpenAI API. OpenCommit uses ChatGPT (3.5-turbo) official model, that is ~15x times cheaper than GPT-4.

opencommit's People

Contributors

di-sukharev avatar matt-degraffenreid avatar moret84 avatar nader-zouaoui avatar mathsgod avatar takuya-o avatar jessicakuijer avatar openefit avatar adrielbento avatar alexcgomez avatar imload avatar bennycode avatar linhdangquang avatar dmazlum avatar ericklima-ca avatar esmerlinjm avatar gamoreli avatar jeroensmink98 avatar joshuahamlet avatar jlopezlira avatar ingwarsw avatar sectex avatar manato1fg avatar moulick avatar the-r4v3n avatar art0rz avatar ta-noshii avatar vladickweb avatar henrycunh avatar kmmaniez avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.