diff --git a/modif/changelog.py b/modif/changelog.py index fbcc5e0..e0cb0cd 100644 --- a/modif/changelog.py +++ b/modif/changelog.py @@ -37,9 +37,13 @@ def build_changelog(config: Config, commits: list[Commit]) -> str: if not selected_commits: continue + selected_commits.sort(key=lambda c: c.committed_at, reverse=True) + changelog_lines.append(f"\n## {group.label}\n") for commit in selected_commits: - changelog_lines.append(f"- {commit.subject} ({commit.author})") + changelog_lines.append( + f"- {commit.subject} ({commit.committed_at.date()}, {commit.author})" + ) return "\n".join(changelog_lines) diff --git a/modif/git.py b/modif/git.py index 33c09f3..2557e56 100644 --- a/modif/git.py +++ b/modif/git.py @@ -2,6 +2,7 @@ import subprocess import dataclasses import json import functools +import datetime @dataclasses.dataclass @@ -11,6 +12,7 @@ class Commit: short_hash: str body: str subject: str + committed_at: datetime.datetime @functools.cache @@ -21,6 +23,7 @@ def _get_commit_format() -> str: "short_hash": "%h", "body": "%b", "subject": "%s", + "committed_at": "%ct", } return json.dumps(log_format) @@ -48,6 +51,9 @@ def log(from_ref: str, to_ref: str) -> list[Commit]: short_hash=commit_parsed["short_hash"], subject=commit_parsed["subject"], body=commit_parsed["body"], + committed_at=datetime.datetime.fromtimestamp( + int(commit_parsed["committed_at"]) + ), ) )