Skip to content

Commit

Permalink
add support for arbitrary user configuration for hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
EdgyEdgemond committed Aug 16, 2024
1 parent cd577a5 commit ef68031
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelog_gen/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ class Config:

post_process: PostProcessConfig | None = None

custom: dict = dataclasses.field(default_factory=dict)

def __post_init__(self: t.Self) -> None:
"""Process parser and validate if strict check enabled."""
self.parser = re.compile(self.parser)
Expand Down
14 changes: 14 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,20 @@ hooks = [
]
```

### `custom`
_**[optional]**_<br />
**default**: None

Arbitrary configuration that can be used in hooks.

Example:

```toml
[tool.changelog_gen.custom]
key = "value"
a_list = ["key", "key2"]
```


## Versioning

Expand Down
7 changes: 7 additions & 0 deletions docs/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ based on current verbosity settings.

The above methods accept a % format string, and `*args`. i.e. `context.error("Hello, %s", "world")`.

### Configuration

Custom configuration can be accessed with `context.config.custom`. This is a
dictionary containing all values defined in `[tool.changelog_gen.custom]`. See
[custom](https://nrwldev.github.io/changelog-gen/configuration/#custom) for
details on providing custom configuration.

## Example

Here is a full example used in another project to generate `.md` files from
Expand Down
4 changes: 4 additions & 0 deletions tests/cli/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def test_config_displayed(cli_runner):
header = 'Miscellaneous'
semver = 'patch'
[custom]
[files]"""
)

Expand All @@ -82,4 +84,6 @@ def test_post_process_config_displayed(cli_runner, config_factory):
body = '{"body": "Released on ::version::"}'
auth_type = 'basic'
[custom]
[files]""")
17 changes: 17 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,23 @@ def test_read_picks_up_list_values(self, config_factory):
c = config.read()
assert c.allowed_branches == ["main", "feature/11"]

def test_read_picks_custom_config(self, config_factory):
config_factory(
"""
[tool.changelog_gen.custom]
key = "value"
key2 = "value2"
custom_list = ["one", "two"]
""",
)

c = config.read()
assert c.custom == {
"key": "value",
"key2": "value2",
"custom_list": ["one", "two"],
}

def test_read_picks_up_commit_types(self, config_factory):
config_factory(
"""
Expand Down

0 comments on commit ef68031

Please sign in to comment.