Skip to main content

AI generated commit messages

Project description

Release Notes Downloads Python Versions GitHub CI Status License: MIT

aiautocommit

Generate intelligent commit messages using AI. aiautocommit analyzes your staged changes and creates conventional commit messages, handling both small tweaks and large changesets effectively.

Yes, there are a lot of these. Main ways this is different:

  • Simple codebase. < 400 LOC and most of it is prompts and comments.
  • Ability to easily customize prompts on a per-repo basis

Installation

pip install aiautocommit

Features

  • Generates conventional commit messages
  • Customizable prompts and exclusions
  • Pre-commit hook integration
  • Supports custom config directories
  • Does not generate a commit during a merge or reversion (when an existing autogen'd msg exists)

Getting Started

Set your OpenAI API key:

export OPENAI_API_KEY=<YOUR API KEY>

Stage your changes and run aiautocommit:

git add .

# this will generate a commit message and commit the changes
aiautocommit commit

# or, just to see what it will do
aiautocommit commit --print-message

Using the CLI directly is the best way to debug and tinker with the project as well.

Customization

Logging

First, you'll want to enable logging so you can extract the diff and prompt and iterate on it in ChatGPT:

export AIAUTOCOMMIT_LOG_LEVEL=DEBUG
export AIAUTOCOMMIT_LOG_FILE=aiautocommit.log

Now, you'll have a nice log you can tail and fiddle with from there.

Using Config Directory

aiautocommit looks for configuration files in these locations (in priority order):

  • .aiautocommit/ in current directory
  • $XDG_CONFIG_HOME/aiautocommit/ (defaults to ~/.config/aiautocommit/)
  • Custom path via aiautocommit_CONFIG environment variable

To get started with customization:

aiautocommit dump-prompts

This creates a .aiautocommit/ directory with:

  • diff_prompt.txt: Template for generating diff summaries
  • commit_prompt.txt: Template for generating commit messages
  • exclusions.txt: List of files to exclude from processing
  • commit_suffix.txt: Static suffix to append to commit messages. Useful for trailers.

Installing Pre-commit Hook

To automatically generate commit messages during git commits:

aiautocommit install-pre-commit

Learn more about git hooks here.

Lefthook Configuration

Lefthook is an excellent tool for managing git hooks. To use aiautocommit with lefthook, add the following to your .lefthook.yml:

prepare-commit-msg:
  commands:
    aiautocommit:
      run: aiautocommit commit --output-file "{1}"
      interactive: true
      env:
        # without this, lefthook will run in an infinite loop
        LEFTHOOK: 0
        # ensures that LOG_LEVEL config of the current project does not interfere with aiautocommit
        LOG_LEVEL: info
        OPENAI_LOG: warn
      skip:
        merge:
        rebase:
        # only run this if the tool exists
        run: ! which aiautocommit > /dev/null

Environment Variables

  • OPENAI_API_KEY: Your OpenAI API key
  • AIAUTOCOMMIT_OPENAI_API_KEY: Unique API key for OpenAI, overrides OPENAI_API_KEY (useful for tracking or costing purposes)
  • AIAUTOCOMMIT_MODEL: AI model to use (default: gpt-4-mini)
  • AIAUTOCOMMIT_CONFIG: Custom config directory path
  • LOG_LEVEL: Logging verbosity
  • AIAUTOCOMMIT_LOG_PATH: Custom log file path

Writing Good Commit Messages

Privacy Disclaimer

gpt-commit uses the OpenAI API to generate commit messages. Both file names and contents from files that contain staged changes will be shared with OpenAI when using gpt-commit. OpenAI will process this data according to their terms of use and API data usage policies. On March 1st 2023 OpenAI pledged that by default, they would not use data submitted by customers via their API to train or improve their models, and that this data will be retained for a maximum of 30 days, after which it will be deleted.

Special Thanks

This project inspired this project. It had a very simple codebase. I've taken the idea and expanded it to include a lot more features, specifically per-project prompt customization.

Related Projects

I looked at a bunch of projects before building this one.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiautocommit-0.9.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiautocommit-0.9.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file aiautocommit-0.9.0.tar.gz.

File metadata

  • Download URL: aiautocommit-0.9.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.4.30

File hashes

Hashes for aiautocommit-0.9.0.tar.gz
Algorithm Hash digest
SHA256 149886f50b1cd1448ad3c4e307f52b0971176a97c3087c7d03e9d5b7627cfa80
MD5 e4d934a0486be2a1cca04f2ae0ab0ebd
BLAKE2b-256 bbe23371a1700dd89b18aa0584580968d1196886a2e09046c666342b3bb68ebf

See more details on using hashes here.

File details

Details for the file aiautocommit-0.9.0-py3-none-any.whl.

File metadata

File hashes

Hashes for aiautocommit-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c97cf3017030705bf3669d142a998fbec16122b1107fc5f428095e7afdc46e2a
MD5 7f28cb3b9020639133b1e192bb852bf6
BLAKE2b-256 2ba16daeb5d1142197b94f07c0beb92a37cca89d50c35a861536c0e78a79a203

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page