Skip to content
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
17 changes: 12 additions & 5 deletions commitizen/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ def __eq__(self, other) -> bool:


class GitCommit(GitObject):
def __init__(self, rev, title, body=""):
def __init__(
self, rev, title, body: str = "", author: str = "", author_email: str = ""
):
self.rev = rev.strip()
self.title = title.strip()
self.body = body.strip()
self.author = author.strip()
self.author_email = author_email.strip()

@property
def message(self):
Expand Down Expand Up @@ -59,7 +63,7 @@ def get_commits(
start: Optional[str] = None,
end: str = "HEAD",
*,
log_format: str = "%H%n%s%n%b",
log_format: str = "%H%n%s%n%an%n%ae%n%b",
delimiter: str = "----------commit-delimiter----------",
args: str = "",
) -> List[GitCommit]:
Expand All @@ -79,11 +83,14 @@ def get_commits(
rev_and_commit = rev_and_commit.strip()
if not rev_and_commit:
continue
rev, title, *body_list = rev_and_commit.split("\n")

rev, 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()
rev=rev.strip(),
title=title.strip(),
body="\n".join(body_list).strip(),
author=author,
author_email=author_email,
)
git_commits.append(git_commit)
return git_commits
Expand Down
30 changes: 15 additions & 15 deletions docs/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ message = "Do you want to add body message in commit?"

#### Detailed `questions` content

| Parameter | Type | Default | Description |
| --------- | ------ | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `type` | `str` | `None` | The type of questions. Valid type: `list`, `input` and etc. [See More](https://github.com/tmbo/questionary#different-question-types) |
| `name` | `str` | `None` | The key for the value answered by user. It's used in `message_template` |
| `message` | `str` | `None` | Detail description for the question. |
| Parameter | Type | Default | Description |
| --------- | ------ | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| `type` | `str` | `None` | The type of questions. Valid type: `list`, `input` and etc. [See More](https://github.com/tmbo/questionary#different-question-types) |
| `name` | `str` | `None` | The key for the value answered by user. It's used in `message_template` |
| `message` | `str` | `None` | Detail description for the question. |
| `choices` | `list` | `None` | (OPTIONAL) The choices when `type = list`. Either use a list of values or a list of dicitionaries with `name` and `value` keys. See examples above. |
| `default` | `Any` | `None` | (OPTIONAL) The default value for this question. |
| `filter` | `str` | `None` | (Optional) Validator for user's answer. **(Work in Progress)** |
| `default` | `Any` | `None` | (OPTIONAL) The default value for this question. |
| `filter` | `str` | `None` | (Optional) Validator for user's answer. **(Work in Progress)** |

## 2. Customize through customizing a class

Expand Down Expand Up @@ -206,13 +206,13 @@ cz -n cz_strange bump
The changelog generator should just work in a very basic manner without touching anything.
You can customize it of course, and this are the variables you need to add to your custom `BaseCommitizen`.

| Parameter | Type | Required | Description |
| ------------------- | ------------------------------------------------------------------------ | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `commit_parser` | `str` | NO | Regex which should provide the variables explained in the [changelog description][changelog-des] |
| `changelog_pattern` | `str` | NO | Regex to validate the commits, this is useful to skip commits that don't meet your rulling standards like a Merge. Usually the same as bump_pattern |
| `change_type_map` | `dict` | NO | Convert the title of the change type that will appear in the changelog, if a value is not found, the original will be provided |
| `changelog_message_builder_hook` | `method: (dict, git.GitCommit) -> dict` | NO | Customize with extra information your message output, like adding links, this function is executed per parsed commit. |
| `changelog_hook` | `method: (full_changelog: str, partial_changelog: Optional[str]) -> str` | NO | Receives the whole and partial (if used incremental) changelog. Useful to send slack messages or notify a compliance department. Must return the full_changelog |
| Parameter | Type | Required | Description |
| -------------------------------- | ------------------------------------------------------------------------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `commit_parser` | `str` | NO | Regex which should provide the variables explained in the [changelog description][changelog-des] |
| `changelog_pattern` | `str` | NO | Regex to validate the commits, this is useful to skip commits that don't meet your rulling standards like a Merge. Usually the same as bump_pattern |
| `change_type_map` | `dict` | NO | Convert the title of the change type that will appear in the changelog, if a value is not found, the original will be provided |
| `changelog_message_builder_hook` | `method: (dict, git.GitCommit) -> dict` | NO | Customize with extra information your message output, like adding links, this function is executed per parsed commit. Each GitCommit contains the following attrs: `rev`, `title`, `body`, `author`, `author_email` |
| `changelog_hook` | `method: (full_changelog: str, partial_changelog: Optional[str]) -> str` | NO | Receives the whole and partial (if used incremental) changelog. Useful to send slack messages or notify a compliance department. Must return the full_changelog |

```python
from commitizen.cz.base import BaseCommitizen
Expand All @@ -232,7 +232,7 @@ class StrangeCommitizen(BaseCommitizen):
def changelog_message_builder_hook(self, parsed_message: dict, commit: git.GitCommit) -> dict:
rev = commit.rev
m = parsed_message["message"]
parsed_message["message"] = f"{m} {rev}"
parsed_message["message"] = f"{m} {rev} [{commit.author}]({commit.author_email})"
return parsed_message

def changelog_hook(self, full_changelog: str, partial_changelog: Optional[str]) -> str:
Expand Down
Loading