# Copyright Contributors to the OpenImageIO project.
# SPDX-License-Identifier: Apache-2.0
# https://github.com/AcademySoftwareFoundation/OpenImageIO

# git-cliff configuration file for OpenImageIO
#
# Lines starting with "#" are comments.
# Configuration options are organized into tables and keys.
# See documentation for more information on available options.
# https://git-cliff.org/docs/configuration
#
# Run like this:
#   git cliff --config-file .github/git-cliff.toml <FIRSTCOMMIT>..<LASTCOMMIT>
#
#

[changelog]
# changelog header
header = """
# Changelog\n
All notable changes to this project will be documented in this file.\n
"""


body = """
{% 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 | upper_first }}
    {% for commit in commits
    | filter(attribute="scope")
    | sort(attribute="scope") %}
        {% raw %}  {% endraw %}- *{{commit.scope}}*:{% if commit.breaking %} [**breaking**]{% endif %} \
            {{ commit.message | upper_first | split(pat="\n") | nth(n=0) }}\
            {% if commit.author.name != 'Larry Gritz' %} \
            (by {{ commit.author.name }})\
            {% endif %}
    {%- endfor -%}
    {% raw %}\n{% endraw %}\
    {%- for commit in commits %}
        {%- if commit.scope -%}
        {% else -%}
            {% raw %}  {% endraw %}- *(uncategorized)*:{% if commit.breaking %} [**breaking**]{% endif %} \
                {{ commit.message | upper_first | split(pat="\n") | nth(n=0) }}\
                {% if commit.author.name != 'Larry Gritz' %} \
                (by {{ commit.author.name }})\
                {% endif %}
        {% endif -%}
    {% endfor -%}
{% endfor %}\n
"""


# remove the leading and trailing whitespace from the template
trim = true
# changelog footer
footer = """
<!-- generated by git-cliff -->
"""

[git]
# parse the commits based on https://www.conventionalcommits.org
conventional_commits = true
# filter out the commits that are not conventional
#orig: filter_unconventional = true
filter_unconventional = false
# process each line of a commit as an individual commit
split_commits = false
# regex for preprocessing the commit messages
commit_preprocessors = [
  { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "[#${2}](https://github.com/AcademySoftwareFoundation/OpenImageIO/pull/${2})"}, # replace issue numbers
  { pattern = '^(BMP|DDS|FFMpeg|HDR|JPEG|IFF|PBM|PNG|PSD|RLA|Targa|TIFF):', replace = "fix(${1}):"},
  { pattern = '^(bmp|dds|ffmpeg|jpeg|iff|pbm|png|psd|rla|targa|tiff):', replace = "fix(${1}):"},
  { pattern = '^(ImageBuf|ImageBufAlgo|ImageCache|ImageInput|ImageOutput|ImageSpec|oiiotool|Python):', replace = "fix(${1}):"},
  { pattern = '^(windows|Windows):', replace = "build(Windows):"},
  { pattern = '^(Strutil|strutil):', replace = "dev(strutil.h):"},
#   { pattern = '^([A-Za-z]+\.h):', replace = "dev(${1}):"},
]


#commit_parsers = [
#    { message = '^fix\((.*)\)', group = 'Fix (${1})' },
#    { message = '^feat\((.*)\)', group = 'Feat (${1})' },
#]
# regex for parsing and grouping commits
commit_parsers = [
#   { message = '^feat\((.*)\)', group = 'Features and API changes (${1})' },
  { message = '^feat', group = '<!-- 10 -->⛰️  Features and API changes' },
  { message = '^api', group = '<!-- 10 -->⛰️  Features and API changes' },
  { message = '^perf', group = '<!-- 20 -->🚀  Performance Improvements', scope='perf' },
  { message = '^fix', group = '<!-- 30 -->🐛  Fixes and feature enhancements' },
  { message = '^enh', group = '<!-- 30 -->🐛  Fixes and feature enhancements' },
  { message = '^int', group = '<!-- 40 -->🔧  Internals and developer goodies' },
  { message = '^dev', group = '<!-- 40 -->🔧  Internals and developer goodies' },
  { message = '^cleanup', group = '<!-- 40 -->🔧  Internals and developer goodies' },
  { message = '^refactor', group = '<!-- 40 -->🔧  Internals and developer goodies', scope='refactor' },
  { message = '^(build|Build)', group = '<!-- 50 -->🏗  Build/test/CI and platform ports' },
  { message = '^(cmake|CMake)', group = '<!-- 50 -->🏗  Build/test/CI and platform ports', scope='cmake' },
  { message = '^(test|Test|testing|Testing)', group = '<!-- 50 -->🏗  Build/test/CI and platform ports', scope='tests' },
#   { message = 'testsuite', group = '<!-- 50 -->🏗  Build/test/CI and platform ports', scope='tests' },
  { message = '^(ci|CI)', group = '<!-- 50 -->🏗  Build/test/CI and platform ports', scope='ci' },
  { message = '^(doc|docs|Docs|Documentation)', group = '<!-- 60 -->📚  Documentation' },
  { message = '^(admin)', group = '<!-- 90 -->🏢  Project Administration' },
  { message = 'RELICENSING', group = '<!-- 90 -->🏢  Project Administration' },
  { message = '^style', group = 'Styling' },
#   { message = '^chore\\(release\\): prepare for', skip = true },
  { message = '^chore', group = 'Miscellaneous Tasks' },
  { body = '.*security', group = 'Security' },
  { message = ".*", group = "Unconventional" },
#   , default_scope = "other"
#   },
]


# protect breaking changes from being skipped due to matching a skipping commit_parser
protect_breaking_commits = false
# filter out the commits that are not matched by commit parsers
filter_commits = false
# glob pattern for matching git tags
tag_pattern = "v[0-9]*"
# regex for skipping tags
skip_tags = "v0.1.0-beta.1"
# regex for ignoring tags
ignore_tags = ""
# sort the tags topologically
topo_order = false
# sort the commits inside sections by oldest/newest order
sort_commits = "oldest"
# limit the number of commits included in the changelog.
# limit_commits = 42
