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 ...@@ -5,6 +5,7 @@ import re
import pathlib import pathlib
import sys import sys
from enum import Enum from enum import Enum
from datetime import datetime
from dataclasses import dataclass from dataclasses import dataclass
from collections import defaultdict from collections import defaultdict
...@@ -21,6 +22,12 @@ with open(ROOT / "templates" / "changelog.md") as fobj: ...@@ -21,6 +22,12 @@ with open(ROOT / "templates" / "changelog.md") as fobj:
CHANGE_LOG_TEMPLATE = Template(fobj.read()) CHANGE_LOG_TEMPLATE = Template(fobj.read())
@dataclass(frozen=True)
class Version:
label: str = "upcoming"
release_date: datetime = datetime.now()
class ChangeType(Enum): class ChangeType(Enum):
chore = "chore" chore = "chore"
ci = "ci" ci = "ci"
...@@ -103,7 +110,7 @@ class Changelog: ...@@ -103,7 +110,7 @@ class Changelog:
def __init__(self): def __init__(self):
self.changes_by_version = defaultdict(lambda: defaultdict(list)) 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) change = self._change_from_commit(commit)
if not change: if not change:
return return
...@@ -131,7 +138,7 @@ class Changelog: ...@@ -131,7 +138,7 @@ class Changelog:
) )
def autochangelog(ui, repo, **opts): def autochangelog(ui, repo, **opts):
changelog = Changelog() changelog = Changelog()
version = "upcoming" version = Version()
user_revs = opts["revs"].decode("utf-8") user_revs = opts["revs"].decode("utf-8")
for rev in repo.revs(f"sort({user_revs}, -date)".encode("utf-8")): for rev in repo.revs(f"sort({user_revs}, -date)".encode("utf-8")):
...@@ -142,7 +149,10 @@ def autochangelog(ui, repo, **opts): ...@@ -142,7 +149,10 @@ def autochangelog(ui, repo, **opts):
tags = [t for t in commit.tags() if t != b"tip"] tags = [t for t in commit.tags() if t != b"tip"]
if tags: 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) changelog.add_commit(commit, version)
print(changelog.render()) print(changelog.render())
...@@ -13,10 +13,10 @@ ...@@ -13,10 +13,10 @@
{%- endmacro %} {%- endmacro %}
# CHANGELOG # CHANGELOG
{% for version, changes in changelog.changes_by_version.items() %} {% for version, changes in changelog.changes_by_version.items() %}
{%- if version == "upcoming" %} {%- if version.label == "upcoming" %}
## Upcoming version ## Upcoming version
{% else %} {% else %}
## Version {{ version }} ## Version {{ version.label }} ({{ version.release_date.strftime('%Y-%m-%d') }})
{%- endif %} {%- endif %}
{{- new_section(changes, ChangeType.feat, "New features") }} {{- new_section(changes, ChangeType.feat, "New features") }}
{{- new_section(changes, ChangeType.perf, "Performance improvements") }} {{- 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