Everduin94 / better-commits

A CLI for creating better commits following the conventional commits specification
MIT License
1.88k stars 69 forks source link

How to add commit trailer based on commit type selected #74

Closed krupis closed 5 months ago

krupis commented 5 months ago

Hello. I use Gitlab built-in feature (glab) to generate Changelogs for my projects based on Commit trailer messages as described here: https://docs.gitlab.com/ee/user/project/changelogs.html

In order for glab to detect commits, each commit needs to have a commit trailer. My commit example:

git commit -m "fixed voltage measurement issue" --trailer "Changelog: fixed"

The following commit with a trailer will then show up in the Gitlab as shown below: image

And when I generate the changelog, it will look something like:

## 1.0.2-5-g796eb48
 (2024-01-25)

### fixed (1 change)

- [fixed voltage measurement issue](testing/universal-testboard-v3@825b7b5474216ab7abc84af033b417a766952e8e) ([merge request](testing/universal-testboard-v3!1))

Since I am making all commit messages and commit trailers by hand, this method is very sensitive to human error. For example if I make typo when writing a commit trailer, the glab will not detect the commits.

I was hoping to use better-commits to automate this process and ensure each commit is tagged with appropriate commit trailer based on selected commit type.

For example, I have a list of commit types:

    "commit_type": {
        "enable": true,
        "initial_value": "feat",
        "infer_type_from_branch": true,
        "append_emoji_to_label": false,
        "append_emoji_to_commit": false,
        "options": [
            {
                "value": "feat",
                "label": "feat",
                "hint": "A new feature",
                "emoji": "✨"
            },
            {
                "value": "fix",
                "label": "fix",
                "hint": "A bug fix",
                "emoji": "πŸ›"
            },
            {
                "value": "docs",
                "label": "docs",
                "hint": "Documentation only changes",
                "emoji": "πŸ“š"
            },
            {
                "value": "test",
                "label": "test",
                "hint": "Adding missing tests or correcting existing tests",
                "emoji": "🚨"
            },
            {
                "value": "ci",
                "label": "ci",
                "hint": "Changes to our CI configuration files and scripts",
                "emoji": "πŸ€–"
            },
            {
                "value": "",
                "label": "none"
            }
        ]
    },

Is there a possibility to append a trailer to commit message based on selected commit type? For example, if I select feat , I want to automatically append Changelog: added as my Commit trailer.

If I select fix, I want to append Changelog: fixed and etc...

Thanks in advance!

Everduin94 commented 5 months ago

Hey thanks for writing up this issue! - I've seen trailers on Github PRs like "Co-Authored by X" but had no idea they were their own flag on git commit, pretty cool!

Yeah I think this makes sense and is easy to add to the project.

github-actions[bot] commented 5 months ago

:tada: This issue has been resolved in version 1.9.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: