ljnsn / cz-conventional-gitmoji

A commitizen plugin that combines gitmoji and conventional commits.
14 stars 3 forks source link

BUG: gitmojify hook not prepending the commit on Windows #120

Closed jjfantini closed 7 months ago

jjfantini commented 7 months ago

I am looking to use the commit hook to append emojis onto my commit messages, although it doesn't seem to be working?

# pyproject.toml

[tool.commitizen]
name = "cz_gitmoji"
version = "0.0.0"
tag_format = "v$version"
update_changelog_on_bump = true
annotated_tag = true
major_version_zero = true
version_files = [
    "pyproject.toml:^version",
]
path = ".cz-config.js"

==================================

#.pre-commit-config.yaml

repos:
  - repo: https://github.com/ljnsn/cz-conventional-gitmoji
    rev: main
    hooks:
      - id: conventional-gitmoji
ljnsn commented 7 months ago

Did you install the commit message pre-commit hooks with pre-commit install --hook-type commit-msg?

jjfantini commented 7 months ago

Yes I have because I am using a commitizen hook as well that uses commit-msg

sent from humblWorkshop


⬇️⬇️ TRY OUR DATA TOOLS ⬇️⬇️ 📈📊humblfinance.io📊📈

⬇️⬇️ JOIN OUR SMALL COMMUNITY ⬇️⬇️  📓📖humblblog.com📖📓

⬇️⬇️ CONTACT ⬇️⬇️ 📧: @. 📧: @. 📱: +1 (307) 278-6561 On Jan 23, 2024 at 8:44 PM +0000, ljnsn @.***>, wrote:

Did you install the commit message pre-commit hooks with pre-commit install --hook-type commit-msg? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

ljnsn commented 7 months ago

Your config looks fine. Could you make a minimal reproducible example repo or describe exactly your workflow?

This works for example:

poetry new foo
cd foo
git init
poetry add pre-commit
# add your cz config to pyproject.toml
# add your pre-commit config
pre-commit install --install-hooks  --hook-type commit-msg
git add .
git commit -m "init: initial version"
# commit message: 🎉 init: initial commit
jjfantini commented 7 months ago

Yes, I am working in this repo. Feel free to take a look! Again, I really appreciate the help.

After running pre-commit install, my hooks get messed up and ruff executable can't be found

jjfantini commented 7 months ago

I have tried doing what you suggested:

Command failed with exit code 1: git commit -m "feat: test"
gitmojify................................................................Failed
- hook id: conventional-gitmoji
- exit code: 1

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\jjfan\.cache\pre-commit\repo_zkw_ns5\py_env-python3\Scripts\gitmojify.EXE\__main__.py", line 7, in <module>
  File "C:\Users\jjfan\.cache\pre-commit\repo_zkw_ns5\py_env-python3\Lib\site-packages\gitmojify\mojify.py", line 57, in run
    f.write(gitmojify(msg))
  File "C:\Users\jjfan\github\gitmoji-test\menv\Lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'charmap' codec can't encode character '\u2728' in position 0: character maps to <undefined>

I am using poetry and micromamba to manage my environments.

ljnsn commented 7 months ago

After running pre-commit install, my hooks get messed up and ruff executable can't be found

The ruff executable missing is something else, for me your repo works just fine (after adding the config you posted above to pre-commit-config, it doesn't seem to be there on the dev/gitmojify branch).

The issue seems to be that windows on writing the file uses latin1 encoding and thus cannot encode the unicode character that is assigned to the gitmoji. Do you get the same error if you run gitmojify -m "fix: foo" on cli?

I'll try to reproduce this and make a fix.

jjfantini commented 7 months ago

No, I don’t get the same error. Using the CLI returns the corrected commit message. :)

sent from humblWorkshop


⬇️⬇️ TRY OUR DATA TOOLS ⬇️⬇️ 📈📊humblfinance.io📊📈

⬇️⬇️ JOIN OUR SMALL COMMUNITY ⬇️⬇️  📓📖humblblog.com📖📓

⬇️⬇️ CONTACT ⬇️⬇️ 📧: @. 📧: @. 📱: +1 (307) 278-6561 On Jan 24, 2024 at 5:42 PM +0000, ljnsn @.***>, wrote:

After running pre-commit install, my hooks get messed up and ruff executable can't be found The ruff executable missing is something else, for me your repo works just fine (after adding the config you posted above to pre-commit-config, it doesn't seem to be there on the dev/gitmojify branch). The issue seems to be that windows on writing the file uses latin1 encoding and thus cannot encode the unicode character that is assigned to the gitmoji. Do you get the same error if you run gitmojify -m "fix: foo" on cli? I'll try to reproduce this and make a fix. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

ljnsn commented 7 months ago

@jjfantini can you check if this is fixed for you if not I'll reopen this

jjfantini commented 7 months ago

Issue Description:

Experiencing difficulties with getting emojis to appear in the repository. No errors are observed, but emojis are not visible in the expected locations.

Branch Reference:

Working on the dev/no_cz_customize branch. Below are the branch settings:

[tool.commitizen]
name = "cz_gitmoji"
version = "0.8.0"
tag_format = "v$version"
update_changelog_on_bump = true
annotated_tag = true
bump_message = "🔖 bump(release): v$current_version → v$new_version"
version_files = ["pyproject.toml:^version"]

===========================================
# https://pre-commit.com
default_install_hook_types: [commit-msg, pre-commit]
default_stages: [commit, manual]
fail_fast: true
repos:
  - repo: https://github.com/ljnsn/cz-conventional-gitmoji
    rev: v0.2.0
    hooks:
      - id: conventional-gitmoji

Testing Results

Commit Method Successful Gitmojify Hook Successful Version Bump
Commitizen commit Not appending emoji ✅ Bumping commit message (without emoji)
CLI cz commit ➖ N.A (commit has emoji already) commit ✅ Bumping commit message (with emoji)
CLI lazygit Not appending emoji ✅ Bumping commit message (without emoji)
VSCode Source Control Text Input Not appending emoji ✅ Bumping commit message (without emoji)
jjfantini commented 7 months ago

Should I try a local pre-commit-config.yaml instead of using your repo?