PyVCC 1.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyvcc-1.2.1/LICENSE +24 -0
- pyvcc-1.2.1/PKG-INFO +15 -0
- pyvcc-1.2.1/README.md +5 -0
- pyvcc-1.2.1/pyproject.toml +101 -0
- pyvcc-1.2.1/pyvcc/__init__.py +4 -0
- pyvcc-1.2.1/pyvcc/__main__.py +27 -0
- pyvcc-1.2.1/pyvcc/cli.py +55 -0
- pyvcc-1.2.1/pyvcc/semver.py +136 -0
- pyvcc-1.2.1/tests/__init__.py +0 -0
- pyvcc-1.2.1/tests/cli/__init__.py +0 -0
- pyvcc-1.2.1/tests/cli/test_cli.py +73 -0
- pyvcc-1.2.1/tests/semver/__init__.py +0 -0
- pyvcc-1.2.1/tests/semver/conftest.py +117 -0
- pyvcc-1.2.1/tests/semver/test_breaking_change.py +41 -0
- pyvcc-1.2.1/tests/semver/test_bump_version.py +118 -0
pyvcc-1.2.1/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
|
2
|
+
|
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
4
|
+
distribute this software, either in source code form or as a compiled
|
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
|
6
|
+
means.
|
|
7
|
+
|
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
|
9
|
+
of this software dedicate any and all copyright interest in the
|
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
|
11
|
+
of the public at large and to the detriment of our heirs and
|
|
12
|
+
successors. We intend this dedication to be an overt act of
|
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
|
14
|
+
software under copyright law.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
|
|
24
|
+
For more information, please refer to <https://unlicense.org>
|
pyvcc-1.2.1/PKG-INFO
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: PyVCC
|
|
3
|
+
Version: 1.2.1
|
|
4
|
+
Summary: PyVCC python version controller using conventional commits
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Requires-Dist: pygit2>=1.18.0
|
|
7
|
+
Requires-Dist: structlog>=25.3.0
|
|
8
|
+
Requires-Dist: typing-extensions>=4.0.0; python_version < "3.11"
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
|
|
11
|
+
# python-version-controller
|
|
12
|
+
conventional version controller for python
|
|
13
|
+
|
|
14
|
+
[](https://codecov.io/gh/lcavalcante/python-version-controller)
|
|
15
|
+
[](https://github.com/lcavalcante/python-version-controller/actions/workflows/code-quality.yml)
|
pyvcc-1.2.1/README.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# python-version-controller
|
|
2
|
+
conventional version controller for python
|
|
3
|
+
|
|
4
|
+
[](https://codecov.io/gh/lcavalcante/python-version-controller)
|
|
5
|
+
[](https://github.com/lcavalcante/python-version-controller/actions/workflows/code-quality.yml)
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "PyVCC"
|
|
3
|
+
version = "1.2.1"
|
|
4
|
+
description = "PyVCC python version controller using conventional commits"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
dependencies = [
|
|
8
|
+
"pygit2>=1.18.0",
|
|
9
|
+
"structlog>=25.3.0",
|
|
10
|
+
"typing-extensions>=4.0.0; python_version < '3.11'",
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
[dependency-groups]
|
|
14
|
+
dev = [
|
|
15
|
+
"coverage[toml]>=7.8.0",
|
|
16
|
+
"pre-commit>=4.2.0",
|
|
17
|
+
"pytest>=8.3.5",
|
|
18
|
+
"pytest-cov>=6.1.1",
|
|
19
|
+
"rich>=14.0.0",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[build-system]
|
|
23
|
+
requires = [
|
|
24
|
+
"pdm-backend",
|
|
25
|
+
]
|
|
26
|
+
build-backend = "pdm.backend"
|
|
27
|
+
|
|
28
|
+
[tool.pdm]
|
|
29
|
+
distribution = true
|
|
30
|
+
|
|
31
|
+
[tool.ruff.lint.isort]
|
|
32
|
+
combine-as-imports = true
|
|
33
|
+
|
|
34
|
+
[tool.pyright]
|
|
35
|
+
include = [
|
|
36
|
+
"pyvcc",
|
|
37
|
+
"tests",
|
|
38
|
+
]
|
|
39
|
+
exclude = [
|
|
40
|
+
"**/__pycache__",
|
|
41
|
+
"**/node_modules",
|
|
42
|
+
"**/.git",
|
|
43
|
+
".venv",
|
|
44
|
+
"venv",
|
|
45
|
+
]
|
|
46
|
+
typeCheckingMode = "standard"
|
|
47
|
+
pythonVersion = "3.13"
|
|
48
|
+
reportMissingImports = true
|
|
49
|
+
reportMissingTypeStubs = false
|
|
50
|
+
|
|
51
|
+
[tool.coverage.run]
|
|
52
|
+
source = [
|
|
53
|
+
".",
|
|
54
|
+
]
|
|
55
|
+
omit = [
|
|
56
|
+
"*/tests/*",
|
|
57
|
+
"*/test_*",
|
|
58
|
+
"*/__pycache__/*",
|
|
59
|
+
"*/venv/*",
|
|
60
|
+
".venv/*",
|
|
61
|
+
"setup.py",
|
|
62
|
+
"*/migrations/*",
|
|
63
|
+
"pyvcc/__main__.py",
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
[tool.coverage.report]
|
|
67
|
+
precision = 2
|
|
68
|
+
show_missing = true
|
|
69
|
+
skip_covered = false
|
|
70
|
+
fail_under = 80
|
|
71
|
+
exclude_lines = [
|
|
72
|
+
"pragma: no cover",
|
|
73
|
+
"def __repr__",
|
|
74
|
+
"if __name__ == .__main__.:",
|
|
75
|
+
"raise NotImplementedError",
|
|
76
|
+
"pass",
|
|
77
|
+
"except ImportError:",
|
|
78
|
+
]
|
|
79
|
+
|
|
80
|
+
[tool.coverage.html]
|
|
81
|
+
directory = "coverage_html_report"
|
|
82
|
+
|
|
83
|
+
[tool.coverage.xml]
|
|
84
|
+
output = "coverage.xml"
|
|
85
|
+
|
|
86
|
+
[tool.pytest.ini_options]
|
|
87
|
+
addopts = "--cov=. --cov-report=xml --cov-report=html --cov-report=term-missing"
|
|
88
|
+
testpaths = [
|
|
89
|
+
"tests",
|
|
90
|
+
]
|
|
91
|
+
python_files = [
|
|
92
|
+
"test_*.py",
|
|
93
|
+
"*_test.py",
|
|
94
|
+
]
|
|
95
|
+
python_classes = [
|
|
96
|
+
"Test*",
|
|
97
|
+
"*Test",
|
|
98
|
+
]
|
|
99
|
+
python_functions = [
|
|
100
|
+
"test_*",
|
|
101
|
+
]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Entry point for running the package as a module.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import sys
|
|
7
|
+
import argparse
|
|
8
|
+
import structlog
|
|
9
|
+
from pyvc.cli import main, validate_args
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
log = structlog.get_logger()
|
|
13
|
+
|
|
14
|
+
if __name__ == "__main__":
|
|
15
|
+
parser = argparse.ArgumentParser(prog="PyVC", description=__doc__)
|
|
16
|
+
parser.add_argument("--root", type=str, default=".", required=False)
|
|
17
|
+
parser.add_argument("--initial-version", type=str, required=False, default="0.1.0")
|
|
18
|
+
parser.add_argument("--initial-commit", type=str, required=False, default="")
|
|
19
|
+
|
|
20
|
+
args = parser.parse_args()
|
|
21
|
+
root = os.getenv(key="PYVC_REPO_ROOT", default=args.root)
|
|
22
|
+
version = os.getenv(key="PYVC_INITIAL_VERSION", default=args.initial_version)
|
|
23
|
+
commit = os.getenv(key="PYVC_INITIAL_COMMIT", default=args.initial_commit)
|
|
24
|
+
if not validate_args(root=root, version=version):
|
|
25
|
+
sys.exit(1)
|
|
26
|
+
|
|
27
|
+
main(root, version, commit)
|
pyvcc-1.2.1/pyvcc/cli.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""
|
|
2
|
+
CLI parsing for pyvc command.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from pygit2 import Commit
|
|
6
|
+
import structlog
|
|
7
|
+
from pathlib import Path, PurePath
|
|
8
|
+
from pygit2.repository import Repository
|
|
9
|
+
from pygit2.enums import SortMode
|
|
10
|
+
|
|
11
|
+
from pyvcc.semver import SemVer
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
log = structlog.get_logger()
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def validate_args(root: str, version: str) -> bool:
|
|
18
|
+
is_valid = True
|
|
19
|
+
repo_path = Path(root) / PurePath(".git")
|
|
20
|
+
if not repo_path.exists():
|
|
21
|
+
is_valid = False
|
|
22
|
+
log.error("repo root does not exist", path=repo_path)
|
|
23
|
+
|
|
24
|
+
try:
|
|
25
|
+
SemVer.semver_from_string(version)
|
|
26
|
+
except Exception as e:
|
|
27
|
+
log.error("invalid initial version", error=str(e))
|
|
28
|
+
is_valid = False
|
|
29
|
+
|
|
30
|
+
return is_valid
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def main(root: str, version: str, start_commit_id: str | None = None) -> str:
|
|
34
|
+
repo_path = Path(root) / PurePath(".git")
|
|
35
|
+
semver = SemVer.semver_from_string(version)
|
|
36
|
+
|
|
37
|
+
repo = Repository(str(repo_path))
|
|
38
|
+
|
|
39
|
+
log.debug("starting repo walk", start_commit_id=start_commit_id)
|
|
40
|
+
commit_walker = repo.walk(repo.head.target, SortMode.TOPOLOGICAL | SortMode.REVERSE)
|
|
41
|
+
|
|
42
|
+
# if start_commit is defined for versioning, skip parents on walk
|
|
43
|
+
if start_commit_id:
|
|
44
|
+
start_commit = repo[start_commit_id]
|
|
45
|
+
if isinstance(start_commit, Commit):
|
|
46
|
+
for parent in start_commit.parent_ids:
|
|
47
|
+
commit_walker.hide(parent)
|
|
48
|
+
|
|
49
|
+
for commit in commit_walker:
|
|
50
|
+
message = commit.message
|
|
51
|
+
log.info("commit", id=commit.id, short=commit.short_id)
|
|
52
|
+
semver.bump_version(message)
|
|
53
|
+
|
|
54
|
+
log.info(f"final version {str(semver)}")
|
|
55
|
+
return str(semver)
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
from enum import Enum, auto
|
|
2
|
+
import sys
|
|
3
|
+
import structlog
|
|
4
|
+
|
|
5
|
+
# Python 3.11+ has Self in typing module
|
|
6
|
+
if sys.version_info >= (3, 11):
|
|
7
|
+
from typing import Self
|
|
8
|
+
else:
|
|
9
|
+
from typing_extensions import Self
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
log = structlog.get_logger()
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class CommitEnum(Enum):
|
|
16
|
+
FEAT = auto()
|
|
17
|
+
FIX = auto()
|
|
18
|
+
BUILD = auto()
|
|
19
|
+
CHORE = auto()
|
|
20
|
+
CI = auto()
|
|
21
|
+
DOCS = auto()
|
|
22
|
+
STYLE = auto()
|
|
23
|
+
REFACTOR = auto()
|
|
24
|
+
PERF = auto()
|
|
25
|
+
TEST = auto()
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class BumpEnum(Enum):
|
|
29
|
+
MAJOR = auto()
|
|
30
|
+
MINOR = auto()
|
|
31
|
+
PATCH = auto()
|
|
32
|
+
NO_BUMP = auto()
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class SemVer:
|
|
36
|
+
def __init__(self, major: int, minor: int, patch: int):
|
|
37
|
+
self.major = major
|
|
38
|
+
self.minor = minor
|
|
39
|
+
self.patch = patch
|
|
40
|
+
|
|
41
|
+
self.log = log
|
|
42
|
+
|
|
43
|
+
def __repr__(self):
|
|
44
|
+
return f"{self.major}.{self.minor}.{self.patch}"
|
|
45
|
+
|
|
46
|
+
@staticmethod
|
|
47
|
+
def is_breaking_change(type: str, message: str) -> bool:
|
|
48
|
+
"""
|
|
49
|
+
SemVer defines that a breaking change is a commit with a type ending in '!'
|
|
50
|
+
OR that contains 'BREAKING CHANGE:' in the messsage body
|
|
51
|
+
|
|
52
|
+
# Parameters:
|
|
53
|
+
type (str): Commit message type (feat, fix, chore, etc)
|
|
54
|
+
message (str): commit message content
|
|
55
|
+
"""
|
|
56
|
+
return type[-1] == "!" or "BREAKING CHANGE:" in message
|
|
57
|
+
|
|
58
|
+
@classmethod
|
|
59
|
+
def semver_from_string(cls, str_version: str) -> Self:
|
|
60
|
+
# TODO: regex?
|
|
61
|
+
list_version = str_version.split(".")
|
|
62
|
+
if len(list_version) != 3:
|
|
63
|
+
# TODO: custom exception
|
|
64
|
+
raise Exception("invalid string formating for semantic versioning")
|
|
65
|
+
|
|
66
|
+
major = int(list_version[0])
|
|
67
|
+
minor = int(list_version[1])
|
|
68
|
+
patch = int(list_version[2])
|
|
69
|
+
return cls(major, minor, patch)
|
|
70
|
+
|
|
71
|
+
@classmethod
|
|
72
|
+
def bump_type(cls, message: str) -> BumpEnum:
|
|
73
|
+
"""
|
|
74
|
+
Given a version number MAJOR.MINOR.PATCH, increment the:
|
|
75
|
+
|
|
76
|
+
- MAJOR: version when you make incompatible API changes
|
|
77
|
+
- MINOR: version when you add functionality in a backward compatible manner
|
|
78
|
+
- PATCH: version when you make backward compatible bug fixes
|
|
79
|
+
Additional labels for pre-release and build metadata are available as
|
|
80
|
+
extensions to the MAJOR.MINOR.PATCH format.
|
|
81
|
+
|
|
82
|
+
fix: a commit of the type fix patches a bug in your codebase
|
|
83
|
+
(this correlates with PATCH in Semantic Versioning).
|
|
84
|
+
|
|
85
|
+
feat: a commit of the type feat introduces a new feature to the codebase
|
|
86
|
+
(this correlates with MINOR in Semantic Versioning).
|
|
87
|
+
|
|
88
|
+
BREAKING CHANGE: a commit that has a footer BREAKING CHANGE:, or appends a !
|
|
89
|
+
after the type/scope, introduces a breaking API change
|
|
90
|
+
(correlating with MAJOR in Semantic Versioning).
|
|
91
|
+
A BREAKING CHANGE can be part of commits of any type.
|
|
92
|
+
|
|
93
|
+
# Parameters:
|
|
94
|
+
message (str): commit message content
|
|
95
|
+
"""
|
|
96
|
+
|
|
97
|
+
bump = BumpEnum.NO_BUMP
|
|
98
|
+
head = message.split("\n")[0]
|
|
99
|
+
|
|
100
|
+
# TODO: regex?
|
|
101
|
+
parsed_head = head.split(":")
|
|
102
|
+
|
|
103
|
+
if len(parsed_head) > 1:
|
|
104
|
+
commit_type = parsed_head[0].strip().upper()
|
|
105
|
+
|
|
106
|
+
if cls.is_breaking_change(commit_type, message):
|
|
107
|
+
bump = BumpEnum.MAJOR
|
|
108
|
+
elif commit_type == CommitEnum.FEAT.name:
|
|
109
|
+
bump = BumpEnum.MINOR
|
|
110
|
+
elif commit_type == CommitEnum.FIX.name:
|
|
111
|
+
bump = BumpEnum.PATCH
|
|
112
|
+
else:
|
|
113
|
+
bump = BumpEnum.NO_BUMP
|
|
114
|
+
else:
|
|
115
|
+
log.info("not in conventional commit spec", message=head)
|
|
116
|
+
|
|
117
|
+
return bump
|
|
118
|
+
|
|
119
|
+
def bump_version(self, message: str) -> None:
|
|
120
|
+
self.log = self.log.bind(message=message)
|
|
121
|
+
|
|
122
|
+
match self.bump_type(message):
|
|
123
|
+
case BumpEnum.MAJOR:
|
|
124
|
+
self.major += 1
|
|
125
|
+
self.minor = 0
|
|
126
|
+
self.patch = 0
|
|
127
|
+
self.log.debug("bump Major")
|
|
128
|
+
case BumpEnum.MINOR:
|
|
129
|
+
self.minor += 1
|
|
130
|
+
self.patch = 0
|
|
131
|
+
self.log.debug("bump Minor")
|
|
132
|
+
case BumpEnum.PATCH:
|
|
133
|
+
self.patch += 1
|
|
134
|
+
self.log.debug("bump Patch")
|
|
135
|
+
case BumpEnum.NO_BUMP:
|
|
136
|
+
self.log.debug("no bump")
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
from pygit2 import Commit
|
|
2
|
+
import pytest
|
|
3
|
+
from pygit2.repository import Repository
|
|
4
|
+
|
|
5
|
+
from pyvcc.cli import main, validate_args
|
|
6
|
+
from pyvcc.semver import BumpEnum, SemVer
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class MockCommit:
|
|
10
|
+
def __init__(self, message, id, short_id):
|
|
11
|
+
self.message = message
|
|
12
|
+
self.id = id
|
|
13
|
+
self.short_id = short_id
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_main_invalid_path():
|
|
17
|
+
with pytest.raises(Exception):
|
|
18
|
+
main("/(7", "1.0.0")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_main_invalid_semver():
|
|
22
|
+
with pytest.raises(Exception):
|
|
23
|
+
main(".", "1.0.0.2")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_validate_version():
|
|
27
|
+
assert validate_args(".", "1.0.a") is False
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_validate_path():
|
|
31
|
+
assert validate_args("/(??", "1.1.1") is False
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_validate_true():
|
|
35
|
+
assert validate_args(".", "1.2.3") is True
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_single_commit(monkeypatch):
|
|
39
|
+
def mock_walk(*args, **kwargs): # noqa
|
|
40
|
+
return [MockCommit(message="feat: x", id="123456789", short_id="1234567")]
|
|
41
|
+
|
|
42
|
+
monkeypatch.setattr(Repository, "walk", mock_walk)
|
|
43
|
+
|
|
44
|
+
assert main(".", "1.0.0") == "1.1.0"
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_two_commits(monkeypatch):
|
|
48
|
+
def mock_walk(*args, **kwargs): # noqa
|
|
49
|
+
return [
|
|
50
|
+
MockCommit(message="feat: x", id="123456789", short_id="1234567"),
|
|
51
|
+
MockCommit(message="feat: y", id="234456789", short_id="2344567"),
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
monkeypatch.setattr(Repository, "walk", mock_walk)
|
|
55
|
+
|
|
56
|
+
assert main(".", "1.0.0") == "1.2.0"
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_head_bump_commit():
|
|
60
|
+
repo = Repository(".git")
|
|
61
|
+
commit = repo[repo.head.target]
|
|
62
|
+
|
|
63
|
+
if isinstance(commit, Commit):
|
|
64
|
+
message = commit.message
|
|
65
|
+
match SemVer.bump_type(message):
|
|
66
|
+
case BumpEnum.MAJOR:
|
|
67
|
+
assert main(".", "1.0.0", str(repo.head.target)) == "2.0.0"
|
|
68
|
+
case BumpEnum.MINOR:
|
|
69
|
+
assert main(".", "1.0.0", str(repo.head.target)) == "1.1.0"
|
|
70
|
+
case BumpEnum.PATCH:
|
|
71
|
+
assert main(".", "1.0.0", str(repo.head.target)) == "1.0.1"
|
|
72
|
+
case BumpEnum.NO_BUMP:
|
|
73
|
+
assert main(".", "1.0.0", str(repo.head.target)) == "1.0.0"
|
|
File without changes
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from pyvcc import SemVer
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@pytest.fixture
|
|
6
|
+
def initial_version() -> SemVer:
|
|
7
|
+
return SemVer(0, 1, 0)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
# Conventional feature commits
|
|
11
|
+
@pytest.fixture
|
|
12
|
+
def feat_commit():
|
|
13
|
+
return ("feat", "feat: Add new user authentication API")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@pytest.fixture
|
|
17
|
+
def feat_breaking_with_exclamation():
|
|
18
|
+
return ("feat!", "feat!: Redesign API endpoint structure")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@pytest.fixture
|
|
22
|
+
def feat_breaking_with_text():
|
|
23
|
+
return (
|
|
24
|
+
"feat",
|
|
25
|
+
"""feat: Migrate to new database schema
|
|
26
|
+
|
|
27
|
+
BREAKING CHANGE: Database schema has changed and requires migration""",
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# Conventional fix commits
|
|
32
|
+
@pytest.fixture
|
|
33
|
+
def fix_commit():
|
|
34
|
+
return ("fix", "fix: Resolve login error on Safari")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@pytest.fixture
|
|
38
|
+
def fix_commit_with_body():
|
|
39
|
+
return (
|
|
40
|
+
"fix",
|
|
41
|
+
"""fix: Fix memory leak in background process
|
|
42
|
+
|
|
43
|
+
The background process was not properly releasing resources
|
|
44
|
+
when tasks completed.""",
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@pytest.fixture
|
|
49
|
+
def fix_breaking_with_exclamation():
|
|
50
|
+
return ("fix!", "fix!: Change authentication flow completely")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# Other conventional commits
|
|
54
|
+
@pytest.fixture
|
|
55
|
+
def chore_commit():
|
|
56
|
+
return ("chore", "chore: Update dependencies")
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@pytest.fixture
|
|
60
|
+
def docs_commit():
|
|
61
|
+
return ("docs", "docs: Update README installation instructions")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@pytest.fixture
|
|
65
|
+
def style_commit():
|
|
66
|
+
return ("style", "style: Format code according to new style guide")
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@pytest.fixture
|
|
70
|
+
def refactor_commit():
|
|
71
|
+
return ("refactor", "refactor: Simplify user management functions")
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@pytest.fixture
|
|
75
|
+
def test_commit():
|
|
76
|
+
return ("test", "test: Add new test cases for payment processing")
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@pytest.fixture
|
|
80
|
+
def ci_commit():
|
|
81
|
+
return ("ci", "ci: Update GitHub Actions workflow")
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
@pytest.fixture
|
|
85
|
+
def build_commit():
|
|
86
|
+
return ("build", "build: Migrate to Webpack 5")
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@pytest.fixture
|
|
90
|
+
def perf_commit():
|
|
91
|
+
return ("perf", "perf: Optimize image loading process")
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
@pytest.fixture
|
|
95
|
+
def chore_breaking_commit():
|
|
96
|
+
return (
|
|
97
|
+
"chore!",
|
|
98
|
+
"""chore!: Drop support for legacy browsers
|
|
99
|
+
|
|
100
|
+
This removes polyfills and workarounds for older browsers.""",
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
# Non-conventional commits
|
|
105
|
+
@pytest.fixture
|
|
106
|
+
def no_cc_simple_commit():
|
|
107
|
+
return (None, "Added new feature")
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
@pytest.fixture
|
|
111
|
+
def no_cc_bug_number_commit():
|
|
112
|
+
return ("Fixed bug", "Fixed bug: #123")
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
@pytest.fixture
|
|
116
|
+
def no_cc_doc_commit_non_conventional():
|
|
117
|
+
return (None, "Updated documentation")
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from pyvcc.semver import SemVer
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def test_feat_normal(feat_commit):
|
|
5
|
+
commit_type, message = feat_commit
|
|
6
|
+
assert SemVer.is_breaking_change(commit_type, message) is False
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def test_fix_normal(fix_commit):
|
|
10
|
+
commit_type, message = fix_commit
|
|
11
|
+
assert SemVer.is_breaking_change(commit_type, message) is False
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def test_feat_with_exclamation(feat_breaking_with_exclamation):
|
|
15
|
+
commit_type, message = feat_breaking_with_exclamation
|
|
16
|
+
assert SemVer.is_breaking_change(commit_type, message) is True
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def test_fix_with_exclamation(fix_breaking_with_exclamation):
|
|
20
|
+
commit_type, message = fix_breaking_with_exclamation
|
|
21
|
+
assert SemVer.is_breaking_change(commit_type, message) is True
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_with_breaking_change_text(feat_breaking_with_text):
|
|
25
|
+
commit_type, message = feat_breaking_with_text
|
|
26
|
+
assert SemVer.is_breaking_change(commit_type, message) is True
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def test_chore_normal(chore_commit):
|
|
30
|
+
commit_type, message = chore_commit
|
|
31
|
+
assert SemVer.is_breaking_change(commit_type, message) is False
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_docs_normal(docs_commit):
|
|
35
|
+
commit_type, message = docs_commit
|
|
36
|
+
assert SemVer.is_breaking_change(commit_type, message) is False
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_chore_with_exclamation():
|
|
40
|
+
commit_type, message = ("chore!", "Major dependency update")
|
|
41
|
+
assert SemVer.is_breaking_change(commit_type, message) is True
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from pyvcc.semver import SemVer
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def test_bump_major(feat_breaking_with_text: tuple[str, str]):
|
|
6
|
+
version = SemVer(0, 1, 0)
|
|
7
|
+
message = feat_breaking_with_text[1]
|
|
8
|
+
version.bump_version(message)
|
|
9
|
+
assert str(version) == "1.0.0"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_bump_major_2(feat_breaking_with_exclamation: tuple[str, str]):
|
|
13
|
+
version = SemVer(0, 1, 0)
|
|
14
|
+
message = feat_breaking_with_exclamation[1]
|
|
15
|
+
version.bump_version(message)
|
|
16
|
+
assert str(version) == "1.0.0"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def test_bump_minor(feat_commit: tuple[str, str]):
|
|
20
|
+
version = SemVer(0, 1, 0)
|
|
21
|
+
message = feat_commit[1]
|
|
22
|
+
version.bump_version(message)
|
|
23
|
+
assert str(version) == "0.2.0"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_bump_patch(fix_commit: tuple[str, str]):
|
|
27
|
+
version = SemVer(0, 1, 0)
|
|
28
|
+
message = fix_commit[1]
|
|
29
|
+
version.bump_version(message)
|
|
30
|
+
assert str(version) == "0.1.1"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def test_no_bump(docs_commit: tuple[str, str]):
|
|
34
|
+
version = SemVer(0, 1, 0)
|
|
35
|
+
message = docs_commit[1]
|
|
36
|
+
version.bump_version(message)
|
|
37
|
+
assert str(version) == "0.1.0"
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def test_no_bump_not_conventional(no_cc_bug_number_commit: tuple[str, str]):
|
|
41
|
+
version = SemVer(1, 0, 0)
|
|
42
|
+
message = no_cc_bug_number_commit[1]
|
|
43
|
+
version.bump_version(message)
|
|
44
|
+
assert str(version) == "1.0.0"
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_no_bump_no_type(no_cc_simple_commit: tuple[str, str]):
|
|
48
|
+
version = SemVer(1, 0, 0)
|
|
49
|
+
message = no_cc_simple_commit[1]
|
|
50
|
+
version.bump_version(message)
|
|
51
|
+
assert str(version) == "1.0.0"
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def test_bump_multiple():
|
|
55
|
+
"""patch -> minor -> major"""
|
|
56
|
+
version = SemVer(0, 1, 0)
|
|
57
|
+
|
|
58
|
+
version.bump_version("fix: Fix login bug")
|
|
59
|
+
assert str(version) == "0.1.1"
|
|
60
|
+
|
|
61
|
+
version.bump_version("feat: Add new feature")
|
|
62
|
+
assert str(version) == "0.2.0"
|
|
63
|
+
|
|
64
|
+
version.bump_version("feat!: Complete API redesign")
|
|
65
|
+
assert str(version) == "1.0.0"
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def test_bump_multiple2():
|
|
69
|
+
"""patch -> patch -> major"""
|
|
70
|
+
version = SemVer(0, 1, 0)
|
|
71
|
+
|
|
72
|
+
version.bump_version("fix: Fix login bug")
|
|
73
|
+
assert str(version) == "0.1.1"
|
|
74
|
+
|
|
75
|
+
version.bump_version("fix: Fix logout bug")
|
|
76
|
+
assert str(version) == "0.1.2"
|
|
77
|
+
|
|
78
|
+
version.bump_version("feat: New API\n\nBREAKING CHANGE: Complete API redesign")
|
|
79
|
+
assert str(version) == "1.0.0"
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def test_bump_multiple3():
|
|
83
|
+
"""patch -> major -> minor"""
|
|
84
|
+
version = SemVer(0, 1, 0)
|
|
85
|
+
|
|
86
|
+
version.bump_version("fix: Fix login bug")
|
|
87
|
+
assert str(version) == "0.1.1"
|
|
88
|
+
|
|
89
|
+
version.bump_version("feat!: Complete API redesign")
|
|
90
|
+
assert str(version) == "1.0.0"
|
|
91
|
+
|
|
92
|
+
version.bump_version("feat: Add new feature")
|
|
93
|
+
assert str(version) == "1.1.0"
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def test_bump_multiple4():
|
|
97
|
+
"""patch -> patch -> minor"""
|
|
98
|
+
version = SemVer(0, 1, 0)
|
|
99
|
+
|
|
100
|
+
version.bump_version("fix: Fix login bug")
|
|
101
|
+
assert str(version) == "0.1.1"
|
|
102
|
+
|
|
103
|
+
version.bump_version("fix: Fix logout bug")
|
|
104
|
+
assert str(version) == "0.1.2"
|
|
105
|
+
|
|
106
|
+
version.bump_version("feat: Add new feature")
|
|
107
|
+
assert str(version) == "0.2.0"
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def test_parse_semver_str():
|
|
111
|
+
version = SemVer.semver_from_string("1.1.0")
|
|
112
|
+
assert str(version) == "1.1.0"
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def test_parse_semver_invalid_str():
|
|
116
|
+
with pytest.raises(Exception) as excinfo:
|
|
117
|
+
SemVer.semver_from_string("1.1.0.2")
|
|
118
|
+
assert "invalid string" in str(excinfo)
|