# SPDX-License-Identifier: PMPL-1.0-or-later
# Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk>
#
# git-cliff configuration for conventional commit changelog generation.
# https://git-cliff.org/docs/configuration
#
# Placeholders — replace before first use:
#   hyperpolymath — GitHub organization or username
#   anvomidaviser  — GitHub repository name

[changelog]
# Changelog header
header = """
# Changelog\n
All notable changes to this project will be documented in this file.\n
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n
<!-- Generated by git-cliff: https://git-cliff.org -->\n
"""
# Template for the changelog body
# https://keats.github.io/tera/docs/#introduction
body = """
{%- macro remote_url() -%}
  https://github.com/hyperpolymath/anvomidaviser
{%- 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 | striptags | trim }}
    {% for commit in commits %}
        - {% if commit.scope %}**{{ commit.scope }}:** {% endif %}\
            {% if commit.breaking %}[**BREAKING**] {% endif %}\
            {{ commit.message | upper_first }}\
            {%- if commit.links %} \
                ({% for link in commit.links %}[{{ link.text }}]({{ link.href }}){% endfor %}){% endif -%}
    {% endfor %}
{% endfor %}

{%- if github -%}
{% if github.contributors | filter(attribute="is_first_time", value=true) | length != 0 %}
    ### New Contributors
{%- 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 %}
{% endif -%}
{% endif -%}

"""
# Template for the changelog footer
footer = """
{%- macro remote_url() -%}
  https://github.com/hyperpolymath/anvomidaviser
{%- 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
        {% endif -%}
    {% endif -%}
{% endfor %}
<!-- Generated by git-cliff -->
"""
# Remove leading and trailing whitespace from templates
trim = true

[git]
# Parse conventional commits
# https://www.conventionalcommits.org
conventional_commits = true
# Filter out unconventional commits
filter_unconventional = true
# Process each line of a commit as an individual commit
split_commits = false
# Regex for commit preprocessing
commit_preprocessors = [
    # Remove issue numbers from commit messages
    { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "" },
]
# Regex for parsing and grouping commits
commit_parsers = [
    { message = "^feat", group = "<!-- 0 -->Features" },
    { message = "^fix", group = "<!-- 1 -->Bug Fixes" },
    { message = "^security", group = "<!-- 2 -->Security" },
    { message = "^perf", group = "<!-- 3 -->Performance" },
    { message = "^refactor", group = "<!-- 4 -->Refactoring" },
    { message = "^docs", group = "<!-- 5 -->Documentation" },
    { message = "^style", group = "<!-- 6 -->Styling" },
    { message = "^test", group = "<!-- 7 -->Testing" },
    { message = "^ci", group = "<!-- 8 -->CI/CD" },
    { message = "^chore\\(release\\)", skip = true },
    { message = "^chore\\(deps.*\\)", skip = true },
    { message = "^chore\\(pr\\)", skip = true },
    { message = "^chore", group = "<!-- 9 -->Miscellaneous" },
    { body = ".*security", group = "<!-- 2 -->Security" },
]
# Protect breaking changes from being skipped by a commit parser
protect_breaking_commits = false
# Filter out merge commits
filter_merge_commits = true
# Filter out commits by tag pattern (skip pre-releases)
# tag_pattern = "v[0-9].*"
# Regex for skipping tags
# skip_tags = "beta|alpha"
# Sort commits within each group by oldest first
sort_commits = "oldest"
