di-sukharev / opencommit

Generate conventional git commit messages with AI in 1 second 🤯🔫
https://www.npmjs.com/package/opencommit
MIT License
5.98k stars 318 forks source link

[Bug]: Hook needs env vars set even when using ollama #378

Closed bjornsnoen closed 4 weeks ago

bjornsnoen commented 1 month ago

Opencommit Version

3.0.17

Node Version

18.18.2

NPM Version

9.8.1

What OS are you seeing the problem on?

Other Linux Distro

What happened?

I used oco hook set to install the prepare commit msg hook and tried to run git commit, which produced the following error message:

┌  opencommit
│
└  ✖ Error: No OPEN_AI_API or OCO_ANTHROPIC_API_KEY or OCO_AZURE_API_KEY exists. Set your key in ~/.opencommit

Simply running oco does work as expected but I'd like to be able to edit the commit message.

This is my .opencommit config:

OCO_DESCRIPTION=false
OCO_EMOJI=false
OCO_LANGUAGE=en
OCO_MESSAGE_TEMPLATE_PLACEHOLDER=$msg
OCO_PROMPT_MODULE=conventional-commit
OCO_AI_PROVIDER=ollama
OCO_GITPUSH=false
OCO_ONE_LINE_COMMIT=false
OCO_TEST_MOCK_TYPE=commit-message

Expected Behavior

Generates a commit message and opens my $EDITOR to allow me to modify the message before commiting.

Current Behavior

Commit gets interrupted with the message above.

Possible Solution

Unify config handling between hook and regular command mode.

Steps to Reproduce

  1. Set provider to ollama with oco config set OCO_AI_PROVIDER=ollama
  2. Clean up config file according to https://github.com/di-sukharev/opencommit/issues/352#issuecomment-2186908034
  3. Install git hook with oco hook set
  4. Run git commit

Relevant log output

No response

di-sukharev commented 4 weeks ago

merged, will be released in 3.1.0 today