Skip to content
/ cmt Public

command-line utility that generates Conventional Commit messages using OpenAI's GPT

License

Notifications You must be signed in to change notification settings

tab/cmt

Repository files navigation

cmt

cmt is a command-line utility that generates Conventional Commit messages using OpenAI's GPT models based on staged Git changes.

It automates the process of writing clear and structured commit messages, enhancing your Git workflow and ensuring consistency across projects.

Features

  • Automated Commit Messages: Generates commit messages following the Conventional Commits specification.
  • Interactive Approval: Allows you to review and approve the generated commit message before committing.
  • Interactive Edit: Supports editing the commit message interactively before committing.
  • Custom Prefixes: Supports adding custom prefixes to commit messages for better traceability (e.g., task IDs, issue numbers).
  • Changelog Generation: Automatically creates changelogs based on your commit history.
  • Integration with OpenAI GPT: Utilizes GPT to analyze your staged changes and produce meaningful commit messages.

Prerequisites

Before installing and using cmt, ensure you have the following:

  • Go: Version 1.16 or higher is recommended.
  • Git: Ensure Git is installed and initialized in your project.
  • OpenAI API Key: Obtain an API key from OpenAI to use GPT models.

Installation

  1. Clone the Repository

    git clone https://github.com/tab/cmt.git
  2. Navigate to the Project Directory

    cd cmt
  3. Set Up Environment Variables

    export OPENAI_API_KEY=your-api-key-here

For permanent setup, add the above line to your shell profile (~/.bashrc, ~/.zshrc, etc.).

  1. Build the Binary

    go build -o cmd/cmt cmd/main.go
  2. Make the Binary Executable

    chmod +x cmd/cmt
  3. Move the Binary to Your PATH

    sudo ln -s $(pwd)/cmd/cmt /usr/local/bin/cmt
  4. Verify Installation

     cmt --version

Usage

Navigate to your git repository and stage the changes you want to commit:

git add .

Run the cmt command to generate a commit message:

cmt

Review the generated commit message and choose whether to commit or not.

💬 Message: feat(core): Add user authentication

Implemented JWT-based authentication for API endpoints. Users can now log in and receive a token for subsequent requests.

Accept, edit, or cancel? (y/e/n):

Type y to accept and commit the changes, e to edit message or n to abort.

🚀 Changes committed:
[feature/jwt 29ca12d] feat(core): Add user authentication
 2 files changed, 106 insertions(+), 68 deletions(-)
 ...

Configuration

Optional prefix for the commit message can be set with the --prefix flag:

cmt --prefix "TASK-1234"

Resulting commit message:

💬 Message: TASK-1234 feat(core): Add user authentication

Implemented JWT-based authentication for API endpoints. Users can now log in and receive a token for subsequent requests.

Accept, edit, or cancel? (y/e/n):

Changelog generation

Run the cmt changelog to generate a changelog based on your commit history:

cmt changelog SHA1..SHA2
cmt changelog v1.0.0..v1.1.0

The command will output the changelog in the following format:

# CHANGELOG

## [1.1.0]

### Features

- **feat(jwt):** Add user authentication
- **feat(api):** Implement rate limiting for API endpoints

### Bug Fixes

- **fix(auth):** Resolve token expiration issue

...

FAQ

Q: How do I obtain an OpenAI API key?

A: You can obtain an API key by signing up at OpenAI's website. After signing in, navigate to the API keys section to generate a new key.


Q: How can I ensure that private information isn't shared with OpenAI?

A: Here are some best practices to prevent sharing private information with OpenAI:

  1. Review Staged Changes: Before running the cmt command, carefully review the changes you have staged using git diff --staged. Ensure that no sensitive information (like passwords, API keys, or personal data) is included.

  2. Exclude Sensitive Files: Use .gitignore to exclude files that contain sensitive information from being tracked and staged. For example:

    .env
    secrets/

License

Distributed under the MIT License. See LICENSE for more information.

Acknowledgements

About

command-line utility that generates Conventional Commit messages using OpenAI's GPT

Topics

Resources

License

Stars

Watchers

Forks

Languages