Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix: use only version tags in changelog #740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
23 changes: 21 additions & 2 deletions 23 commitizen/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,20 @@
import re
from collections import OrderedDict, defaultdict
from datetime import date
from typing import TYPE_CHECKING, Callable, Iterable, cast
from typing import TYPE_CHECKING, Callable, Iterable, Type, cast

from jinja2 import Environment, PackageLoader

from commitizen import out
from commitizen.bump import normalize_tag
from commitizen.exceptions import InvalidConfigurationError, NoCommitsFoundError
from commitizen.git import GitCommit, GitTag
from commitizen.version_schemes import DEFAULT_SCHEME, Pep440, InvalidVersion
from commitizen.version_schemes import (
DEFAULT_SCHEME,
BaseVersion,
InvalidVersion,
Pep440,
)

if TYPE_CHECKING:
from commitizen.version_schemes import VersionScheme
Expand Down Expand Up @@ -67,6 +73,19 @@ def tag_included_in_changelog(
return True


def get_version_tags(scheme: Type[BaseVersion], tags: list[GitTag]) -> list[GitTag]:
valid_tags: list[GitTag] = []
for tag in tags:
try:
scheme(tag.name)
except InvalidVersion:
out.warn(f"InvalidVersion {tag}")
else:
valid_tags.append(tag)

return valid_tags


def generate_tree_from_commits(
commits: list[GitCommit],
tags: list[GitTag],
Expand Down
5 changes: 1 addition & 4 deletions 5 commitizen/commands/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,9 @@ def __call__(self):
# Don't continue if no `file_name` specified.
assert self.file_name

tags = git.get_tags()
if not tags:
tags = []
tags = changelog.get_version_tags(self.scheme, git.get_tags()) or []

end_rev = ""

if self.incremental:
changelog_meta = changelog.get_metadata(self.file_name, self.scheme)
latest_version = changelog_meta.get("latest_version")
Expand Down
15 changes: 13 additions & 2 deletions 15 commitizen/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,22 @@ def tag(tag: str, annotated: bool = False, signed: bool = False) -> cmd.Command:
return c


def commit(message: str, args: str = "") -> cmd.Command:
def commit(
message: str, args: str = "", committer_date: str | None = None
) -> cmd.Command:
f = NamedTemporaryFile("wb", delete=False)
f.write(message.encode("utf-8"))
f.close()
c = cmd.run(f"git commit {args} -F {f.name}")

command = f"git commit {args} -F {f.name}"

if committer_date and os.name == "nt": # pragma: no cover
# Using `cmd /v /c "{command}"` sets environment variables only for that command
command = f'cmd /v /c "set GIT_COMMITTER_DATE={committer_date}&& {command}"'
elif committer_date:
command = f"GIT_COMMITTER_DATE={committer_date} {command}"

c = cmd.run(command)
os.unlink(f.name)
return c

Expand Down
125 changes: 124 additions & 1 deletion 125 poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions 3 pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ types-termcolor = "^0.1.1"
# documentation
mkdocs = "^1.4.2"
mkdocs-material = "^9.1.6"
deprecated = "^1.2.13"
types-deprecated = "^1.2.9.2"
types-python-dateutil = "^2.8.19.13"


[tool.poetry.scripts]
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.