From 7f4d21530a0d1da469290e63a0211b278799799a Mon Sep 17 00:00:00 2001 From: Mack Solomon Date: Tue, 18 Apr 2023 21:15:21 -0700 Subject: [PATCH 1/7] chore: update env variable override format --- git-cliff-core/src/config.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/git-cliff-core/src/config.rs b/git-cliff-core/src/config.rs index 8f771676e4..0b1da5ae22 100644 --- a/git-cliff-core/src/config.rs +++ b/git-cliff-core/src/config.rs @@ -144,7 +144,9 @@ impl Config { config::Config::builder().add_source(config::File::from(path)) }; Ok(config_builder - .add_source(config::Environment::with_prefix("CLIFF").separator("_")) + .add_source( + config::Environment::with_prefix("CLIFF_GIT").separator("__"), + ) .build()? .try_deserialize()?) } @@ -164,7 +166,7 @@ mod test { .to_path_buf() .join("config") .join(crate::DEFAULT_CONFIG); - env::set_var("CLIFF_CHANGELOG_FOOTER", "test"); + env::set_var("CLIFF_GIT__CHANGELOG__FOOTER", "test"); let config = Config::parse(&path)?; assert_eq!(Some(String::from("test")), config.changelog.footer); Ok(()) From cd613a0c392d973d5c7afb21234b75b5201eb47a Mon Sep 17 00:00:00 2001 From: Mack Solomon Date: Wed, 19 Apr 2023 19:23:22 -0700 Subject: [PATCH 2/7] tests: add a copule env override assertions --- git-cliff-core/src/config.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/git-cliff-core/src/config.rs b/git-cliff-core/src/config.rs index 0b1da5ae22..15abb5281e 100644 --- a/git-cliff-core/src/config.rs +++ b/git-cliff-core/src/config.rs @@ -166,9 +166,29 @@ mod test { .to_path_buf() .join("config") .join(crate::DEFAULT_CONFIG); - env::set_var("CLIFF_GIT__CHANGELOG__FOOTER", "test"); + + const FOOTER_VALUE: &str = "test"; + const TAG_PATTERN_VALUE: &str = "*[0-9]*"; + const IGNORE_TAGS_VALUE: &str = "v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+"; + + env::set_var("CLIFF_GIT__CHANGELOG__FOOTER", FOOTER_VALUE); + env::set_var("CLIFF_GIT__GIT__TAG_PATTERN", TAG_PATTERN_VALUE); + env::set_var("CLIFF_GIT__GIT__IGNORE_TAGS", IGNORE_TAGS_VALUE); + let config = Config::parse(&path)?; - assert_eq!(Some(String::from("test")), config.changelog.footer); + + assert_eq!(Some(String::from(FOOTER_VALUE)), config.changelog.footer); + assert_eq!( + Some(String::from(TAG_PATTERN_VALUE)), + config.git.tag_pattern + ); + assert_eq!( + Some(String::from(IGNORE_TAGS_VALUE)), + config + .git + .ignore_tags + .map(|ignore_tags| ignore_tags.to_string()) + ); Ok(()) } } From 2b7269c869b5ef69076f6e7c466ca03fa256738f Mon Sep 17 00:00:00 2001 From: Mack Solomon Date: Thu, 20 Apr 2023 23:19:11 -0700 Subject: [PATCH 3/7] docs: add a doc for env overrides --- website/docs/configuration.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/website/docs/configuration.md b/website/docs/configuration.md index b702917113..9fbc389145 100644 --- a/website/docs/configuration.md +++ b/website/docs/configuration.md @@ -276,3 +276,27 @@ Examples: `limit_commits` is a **optional** positive integer number that limits the number of included commits in the generated changelog. `limit_commits` is not part of the default configuration. + +### Environment Configuration Overrides + +It's possible to override configuration elements environment variables. If an environment variable matches a configuration element the variable's value will be used instead of the value from the config file. + +Examples: + +To override the `footer` element: + +```bash +export CLIFF_GIT__CHANGELOG__FOOTER="" +``` + +To override the `ignore_tags` element: + +```bash +export CLIFF_GIT__GIT__IGNORE_TAGS="v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+" +``` + +If it's not clear from the examples the format of the variable name is: + +``` +[PREFIX]__[CONFIG SECTION]__[FIELD NAME] +``` From 248b10273a2465a7ed71385c8bc8adfc56bc0906 Mon Sep 17 00:00:00 2001 From: Mack Solomon Date: Fri, 21 Apr 2023 08:07:40 -0700 Subject: [PATCH 4/7] docs: wording --- website/docs/configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/configuration.md b/website/docs/configuration.md index 9fbc389145..1f0b3d85eb 100644 --- a/website/docs/configuration.md +++ b/website/docs/configuration.md @@ -279,7 +279,7 @@ Examples: ### Environment Configuration Overrides -It's possible to override configuration elements environment variables. If an environment variable matches a configuration element the variable's value will be used instead of the value from the config file. +It's possible to use environment variable to override configuration elements. If an environment variable matches a configuration element the variable's value will be used instead of the element's. Examples: From 706025d8b3ea61f6ae3bb3f6ba9928f0b572e99f Mon Sep 17 00:00:00 2001 From: Mack Solomon Date: Fri, 21 Apr 2023 12:06:13 -0700 Subject: [PATCH 5/7] docs: wording --- website/docs/configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/configuration.md b/website/docs/configuration.md index 1f0b3d85eb..b261c746ba 100644 --- a/website/docs/configuration.md +++ b/website/docs/configuration.md @@ -279,7 +279,7 @@ Examples: ### Environment Configuration Overrides -It's possible to use environment variable to override configuration elements. If an environment variable matches a configuration element the variable's value will be used instead of the element's. +It's possible to use environment variables to override configuration elements. If an environment variable matches a configuration element the variable's value will be used instead of the element's. Examples: From 17423e183e4cc6740e082337a1a98612cd7745bc Mon Sep 17 00:00:00 2001 From: Mack Solomon Date: Sat, 22 Apr 2023 10:02:04 -0700 Subject: [PATCH 6/7] fix: prefix --- git-cliff-core/src/config.rs | 8 ++++---- website/docs/configuration.md | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/git-cliff-core/src/config.rs b/git-cliff-core/src/config.rs index 15abb5281e..82e95f59a0 100644 --- a/git-cliff-core/src/config.rs +++ b/git-cliff-core/src/config.rs @@ -145,7 +145,7 @@ impl Config { }; Ok(config_builder .add_source( - config::Environment::with_prefix("CLIFF_GIT").separator("__"), + config::Environment::with_prefix("GIT_CLIFF").separator("__"), ) .build()? .try_deserialize()?) @@ -171,9 +171,9 @@ mod test { const TAG_PATTERN_VALUE: &str = "*[0-9]*"; const IGNORE_TAGS_VALUE: &str = "v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+"; - env::set_var("CLIFF_GIT__CHANGELOG__FOOTER", FOOTER_VALUE); - env::set_var("CLIFF_GIT__GIT__TAG_PATTERN", TAG_PATTERN_VALUE); - env::set_var("CLIFF_GIT__GIT__IGNORE_TAGS", IGNORE_TAGS_VALUE); + env::set_var("GIT_CLIFF__CHANGELOG__FOOTER", FOOTER_VALUE); + env::set_var("GIT_CLIFF__GIT__TAG_PATTERN", TAG_PATTERN_VALUE); + env::set_var("GIT_CLIFF__GIT__IGNORE_TAGS", IGNORE_TAGS_VALUE); let config = Config::parse(&path)?; diff --git a/website/docs/configuration.md b/website/docs/configuration.md index b261c746ba..22b36e06dc 100644 --- a/website/docs/configuration.md +++ b/website/docs/configuration.md @@ -286,13 +286,13 @@ Examples: To override the `footer` element: ```bash -export CLIFF_GIT__CHANGELOG__FOOTER="" +export GIT_CLIFF__CHANGELOG__FOOTER="" ``` To override the `ignore_tags` element: ```bash -export CLIFF_GIT__GIT__IGNORE_TAGS="v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+" +export GIT_CLIFF__GIT__IGNORE_TAGS="v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+" ``` If it's not clear from the examples the format of the variable name is: From 070dbc1b221c516da710ffb4f16f2e61dfcc0d08 Mon Sep 17 00:00:00 2001 From: Mack Solomon Date: Sat, 22 Apr 2023 10:06:25 -0700 Subject: [PATCH 7/7] docs: format first --- website/docs/configuration.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/website/docs/configuration.md b/website/docs/configuration.md index 22b36e06dc..09821b679a 100644 --- a/website/docs/configuration.md +++ b/website/docs/configuration.md @@ -281,6 +281,11 @@ Examples: It's possible to use environment variables to override configuration elements. If an environment variable matches a configuration element the variable's value will be used instead of the element's. +Format: +``` +[PREFIX]__[CONFIG SECTION]__[FIELD NAME] +``` + Examples: To override the `footer` element: @@ -293,10 +298,4 @@ To override the `ignore_tags` element: ```bash export GIT_CLIFF__GIT__IGNORE_TAGS="v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+" -``` - -If it's not clear from the examples the format of the variable name is: - -``` -[PREFIX]__[CONFIG SECTION]__[FIELD NAME] -``` +``` \ No newline at end of file