di-sukharev / opencommit

Generate conventional git commit messages with AI in 1 second πŸ€―πŸ”«
https://www.npmjs.com/package/opencommit
MIT License
6.11k stars 328 forks source link

[Bug]: Commit Types Not Included in Generated Commit Messages #331

Closed thissayantan closed 5 months ago

thissayantan commented 6 months ago

Opencommit Version

3.0.12

Node Version

22.1.0

NPM Version

10.7.0

What OS are you seeing the problem on?

Mac, Windows, Other Linux Distro

What happened?

I've been using OpenCommit to automate the generation of commit messages in my projects. However, I noticed that the commit messages generated do not include the conventional commit types (e.g., feat:, fix:) as outlined in the Conventional Commits specification.

Expected Behavior

The commit messages should include prefixes like feat:, fix:, etc., to categorize the type of change being committed, as per the Conventional Commits standard.

example, πŸŽ‰ feat(README.md): add comprehensive documentation on how to install, use, contribute, license and contact the project.

Current Behavior

The generated commit messages lack these prefixes, making it hard to categorize changes automatically.

This seems to be an oversight in the configuration or in the way the messages are generated. Including commit types would greatly enhance the utility of OpenCommit by ensuring compliance with widely-accepted commit message standards.

Possible Solution

I tried switching to OCO_PROMPT_MODULE=@commitlint to resolve this, hoping it would enforce the Conventional Commits format. Unfortunately, this resulted in errors regarding ES Module compatibility, specifically with @commitlint/load, making this workaround impractical without further adjustments to the code or environment.

Including commit types would greatly enhance the utility of OpenCommit by ensuring compliance with widely-accepted commit message standards.

Steps to Reproduce

  1. Set up OpenCommit with default settings.
  2. Generate a commit message using oco commit.

Relevant log output

No response

matscube commented 6 months ago

@thissayantan Hello,

I tried switching to OCO_PROMPT_MODULE=@commitlint to resolve this, hoping it would enforce the Conventional Commits format. Unfortunately, this resulted in errors regarding ES Module compatibility, specifically with @commitlint/load, making this workaround impractical without further adjustments to the code or environment.

I have confirmed that there is a bug in the OCO_PROMPT_MODULE=@commitlint mode. I am currently trying to fix this bug. https://github.com/di-sukharev/opencommit/pull/336

I've been using OpenCommit to automate the generation of commit messages in my projects. However, I noticed that the commit messages generated do not include the conventional commit types (e.g., feat:, fix:) as outlined in the Conventional Commits specification.

I could not reproduce the issue with the prefix in the default conventional-commit mode. It may be a phenomenon that only occurs under certain configuration conditions. Sharing the settings of .opencommit/.env you are using would make it easier to check the situation. In particular, changing the OCO_MODEL may change the results, as there should be differences in inference capabilities depending on the OCO_MODEL.

joshuadanpeterson commented 5 months ago

I experienced the same issue. I switched to a few different models and also got the same message. I tried switching to @commitlint and can confirm the bug there as well.

thissayantan commented 5 months ago

@thissayantan Hello,

I tried switching to OCO_PROMPT_MODULE=@commitlint to resolve this, hoping it would enforce the Conventional Commits format. Unfortunately, this resulted in errors regarding ES Module compatibility, specifically with @commitlint/load, making this workaround impractical without further adjustments to the code or environment.

I have confirmed that there is a bug in the OCO_PROMPT_MODULE=@commitlint mode. I am currently trying to fix this bug. #336

I've been using OpenCommit to automate the generation of commit messages in my projects. However, I noticed that the commit messages generated do not include the conventional commit types (e.g., feat:, fix:) as outlined in the Conventional Commits specification.

I could not reproduce the issue with the prefix in the default conventional-commit mode. It may be a phenomenon that only occurs under certain configuration conditions. Sharing the settings of .opencommit/.env you are using would make it easier to check the situation. In particular, changing the OCO_MODEL may change the results, as there should be differences in inference capabilities depending on the OCO_MODEL.

hi @matscube ,

Thanks for your reply and sorry for my late response.

my ~/.opencommit looks like the following

OCO_OPENAI_API_KEY=sk-xxxx
OCO_OPENAI_MAX_TOKENS=undefined
OCO_OPENAI_BASE_PATH=undefined
OCO_DESCRIPTION=undefined
OCO_EMOJI=true
OCO_MODEL=gpt-4
OCO_LANGUAGE=en
OCO_MESSAGE_TEMPLATE_PLACEHOLDER=$msg
OCO_PROMPT_MODULE=conventional-commit

I was going through the code. I think in prompt.ts the place where OCO_EMOJI is being cheked there os a bit of a issue. If it's possible for you can you please take a look? Or else I also can create a PR to fix this. Honestly this bug bothers me a bit. But I'm really wondering how come other people are not facing the same issue?!! πŸ€”

matscube commented 5 months ago

@thissayantan Thank you for sharing your config file. I've tried again with the same configuration and can confirm that the issue you've reported is reproducible. As you've noted, the OCO_EMOJI function seems to toggle this behavior.

However, emojis might serve as an alternative to the conventional commit prefix keywords (feat, fix, etc.). Therefore, this behavior might be intended. For more details on implementing the emoji function, the following link might be helpful:

https://github.com/di-sukharev/opencommit/pull/249

The loss of fix, chore, etc, is done on purpose. This is due to the changes on src/prompts.ts:143-144. As my understanding the fix & chore are keywords in Conventional Commits and not present in the GitMoji standard.

If you'd like to use both emojis and conventional commit prefixes, it would be a good idea to propose this as a new feature PR.

OCO_PROMPT_MODULE's bug

I've submitted a PR to address the bug with OCO_PROMPT_MODULE and am awaiting review and merge.

thissayantan commented 5 months ago

@matscube Thanks for the clarification. And you're right I was indeed looking forward to use the both emojis and conventional commit prefixes. As that used to be case before.

example, πŸŽ‰ feat(README.md): add comprehensive documentation on how to install, use, contribute, license and contact the project.

But as you pointed out this has been done on purpose. Thanks for that. I'll open a feature request.