Welcome to commit_ai, a Ruby gem designed to help developers generate meaningful commit messages automatically by analyzing staged git diffs using OpenAI's GPT models. Whether you're working with single-line or multi-line commits, CommitAi streamlines the commit process by providing concise, informative, and context-aware messages that follow best practices. With optional user input for change descriptions and smart minification of the git diff, this gem ensures clarity while preserving essential details in your commit messages.
Installation
You can install commit_ai by running the following command in your terminal:
$ gem install commit_ai
Usage
To use CommitAi, simply run the following command in your terminal after staging your changes:
$ commit_ai
Setting Up OpenAI API Key
Before using the gem, set up your OpenAI API key by adding it to your environment variables. You can do this by running:
export OPENAI_ACCESS_TOKEN='your_openai_access_token_here'
This command sets the OPENAI_ACCESS_TOKEN
variable for your current session. To make this change permanent, add the above line to your shell's configuration file (e.g., .bashrc
, .bash_profile
, or .zshrc
).
This command will:
- Analyze your staged changes (the
git diff --staged
). - Generate a suggested commit message based on the changes using OpenAI's GPT models.
- Present the generated message, allowing you to accept, regenerate, or edit it as needed.
Options During Execution:
- y: Accept the generated commit message and proceed with the commit.
- r: Regenerate a new commit message.
- e: Edit the generated commit message.
- n: Abort the commit.
Development
To start contributing or testing locally, follow these steps:
-
Clone the repository and check out the code:
$ git clone https://github.com/ken-narra/commit_ai.git $ cd commit_ai
-
Install dependencies:
$ bin/setup
-
Run an interactive console for experimenting with the gem:
$ bin/console
-
To install the gem onto your local machine, run:
$ bundle exec rake install
-
Release a new version:
- Update the version number in
lib/commit_ai/version.rb
. - Run the following command to create a git tag, push it to the repo, and upload the
.gem
file to RubyGems:$ bundle exec rake release
- Update the version number in
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/ken-narra/commit_ai. This project follows the Contributor Covenant code of conduct, and we expect all contributors to adhere to it in all project spaces.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the CommitAi project's codebases, issue trackers, chat rooms, and mailing lists is expected to follow the code of conduct.