feat: sort grouped commits by commit date
All checks were successful
Pull Request / static-analysis (pull_request) Successful in 1m5s
Pull Request / export-trace (pull_request) Successful in 29s
Push / static-analysis (push) Successful in 1m0s
Push / export-trace (push) Successful in 41s

This commit is contained in:
Marc 2024-11-11 23:01:18 -05:00
parent 30299300bb
commit 13d132708b
Signed by: marc
GPG key ID: 048E042F22B5DC79
2 changed files with 11 additions and 1 deletions

View file

@ -37,9 +37,13 @@ def build_changelog(config: Config, commits: list[Commit]) -> str:
if not selected_commits: if not selected_commits:
continue continue
selected_commits.sort(key=lambda c: c.committed_at, reverse=True)
changelog_lines.append(f"\n## {group.label}\n") changelog_lines.append(f"\n## {group.label}\n")
for commit in selected_commits: 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) return "\n".join(changelog_lines)

View file

@ -2,6 +2,7 @@ import subprocess
import dataclasses import dataclasses
import json import json
import functools import functools
import datetime
@dataclasses.dataclass @dataclasses.dataclass
@ -11,6 +12,7 @@ class Commit:
short_hash: str short_hash: str
body: str body: str
subject: str subject: str
committed_at: datetime.datetime
@functools.cache @functools.cache
@ -21,6 +23,7 @@ def _get_commit_format() -> str:
"short_hash": "%h", "short_hash": "%h",
"body": "%b", "body": "%b",
"subject": "%s", "subject": "%s",
"committed_at": "%ct",
} }
return json.dumps(log_format) 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"], short_hash=commit_parsed["short_hash"],
subject=commit_parsed["subject"], subject=commit_parsed["subject"],
body=commit_parsed["body"], body=commit_parsed["body"],
committed_at=datetime.datetime.fromtimestamp(
int(commit_parsed["committed_at"])
),
) )
) )