# git-cliff ~ configuration file
# https://git-cliff.org/docs/configuration

[remote.github]
owner = "vhspace"
repo = "sdl3-rs"

[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.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\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 -%}

{% for group, commits in commits | group_by(attribute="group") %}
    ### {{ group | upper_first }}
    {%- for commit in commits %}
        - {{ commit.message | split(pat="\n") | first | upper_first | trim }}\
    {% endfor %}
{% endfor %}

"""
# 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 -%}

{% 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 -%}
        {% if release.previous.version -%}
            [unreleased]: {{ self::remote_url() }}/compare/{{ release.previous.version }}...HEAD
        {% else -%}
            [unreleased]: {{ self::remote_url() }}/compare/21b9f0c7a763a8612c9c153fb0935f70fc88abbd...HEAD
        {% endif -%}
    {% endif -%}
{% endfor %}
<!-- generated by git-cliff -->
"""
# Remove leading and trailing whitespaces from the changelog's body.
trim = true
# Render body even when there are no releases to process.
render_always = true
# An array of regex based postprocessors to modify the changelog.
postprocessors = [
    # Replace the placeholder <REPO> with a URL.
    { pattern = '<REPO>', replace = "https://github.com/vhspace/sdl3-rs" },
]

[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 = [
  # Replace issue numbers with link templates to be updated in `changelog.postprocessors`.
  { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](<REPO>/pull/${2}))" },
  # Check spelling of the commit message using https://github.com/crate-ci/typos.
  # If the spelling is incorrect, it will be fixed automatically.
  #{ pattern = '.*', replace_command = 'typos --write-changes -' },
]
# 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", group = "<!-- 0 -->Added" },
    { message = "^doc", group = "<!-- 5 -->Documentation" },
    { message = "^perf", group = "<!-- 1 -->Changed" },
    { message = "^test", group = "<!-- 2 -->Fixed" },
    { message = "^fix", group = "<!-- 2 -->Fixed" },
    { message = "^refactor", group = "<!-- 1 -->Changed" },
    { message = "^style", skip = true },
    { message = "^chore: Release sdl3 version", skip = true },
    { message = "^chore: update CHANGELOG.md", skip = true },
    { message = "^chore\\(deps.*\\)", group = "<!-- 4 -->Dependencies" },
    { message = "^chore|^ci", group = "<!-- 1 -->Changed" },
    { message = "^revert", group = "<!-- 1 -->Changed" },

    # No conventional commit support
    { message = "^[a|A]dd", group = "<!-- 0 -->Added" },
    { message = "^[s|S]upport", group = "<!-- 0 -->Added" },
    { message = "^[r|R]emove", group = "<!-- 3 -->Removed" },
    { message = "^.*: add", group = "<!-- 0 -->Added" },
    { message = "^.*: support", group = "<!-- 0 -->Added" },
    { message = "^.*: remove", group = "<!-- 3 -->Removed" },
    { message = "^.*: delete", group = "<!-- 3 -->Removed" },
    { message = "^.*: fix", group = "<!-- 2 -->Fixed" },
    { message = "^.*", group = "<!-- 1 -->Changed" },
]
# 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"
