feat: sort grouped commits by commit date
This commit is contained in:
parent
30299300bb
commit
13d132708b
2 changed files with 11 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -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"])
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue