{% import "macros" as macros %}
{% if version.tag and from.tag -%}
    ## [{{ version.tag }}]({{repository_url ~ "/compare/" ~ from.tag ~ ".." ~ version.tag}}) - {{ date | date(format="%Y-%m-%d") }}
{% elif version.tag and from.id -%}
    ## [{{ version.tag }}]({{repository_url ~ "/compare/" ~ from.id ~ ".." ~ version.tag}}) - {{ date | date(format="%Y-%m-%d") }}
{% else -%}
    {% set from = from.id -%}
    {% set to = version.id -%}

    {% set from_shorthand = from.id | truncate(length=7, end="") -%}
    {% set to_shorthand = version.id | truncate(length=7, end="") -%}

    ## Unreleased ([{{ from_shorthand ~ ".." ~ to_shorthand }}]({{repository_url ~ "/compare/" ~ from_shorthand ~ ".." ~ to_shorthand}}))
{% endif -%}

{% if package_lock -%}
### Packages
{% for package in packages -%}
{% if package.version.tag -%}
- [{{ package.version.tag }}]({{ package.package_path }}) locked to [{{ package.version.tag }}]({{repository_url ~ "/tree/" ~ package.version.tag }})
{% endif -%}
{% endfor -%}
{% else -%}
### Package updates
{% for package in packages -%}
{% if package.version.tag and package.from.tag -%}
- [{{ package.version.tag }}]({{ package.package_path }}) bumped to [{{ package.version.tag }}]({{repository_url ~ "/compare/" ~ package.from.tag ~ ".." ~ package.version.tag}})
{% elif package.version.tag and package.from.id -%}
- [{{ package.package_name }}]({{ package.package_path }}) bumped to [{{ package.version.tag }}]({{repository_url ~ "/compare/" ~ package.from.id ~ ".." ~ package.version.tag}})
{% else -%}
{% endif -%}
{% endfor -%}
{% endif -%}

### All changes
{% for value in commits | group_by_type-%}
#### {{ value.0 | upper_first }}
{% for scope, scoped_commits in value.1 | group_by(attribute="scope") -%}

{% for commit in scoped_commits | sort(attribute="scope") -%}
{{macros::remote(commit=commit)}}
{% endfor -%}

{% endfor -%}

{% for commit in value.1 | unscoped -%}
{{macros::remote(commit=commit)}}
{% endfor -%}

{% endfor -%}
