This plugin extends commitzen for ai functions. The plugin will use Google Gemini API.
There are two options the plugin provides.
- auto generate commit messages base on changes.
- spell checking your commit message
- include CHANGELOG templates with issus and author link
The plugin strongly based on original customize plugin, so you are also able to customize it the same way.
To be able to use the Gemini API you must have an GOOGLE_API_KEY. You can create one for free here. The plugin provide two option to configure the GOOGLE_API_KEY. You can put it in the config section or you can set it to your environment.
❗ I strongly recommend to you to use the environment option for security reason. ❗
The environment variable has to called GOOGLE_API_KEY
You can install it with pip from TestPyPi
pip install -i https://test.pypi.org/simple/ cz-gemini
First we have to clone it to your local machine
git clone https://github.com/avjui/cz_gemini
cd cz_gemini
After that we can install it
pip3 install .
To use the plugin you have to set name variable in your commitizen config file to cz_gemini.
{
"commitizen": {
"name": "cz_gemini",
...
for configuration plugin himself add section gemini to your commitzen config file.
"gemini": {
"autogenerate": true|false
...
📕 if autogenerate is set to false
you have enabled the spellchecker functionality.
you also can provide a custom gemini template for get maybe better results. In the default template are 4 variable given. The diff
will autogenerated. The number
give you the max number of results. This can also be set by config. Default it is set to 5.
📓 Sometimes you get less messages. It seems the the pattern to parse the messages is not optimal.
"answer_number" : "5"
scope
and type
can be set by the question
option in the config. There will automatically passed the scope|type and description for it.
"template": "suggest {{number}} commit messages based on the following diff:\n
{{diff}}\n
commit messages should:\n
- follow conventional commits \n
- message format should be: <type>[scope]: <description> - <detail> \n
- description should not be longer then 50 character \n
- description should be lower case and no period \n
- detail should contain detail information of changes \n
- valid type name (key name is 'value') and descriptions of the type name (key name is 'name') can be found in following dict with the key name 'value' {{types}}\n
- valid scope name (key name 'value') and description of the scope name (key name is 'name') can be found in following dict with the key name 'value' {{scopes}} \n
- only return commit messages without description or other text \n
\n
examples: \n
- fix(back): add password regex pattern \n
- test(perf): add new test cases\n "
if you use a custom template maybe it is also necessary to provide regex pattern for this. The first one parse the answer, replayed from gemini. The second one create the commitzen needed format from parsed text. For better development the regex pattern you can enable verbose to print the necessary information's.
"answer_pattern": "(?:\```?\n?)",
"commitizen_pattern": "(?P<type>.*?)\((?P<scope>.*?)\)\:\ (?P<subject>.*?)\-\ (?P<body>.*?)\n"
"verbose" : true|false
If you set autogenerate
to true
you will get the complete answers to choice from the gemini ai
$ cz commit
? Select one of the autogenerated commit message (Use arrow keys)
» feat(docs): add usage and todo sections to readme - added sections for usage and a todo list
feat(docs): add testpypi installation instructions - included instructions for installing from TestPyPi
feat(docs): improve readme with badges and details - added badges and clarified installation options
feat(docs): add changelog template information - specified that changelog templates with issue and author links are included
fix(docs): clarify gemini template variables and limitations - improved explanation of template variables and potential limitations in result count
If you have set autogenerate
to false
all will be the same, but gemini will spellcheck your commit message for you.
- more tests
- maybe we need to optimize the pattern and message template to get better results
- maybe change the behavior that gemini generate the complete message. maybe we change this to get only the commit message and have to choice
scope
antchange_type
manual