Skip to content
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

feat(customize.py/test_cz_customize.py): inherit from ConventionalCom… #1274

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
9f085a1
build(deps-dev): bump ruff from 0.6.1 to 0.6.2
dependabot[bot] Aug 23, 2024
3333275
build(deps-dev): bump mypy from 1.11.1 to 1.11.2
dependabot[bot] Aug 26, 2024
ef57d14
build(deps-dev): bump mkdocs-material from 9.5.32 to 9.5.33
dependabot[bot] Aug 26, 2024
7c02669
build(deps-dev): bump rich from 13.7.1 to 13.8.0
dependabot[bot] Aug 27, 2024
100936b
build(deps-dev): bump ruff from 0.6.2 to 0.6.3
dependabot[bot] Aug 30, 2024
d90c8a8
build(deps-dev): bump mkdocs from 1.6.0 to 1.6.1
dependabot[bot] Sep 2, 2024
d874e71
build(deps-dev): bump mkdocs-material from 9.5.33 to 9.5.34
dependabot[bot] Sep 2, 2024
74f66d1
build(deps-dev): bump ruff from 0.6.3 to 0.6.4
dependabot[bot] Sep 6, 2024
3197556
build(deps-dev): bump types-python-dateutil
dependabot[bot] Sep 9, 2024
d6547c1
test(check): Python 3.13 help text format has been changed. Change th…
Lee-W Sep 12, 2024
6a5c1b1
build(deps-dev): bump ruff from 0.6.4 to 0.6.5
dependabot[bot] Sep 16, 2024
7e881da
build(deps-dev): bump pytest from 8.3.2 to 8.3.3
dependabot[bot] Sep 16, 2024
620b975
build(deps-dev): bump rich from 13.8.0 to 13.8.1
dependabot[bot] Sep 16, 2024
a4ef250
build(deps-dev): bump types-pyyaml
dependabot[bot] Sep 18, 2024
90a454a
build(deps): bump importlib-metadata from 8.4.0 to 8.5.0
dependabot[bot] Sep 16, 2024
31212ba
build(deps-dev): bump mkdocs-material from 9.5.34 to 9.5.35
dependabot[bot] Sep 19, 2024
d151e9e
build(deps-dev): bump ruff from 0.6.5 to 0.6.7
dependabot[bot] Sep 23, 2024
ee41af2
build(deps-dev): bump mkdocs-material from 9.5.35 to 9.5.36
dependabot[bot] Sep 23, 2024
88f1e21
build(deps-dev): bump mkdocs-material from 9.5.36 to 9.5.37
dependabot[bot] Sep 26, 2024
db09538
fix(changelog): handle custom tag_format in changelog generation
grahamhar Feb 26, 2024
b023711
test(changelog): handle custom tag_format in changelog generation
grahamhar Mar 2, 2024
12c3f31
fix(changelog): Handle tag format without version pattern
grahamhar Apr 1, 2024
ca3865f
fix(changelog): Factorized TAG_FORMAT_REGEXES
grahamhar Apr 20, 2024
76f7fcb
docs(bump): Document the use of tag_format variables with curly brackets
grahamhar Apr 20, 2024
916b5aa
refactor: Use format strings
grahamhar Apr 27, 2024
a3498ab
bump: version 3.29.0 → 3.29.1
github-actions[bot] Sep 26, 2024
41ca730
build(deps-dev): bump mkdocs-material from 9.5.37 to 9.5.38
dependabot[bot] Sep 27, 2024
8816957
build(deps-dev): bump ruff from 0.6.7 to 0.6.8
dependabot[bot] Sep 27, 2024
4db164f
build(deps-dev): bump mkdocs-material from 9.5.38 to 9.5.39
dependabot[bot] Sep 30, 2024
15f0812
build(deps-dev): bump rich from 13.8.1 to 13.9.1
dependabot[bot] Oct 2, 2024
eafcef6
build(deps-dev): bump types-python-dateutil
dependabot[bot] Oct 4, 2024
1f85775
build(deps-dev): bump rich from 13.9.1 to 13.9.2
dependabot[bot] Oct 7, 2024
1c14b02
build(deps-dev): bump ruff from 0.6.8 to 0.6.9
dependabot[bot] Oct 7, 2024
ebb6a2c
docs: improve monorepo docs
woile Sep 27, 2024
d755de9
docs: update docs/tutorials/monorepo_guidance.md
woile Oct 7, 2024
5aeb1df
docs: update docs/tutorials/monorepo_guidance.md
woile Oct 7, 2024
fad5e82
build(deps): bump argcomplete from 3.5.0 to 3.5.1
dependabot[bot] Oct 8, 2024
a54bf54
build(deps): bump charset-normalizer from 3.3.2 to 3.4.0
dependabot[bot] Oct 10, 2024
1a1ddd2
build(deps-dev): bump mkdocs-material from 9.5.39 to 9.5.40
dependabot[bot] Oct 11, 2024
59c7e7b
docs: update README to include conda
kmnhan Oct 14, 2024
c95404b
docs: `Allowed Prefixes` default value typo
gbaian10 Oct 13, 2024
00d2d96
build(deps-dev): bump mypy from 1.11.2 to 1.12.0
dependabot[bot] Oct 15, 2024
a9aacec
ci(deps): bump dawidd6/action-homebrew-bump-formula from 3 to 4
dependabot[bot] Oct 16, 2024
e1784c6
build(deps-dev): bump mkdocs-material from 9.5.40 to 9.5.41
dependabot[bot] Oct 16, 2024
16b80d3
docs(third-party-commitizen): add commitizen-deno-provider to the thi…
dhmmasson Oct 14, 2024
e821569
docs(third-party-commitizen): update deno-provider code block syntax …
dhmmasson Oct 15, 2024
1d5f295
docs(third-party-commitizen): uniformize the third party page
dhmmasson Oct 15, 2024
36cfcab
build(deps-dev): bump ruff from 0.6.9 to 0.7.0
dependabot[bot] Oct 18, 2024
4968868
build(deps-dev): bump mypy from 1.12.0 to 1.12.1
dependabot[bot] Oct 21, 2024
29d6e64
build(deps-dev): bump mkdocs-material from 9.5.41 to 9.5.42
dependabot[bot] Oct 21, 2024
af3553b
build(deps-dev): bump rich from 13.9.2 to 13.9.3
dependabot[bot] Oct 23, 2024
e5aaec4
build(deps-dev): bump mypy from 1.12.1 to 1.13.0
dependabot[bot] Oct 23, 2024
78dc765
docs(commit): add multiline option `questions` content table
ArneSchwerdt Oct 17, 2024
2f6b7cc
docs(customization): Unify capitalization
Lee-W Oct 23, 2024
08a259d
feat(commands/commit): add force-edit functionality after answering q…
josix Oct 15, 2024
bfe422f
bump: version 3.29.1 → 3.30.0
github-actions[bot] Oct 23, 2024
e4d508a
feat(customize.py/test_cz_customize.py): inherit from ConventionalCom…
AtticusZeller Oct 23, 2024
ff8a092
fix(customize.py): default questions as super().questions() instead o…
AtticusZeller Oct 23, 2024
c239c92
test(test_cz_customize.py): add more tests
AtticusZeller Oct 23, 2024
5057ef1
style(test_cz_customize.py): pre-commit run
AtticusZeller Oct 23, 2024
e374cf3
test(test_cz_customize.py): add the ommited bump_map_major_version_ze…
AtticusZeller Oct 23, 2024
5d55fde
docs(customization.md): add feature notes
AtticusZeller Oct 23, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/homebrewpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
run: |
echo "project_version=$(cz version --project)" >> $GITHUB_ENV
- name: Update Homebrew formula
uses: dawidd6/action-homebrew-bump-formula@v3
uses: dawidd6/action-homebrew-bump-formula@v4
with:
token: ${{secrets.PERSONAL_ACCESS_TOKEN}}
formula: commitizen
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ repos:
- tomli

- repo: https://github.com/commitizen-tools/commitizen
rev: v3.29.0 # automatically updated by Commitizen
rev: v3.30.0 # automatically updated by Commitizen
hooks:
- id: commitizen
- id: commitizen-branch
Expand Down
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
## v3.30.0 (2024-10-23)

### Feat

- **commands/commit**: add force-edit functionality after answering questions

### Refactor

- remove redundant return None

## v3.29.1 (2024-09-26)

### Fix

- **changelog**: Factorized TAG_FORMAT_REGEXES
- **changelog**: Handle tag format without version pattern
- **changelog**: handle custom tag_format in changelog generation

### Refactor

- Use format strings

## v3.29.0 (2024-08-11)

### Feat
Expand Down
2 changes: 1 addition & 1 deletion commitizen/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "3.29.0"
__version__ = "3.30.0"
21 changes: 13 additions & 8 deletions commitizen/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from commitizen import out
from commitizen.bump import normalize_tag
from commitizen.cz.base import ChangelogReleaseHook
from commitizen.defaults import get_tag_regexes
from commitizen.exceptions import InvalidConfigurationError, NoCommitsFoundError
from commitizen.git import GitCommit, GitTag
from commitizen.version_schemes import (
Expand Down Expand Up @@ -93,16 +94,21 @@ def tag_included_in_changelog(
return True


def get_version_tags(scheme: type[BaseVersion], tags: list[GitTag]) -> list[GitTag]:
def get_version_tags(
scheme: type[BaseVersion], tags: list[GitTag], tag_format: str
) -> list[GitTag]:
valid_tags: list[GitTag] = []
TAG_FORMAT_REGEXS = get_tag_regexes(scheme.parser.pattern)
tag_format_regex = tag_format
for pattern, regex in TAG_FORMAT_REGEXS.items():
tag_format_regex = tag_format_regex.replace(pattern, regex)
for tag in tags:
try:
scheme(tag.name)
except InvalidVersion:
out.warn(f"InvalidVersion {tag}")
else:
if re.match(tag_format_regex, tag.name):
valid_tags.append(tag)

else:
out.warn(
f"InvalidVersion {tag.name} doesn't match configured tag format {tag_format}"
)
return valid_tags


Expand Down Expand Up @@ -351,7 +357,6 @@ def get_oldest_and_newest_rev(
oldest, newest = version.split("..")
except ValueError:
newest = version

newest_tag = normalize_tag(newest, tag_format=tag_format, scheme=scheme)

oldest_tag = None
Expand Down
14 changes: 13 additions & 1 deletion commitizen/changelog_formats/asciidoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,19 @@ def parse_version_from_title(self, line: str) -> str | None:
matches = list(re.finditer(self.version_parser, m.group("title")))
if not matches:
return None
return matches[-1].group("version")
if "version" in matches[-1].groupdict():
return matches[-1].group("version")
partial_matches = matches[-1].groupdict()
try:
partial_version = f"{partial_matches['major']}.{partial_matches['minor']}.{partial_matches['patch']}"
except KeyError:
return None

if partial_matches.get("prerelease"):
partial_version = f"{partial_version}-{partial_matches['prerelease']}"
if partial_matches.get("devrelease"):
partial_version = f"{partial_version}{partial_matches['devrelease']}"
return partial_version

def parse_title_level(self, line: str) -> int | None:
m = self.RE_TITLE.match(line)
Expand Down
10 changes: 9 additions & 1 deletion commitizen/changelog_formats/base.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from __future__ import annotations

import os
import re
from abc import ABCMeta
from re import Pattern
from typing import IO, Any, ClassVar

from commitizen.changelog import Metadata
from commitizen.config.base_config import BaseConfig
from commitizen.defaults import get_tag_regexes
from commitizen.version_schemes import get_version_scheme

from . import ChangelogFormat
Expand All @@ -25,10 +27,16 @@ def __init__(self, config: BaseConfig):
# See: https://bugs.python.org/issue44807
self.config = config
self.encoding = self.config.settings["encoding"]
self.tag_format = self.config.settings["tag_format"]

@property
def version_parser(self) -> Pattern:
return get_version_scheme(self.config).parser
tag_regex: str = self.tag_format
version_regex = get_version_scheme(self.config).parser.pattern
TAG_FORMAT_REGEXS = get_tag_regexes(version_regex)
for pattern, regex in TAG_FORMAT_REGEXS.items():
tag_regex = tag_regex.replace(pattern, regex)
return re.compile(tag_regex)

def get_metadata(self, filepath: str) -> Metadata:
if not os.path.isfile(filepath):
Expand Down
16 changes: 15 additions & 1 deletion commitizen/changelog_formats/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,21 @@ def parse_version_from_title(self, line: str) -> str | None:
m = re.search(self.version_parser, m.group("title"))
if not m:
return None
return m.group("version")
if "version" in m.groupdict():
return m.group("version")
matches = m.groupdict()
try:
partial_version = (
f"{matches['major']}.{matches['minor']}.{matches['patch']}"
)
except KeyError:
return None

if matches.get("prerelease"):
partial_version = f"{partial_version}-{matches['prerelease']}"
if matches.get("devrelease"):
partial_version = f"{partial_version}{matches['devrelease']}"
return partial_version

def parse_title_level(self, line: str) -> int | None:
m = self.RE_TITLE.match(line)
Expand Down
28 changes: 23 additions & 5 deletions commitizen/changelog_formats/restructuredtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def get_metadata_from_file(self, file: IO[Any]) -> Metadata:
third = third.strip().lower()
title: str | None = None
kind: TitleKind | None = None

if self.is_overlined_title(first, second, third):
title = second
kind = (first[0], third[0])
Expand All @@ -67,10 +66,29 @@ def get_metadata_from_file(self, file: IO[Any]) -> Metadata:
# Try to find the latest release done
m = re.search(self.version_parser, title)
if m:
version = m.group("version")
meta.latest_version = version
meta.latest_version_position = index
break # there's no need for more info
matches = m.groupdict()
if "version" in matches:
version = m.group("version")
meta.latest_version = version
meta.latest_version_position = index
break # there's no need for more info
try:
partial_version = (
f"{matches['major']}.{matches['minor']}.{matches['patch']}"
)
if matches.get("prerelease"):
partial_version = (
f"{partial_version}-{matches['prerelease']}"
)
if matches.get("devrelease"):
partial_version = (
f"{partial_version}{matches['devrelease']}"
)
meta.latest_version = partial_version
meta.latest_version_position = index
break
except KeyError:
pass
if meta.unreleased_start is not None and meta.unreleased_end is None:
meta.unreleased_end = (
meta.latest_version_position if meta.latest_version else index + 1
Expand Down
19 changes: 18 additions & 1 deletion commitizen/changelog_formats/textile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,24 @@ def parse_version_from_title(self, line: str) -> str | None:
m = re.search(self.version_parser, line)
if not m:
return None
return m.group("version")
if "version" in m.groupdict():
return m.group("version")
matches = m.groupdict()
if not all(
[
version_segment in matches
for version_segment in ("major", "minor", "patch")
]
):
return None

partial_version = f"{matches['major']}.{matches['minor']}.{matches['patch']}"

if matches.get("prerelease"):
partial_version = f"{partial_version}-{matches['prerelease']}"
if matches.get("devrelease"):
partial_version = f"{partial_version}{matches['devrelease']}"
return partial_version

def parse_title_level(self, line: str) -> int | None:
m = self.RE_TITLE.match(line)
Expand Down
6 changes: 6 additions & 0 deletions commitizen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ def __call__(
"action": "store_true",
"help": "Tell the command to automatically stage files that have been modified and deleted, but new files you have not told Git about are not affected.",
},
{
"name": ["-e", "--edit"],
"action": "store_true",
"default": False,
"help": "edit the commit message before committing",
},
{
"name": ["-l", "--message-length-limit"],
"type": int,
Expand Down
9 changes: 4 additions & 5 deletions commitizen/commands/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,10 @@ def __call__(self):
# Don't continue if no `file_name` specified.
assert self.file_name

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

tags = (
changelog.get_version_tags(self.scheme, git.get_tags(), self.tag_format)
or []
)
end_rev = ""
if self.incremental:
changelog_meta = self.changelog_format.get_metadata(self.file_name)
Expand All @@ -182,21 +184,18 @@ def __call__(self):
start_rev = self._find_incremental_rev(
strip_local_version(latest_tag_version), tags
)

if self.rev_range:
start_rev, end_rev = changelog.get_oldest_and_newest_rev(
tags,
version=self.rev_range,
tag_format=self.tag_format,
scheme=self.scheme,
)

commits = git.get_commits(start=start_rev, end=end_rev, args="--topo-order")
if not commits and (
self.current_version is None or not self.current_version.is_prerelease
):
raise NoCommitsFoundError("No commits found")

tree = changelog.generate_tree_from_commits(
commits,
tags,
Expand Down
24 changes: 24 additions & 0 deletions commitizen/commands/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import contextlib
import os
import shutil
import subprocess
import tempfile

import questionary

Expand Down Expand Up @@ -72,9 +75,27 @@ def prompt_commit_questions(self) -> str:

return message

def manual_edit(self, message: str) -> str:
editor = git.get_core_editor()
if editor is None:
raise RuntimeError("No 'editor' value given and no default available.")
exec_path = shutil.which(editor)
if exec_path is None:
raise RuntimeError(f"Editor '{editor}' not found.")
with tempfile.NamedTemporaryFile(mode="w", delete=False) as file:
file.write(message)
file_path = file.name
argv = [exec_path, file_path]
subprocess.call(argv)
with open(file_path) as temp_file:
message = temp_file.read().strip()
file.unlink()
return message

def __call__(self):
dry_run: bool = self.arguments.get("dry_run")
write_message_to_file: bool = self.arguments.get("write_message_to_file")
manual_edit: bool = self.arguments.get("edit")

is_all: bool = self.arguments.get("all")
if is_all:
Expand All @@ -101,6 +122,9 @@ def __call__(self):
else:
m = self.prompt_commit_questions()

if manual_edit:
m = self.manual_edit(m)

out.info(f"\n{m}\n")

if write_message_to_file:
Expand Down
Loading
Loading