From dae89e59efbd92e3569cf29a3cf863a5bcb6adda Mon Sep 17 00:00:00 2001 From: Miguel Ramos Date: Fri, 19 Jul 2024 16:34:40 +0100 Subject: [PATCH] chore: make changes type available --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/changes.rs | 35 +++++++++++++++++++++-------------- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e5c6e557..ecb66e48 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2576,7 +2576,7 @@ dependencies = [ [[package]] name = "workspace-node-tools" -version = "1.0.7" +version = "1.0.8" dependencies = [ "chrono", "execute", diff --git a/Cargo.toml b/Cargo.toml index c7d58ff6..b5b7d17d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "workspace-node-tools" -version = "1.0.7" +version = "1.0.8" edition = "2021" description = "Node workspace version tools" repository = "https://github.com/websublime/workspace-node-tools" diff --git a/src/changes.rs b/src/changes.rs index 4cf80c00..7ca2e29f 100644 --- a/src/changes.rs +++ b/src/changes.rs @@ -25,6 +25,8 @@ use std::{ path::{Path, PathBuf}, }; +use crate::bumps::Bump; + use super::git::git_current_branch; use super::paths::get_project_root_path; @@ -75,7 +77,7 @@ pub struct Changes { #[derive(Debug, Clone, Deserialize, Serialize, PartialEq)] pub struct Change { pub package: String, - pub release_as: String, + pub release_as: Bump, pub deploy: Vec, } @@ -84,7 +86,7 @@ pub struct Change { #[derive(Debug, Clone, Deserialize, Serialize, PartialEq)] pub struct Change { pub package: String, - pub release_as: String, + pub release_as: Bump, pub deploy: Vec, } @@ -155,7 +157,7 @@ pub fn add_change(change: &Change, cwd: Option) -> bool { let branch_changes = changes.changes.get_mut(&branch).unwrap(); branch_changes.push(Change { package: change.package.to_string(), - release_as: change.release_as.to_string(), + release_as: change.release_as, deploy: change.deploy.to_vec(), }); } else { @@ -163,7 +165,7 @@ pub fn add_change(change: &Change, cwd: Option) -> bool { branch, vec![Change { package: change.package.to_string(), - release_as: change.release_as.to_string(), + release_as: change.release_as, deploy: change.deploy.to_vec(), }], ); @@ -210,7 +212,7 @@ pub fn remove_change(branch_name: String, cwd: Option) -> bool { false } -pub fn get_changes(cwd: Option) -> ChangesData { +pub fn get_changes(cwd: Option) -> Changes { let ref root = match cwd { Some(ref dir) => get_project_root_path(Some(PathBuf::from(dir))).unwrap(), None => get_project_root_path(None).unwrap(), @@ -224,10 +226,15 @@ pub fn get_changes(cwd: Option) -> ChangesData { let changes_reader = BufReader::new(changes_file); let changes: ChangesFileData = serde_json::from_reader(changes_reader).unwrap(); - return changes.changes; + + return Changes { + changes: changes.changes, + }; } - ChangesData::new() + Changes { + changes: ChangesData::new(), + } } pub fn get_change(branch: String, cwd: Option) -> Vec { @@ -310,7 +317,7 @@ mod tests { let change = Change { package: String::from("test-package"), - release_as: String::from("1.0.0"), + release_as: Bump::Major, deploy: vec![String::from("production")], }; @@ -334,7 +341,7 @@ mod tests { let change = Change { package: String::from("test-package"), - release_as: String::from("1.0.0"), + release_as: Bump::Major, deploy: vec![String::from("production")], }; @@ -360,7 +367,7 @@ mod tests { let change = Change { package: String::from("test-package"), - release_as: String::from("1.0.0"), + release_as: Bump::Major, deploy: vec![String::from("production")], }; @@ -371,8 +378,8 @@ mod tests { let changes = get_changes(Some(root.to_string())); - assert_eq!(changes.contains_key(&String::from("main")), true); - assert_eq!(changes.get(&String::from("main")).unwrap().len(), 1); + assert_eq!(changes.changes.contains_key(&String::from("main")), true); + assert_eq!(changes.changes.get(&String::from("main")).unwrap().len(), 1); assert_eq!(changes_path.is_file(), true); remove_dir_all(&monorepo_dir)?; Ok(()) @@ -387,7 +394,7 @@ mod tests { let change = Change { package: String::from("test-package"), - release_as: String::from("1.0.0"), + release_as: Bump::Major, deploy: vec![String::from("production")], }; @@ -413,7 +420,7 @@ mod tests { let change = Change { package: String::from("test-package"), - release_as: String::from("1.0.0"), + release_as: Bump::Major, deploy: vec![String::from("production")], };