[changelog]
# A Tera template to be rendered as the changelog's header.
# See https://keats.github.io/tera/docs/#introduction
header = """
# Changelog\n
All notable changes to this project will be documented in this file.\n
"""
# A Tera template to be rendered for each release in the changelog.
# See https://keats.github.io/tera/docs/#introduction
body = """
{%- macro remote_url() -%}
  https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}
{%- endmacro -%}
{% if version -%}
    ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
{% else -%}
    ## [Unreleased]
{% endif -%}

{# Highlight Breaking Changes #}
{% set breaking = commits | filter(attribute="group", value="Breaking Changes") %}
{% if breaking | length > 0 %}
### 🚨 Breaking Changes
{% for commit in breaking %}
- {{ commit.message | split(pat="\n") | first | upper_first | trim }} \
  {% if commit.remote.username %} by @{{ commit.remote.username }}{% endif %}
  {% if commit.remote.pr_number %} in [#{{ commit.remote.pr_number }}]({{ self::remote_url() }}/pull/{{ commit.remote.pr_number }}){% endif %}
{% endfor %}
{% endif %}

{% for group, commits in commits | group_by(attribute="group") %}
    {% if group != "Breaking Changes" %}
    ### {{ group | upper_first }}
    {%- for commit in commits %}
        - {% if commit.scope %}(*{{ commit.scope }}*) {% endif %} {{ commit.message | split(pat="\n") | first | upper_first | trim }}\
            {% if commit.remote.username %} by @{{ commit.remote.username }}{%- endif -%}
            {% if commit.remote.pr_number %} in \
            [#{{ commit.remote.pr_number }}]({{ self::remote_url() }}/pull/{{ commit.remote.pr_number }}) \
            {%- endif -%}
    {% endfor %}
    {% endif %}
{% endfor %}
{%- set prs = commits | filter(attribute="remote.pr_number") | unique(attribute="remote.pr_number") %}
{%- if prs | length != 0 %}
    ### Pull Requests
    {%- for commit in prs %}
    - [#{{ commit.remote.pr_number }}]({{ self::remote_url() }}/pull/{{ commit.remote.pr_number }}) - {{ commit.message | split(pat="\n") | first | trim }}
    {%- endfor %}
{% endif -%}

{%- if github.contributors | filter(attribute="is_first_time", value=true) | length != 0 %}
    ### New Contributors
{%- endif -%}
{% for contributor in github.contributors | filter(attribute="is_first_time", value=true) %}
  * @{{ contributor.username }} made their first contribution
    {%- if contributor.pr_number %} in \
      [#{{ contributor.pr_number }}]({{ self::remote_url() }}/pull/{{ contributor.pr_number }}) \
    {%- endif %}
{%- endfor %}\n

{%- if github.contributors | length != 0 %}{% raw %}\n{% endraw -%}{% endif %}

"""
# A Tera template to be rendered as the changelog's footer.
# See https://keats.github.io/tera/docs/#introduction
footer = """
{%- macro remote_url() -%}
  https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}
{%- endmacro -%}
\n
{% for release in releases -%}
    {% if release.version -%}
        {% if release.previous.version -%}
            [{{ release.version | trim_start_matches(pat="v") }}]: \
                {{ self::remote_url() }}/compare/{{ release.previous.version }}...{{ release.version }}
        {% endif -%}
    {% else -%}
        [unreleased]: {{ self::remote_url() }}/compare/{{ release.previous.version }}...HEAD
    {% endif -%}
{% endfor %}
<!-- generated by git-cliff -->
"""
# Remove leading and trailing whitespaces from the changelog's body.
trim = true

[git]
# Parse commits according to the conventional commits specification.
# See https://www.conventionalcommits.org
conventional_commits = true
# Exclude commits that do not match the conventional commits specification.
filter_unconventional = false
# An array of regex based parsers to modify commit messages prior to further processing.
commit_preprocessors = [
  # Remove issue numbers.
  { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "" },
]
# An array of regex based parsers for extracting data from the commit message.
# Assigns commits to groups.
# Optionally sets the commit's scope and can decide to exclude commits from further processing.
commit_parsers = [
  { message = "^(feat|fix|refactor|perf|style|doc|test|chore)(\\([^)]+\\))?!:", group = "Breaking Changes" },
  { message = "^(feat|fix|refactor|perf|style|doc|test|chore)!:", group = "Breaking Changes" },
  { message = "^feat", group = "Features" },
  { message = "^fix", group = "Bug Fixes" },
  { message = "^doc", group = "Documentation" },
  { message = "^perf", group = "Performance" },
  { message = "^refactor", group = "Refactor" },
  { message = "^style", group = "Styling" },
  { message = "^test", group = "Testing" },
  { message = "^chore\\(release\\): update changelog", skip = true },
  { message = "^chore", group = "Miscellaneous Tasks" },
  { body = ".*security", group = "Security" },
]
# Exclude commits that are not matched by any commit parser.
filter_commits = false
# Order releases topologically instead of chronologically.
topo_order = false
# Order of commits in each group/release within the changelog.
# Allowed values: newest, oldest
sort_commits = "newest"

[remote.github]
owner = "STMicroelectronics"
repo = "ilps22qs-rs"
