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:
|
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)
|
||||||
|
|
|
@ -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"])
|
||||||
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue