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: changelog sorting options #165

Merged
merged 6 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
35 changes: 18 additions & 17 deletions changelogs/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,27 @@ notesdir: fragments
prelude_section_name: release_summary
prelude_section_title: Release Summary
sections:
- - major_changes
- Major Changes
- - minor_changes
- Minor Changes
- - breaking_changes
- Breaking Changes / Porting Guide
- - deprecated_features
- Deprecated Features
- - removed_features
- Removed Features (previously deprecated)
- - security_fixes
- Security Fixes
- - bugfixes
- Bugfixes
- - known_issues
- Known Issues
- - major_changes
- Major Changes
- - minor_changes
- Minor Changes
- - breaking_changes
- Breaking Changes / Porting Guide
- - deprecated_features
- Deprecated Features
- - removed_features
- Removed Features (previously deprecated)
- - security_fixes
- Security Fixes
- - bugfixes
- Bugfixes
- - known_issues
- Known Issues
use_semantic_versioning: true
title: Ansible Changelog Tool
output_formats:
- rst
- md
add_plugin_period: false
changelog_nice_yaml: false
changelog_nice_yaml: false
changelog_semantic_versioning_sort: false
7 changes: 7 additions & 0 deletions docs/changelog-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ YAML encoding that is compatible with ansible-lint's default rules.
The exact format used might be adjusted in the future if new releases of ansible-lint
adjust their yamllint configuration.

### `changelog_semantic_versioning_sort` (boolean)
gardar marked this conversation as resolved.
Show resolved Hide resolved

The default is `false`.

When set to `true` the changelog entries in `changelogs/changelog.yaml` entries will
be sorted by semantic version.

### `flatmap` (optional boolean)

The default value is `null`.
Expand Down
19 changes: 17 additions & 2 deletions src/antsibull_changelog/changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ def save(self) -> None:
"""
self.sort()
self.data["ancestor"] = self.ancestor
store_yaml(self.path, self.data, self.config.changelog_nice_yaml)
store_yaml(
self.path,
self.data,
self.config.changelog_nice_yaml,
self.config.changelog_semantic_versioning_sort,
)

def add_release(
self,
Expand Down Expand Up @@ -416,7 +421,17 @@ def update_fragments(
def sort(self) -> None:
"""
Sort change metadata in place.
"""
Optionally sorts by semantic version.
"""
if self.config.changelog_semantic_versioning_sort:
self.data["releases"] = dict(
sorted(
self.data["releases"].items(),
key=lambda t: [int(v) for v in t[0].split(".")],
gardar marked this conversation as resolved.
Show resolved Hide resolved
reverse=True,
gardar marked this conversation as resolved.
Show resolved Hide resolved
),
)

for _, config in self.data["releases"].items():
if "modules" in config:
config["modules"] = sorted(config["modules"])
Expand Down
7 changes: 7 additions & 0 deletions src/antsibull_changelog/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ class ChangelogConfig:
output_formats: set[TextFormat]
add_plugin_period: bool
changelog_nice_yaml: bool
changelog_semantic_versioning_sort: bool

def __init__(
self,
Expand Down Expand Up @@ -471,6 +472,10 @@ def __init__(

self.changelog_nice_yaml = self.config.get("changelog_nice_yaml", False)

self.changelog_semantic_versioning_sort = self.config.get(
"changelog_semantic_versioning_sort", False
)

self._validate_config(ignore_is_other_project)

def _validate_config(self, ignore_is_other_project: bool) -> None:
Expand Down Expand Up @@ -522,6 +527,7 @@ def store(self) -> None: # noqa: C901
"sanitize_changelog": self.sanitize_changelog,
"add_plugin_period": self.add_plugin_period,
"changelog_nice_yaml": self.changelog_nice_yaml,
"changelog_semantic_versioning_sort": self.changelog_semantic_versioning_sort,
}
if not self.is_collection:
if self.use_semantic_versioning:
Expand Down Expand Up @@ -602,6 +608,7 @@ def default(
"sanitize_changelog": True,
"add_plugin_period": True,
"changelog_nice_yaml": False,
"changelog_semantic_versioning_sort": False,
}
if title is not None:
config["title"] = title
Expand Down
3 changes: 2 additions & 1 deletion src/antsibull_changelog/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def load_yaml(path: str) -> Any:
return yaml.load(stream, Loader=_SafeLoader)


def store_yaml(path: str, content: Any, nice: bool = False) -> None:
def store_yaml(path: str, content: Any, nice: bool = False, sort: bool = False) -> None:
gardar marked this conversation as resolved.
Show resolved Hide resolved
"""
Store ``content`` as YAML file under ``path``.
"""
Expand All @@ -53,4 +53,5 @@ def store_yaml(path: str, content: Any, nice: bool = False) -> None:
default_flow_style=False,
Dumper=_IndentedDumper if nice else _SafeDumper,
explicit_start=nice,
sort_keys=not sort,
)