diff --git a/changelog_gen/config.py b/changelog_gen/config.py index f6ca744..6233764 100644 --- a/changelog_gen/config.py +++ b/changelog_gen/config.py @@ -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) diff --git a/docs/configuration.md b/docs/configuration.md index e0c7a43..7f63d9d 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -187,6 +187,20 @@ hooks = [ ] ``` +### `custom` + _**[optional]**_
+ **default**: None + + Arbitrary configuration that can be used in hooks. + + Example: + +```toml +[tool.changelog_gen.custom] +key = "value" +a_list = ["key", "key2"] +``` + ## Versioning diff --git a/docs/hooks.md b/docs/hooks.md index 08ab754..e1a4c29 100644 --- a/docs/hooks.md +++ b/docs/hooks.md @@ -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 diff --git a/tests/cli/test_config.py b/tests/cli/test_config.py index 71d23be..12861a3 100644 --- a/tests/cli/test_config.py +++ b/tests/cli/test_config.py @@ -66,6 +66,8 @@ def test_config_displayed(cli_runner): header = 'Miscellaneous' semver = 'patch' +[custom] + [files]""" ) @@ -82,4 +84,6 @@ def test_post_process_config_displayed(cli_runner, config_factory): body = '{"body": "Released on ::version::"}' auth_type = 'basic' +[custom] + [files]""") diff --git a/tests/test_config.py b/tests/test_config.py index 4c744d8..c5e095f 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -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( """