freepik-company / gommitizen

A commitizen written in go for monorepo
MIT License
8 stars 1 forks source link

Fail marshaling a json string based on commit information containing invalid characters #53

Closed sergiotejon closed 2 weeks ago

sergiotejon commented 2 weeks ago

Fail marshaling a json string based on commit information containing the character ".

When running a bump over a commit message of this kind we received the next error:

# gommitizen bump
Running bump in project /Users/stejon/develop/gommitizen/playground/demo-repo/apps/app1
bump by config: commit messages: fail unmarshal json git log --pretty=format:'{"hash": "%H", "date": "%ad", "subject": "%s"}' --date=format-local:'%Y-%m-%dT%H:%M:%SZ' 7afadac4444164777ea8c736f2e9f342e8a7d61a.. -- /Users/stejon/develop/gommitizen/playground/demo-repo/apps/app1: invalid character 'a' after object key:value pair

This is the log that shows us by the git log information where we can check that the message has invalid characters in the json string:

# git log --pretty=format:'{"hash": "%H", "date": "%ad", "subject": "%s"}' --date=format-local:'%Y-%m-%dT%H:%M:%SZ' 7afadac4444164777ea8c736f2e9f342e8a7d61a.. -- /Users/stejon/develop/gommitizen/playground/demo-repo/apps/app1

{"hash": "3e25df33526e19da9bd924fe19a54c9da6dcf6c0", "date": "2024-11-08T14:34:35Z", "subject": "feat(apps/app1/Mi_App): Introduce "asi es" and replace "Po eso""}
{"hash": "0adcdef214cfa0f833410f81b792538ce157263d", "date": "2024-11-08T14:32:27Z", "subject": "feat(apps/app1): Initialize app1 structure"}

We need to sanitize the git log output in JSON format before we try to unmarshal it in the code.

sergiotejon commented 2 weeks ago

Fixed this problem formating using this pattern || for splitting the string given by git log.

Now I'm getting this information through debug information:

ignore commit, no cc by pattern: feat(apps/app1/Mi_App): Introduce "asi es" and replace "Po eso"
ignore commit, no cc by pattern: feat(apps/app1): Initialize app1 structure
sergiotejon commented 2 weeks ago

Fixed implementing the usage of https://github.com/leodido/go-conventionalcommits to parser the conventional commit information instead of regex directly.