Skip to content

Commit

Permalink
refactor: change config name to cog.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
oknozor committed Sep 29, 2020
1 parent 7f04a98 commit d4aa61b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
File renamed without changes.
7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use std::process::{exit, Command, Stdio};
use tempdir::TempDir;

pub type CommitsMetadata = HashMap<CommitType, CommitConfig>;
pub const CONFIG_PATH: &str = "cog.toml";

lazy_static! {
// This cannot be carried by `Cocogitto` struct since we need it to be available in `Changelog`,
Expand Down Expand Up @@ -97,15 +98,15 @@ pub fn init<S: AsRef<Path> + ?Sized>(path: &S) -> Result<()> {
};

let settings = Settings::default();
let settings_path = path.join("coco.toml");
let settings_path = path.join(CONFIG_PATH);
if settings_path.exists() {
eprint!("Found coco.toml in {:?}, Nothing to do", &path);
eprint!("Found {} in {:?}, Nothing to do", CONFIG_PATH, &path);
exit(1);
} else {
std::fs::write(
&settings_path,
toml::to_string(&settings)
.map_err(|err| anyhow!("Failed to serialize coco.toml : {}", err))?,
.map_err(|err| anyhow!("Failed to serialize {} : {}", CONFIG_PATH, err))?,
)
.map_err(|err| anyhow!("Could not write file `{:?}` : {}", &settings_path, err))?;
}
Expand Down
4 changes: 2 additions & 2 deletions src/settings.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::commit::{CommitConfig, CommitType};
use crate::repository::Repository;
use crate::CommitsMetadata;
use crate::{CommitsMetadata, CONFIG_PATH};
use anyhow::Result;
use config::{Config, File};
use std::collections::HashMap;
Expand Down Expand Up @@ -44,7 +44,7 @@ impl Settings {
pub(crate) fn get(repository: &Repository) -> Result<Self> {
match repository.get_repo_dir() {
Some(repo_path) => {
let settings_path = repo_path.join("coco.toml");
let settings_path = repo_path.join(CONFIG_PATH);
if settings_path.exists() {
let mut s = Config::new();
s.merge(File::from(settings_path))?;
Expand Down
3 changes: 2 additions & 1 deletion tests/cog_init_test_it.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::Result;
use assert_cmd::prelude::*;
use cocogitto::CONFIG_PATH;
use helper::*;
use std::process::Command;
use temp_testdir::TempDir;
Expand Down Expand Up @@ -54,7 +55,7 @@ fn fail_if_config_exist() -> Result<()> {
std::env::set_current_dir(&temp_dir)?;
helper::git_init("test_repo_existing")?;
std::fs::write(
&temp_dir.join("test_repo_existing").join("coco.toml"),
&temp_dir.join("test_repo_existing").join(CONFIG_PATH),
"[hooks]",
)?;
helper::git_commit("chore: test commit")?;
Expand Down
3 changes: 2 additions & 1 deletion tests/helper.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::Result;
use cocogitto::CONFIG_PATH;
use rand::Rng;
use std::process::{Command, Stdio};

Expand Down Expand Up @@ -76,6 +77,6 @@ pub fn assert_tag(tag: &str) -> Result<()> {

#[allow(dead_code)]
pub fn create_empty_config() -> Result<()> {
std::fs::File::create("coco.toml")?;
std::fs::File::create(CONFIG_PATH)?;
Ok(())
}

0 comments on commit d4aa61b

Please sign in to comment.