/magiccommits

Magiccommit: Effortless Git Commits with AI

Primary LanguagePythonMIT LicenseMIT

MagicCommits

Magiccommits: Effortless Git Commits with AI

Magiccommits


Installation

Before you start using MagicCommits, make sure you have Python and pip installed. Then, you can install MagicCommits using pip:

pip install magiccommits

If you are using python3 then

pip3 install magiccommits

Before you can use MagicCommits, you'll need to configure it with your OpenAI API key. If you haven't already, you can retrieve your API key from OpenAI (Note: You may need to create an account and set up billing).

Set the OPENAI_KEY

   mc config set OPENAI_KEY=<your-token>

This will create a .mc file in your home directory (~/.mc).

Usage

Execute magiccommits or mc to generate the commit messages

Additional Options

Command Example Functionality
1 -t or --ticket mc -t PROJ-123 Set the ticket number for your commit message
2 -a or --add mc -a Perform a git add . operation before commit
3 -u or --update mc commit -u Perform a git add --update operation

You can use these additional options to customize your commit messages and perform relevant Git operations as needed in your project workflow.

Demo: mc -a mc -a
Demo: copy message to clipboard mc -a

Configuration

You can use these keys to configure various aspects of the project. To set the value for a key, you must use the format key=value when using the mc config set command. To retrieve the values for these keys, you can use the mc config get command, either for all values or a specific key.

Configuration Keys

OPENAI_KEY [Required]

  • Description: This key is used to specify the OpenAI API key.
  • Example Setting:
    • To set the value:
      mc config set OPENAI_KEY=sk-test
    • To retrieve the value:
      mc config get OPENAI_KEY

locale [OPT]

  • Description: This key defines the locale or language for text generation.
  • Example Setting:
    • To set the value:
      mc config set locale=en
    • To retrieve the value:
      mc config get locale

generate [OPT]

  • Description: This key determines the number of commit message to generate.
  • Example Setting:
    • To set the value:
      mc config set generate=4
    • To retrieve the value:
      mc config get generate

type [OPT]

  • Description: This key specifies the type of commit generation.

  • Example Setting:

    • To set the value:
      mc config set type=conventional
    • To retrieve the value:
      mc config get type

conventional

  • Explanation: Generates commit messages following the conventional commit format.

  • Example:

    • Commit Message: feat: add new feature
    • Description: A conventional commit format with a type ("feat" for feature) and a brief description.

conventional-emoji

  • Explanation: Generates commit messages following the conventional commit format with added emojis.

  • Example:

    • Commit Message: feat: add new feature :sparkles:
    • Description: A conventional commit format with an emoji (:sparkles:) for visual appeal and a type ("feat") with a brief description.

message

  • Explanation: Generates simple and concise commit messages.

  • Example:

    • Commit Message: Update README.md
    • Description: A straightforward commit message with a focus on the action ("Update README.md").

message-emoji

  • Explanation: Generates simple commit messages with added emojis.

  • Example:

    • Commit Message: Fix a critical bug :bug:
    • Description: A simple commit message with an emoji (:bug:) for visual context, describing the action ("Fix a critical bug").

proxy [OPT]

  • Description: This key allows you to set a proxy server for network requests.
  • Example Setting:
    • To set the value:
      mc config set proxy=http
    • To retrieve the value:
      mc config get proxy

model [OPT]

  • Description: This key defines the model to be used for commit generation.
  • Example Setting:
    • To set the value:
      mc config set model=gpt-3.5-turbo
    • To retrieve the value:
      mc config get model

timeout [OPT]

  • Description: This key sets the maximum timeout (in milliseconds) for API requests.
  • Example Setting:
    • To set the value:
      mc config set timeout=10000
    • To retrieve the value:
      mc config get timeout

max_length [OPT]

  • Description: This key specifies the maximum length of generated text.
  • Example Setting:
    • To set the value:
      mc config set max_length=50
    • To retrieve the value:
      mc config get max_length

max_token [OPT]

  • Description: This key determines the maximum number of tokens in the generated text.
  • Example Setting:
    • To set the value:
      mc config set max_token=200
    • To retrieve the value:
      mc config get max_token

copy_commit [OPT]

  • Description: This key is a boolean flag that determines whether to copy the generated text to the clipboard.
  • Example Setting (True):
    • To set the value:
      mc config set copy_commit=True
    • To retrieve the value:
      mc config get copy_commit

Getting Configuration Values

To retrieve the values for these configuration keys, you can use the following commands:

  • To get all configuration values:
mc config get

Usage

Generate Commit Messages

You can use MagicCommits to effortlessly generate commit messages for your staged changes:

MagicCommits will analyze your Git diff and employ AI to suggest a commit message. You can then choose to commit, commit and push, or copy the message to your clipboard.

Version

To check the current version of MagicCommits, you can use the following command:

mc --version

Credits

MagicCommits is inspired by AI Commits, created by Hassan El Mghari.

Contributing

If you want to help fix a bug or implement a feature in Issues, checkout the Contribution Guide to learn how to setup project.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Made in Nepal Nepal Flag