Debian Codegraph @

docs/customization/changelog_template.md

raw
1
2 # Customizing the changelog template
3
4 Commitizen gives you the possibility to provide your own changelog template, by:
5
6 - providing one with your customization class
7 - providing one from the current working directory and setting it:
8 - Through the configuration file
9 - as `--template` parameter to both `bump` and `changelog` commands
10 - either by providing a template with the same name as the default template
11
12 By default, the template used is the `CHANGELOG.md.j2` file from the Commitizen repository.
13
14 ## Providing a template with your customization class
15
16 There are 3 parameters available to change the template rendering from your custom `BaseCommitizen`.
17
18 | Parameter | Type | Default | Description |
19 | ----------------- | ------ | ------- | ----------------------------------------------------------------------------------------------------- |
20 | `template` | `str` | `None` | Provide your own template name (default to `CHANGELOG.md.j2`) |
21 | `template_loader` | `str` | `None` | Override the default template loader (so you can provide template from your customization class) |
22 | `template_extras` | `dict` | `None` | Provide some extra template parameters |
23
24 Let's see an example.
25
26 ```python
27 from commitizen.cz.base import BaseCommitizen
28 from jinja2 import PackageLoader
29
30
31 class MyPlugin(BaseCommitizen):
32 template = "CHANGELOG.md.jinja"
33 template_loader = PackageLoader("my_plugin", "templates")
34 template_extras = {"key": "value"}
35 ```
36
37 This snippet will:
38
39 - use `CHANGELOG.md.jinja` as template name
40 - search for it in the `templates` directory for `my_plugin` package
41 - add the `key=value` variable in the template
42
43 ## Providing a template from the current working directory
44
45 Users can provide their own template from their current working directory (your project root) by:
46
47 - providing a template with the same name (`CHANGELOG.md.j2` unless overridden by your custom class)
48 - setting your template path as `template` configuration
49 - giving your template path as `--template` parameter to `bump` and `changelog` commands
50
51 !!! note
52 The path is relative to the current working directory, aka your project root most of the time.
53
54 ## Template variables
55
56 The default template use a single `tree` variable which is a list of entries (a release) with the following format:
57
58 | Name | Type | Description |
59 | ---- | ---- | ----------- |
60 | version | `str` | The release version |
61 | date | `datetime` | The release date |
62 | changes | `list[tuple[str, list[Change]]]` | The release sorted changes list in the form `(type, changes)` |
63
64 Each `Change` has the following fields:
65
66 | Name | Type | Description |
67 | ---- | ---- | ----------- |
68 | scope | `str | None` | An optional scope |
69 | message | `str` | The commit message body |
70 | sha1 | `str` | The commit `sha1` |
71 | parents | `list[str]` | The parent commit(s) `sha1`(s) |
72 | author | `str` | The commit author name |
73 | author_email | `str` | The commit author email |
74
75 !!! note
76 The field values depend on the customization class and/or the settings you provide
77
78 The `parents` field can be used to identify merge commits and generate a changelog based on those. Another use case
79 is listing commits that belong to the same pull request.
80
81 When using another template (either provided by a plugin or by yourself), you can also pass extra template variables
82 by:
83
84 - defining them in your configuration with the `extras` settings
85 - providing them on the command line with the `--extra/-e` parameter to `bump` and `changelog` commands