Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ repos:
hooks:
- id: check-vcs-permalinks
- id: end-of-file-fixer
exclude: "tests/[test_*|data]/*"
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- id: debug-statements
Expand Down
21 changes: 9 additions & 12 deletions commitizen/bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,21 +186,18 @@ def _bump_with_regex(version_file_contents, current_version, new_version, regex)
for match in re.finditer(regex, version_file_contents, re.MULTILINE):
left = version_file_contents[: match.end() + offset]
right = version_file_contents[match.end() + offset :]
line_break = _get_line_break_position(right)

line_break = right.find("\n")
middle = right[:line_break]
current_version_found_in_block = current_version in middle
offset += len(new_version) - len(current_version)
current_version_found |= current_version_found_in_block
right = right[line_break:]
version_file_contents = (
left + middle.replace(current_version, new_version) + right
)
return current_version_found, version_file_contents


def _get_line_break_position(text: str) -> int:
position = text.find("\n")
return max(position, 0)
if current_version in middle:
offset += len(new_version) - len(current_version)
current_version_found = True
version_file_contents = (
left + middle.replace(current_version, new_version) + right
)
return current_version_found, version_file_contents


def _version_to_regex(version: str):
Expand Down
4 changes: 2 additions & 2 deletions commitizen/config/toml_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def _parse_setting(self, data: Union[bytes, str]):
name = "cz_conventional_commits"
```
"""
doc = parse(data)
doc = parse(data) # type: ignore
try:
self.settings.update(doc["tool"]["commitizen"])
self.settings.update(doc["tool"]["commitizen"]) # type: ignore
except exceptions.NonExistentKey:
self.is_empty_config = True
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ isort = "^5.7.0"
freezegun = "^0.3.15"
pydocstyle = "^5.0.2"
pre-commit = "^2.6.0"
pytest-regressions = "^2.2.0"

[tool.poetry.scripts]
cz = "commitizen.cli:main"
Expand Down
4 changes: 4 additions & 0 deletions tests/data/inconsistent_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
__title__ = "requests"
__description__ = "Python HTTP for Humans."
__url__ = "http://python-requests.org"
__version__ = "2.10.3"
27 changes: 27 additions & 0 deletions tests/data/multiple_versions_to_update_pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[[package]]
name = "to-update-1"
version = "1.2.9"

[[package]]
name = "not-to-update"
version = "1.3.3"

[[package]]
name = "not-to-update"
version = "1.3.3"

[[package]]
name = "not-to-update"
version = "1.3.3"

[[package]]
name = "not-to-update"
version = "1.3.3"

[[package]]
name = "not-to-update"
version = "1.3.3"

[[package]]
name = "to-update-2"
version = "1.2.9"
27 changes: 27 additions & 0 deletions tests/data/multiple_versions_to_update_pyproject_wo_eol.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[[package]]
name = "to-update-1"
version = "1.2.9"

[[package]]
name = "not-to-update"
version = "1.3.3"

[[package]]
name = "not-to-update"
version = "1.3.3"

[[package]]
name = "not-to-update"
version = "1.3.3"

[[package]]
name = "not-to-update"
version = "1.3.3"

[[package]]
name = "not-to-update"
version = "1.3.3"

[[package]]
name = "to-update-2"
version = "1.2.9"
7 changes: 7 additions & 0 deletions tests/data/repeated_version_number.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "magictool",
"version": "1.2.3",
"dependencies": {
"lodash": "1.2.3"
}
}
11 changes: 11 additions & 0 deletions tests/data/sample_cargo.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[[package]]
name = "textwrap"
version = "1.2.3"

[[package]]
name = "there-i-fixed-it"
version = "1.2.3"

[[package]]
name = "other-project"
version = "1.2.3"
6 changes: 6 additions & 0 deletions tests/data/sample_docker_compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: "3.3"

services:
app:
image: my-repo/my-container:v1.2.3
command: my-command
3 changes: 3 additions & 0 deletions tests/data/sample_pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[tool.poetry]
name = "commitizen"
version = "1.2.3"
4 changes: 4 additions & 0 deletions tests/data/sample_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
__title__ = "requests"
__description__ = "Python HTTP for Humans."
__url__ = "http://python-requests.org"
__version__ = "1.2.3"
Loading