Skip to content

feat(changelog): expose commit parents #1376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions commitizen/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def process_commit_message(
):
message: dict = {
"sha1": commit.rev,
"parents": commit.parents,
"author": commit.author,
"author_email": commit.author_email,
**parsed.groupdict(),
Expand Down
16 changes: 13 additions & 3 deletions commitizen/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,20 @@ def __eq__(self, other) -> bool:

class GitCommit(GitObject):
def __init__(
self, rev, title, body: str = "", author: str = "", author_email: str = ""
self,
rev,
title,
body: str = "",
author: str = "",
author_email: str = "",
parents: list[str] | None = None,
):
self.rev = rev.strip()
self.title = title.strip()
self.body = body.strip()
self.author = author.strip()
self.author_email = author_email.strip()
self.parents = parents or []

@property
def message(self):
Expand Down Expand Up @@ -137,14 +144,17 @@ def get_commits(
for rev_and_commit in git_log_entries:
if not rev_and_commit:
continue
rev, title, author, author_email, *body_list = rev_and_commit.split("\n")
rev, parents, title, author, author_email, *body_list = rev_and_commit.split(
"\n"
)
if rev_and_commit:
git_commit = GitCommit(
rev=rev.strip(),
title=title.strip(),
body="\n".join(body_list).strip(),
author=author,
author_email=author_email,
parents=[p for p in parents.strip().split(" ") if p],
)
git_commits.append(git_commit)
return git_commits
Expand Down Expand Up @@ -286,7 +296,7 @@ def smart_open(*args, **kargs):
def _get_log_as_str_list(start: str | None, end: str, args: str) -> list[str]:
"""Get string representation of each log entry"""
delimiter = "----------commit-delimiter----------"
log_format: str = "%H%n%s%n%an%n%ae%n%b"
log_format: str = "%H%n%P%n%s%n%an%n%ae%n%b"
git_log_cmd = (
f"git -c log.showSignature=False log --pretty={log_format}{delimiter} {args}"
)
Expand Down
4 changes: 4 additions & 0 deletions docs/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,12 +507,16 @@ Each `Change` has the following fields:
| scope | `str | None` | An optional scope |
| message | `str` | The commit message body |
| sha1 | `str` | The commit `sha1` |
| parents | `list[str]` | The parent commit(s) `sha1`(s) |
| author | `str` | The commit author name |
| author_email | `str` | The commit author email |

!!! Note
The field values depend on the customization class and/or the settings you provide

The `parents` field can be used to identify merge commits and generate a changelog based on those. Another use case
is listing commits that belong to the same pull request.

When using another template (either provided by a plugin or by yourself), you can also pass extra template variables
by:

Expand Down
Loading