Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

feat(config): Deprecate config.sections and config.section_mapping, replace with config.type_headers #83

Merged
merged 84 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
0910040
reject empty changes configuration support
EdgyEdgemond Feb 23, 2024
48e6aba
update README
EdgyEdgemond Feb 23, 2024
3f40aad
add release notes;
EdgyEdgemond Feb 23, 2024
08b2356
0.x semver follows breaking minor, others patch
EdgyEdgemond Feb 23, 2024
45afac4
add release note
EdgyEdgemond Feb 23, 2024
c49572c
support configuration in pyproject.toml
EdgyEdgemond Feb 23, 2024
789dbb8
migrate configuration to pyproject.toml
EdgyEdgemond Feb 23, 2024
845b0ce
initial support for log extraction
EdgyEdgemond Feb 23, 2024
4fbb7c2
Add a multiline commit message
EdgyEdgemond Feb 23, 2024
42a7b83
process conventional commit messages
EdgyEdgemond Feb 23, 2024
05005ba
clean up PR reviews
EdgyEdgemond Feb 23, 2024
8193d4d
add PR template
EdgyEdgemond Feb 23, 2024
cf5be2e
update template
EdgyEdgemond Feb 23, 2024
b14dd3e
Add conventional commit support notes to README
EdgyEdgemond Feb 23, 2024
cd2ab78
cleanup and update readme
EdgyEdgemond Feb 24, 2024
8435492
Remove need for python string formatting "hacks" to maintain `{` and …
EdgyEdgemond Feb 24, 2024
c861ea5
clean up tests and usage
EdgyEdgemond Feb 24, 2024
5541ec9
add details to unsupported derived section error message
EdgyEdgemond Feb 24, 2024
a273cb5
clearer message
EdgyEdgemond Feb 24, 2024
eed9336
update TODOs
EdgyEdgemond Feb 24, 2024
5c9664d
update test and remove a TODO
EdgyEdgemond Feb 24, 2024
465bec9
rollback changelog commit, if bumpversion release fails
EdgyEdgemond Feb 24, 2024
714d968
support more conventional commit types out of the box, and handle no …
EdgyEdgemond Feb 24, 2024
5445a40
add new TODO
EdgyEdgemond Feb 24, 2024
7e9e928
pull version string from configuration
EdgyEdgemond Feb 24, 2024
f5ef28f
restore TODO
EdgyEdgemond Feb 24, 2024
a7e20e4
add new TODO
EdgyEdgemond Feb 24, 2024
0188298
pull post_process headers from config
EdgyEdgemond Feb 24, 2024
65b9c84
require link with TODOs
EdgyEdgemond Feb 24, 2024
b5aaaf8
add in additional configuration
EdgyEdgemond Feb 24, 2024
753010a
update readme
EdgyEdgemond Feb 24, 2024
804d085
handle custom sections mapping to semver releases
EdgyEdgemond Feb 24, 2024
d69ee40
reject empty in self
EdgyEdgemond Feb 24, 2024
922479c
mark breaking changes in changelog
EdgyEdgemond Feb 24, 2024
ddd9a53
convert change dict to a dataclass and capture additional authors foo…
EdgyEdgemond Feb 25, 2024
aaa3fda
sort changes by breaking, scope and then issue ref
EdgyEdgemond Feb 25, 2024
a084e49
add string format functions to allow writers to override where requred.
EdgyEdgemond Feb 25, 2024
4079b27
add string format functions to allow writers to override where requred.
EdgyEdgemond Feb 25, 2024
495e724
add footer to readme
EdgyEdgemond Feb 25, 2024
d596ae6
Merge branch 'feat/76' into feat/75
EdgyEdgemond Feb 25, 2024
62081e1
include commit hash link if configured and conventional commits used
EdgyEdgemond Feb 25, 2024
5cbde12
configure writer with commit_link
EdgyEdgemond Feb 25, 2024
03ddf12
cleanup README
EdgyEdgemond Feb 25, 2024
c3387d4
Update README and include docs/misc sections
EdgyEdgemond Feb 25, 2024
f51e065
Merge branch 'fix/37' into fix/37.1
EdgyEdgemond Feb 25, 2024
394d67a
Merge branch 'fix/37.1' into feat/70
EdgyEdgemond Feb 25, 2024
d25a186
update semver mapping
EdgyEdgemond Feb 25, 2024
564ac4c
update defaults
EdgyEdgemond Feb 25, 2024
e867bf1
update configuration
EdgyEdgemond Feb 25, 2024
2fbfe36
Merge branch 'feat/68' into feat/73
EdgyEdgemond Feb 26, 2024
e657215
Merge branch 'feat/73' into feat/76
EdgyEdgemond Feb 26, 2024
a85a870
Merge branch 'feat/76' into feat/75
EdgyEdgemond Feb 26, 2024
69858ce
merge upstream
EdgyEdgemond Feb 26, 2024
287484e
Deprecate sections and section_mappings configuration, replace with t…
EdgyEdgemond Feb 26, 2024
b87855b
neaten pyproject.toml
EdgyEdgemond Feb 26, 2024
34c49ab
use ::replace:: to prevent scenarios like $VERSION_TAG resulting in 1…
EdgyEdgemond Feb 27, 2024
14588c9
raise an error on unexpected replace string
EdgyEdgemond Feb 27, 2024
82ba3b4
merge update
EdgyEdgemond Feb 27, 2024
5c62a9f
Merge branch 'fix/54' into fix/36
EdgyEdgemond Feb 27, 2024
b5591f5
Merge branch 'fix/36' into fix/37
EdgyEdgemond Feb 27, 2024
5d29c95
Merge branch 'fix/37' into fix/37.1
EdgyEdgemond Feb 27, 2024
f9c722f
merge update
EdgyEdgemond Feb 27, 2024
48cba1f
Merge branch 'feat/70' into feat/68
EdgyEdgemond Feb 27, 2024
0230d6c
Merge branch 'feat/68' into feat/73
EdgyEdgemond Feb 27, 2024
bdd50fc
Merge branch 'feat/73' into feat/76
EdgyEdgemond Feb 27, 2024
541f358
Merge branch 'feat/76' into feat/75
EdgyEdgemond Feb 27, 2024
86077a8
merge update
EdgyEdgemond Feb 27, 2024
8e1cdee
merge update
EdgyEdgemond Feb 27, 2024
771dc6e
Merge branch 'master' into fix/50
EdgyEdgemond Feb 27, 2024
516ba46
cleanup setup.cfg
EdgyEdgemond Feb 27, 2024
871bd41
Merge branch 'feat/55' into feat/15
EdgyEdgemond Feb 27, 2024
1ba01f3
merge update
EdgyEdgemond Feb 27, 2024
352fd0b
Merge branch 'feat/62' into fix/54
EdgyEdgemond Feb 27, 2024
afd1e78
Merge branch 'fix/54' into fix/36
EdgyEdgemond Feb 27, 2024
584ffe0
Merge branch 'fix/36' into fix/37
EdgyEdgemond Feb 27, 2024
761689a
Merge branch 'fix/37' into fix/37.1
EdgyEdgemond Feb 27, 2024
8bca01e
Merge branch 'fix/37.1' into feat/70
EdgyEdgemond Feb 27, 2024
5494b96
Merge branch 'feat/70' into feat/68
EdgyEdgemond Feb 27, 2024
b9df539
Merge branch 'feat/68' into feat/73
EdgyEdgemond Feb 27, 2024
390d781
Merge branch 'feat/73' into feat/76
EdgyEdgemond Feb 27, 2024
7d51d07
Merge branch 'feat/76' into feat/75
EdgyEdgemond Feb 27, 2024
4245a66
Merge branch 'feat/75' into feat/79
EdgyEdgemond Feb 27, 2024
6ac819f
Merge branch 'feat/79' into feat/82
EdgyEdgemond Feb 27, 2024
475d303
merge upstream
EdgyEdgemond Mar 2, 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
59 changes: 45 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ changes from a `release_notes` folder.
NOTE: `release_notes` support will be dropped in a future version, migration to
conventional commits is recommended.

By default supported sections are `feat`, `fix`, `docs` and `misc`. Additional types can be configured
to map to these initial sections, custom sections can be added and mapped to types as well.

See [Configuration](#Configuration) below for default sections and section
mappings and how to customize them.
See [Configuration](#Configuration) below for default commit type configuration
and how to customize them.

```md
## <version>
Expand Down Expand Up @@ -185,13 +182,13 @@ issue_link = "http://github.com/EdgyEdgemond/changelog-gen/issues/::issue_ref::"
**default**: None

Create links in the CHANGELOG to the originating commit. A url that contains
an `$COMMIT_HASH` placeholder for replacement.
an `::commit_hash::` placeholder for replacement.

Example:

```toml
[toolchangelog_gen]
commit_link = "http://github.com/EdgyEdgemond/changelog-gen/commit/$COMMIT_HASH"
commit_link = "http://github.com/EdgyEdgemond/changelog-gen/commit/::commit_hash::"
```

#### `version_string =`
Expand Down Expand Up @@ -246,17 +243,23 @@ allowed_branches = [
]
```

#### `sections =`
#### `type_headers = `
_**[optional]**_<br />
**default**: {
"feat": "Features and Improvements",
"fix": "Bug fixes",
"docs": "Documentation",
"misc": "Miscellaneous",
"bug": "Bug fixes",
"chore": "Miscellaneous",
"ci": "Miscellaneous",
"perf": "Miscellaneous",
"refactor": "Miscellaneous",
"revert": "Miscellaneous",
"style": "Miscellaneous",
"test": "Miscellaneous",
}

Define custom headers or new sections/headers, new sections will require a
matching section_mapping configuration.
Define commit types and which headers in the changelog they should map to.

Example:

Expand All @@ -277,19 +280,45 @@ fix = "Bugfixes"
"misc": "patch"
}

Define custom section mappings for semver tagging. Any custom sections need
to be mapped to `major`, `minor`, `patch`. Any unknown sections will be
Define custom type mappings for semver tagging. Any custom types need
to be mapped to `major`, `minor`, `patch`. Any unknown types will be
treated as a `patch`.

Example:

```toml
[tool.changelog_gen.sections]
[tool.changelog_gen.semver_mapping]
change = "patch"
remove = "minor"
```

#### `sections =`
_**[Deprecated]**_<br />
_**[optional]**_<br />
**default**: {
"feat": "Features and Improvements",
"fix": "Bug fixes",
"docs": "Documentation",
"misc": "Miscellaneous",
}

Define custom headers or new sections/headers, new sections will require a
matching section_mapping configuration.

This configuration has been deprecated, use `type_headers` instead.

Example:

```toml
[tool.changelog_gen.sections]
feat = "New Features"
change = "Changes"
remove = "Removals"
fix = "Bugfixes"
```

#### `section_mapping =`
_**[Deprecated]**_<br />
_**[optional]**_<br />
**default**: {
"bug": "fix",
Expand All @@ -305,6 +334,8 @@ remove = "minor"

Configure additional supported commit types to supported changelog sections.

This configuration has been deprecated, use `type_headers` instead.

Example:

```toml
Expand Down
14 changes: 6 additions & 8 deletions changelog_gen/cli/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,11 @@ def _gen(cfg: config.Config, version_tag: str | None = None, *, dry_run: bool =

process_info(Git.get_latest_tag_info(), cfg, dry_run=dry_run)

section_mapping = cfg.section_mapping
supported_sections = cfg.sections
e = extractor.ReleaseNoteExtractor(dry_run=dry_run, type_headers=cfg.type_headers)
sections = e.extract()

e = extractor.ReleaseNoteExtractor(dry_run=dry_run, supported_sections=supported_sections)
sections = e.extract(section_mapping)

if not e.unique_issues(sections) and cfg.reject_empty:
unique_issues = e.unique_issues(sections)
if not unique_issues and cfg.reject_empty:
typer.echo("No changes present and reject_empty configured.")
raise typer.Exit(code=0)

Expand All @@ -163,15 +161,15 @@ def _gen(cfg: config.Config, version_tag: str | None = None, *, dry_run: bool =
w = writer.new_writer(extension, dry_run=dry_run, issue_link=cfg.issue_link, commit_link=cfg.commit_link)

w.add_version(version_string)
w.consume(supported_sections, sections)
w.consume(cfg.type_headers, sections)

typer.echo(w)

processed = _finalise(w, e, version_tag, extension, cfg, dry_run=dry_run)

post_process = cfg.post_process
if post_process and processed:
unique_issues = [r for r in e.unique_issues(sections) if not r.startswith("__")]
unique_issues = [r for r in unique_issues if not r.startswith("__")]
per_issue_post_process(post_process, sorted(unique_issues), version_tag, dry_run=dry_run)


Expand Down
149 changes: 95 additions & 54 deletions changelog_gen/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,40 @@

logger = logging.getLogger(__name__)

SUPPORTED_SECTIONS = {
TYPE_HEADERS = {
"feat": "Features and Improvements",
"fix": "Bug fixes",
"docs": "Documentation",
"misc": "Miscellaneous",
"bug": "Bug fixes",
"chore": "Miscellaneous",
"ci": "Miscellaneous",
"perf": "Miscellaneous",
"refactor": "Miscellaneous",
"revert": "Miscellaneous",
"style": "Miscellaneous",
"test": "Miscellaneous",
}

SEMVER_MAPPING = {
"feat": "minor",
"fix": "patch",
"bug": "patch",
"chore": "patch",
"ci": "patch",
"docs": "patch",
"misc": "patch",
"perf": "patch",
"refactor": "patch",
"revert": "patch",
"style": "patch",
"test": "patch",
}

# Deprecated
SUPPORTED_SECTIONS = {
"feat": "Features and Improvements",
"fix": "Bug fixes",
"docs": "Documentation",
"misc": "Miscellaneous",
}

DEFAULT_SECTION_MAPPING = {
Expand Down Expand Up @@ -134,9 +156,8 @@
version_string: str = "v{new_version}"

allowed_branches: list[str] = dataclasses.field(default_factory=list)
sections: dict = dataclasses.field(default_factory=lambda: SUPPORTED_SECTIONS)
type_headers: dict = dataclasses.field(default_factory=lambda: TYPE_HEADERS)
semver_mapping: dict = dataclasses.field(default_factory=lambda: SEMVER_MAPPING)
section_mapping: dict = dataclasses.field(default_factory=lambda: DEFAULT_SECTION_MAPPING)

release: bool = False
commit: bool = False
Expand Down Expand Up @@ -174,9 +195,6 @@
if "tool" not in data or "changelog_gen" not in data["tool"]:
return cfg

if "post_process" in data["tool"]["changelog_gen"]:
pp = data["tool"]["changelog_gen"]["post_process"]
data["tool"]["changelog_gen"]["post_process"] = PostProcessConfig.from_dict(pp)
return data["tool"]["changelog_gen"]


Expand All @@ -197,9 +215,11 @@
("date_format", extract_string_value),
("version_string", extract_string_value),
("allowed_branches", extract_list_value),
("type_headers", extract_dict_value),
("sections", extract_dict_value),
("semver_mapping", extract_dict_value),
("section_mapping", extract_dict_value),
("post_process", extract_dict_value),
("release", extract_boolean_value),
("commit", extract_boolean_value),
("allow_dirty", extract_boolean_value),
Expand All @@ -209,21 +229,53 @@
if value:
cfg[valuename] = value

for objectname, object_class in [
("post_process", PostProcessConfig),
]:
dictvalue = extract_dict_value(parser, objectname)
if dictvalue is None:
continue
try:
cfg[objectname] = object_class.from_dict(dictvalue)
except Exception as e: # noqa: BLE001
msg = f"Failed to create {objectname}: {e!s}"
raise RuntimeError(msg) from e

return cfg


def check_deprecations(cfg: dict) -> None:
"""Check parsed configuration dict for deprecated features."""
if cfg.get("post_process"):
url = cfg["post_process"].get("url", "")
body = cfg["post_process"].get("body", "")
if "{issue_ref}" in url or "{new_version}" in url:
warn(
"{replace} format strings are not supported in `post_process.url` configuration, use ::replace:: instead.", # noqa: E501
DeprecationWarning,
stacklevel=2,
)
cfg["post_process"]["url"] = url.format(issue_ref="::issue_ref::", new_version="::version::")
if "{issue_ref}" in body or "{new_version}" in body:
warn(
"{replace} format strings are not supported in `post_process.body` configuration, use ::replace:: instead.", # noqa: E501
DeprecationWarning,
stacklevel=2,
)
cfg["post_process"]["body"] = body.format(issue_ref="::issue_ref::", new_version="::version::")

if cfg.get("issue_link") and "{issue_ref}" in cfg["issue_link"]:
warn(
"{replace} format strings are not supported in `issue_link` configuration, use ::replace:: instead.",
DeprecationWarning,
stacklevel=2,
)
cfg["issue_link"] = cfg["issue_link"].format(issue_ref="::issue_ref::", new_version="::version::")

if cfg.get("commit_link") and "{commit_hash}" in cfg["config_link"]:
warn(

Check warning on line 264 in changelog_gen/config.py

View check run for this annotation

Codecov / codecov/patch

changelog_gen/config.py#L264

Added line #L264 was not covered by tests
"{replace} format strings are not supported in `config_link` configuration, use ::replace:: instead.",
DeprecationWarning,
stacklevel=2,
)
cfg["commit_link"] = cfg["commit_link"].format(commit_hash="::commit_hash::")

Check warning on line 269 in changelog_gen/config.py

View check run for this annotation

Codecov / codecov/patch

changelog_gen/config.py#L269

Added line #L269 was not covered by tests

if cfg.get("section_mapping") or cfg.get("sections"):
warn(
"`sections` and `section_mapping` are no longer supported, use `type_headers` instead.",
DeprecationWarning,
stacklevel=2,
)


def read(**kwargs) -> Config: # noqa: C901, PLR0912
"""Read configuration from local environment.

Expand All @@ -245,39 +297,36 @@
cfg = _process_setup_cfg(setup)

if "post_process" not in cfg and post_process:
cfg["post_process"] = post_process
cfg["post_process"] = {
"url": post_process.url,
"auth_env": post_process.auth_env,
}

if "post_process" in cfg and post_process:
cfg["post_process"].url = post_process.url or cfg["post_process"].url
cfg["post_process"].auth_env = post_process.auth_env or cfg["post_process"].auth_env
cfg["post_process"]["url"] = post_process.url or cfg["post_process"].get("url")
cfg["post_process"]["auth_env"] = post_process.auth_env or cfg["post_process"].get("auth_env")

cfg.update(overrides)

check_deprecations(cfg)

if cfg.get("post_process"):
url = cfg["post_process"].url
body = cfg["post_process"].body
if "{issue_ref}" in url or "{new_version}" in url:
warn(
"{replace} format strings are not supported in `post_process.url` configuration, use ::replace:: instead.", # noqa: E501
DeprecationWarning,
stacklevel=2,
)
cfg["post_process"].url = url.format(issue_ref="::issue_ref::", new_version="::version::")
if "{issue_ref}" in body or "{new_version}" in body:
warn(
"{replace} format strings are not supported in `post_process.body` configuration, use ::replace:: instead.", # noqa: E501
DeprecationWarning,
stacklevel=2,
)
cfg["post_process"].body = body.format(issue_ref="::issue_ref::", new_version="::version::")
pp = cfg["post_process"]
try:
cfg["post_process"] = PostProcessConfig.from_dict(pp)
except Exception as e: # noqa: BLE001
msg = f"Failed to create post_process: {e!s}"
raise RuntimeError(msg) from e

if cfg.get("issue_link") and "{issue_ref}" in cfg["issue_link"]:
warn(
"{replace} format strings are not supported in `issue_link` configuration, use ::replace:: instead.",
DeprecationWarning,
stacklevel=2,
)
cfg["issue_link"] = cfg["issue_link"].format(issue_ref="::issue_ref::", new_version="::version::")
if cfg.get("section_mapping") or cfg.get("sections") and not cfg.get("type_headers"):
sm = cfg.pop("section_mapping", DEFAULT_SECTION_MAPPING.copy())
s = cfg.pop("sections", SUPPORTED_SECTIONS.copy())

type_headers = s
for type_, section in sm.items():
type_headers[type_] = s.get(section, "Unknown")

cfg["type_headers"] = type_headers

# this feels messy, but later on there is an update that should assist in cleaning this up.
for key_path in [
Expand Down Expand Up @@ -306,12 +355,4 @@
msg = f"Replace string {replace}, not supported."
raise errors.UnsupportedReplaceError(msg)

if cfg.get("commit_link") and "{commit_hash}" in cfg["config_link"]:
warn(
"{replace} format strings are not supported in `config_link` configuration, use $REPLACE instead.",
DeprecationWarning,
stacklevel=2,
)
cfg["commit_link"] = cfg["commit_link"].format(commit_hash="$COMMIT_HASH")

return Config(**cfg)
Loading
Loading