commit-ai

command module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2025 License: MIT Imports: 10 Imported by: 0

README ΒΆ

πŸ’Ύ commit-ai: write your commit messages with AI πŸ€–

Go Reference GitHub go.mod Go version Go Report Card GitHub License

As a Go developer, I looked at the world and thought:

You know what this planet really needs? One more commit message generator!

So, naturally, I built one. Wellcome to another commit-ai, the tool for generating commit messages using the OpenAI API. It analyzes Git changes and generates concise, meaningful commit messages for your repository.

✨ Features

  • Generates a commit message based on changes staged using git add.
  • Automatically extracts changed directories as go packages and adds them to the message (optional).
  • Applies rules for creating commit messages: starts with an imperative verb in the present tense, no period at the end, and limited to 10 words.
  • Option to exclude package names or the full commit command from the message.

πŸ“‹ Requirements

  • Go 1.18 or higher
  • OpenAI API key (set in the OPENAI_API_KEY environment variable)

πŸš€ Getting Started

You can install commit-ai directly using Go:

go install github.com/adobromilskiy/commit-ai@latest

Or manually:

  1. Clone the repository:

    git clone https://github.com/adobromilskiy/commit-ai.git
    cd commit-ai
    
  2. Install dependencies:

    go install
    
  3. Set your OpenAI API key:

    export OPENAI_API_KEY=your-api-key-here
    

πŸ“š Usage

Main Command

Run the command:

commit-ai

This will generate a commit message based on the staged changes in your repository.

Flags
  • --no-pkg β€” exclude package names from the commit message.
  • --no-cmd β€” output only the commit message without the git commit command.
Command Examples:
  1. Generate a commit message with package names:
commit-ai
  1. Generate a commit message without package names:
commit-ai --no-pkg
  1. Output only the commit message, without the git commit command:
commit-ai --no-cmd
  1. Generate just the commit message without packages and command:
commit-ai --no-pkg --no-cmd
Example Output

If there are staged changes, the tool may generate a commit message like:

git commit -m "core, database: refactor incoming params"

If the --no-pkg flag is enabled, it will generate:

git commit -m "refactor incoming params"

πŸ› οΈ Tricks & Shortcuts

To make working with commit-ai even faster, you can add the following Git aliases:

git config --global alias.addcommit '!f() { git add "$@" && git commit -m "$(commit-ai --no-cmd)"; }; f'
git config --global alias.prepcommit '!git add $@ && commit-ai'
πŸ”Ή git addcommit <files>

This alias adds files to staging and immediately commits them using commit-ai to generate the commit message.

Example usage:

git addcommit file1.go file2.go

Equivalent to:

git add file1.go file2.go && git commit -m "$(commit-ai)"

It automatically stages the provided files and runs commit-ai, committing the changes with an AI-generated message.

πŸ”Ή git prepcommit <files>

This alias stages files and suggests a commit message without actually committing.

Example usage:

git prepcommit file1.go

Equivalent to:

git add file1.go && commit-ai

This lets you preview the AI-generated commit message before manually committing.

Documentation ΒΆ

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL