Commit 48d6c712 authored by Simon Chabot's avatar Simon Chabot
Browse files

feat: show the version release date in the changelog

parent 76ef4e904a54
......@@ -5,6 +5,7 @@ import re
import pathlib
import sys
from enum import Enum
from datetime import datetime
from dataclasses import dataclass
from collections import defaultdict
......@@ -21,6 +22,12 @@ with open(ROOT / "templates" / "changelog.md") as fobj:
CHANGE_LOG_TEMPLATE = Template(fobj.read())
@dataclass(frozen=True)
class Version:
label: str = "upcoming"
release_date: datetime = datetime.now()
class ChangeType(Enum):
chore = "chore"
ci = "ci"
......@@ -103,7 +110,7 @@ class Changelog:
def __init__(self):
self.changes_by_version = defaultdict(lambda: defaultdict(list))
def add_commit(self, commit, version=None):
def add_commit(self, commit, version=Version()):
change = self._change_from_commit(commit)
if not change:
return
......@@ -131,7 +138,7 @@ class Changelog:
)
def autochangelog(ui, repo, **opts):
changelog = Changelog()
version = "upcoming"
version = Version()
user_revs = opts["revs"].decode("utf-8")
for rev in repo.revs(f"sort({user_revs}, -date)".encode("utf-8")):
......@@ -142,7 +149,10 @@ def autochangelog(ui, repo, **opts):
tags = [t for t in commit.tags() if t != b"tip"]
if tags:
version = tags[0].decode("utf-8")
version = Version(
tags[0].decode("utf-8"),
datetime.fromtimestamp(commit.date()[0])
)
changelog.add_commit(commit, version)
print(changelog.render())
......@@ -13,10 +13,10 @@
{%- endmacro %}
# CHANGELOG
{% for version, changes in changelog.changes_by_version.items() %}
{%- if version == "upcoming" %}
{%- if version.label == "upcoming" %}
## Upcoming version
{% else %}
## Version {{ version }}
## Version {{ version.label }} ({{ version.release_date.strftime('%Y-%m-%d') }})
{%- endif %}
{{- new_section(changes, ChangeType.feat, "New features") }}
{{- new_section(changes, ChangeType.perf, "Performance improvements") }}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment