summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2023-04-29 10:55:38 +0000
committerGitHub <noreply@github.com>2023-04-29 10:55:38 +0000
commit438d3c55349e85bde042734f9e3f874bf5680951 (patch)
treef93a25cd10a8a64a099bcaba5616b0929567b7af
parent71253a2de7b4554ed1186d36a7b3194f1702b462 (diff)
parent33a5c1ec986a6af2d7b2e9b7a1bd1e6a46e7a28c (diff)
Merge #225
225: Feature/add multiple config r=matthiasbeyer a=TheNeikos Solves #223 Co-authored-by: Marcel Müller <neikos@neikos.email>
-rw-r--r--.changelogs/unreleased/2023-04-29T10_41_03_511451575.md8
-rw-r--r--changelog.toml (renamed from .changelog.toml)0
-rw-r--r--src/config.rs27
-rw-r--r--src/error.rs7
-rw-r--r--src/main.rs2
-rw-r--r--tests/init_command.rs2
-rw-r--r--tests/new_command.rs2
-rw-r--r--tests/new_command_creates_default_header.rs2
8 files changed, 35 insertions, 15 deletions
diff --git a/.changelogs/unreleased/2023-04-29T10_41_03_511451575.md b/.changelogs/unreleased/2023-04-29T10_41_03_511451575.md
new file mode 100644
index 0000000..b1ad900
--- /dev/null
+++ b/.changelogs/unreleased/2023-04-29T10_41_03_511451575.md
@@ -0,0 +1,8 @@
++++
+subject = "Multiple configuration files are now checked"
+type = "Feature"
++++
+
+So far only `.changelog.toml` was supported as configuration file. Now one can
+choose between `changelog.toml` or `.changelog.toml`. The non-hidden version,
+without the dot, is now the default on `init`.
diff --git a/.changelog.toml b/changelog.toml
index 1c68941..1c68941 100644
--- a/.changelog.toml
+++ b/changelog.toml
diff --git a/src/config.rs b/src/config.rs
index cae5d7b..f917e15 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -7,7 +7,8 @@ use miette::IntoDiagnostic;
use crate::error::Error;
use crate::fragment::FragmentDataDesc;
-pub const CONFIG_FILE_NAME: &str = ".changelog.toml";
+pub const CONFIG_FILE_NAMES: &[&str] = &[".changelog.toml", "changelog.toml"];
+pub const CONFIG_FILE_DEFAULT_NAME: &str = CONFIG_FILE_NAMES[1];
pub const DEFAULT_CONFIG: &str = include_str!("../assets/default_config.toml");
#[derive(Debug, getset::Getters, getset::CopyGetters, serde::Deserialize, serde::Serialize)]
@@ -108,16 +109,24 @@ impl std::str::FromStr for EditFormat {
/// Load the configuration from the repository
pub fn load(repo_workdir_path: &Path) -> miette::Result<Configuration> {
- let changelog_config_path = {
- let mut cfg_path = repo_workdir_path.to_path_buf();
- cfg_path.push(CONFIG_FILE_NAME);
- cfg_path
- };
-
- if !changelog_config_path.exists() {
- miette::bail!(Error::ConfigDoesNotExist(changelog_config_path))
+ let mut changelog_config_path = None;
+ for config_path in CONFIG_FILE_NAMES {
+ let check_path = {
+ let mut cfg_path = repo_workdir_path.to_path_buf();
+ cfg_path.push(config_path);
+ cfg_path
+ };
+
+ if check_path.exists() {
+ changelog_config_path = Some(check_path);
+ break;
+ }
}
+ let Some(changelog_config_path) = changelog_config_path else {
+ miette::bail!(Error::ConfigDoesNotExist)
+ };
+
let config = std::fs::read_to_string(changelog_config_path)
.map_err(Error::from)
.into_diagnostic()?;
diff --git a/src/error.rs b/src/error.rs
index 5d869bc..9330d40 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -35,8 +35,11 @@ pub enum Error {
#[error("Repository has no worktree")]
NoWorkTree,
- #[error("Configuration file does not exist: {0}")]
- ConfigDoesNotExist(PathBuf),
+ #[error(
+ "Configuration file does not exist, tried {:?}",
+ crate::config::CONFIG_FILE_NAMES
+ )]
+ ConfigDoesNotExist,
#[error("Not a file: {0}")]
NotAFile(PathBuf),
diff --git a/src/main.rs b/src/main.rs
index 0802a24..d57e5f6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -118,7 +118,7 @@ fn init(repo_workdir_path: PathBuf) -> miette::Result<()> {
.create(true)
.append(false)
.write(true)
- .open(repo_workdir_path.join(crate::config::CONFIG_FILE_NAME))
+ .open(repo_workdir_path.join(crate::config::CONFIG_FILE_DEFAULT_NAME))
.map_err(Error::from)
.into_diagnostic()?;
diff --git a/tests/init_command.rs b/tests/init_command.rs
index c827321..843caaf 100644
--- a/tests/init_command.rs
+++ b/tests/init_command.rs
@@ -9,7 +9,7 @@ fn init_command_creates_config_file() {
self::common::init_git(temp_dir.path());
self::common::init_cargo_changelog(temp_dir.path());
- let config_file_path = temp_dir.path().join(".changelog.toml");
+ let config_file_path = temp_dir.path().join("changelog.toml");
if !config_file_path.exists() {
panic!("Config file does not exist after `cargo-changelog init`");
}
diff --git a/tests/new_command.rs b/tests/new_command.rs
index 702e9de..fb32a43 100644
--- a/tests/new_command.rs
+++ b/tests/new_command.rs
@@ -292,7 +292,7 @@ fn new_command_cannot_create_nonexistent_oneof() {
{
// Write some header field to the config file
- let config_file_path = temp_dir.path().join(".changelog.toml");
+ let config_file_path = temp_dir.path().join("changelog.toml");
let mut file = std::fs::OpenOptions::new()
.append(true)
.write(true)
diff --git a/tests/new_command_creates_default_header.rs b/tests/new_command_creates_default_header.rs
index c14bcb0..577df7c 100644
--- a/tests/new_command_creates_default_header.rs
+++ b/tests/new_command_creates_default_header.rs
@@ -13,7 +13,7 @@ fn new_command_creates_default_header() {
{
// Write some header field to the config file
- let config_file_path = temp_dir.path().join(".changelog.toml");
+ let config_file_path = temp_dir.path().join("changelog.toml");
let mut file = std::fs::OpenOptions::new()
.append(true)
.write(true)