From 10b76b9d3ebae0ea35155c5e9f694c583401df44 Mon Sep 17 00:00:00 2001 From: Daniel McGregor Date: Wed, 21 Aug 2024 16:58:42 +0800 Subject: [PATCH] build: filter release notes to useful categories (#16) --- templates/.macros.j2 | 20 ++++++++++++++++++++ templates/.release_notes.md.j2 | 3 +++ templates/CHANGELOG.md.j2 | 10 ++++++++++ 3 files changed, 33 insertions(+) create mode 100644 templates/.macros.j2 create mode 100644 templates/.release_notes.md.j2 create mode 100644 templates/CHANGELOG.md.j2 diff --git a/templates/.macros.j2 b/templates/.macros.j2 new file mode 100644 index 0000000..b03f659 --- /dev/null +++ b/templates/.macros.j2 @@ -0,0 +1,20 @@ +{%- macro render_type_commits(type_commits) -%} +{%- for type_ in ("breaking", "feature", "performance", "fix", "documentation") -%} +{%- if type_ in type_commits %} +### {{ type_ | capitalize }} +{% for commit in type_commits[type_] %} +* {{ commit["descriptions"][0] }} ([`{{ commit.short_hash }}`]({{ commit.hexsha | commit_hash_url }})) +{% set ns = namespace(skip_line=false) -%} +{%- for line in commit["descriptions"][1:] -%} +{# skip co-author annotations in commit messages and internal notes #} +{%- if "---------" in line -%} +{%- set ns.skip_line = true -%} +{%- elif not ns.skip_line %} +{{ line | indent(2, first=True, blank=True)}} +{% endif -%} +{%- endfor %} +{%- endfor -%} +{%- endif %} +{%- endfor -%} +{%- endmacro -%} + diff --git a/templates/.release_notes.md.j2 b/templates/.release_notes.md.j2 new file mode 100644 index 0000000..ab45410 --- /dev/null +++ b/templates/.release_notes.md.j2 @@ -0,0 +1,3 @@ +{% import '.macros.j2' as macros -%} +# {{ version.as_tag() }} ({{ release.tagged_date.strftime("%Y-%m-%d") }}) +{{ macros.render_type_commits(release["elements"]) }} diff --git a/templates/CHANGELOG.md.j2 b/templates/CHANGELOG.md.j2 new file mode 100644 index 0000000..7c29da2 --- /dev/null +++ b/templates/CHANGELOG.md.j2 @@ -0,0 +1,10 @@ +{% import '.macros.j2' as macros -%} +# CHANGELOG +{%- if context.history.unreleased | length > 0 %} +## Unreleased +{{ macros.render_type_commits(context.history.unreleased) }} +{%- endif %} +{%- for version, release in context.history.released.items() %} +## {{ version.as_semver_tag() }} ({{ release.tagged_date.strftime("%Y-%m-%d") }}) +{{ macros.render_type_commits(release["elements"]) }} +{%- endfor %}