Skip to content

Commit

Permalink
build: add templates for changelog and release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
kmnhan committed Apr 8, 2024
1 parent 8a6b818 commit be72b24
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
23 changes: 23 additions & 0 deletions templates/.macros.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% macro render_single_commit(commit) -%}
* {% if commit["scope"] is not none %}**{{ commit["scope"] }}** {% endif %}{{ commit["descriptions"][0].rstrip() }} ([`{{commit.short_hash }}`]({{ commit.hexsha | commit_hash_url }}))
{% for line in commit["descriptions"][1:] %}
{{ line | indent(2, first=True, blank=True) -}}
{% endfor %}
{%- endmacro %}

{% macro render_unknown_commit(commit) -%}
* {{ commit.message.rstrip().split("\n")[0] }} ([`{{ commit.short_hash }}`]({{ commit.hexsha | commit_hash_url }}))
{% for line in commit.message.rstrip().split("\n")[1:] %}
{{ line | indent(2, first=True, blank=True) -}}
{% endfor %}
{%- endmacro %}

{%- macro render_elements(elements) -%}
{% for type_, commits in elements | dictsort %}
### {{ type_ | capitalize }}
{% for commit in commits -%}{% if type_ != "unknown" %}
{{ render_single_commit(commit).rstrip() }}
{% else %}
{{ render_unknown_commit(commit).rstrip() }}
{% endif %}{%- endfor %}{% endfor %}
{%- endmacro -%}
3 changes: 3 additions & 0 deletions templates/.release_notes.md.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% import ".macros.j2" as macros -%}
# {{ version.as_tag() }} ({{ release.tagged_date.strftime("%Y-%m-%d") }})
{{ macros.render_elements(release["elements"]) }}
12 changes: 12 additions & 0 deletions templates/CHANGELOG.md.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# CHANGELOG
{% import ".macros.j2" as macros -%}
{% if context.history.unreleased | length > 0 %}
{# UNRELEASED #}
## Unreleased
{{ macros.render_elements(context.history.unreleased) -}}
{% endif %}
{% for version, release in context.history.released.items() %}
{# RELEASED #}
## {{ version.as_semver_tag() }} ({{ release.tagged_date.strftime("%Y-%m-%d") }})
{{ macros.render_elements(release["elements"]) -}}
{% endfor %}

0 comments on commit be72b24

Please sign in to comment.