Skip to content

Commit

Permalink
fix: Update version regex
Browse files Browse the repository at this point in the history
For repositories which mark versions with a `v` before the version
numbers, the `v` needs to be included in the captured version from the
changelog, or we won't find a matching version for filtering out already
added entries, and they will be duplicated.
  • Loading branch information
kmsquire authored and pawamoy committed May 10, 2023
1 parent f463c93 commit a50d6a2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/usage.md
Expand Up @@ -335,7 +335,7 @@ To support in-place updates in a custom template, you have two choices:
to insert new entries. Here are these default values:

```python
DEFAULT_VERSION_REGEX = r"^## \[v?(?P<version>[^\]]+)"
DEFAULT_VERSION_REGEX = r"^## \[(?P<version>v?[^\]]+)"
DEFAULT_MARKER_LINE = "<!-- insertion marker -->"
```

Expand Down
2 changes: 1 addition & 1 deletion src/git_changelog/cli.py
Expand Up @@ -34,7 +34,7 @@
else:
from importlib import metadata

DEFAULT_VERSION_REGEX = r"^## \[v?(?P<version>[^\]]+)"
DEFAULT_VERSION_REGEX = r"^## \[(?P<version>v?[^\]]+)"
DEFAULT_MARKER_LINE = "<!-- insertion marker -->"
CONVENTIONS = ("angular", "atom", "conventional", "basic")

Expand Down
18 changes: 14 additions & 4 deletions tests/test_end_to_end.py
Expand Up @@ -21,6 +21,7 @@
from pathlib import Path

VERSIONS = ("0.1.0", "0.2.0", "0.2.1", "1.0.0", "1.1.0", "")
VERSIONS_V = ("v0.1.0", "v0.2.0", "v0.2.1", "v1.0.0", "v1.1.0", "")
KEEP_A_CHANGELOG = get_template("keepachangelog")


Expand All @@ -38,8 +39,11 @@ def _commit(repo: Path, filename: str, section: str) -> None:
_git("-C", str(repo), "commit", "-m", f"{section}: Commit with '{section}' type")


@pytest.fixture(scope="module", name="repo")
def git_repo(tmp_path_factory: pytest.TempPathFactory) -> Iterator[Path]:
@pytest.fixture(scope="module", name="repo", params=(VERSIONS, VERSIONS_V))
def git_repo(
tmp_path_factory: pytest.TempPathFactory,
request: pytest.Subrequest,
) -> Iterator[Path]:
"""Pytest fixture setting up a temporary Git repository.
Parameters:
Expand All @@ -49,13 +53,15 @@ def git_repo(tmp_path_factory: pytest.TempPathFactory) -> Iterator[Path]:
The path to a temporary Git repository.
"""
tmp_path = tmp_path_factory.mktemp("git_changelog")
tmp_path.mkdir(exist_ok=True, parents=True)
git = partial(_git, "-C", str(tmp_path))
commit = partial(_commit, tmp_path, "dummy")
git("init")
git("config", "user.name", "dummy")
git("config", "user.email", "dummy@example.com")
git("remote", "add", "origin", "git@github.com:example/example")
for version in VERSIONS:
versions = request.param
for version in versions:
for section in AngularConvention.TYPES:
commit(section)
commit(section)
Expand All @@ -73,7 +79,11 @@ def test_bumping_latest(repo: Path) -> None:
"""
changelog = Changelog(repo, convention=AngularConvention, bump_latest=True)
# features, no breaking changes: minor bumped
assert changelog.versions_list[0].planned_tag == bump(VERSIONS[-2], "minor")
assert changelog.versions_list[0].planned_tag is not None
assert changelog.versions_list[0].planned_tag.lstrip("v") == bump(
VERSIONS[-2],
"minor",
)
rendered = KEEP_A_CHANGELOG.render(changelog=changelog)
assert "Unreleased" not in rendered

Expand Down

0 comments on commit a50d6a2

Please sign in to comment.