Skip to content

Commit 95ec261

Browse files
woileLee-W
authored andcommitted
feat: add author and author_email to git commit
Extra useful information for hooks Closes #188
1 parent ab91e62 commit 95ec261

File tree

3 files changed

+171
-9
lines changed

3 files changed

+171
-9
lines changed

commitizen/git.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ def __eq__(self, other) -> bool:
1818

1919

2020
class GitCommit(GitObject):
21-
def __init__(self, rev, title, body=""):
21+
def __init__(
22+
self, rev, title, body: str = "", author: str = "", author_email: str = ""
23+
):
2224
self.rev = rev.strip()
2325
self.title = title.strip()
2426
self.body = body.strip()
27+
self.author = author.strip()
28+
self.author_email = author_email.strip()
2529

2630
@property
2731
def message(self):
@@ -59,7 +63,7 @@ def get_commits(
5963
start: Optional[str] = None,
6064
end: str = "HEAD",
6165
*,
62-
log_format: str = "%H%n%s%n%b",
66+
log_format: str = "%H%n%s%n%an%n%ae%n%b",
6367
delimiter: str = "----------commit-delimiter----------",
6468
args: str = "",
6569
) -> List[GitCommit]:
@@ -79,11 +83,14 @@ def get_commits(
7983
rev_and_commit = rev_and_commit.strip()
8084
if not rev_and_commit:
8185
continue
82-
rev, title, *body_list = rev_and_commit.split("\n")
83-
86+
rev, title, author, author_email, *body_list = rev_and_commit.split("\n")
8487
if rev_and_commit:
8588
git_commit = GitCommit(
86-
rev=rev.strip(), title=title.strip(), body="\n".join(body_list).strip()
89+
rev=rev.strip(),
90+
title=title.strip(),
91+
body="\n".join(body_list).strip(),
92+
author=author,
93+
author_email=author_email,
8794
)
8895
git_commits.append(git_commit)
8996
return git_commits

0 commit comments

Comments
 (0)