commitizen icon indicating copy to clipboard operation
commitizen copied to clipboard

Bumping issue with PATCH version

Open Lavish-jain-5 opened this issue 2 years ago • 1 comments

Description

While using commitizen, if we have any non-eligible bump commits, like if we defined custom bump map. In which if I defined style or docs as non-eligible bumping commits. So when I did any non-bumping commits after that If I do PATCH version bumping commits. It's not bumping the version. It just bumps when any MAJOR or MINOR version is present.

Steps to reproduce

  1. Define bump_pattern = r"^(break|fix|feat|docs|style|refactor|perf|test)((.+))?(:.*)" bump_map = {"break": "MAJOR", "feat": "MINOR", "fix": "PATCH", "refactor": "PATCH", "perf": "PATCH"}

  2. Then do any non-eligible bumping commits like (docs, style, test) commit.

  3. After that do any PATCH version commit like (fix, perf)

Current behavior

So while doing PATCH commits after any non-eligible commits. It's not bumping the PATCH version. We need to do any MAJOR or MINOR commit to bump the version.

Desired behavior

It should Bump the version if we have any PATCH commit in stack with any non-eligible commits.

Screenshots

No response

Environment

ubuntu wsl

Lavish-jain-5 avatar Sep 27 '23 12:09 Lavish-jain-5

So we can solve this issue by adding one condition in find_increment function in commitizen.bump file.


def patched_find_increment(commits, regex: str, increments_map) -> str:
    if isinstance(increments_map, dict):
        increments_map = OrderedDict(increments_map)

    # Most important cases are major and minor.
    # Everything else will be considered patch.
    select_pattern = re.compile(regex)
    increment = None
    for commit in commits:
        for message in commit.message.split("\n"):
            result = select_pattern.search(message)
            if result:
                found_keyword = result.group(1)
                new_increment = None
                for match_pattern in increments_map.keys():
                    if re.match(match_pattern, found_keyword):
                        new_increment = increments_map[match_pattern]
                        break

                if increment == MAJOR:
                    break
                elif increment == MINOR and new_increment == MAJOR:
                    increment = new_increment
                elif increment == PATCH and new_increment is None:
                    increment = increment
                elif increment == PATCH or increment is None:
                    increment = new_increment

    return increment

Lavish-jain-5 avatar Sep 27 '23 12:09 Lavish-jain-5

Hi @Lavish-jain-5, thanks for reporting this issue. I just tested it with the latest version (3.26.0) without encountering this issue. Could you please update the commitizen and see whether the issue still persists? I'm going to close this one, but let me know if the issue is still there 🙂

Lee-W avatar May 20 '24 21:05 Lee-W