diff --git a/git-cliff-core/src/config.rs b/git-cliff-core/src/config.rs index 8f771676e4..82e95f59a0 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("GIT_CLIFF").separator("__"), + ) .build()? .try_deserialize()?) } @@ -164,9 +166,29 @@ mod test { .to_path_buf() .join("config") .join(crate::DEFAULT_CONFIG); - env::set_var("CLIFF_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("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)?; - 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(()) } } diff --git a/website/docs/configuration.md b/website/docs/configuration.md index b702917113..09821b679a 100644 --- a/website/docs/configuration.md +++ b/website/docs/configuration.md @@ -276,3 +276,26 @@ 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 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: + +```bash +export GIT_CLIFF__CHANGELOG__FOOTER="" +``` + +To override the `ignore_tags` element: + +```bash +export GIT_CLIFF__GIT__IGNORE_TAGS="v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+" +``` \ No newline at end of file