Esempio n. 1
0
def infer_vnext(log,
                suffix=None,
                suffix_dot_suffix=False,
                suffix_dash_prefix=False):
    latest_tag_index = get_latest_tag_index(log)
    if latest_tag_index is None:
        if suffix:
            return SemVer(
                0,
                1,
                0,
                suffix=suffix,
                suffix_number=1,
                suffix_dot_suffix=suffix_dot_suffix,
                suffix_dash_prefix=suffix_dash_prefix,
            )
        else:
            return SemVer(0, 1, 0)
    else:
        version = SemVer.fromstr(log[latest_tag_index]["tag"].replace("v", ""))
        if (version.isprerelease()
                and version.suffix_dash_prefix == suffix_dash_prefix
                and version.suffix == suffix
                and version.suffix_dot_suffix == suffix_dot_suffix):
            version.increment_suffix_number()
            return version
        if latest_tag_index == len(log) - 1:
            version.increment_micro()
            return version
        major_bump, minor_bump = False, False
        for commit in log[latest_tag_index + 1:]:
            try:
                cc_msg_type = ConventionalCommitMsg(commit["message"]).msg_type
                if cc_msg_type == "BREAKING CHANGE":
                    major_bump = True
                elif cc_msg_type == "feat":
                    minor_bump = True
            except Exception as e:
                print(
                    f"WARNING: Commit '{commit['hash']}' did not have a Conventional Commits-compliant message.",
                    file=sys.stderr,
                )
                print(e, file=sys.stderr)
        if major_bump:
            version.increment_major()
        elif minor_bump:
            version.increment_minor()
        else:
            version.increment_micro()
        return version
Esempio n. 2
0
def test_fromstr_parses_correctly(
    param,
    major,
    minor,
    micro,
    suffix_dash_prefix,
    suffix,
    suffix_dot_suffix,
    suffix_number,
):
    s = SemVer.fromstr(param)
    assert s.major == major
    assert s.minor == minor
    assert s.micro == micro
    assert s.suffix_dash_prefix == suffix_dash_prefix
    assert s.suffix == suffix
    assert s.suffix_dot_suffix == suffix_dot_suffix
    assert s.suffix_number == suffix_number
    assert s == param
Esempio n. 3
0
def test_isprelease(version, isprerelease):
    assert SemVer.fromstr(version).isprerelease() == isprerelease
Esempio n. 4
0
def test_bad_param_in_fromstr_raises_valueerror(param):
    with pytest.raises(ValueError):
        SemVer.fromstr(param)
Esempio n. 5
0
def test_fromstr(param):
    assert SemVer.fromstr(param) == param